iPXE
Data Structures | Macros | Functions | Variables
slk.c File Reference

Soft label key functions. More...

#include <curses.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "mucurses.h"
#include "cursor.h"

Go to the source code of this file.

Data Structures

struct  _softlabel
 
struct  _softlabelkeys
 

Macros

#define MIN_SPACE_SIZE   2
 
#define SLK_MAX_LABEL_LEN   8
 
#define SLK_MAX_NUM_LABELS   12
 
#define SLK_MAX_NUM_SPACES   2
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static void _enter_slk (void)
 
static void _leave_slk (void)
 
static void _print_label (struct _softlabel sl)
 
attr_t slk_attr (void)
 Return the attribute used for the soft function keys. More...
 
int slk_attroff (const chtype attrs)
 Turn off soft function key attributes. More...
 
int slk_attron (const chtype attrs)
 Turn on soft function key attributes. More...
 
int slk_attrset (const chtype attrs)
 Set soft function key attributes. More...
 
int slk_attr_off (const attr_t attrs, void *opts __unused)
 Turn off soft function key attributes. More...
 
int slk_attr_on (attr_t attrs, void *opts __unused)
 Turn on soft function key attributes. More...
 
int slk_attr_set (const attr_t attrs, short colour_pair_number, void *opts __unused)
 Set soft function key attributes. More...
 
int slk_clear (void)
 Clear the soft function key labels from the screen. More...
 
int slk_colour (short colour_pair_number)
 Set soft label colour pair. More...
 
int slk_init (int fmt)
 Initialise the soft function keys. More...
 
char * slk_label (int labnum)
 Return the label for the specified soft key. More...
 
int slk_restore (void)
 Restore soft function key labels to the screen. More...
 
int slk_set (int labnum, const char *label, int fmt)
 Configure specified soft key. More...
 

Variables

static struct _softlabelkeysslks
 

Detailed Description

Soft label key functions.

Definition in file slk.c.

Macro Definition Documentation

◆ MIN_SPACE_SIZE

#define MIN_SPACE_SIZE   2

Definition at line 16 of file slk.c.

◆ SLK_MAX_LABEL_LEN

#define SLK_MAX_LABEL_LEN   8

Definition at line 18 of file slk.c.

◆ SLK_MAX_NUM_LABELS

#define SLK_MAX_NUM_LABELS   12

Definition at line 20 of file slk.c.

◆ SLK_MAX_NUM_SPACES

#define SLK_MAX_NUM_SPACES   2

Definition at line 22 of file slk.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ _enter_slk()

static void _enter_slk ( void  )
static

Definition at line 64 of file slk.c.

64  {
67  LINES++;
68  wmove ( stdscr, LINES, 0 );
69  wattrset ( stdscr, slks->attrs );
70 }
attr_t saved_attrs
Definition: slk.c:51
int wmove(WINDOW *win, int y, int x) __nonnull
Move a window's cursor to the specified position.
Definition: mucurses.c:135
int wattrset(WINDOW *win, int attrs)
Set attributes in a window.
Definition: winattrs.c:52
short saved_pair
Definition: slk.c:52
attr_t attrs
Definition: slk.c:37
int wattr_get(WINDOW *win, attr_t *attrs, short *pair, void *opts __unused)
Get attributes and colour pair information.
Definition: winattrs.c:66
#define LINES(...)
Define inline lines.
Definition: linebuf_test.c:44
static struct _softlabelkeys * slks
Definition: slk.c:55
#define stdscr
Definition: curses.h:110
struct cursor_pos saved_cursor
Definition: slk.c:50
static void _store_curs_pos(WINDOW *win, struct cursor_pos *pos)
Store cursor position for later restoration.
Definition: cursor.h:32
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References _store_curs_pos(), _softlabelkeys::attrs, LINES, NULL, _softlabelkeys::saved_attrs, _softlabelkeys::saved_cursor, _softlabelkeys::saved_pair, slks, stdscr, wattr_get(), wattrset(), and wmove().

Referenced by slk_clear(), and slk_restore().

◆ _leave_slk()

static void _leave_slk ( void  )
static

Definition at line 72 of file slk.c.

72  {
73  LINES--;
76 }
attr_t saved_attrs
Definition: slk.c:51
short saved_pair
Definition: slk.c:52
#define LINES(...)
Define inline lines.
Definition: linebuf_test.c:44
static struct _softlabelkeys * slks
Definition: slk.c:55
#define stdscr
Definition: curses.h:110
struct cursor_pos saved_cursor
Definition: slk.c:50
static void _restore_curs_pos(WINDOW *win, struct cursor_pos *pos)
Restore cursor position from encoded backup variable.
Definition: cursor.h:22
int wattr_set(WINDOW *win, attr_t attrs, short cpair, void *opts __unused)
Set attributes and colour pair information in a window.
Definition: winattrs.c:110
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References _restore_curs_pos(), LINES, NULL, _softlabelkeys::saved_attrs, _softlabelkeys::saved_cursor, _softlabelkeys::saved_pair, slks, stdscr, and wattr_set().

Referenced by slk_clear(), and slk_restore().

◆ _print_label()

static void _print_label ( struct _softlabel  sl)
static

Definition at line 78 of file slk.c.

78  {
79  int space_ch;
80  char str[SLK_MAX_LABEL_LEN + 1];
81 
83  space_ch = ' ';
84  memset ( str, 0, sizeof ( str ) );
85 
86  // protect against gaps in the soft label keys array
87  if ( ! sl.label[0] ) {
88  memset( str, space_ch, (size_t)(slks->max_label_len) );
89  } else {
90  /* we need to pad the label with varying amounts of leading
91  pad depending on the format of the label */
92  if ( sl.fmt == 1 ) {
93  memset( str, space_ch,
94  (size_t)(slks->max_label_len
95  - strlen(sl.label)) / 2 );
96  }
97  if ( sl.fmt == 2 ) {
98  memset( str, space_ch,
99  (size_t)(slks->max_label_len
100  - strlen(sl.label)) );
101  }
102  strcat(str,sl.label);
103 
104  // post-padding
105  memset(str+strlen(str), space_ch,
106  (size_t)(slks->max_label_len - strlen(str)) );
107  }
108 
109  // print the formatted label
111 }
void _wputstr(WINDOW *win, const char *str, int wrap, int n) __nonnull
Write a standard c-style string to a window.
Definition: mucurses.c:121
unsigned int max_label_len
Definition: slk.c:45
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static struct _softlabelkeys * slks
Definition: slk.c:55
#define stdscr
Definition: curses.h:110
#define NOWRAP
Definition: mucurses.h:13
u8 sl
Definition: CIB_PRM.h:42
size_t strlen(const char *src)
Get length of string.
Definition: string.c:243
char * strcat(char *dest, const char *src)
Concatenate string.
Definition: string.c:381
#define SLK_MAX_LABEL_LEN
Definition: slk.c:18
void * memset(void *dest, int character, size_t len) __nonnull

References _wputstr(), assert(), _softlabelkeys::max_label_len, memset(), NOWRAP, sl, SLK_MAX_LABEL_LEN, slks, stdscr, strcat(), and strlen().

Referenced by slk_restore().

◆ slk_attr()

attr_t slk_attr ( void  )

Return the attribute used for the soft function keys.

Return values
attrsthe current attributes of the soft function keys

Definition at line 118 of file slk.c.

118  {
119  return ( slks == NULL ? 0 : slks->attrs );
120 }
attr_t attrs
Definition: slk.c:37
static struct _softlabelkeys * slks
Definition: slk.c:55
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References _softlabelkeys::attrs, NULL, and slks.

◆ slk_attroff()

int slk_attroff ( const chtype  attrs)

Turn off soft function key attributes.

Parameters
attrsattribute bit mask
Return values
rcreturn status code

Definition at line 128 of file slk.c.

128  {
129  if ( slks == NULL )
130  return ERR;
131  slks->attrs &= ~( attrs & A_ATTRIBUTES );
132  return OK;
133 }
#define A_ATTRIBUTES
Definition: curses.h:146
attr_t attrs
Definition: slk.c:37
Definition: sis900.h:208
#define ERR
Definition: curses.h:18
uint32_t attrs
Extended attributes (optional)
Definition: memmap.c:32
static struct _softlabelkeys * slks
Definition: slk.c:55
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References A_ATTRIBUTES, attrs, _softlabelkeys::attrs, ERR, NULL, OK, and slks.

Referenced by slk_attr_off().

◆ slk_attron()

int slk_attron ( const chtype  attrs)

Turn on soft function key attributes.

Parameters
attrsattribute bit mask
Return values
rcreturn status code

Definition at line 141 of file slk.c.

141  {
142  if ( slks == NULL )
143  return ERR;
144  slks->attrs |= ( attrs & A_ATTRIBUTES );
145  return OK;
146 }
#define A_ATTRIBUTES
Definition: curses.h:146
attr_t attrs
Definition: slk.c:37
Definition: sis900.h:208
#define ERR
Definition: curses.h:18
uint32_t attrs
Extended attributes (optional)
Definition: memmap.c:32
static struct _softlabelkeys * slks
Definition: slk.c:55
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References A_ATTRIBUTES, attrs, _softlabelkeys::attrs, ERR, NULL, OK, and slks.

Referenced by slk_attr_on().

◆ slk_attrset()

int slk_attrset ( const chtype  attrs)

Set soft function key attributes.

Parameters
attrsattribute bit mask
Return values
rcreturn status code

Definition at line 154 of file slk.c.

154  {
155  if ( slks == NULL )
156  return ERR;
157  slks->attrs = ( attrs & A_ATTRIBUTES );
158  return OK;
159 }
#define A_ATTRIBUTES
Definition: curses.h:146
attr_t attrs
Definition: slk.c:37
Definition: sis900.h:208
#define ERR
Definition: curses.h:18
uint32_t attrs
Extended attributes (optional)
Definition: memmap.c:32
static struct _softlabelkeys * slks
Definition: slk.c:55
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References A_ATTRIBUTES, attrs, _softlabelkeys::attrs, ERR, NULL, OK, and slks.

◆ slk_attr_off()

int slk_attr_off ( const attr_t  attrs,
void *opts  __unused 
)

Turn off soft function key attributes.

Parameters
attrsattribute bit mask
*optsundefined (for future implementation)
Return values
rcreturn status code

Definition at line 168 of file slk.c.

168  {
169  return slk_attroff( attrs );
170 }
int slk_attroff(const chtype attrs)
Turn off soft function key attributes.
Definition: slk.c:128
uint32_t attrs
Extended attributes (optional)
Definition: memmap.c:32

References attrs, and slk_attroff().

◆ slk_attr_on()

int slk_attr_on ( attr_t  attrs,
void *opts  __unused 
)

Turn on soft function key attributes.

Parameters
attrsattribute bit mask
*optsundefined (for future implementation)
Return values
rcreturn status code

Definition at line 179 of file slk.c.

179  {
180  return slk_attron( attrs );
181 }
uint32_t attrs
Extended attributes (optional)
Definition: memmap.c:32
int slk_attron(const chtype attrs)
Turn on soft function key attributes.
Definition: slk.c:141

References attrs, and slk_attron().

◆ slk_attr_set()

int slk_attr_set ( const attr_t  attrs,
short  colour_pair_number,
void *opts  __unused 
)

Set soft function key attributes.

Parameters
attrsattribute bit mask
colour_pair_numbercolour pair integer
*optsundefined (for future implementation)
Return values
rcreturn status code

Definition at line 191 of file slk.c.

192  {
193  if ( slks == NULL )
194  return ERR;
195 
196  if ( ( unsigned short )colour_pair_number > COLORS )
197  return ERR;
198 
199  slks->attrs = ( (unsigned short)colour_pair_number << CPAIR_SHIFT ) |
200  ( attrs & A_ATTRIBUTES );
201  return OK;
202 }
#define A_ATTRIBUTES
Definition: curses.h:146
attr_t attrs
Definition: slk.c:37
#define COLORS
Definition: curses.h:207
Definition: sis900.h:208
#define ERR
Definition: curses.h:18
uint32_t attrs
Extended attributes (optional)
Definition: memmap.c:32
static struct _softlabelkeys * slks
Definition: slk.c:55
#define CPAIR_SHIFT
Definition: curses.h:115
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References A_ATTRIBUTES, attrs, _softlabelkeys::attrs, COLORS, CPAIR_SHIFT, ERR, NULL, OK, and slks.

◆ slk_clear()

int slk_clear ( void  )

Clear the soft function key labels from the screen.

Return values
rcreturn status code

Definition at line 209 of file slk.c.

209  {
210  if ( slks == NULL )
211  return ERR;
212 
213  _enter_slk();
214  wclrtoeol ( stdscr );
215  _leave_slk();
216 
217  return OK;
218 }
static void _leave_slk(void)
Definition: slk.c:72
Definition: sis900.h:208
#define ERR
Definition: curses.h:18
static struct _softlabelkeys * slks
Definition: slk.c:55
#define stdscr
Definition: curses.h:110
static void _enter_slk(void)
Definition: slk.c:64
int wclrtoeol(WINDOW *win)
Clear a window to the end of the current line.
Definition: clear.c:37
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References _enter_slk(), _leave_slk(), ERR, NULL, OK, slks, stdscr, and wclrtoeol().

Referenced by slk_refresh().

◆ slk_colour()

int slk_colour ( short  colour_pair_number)

Set soft label colour pair.

Definition at line 223 of file slk.c.

223  {
224  if ( slks == NULL )
225  return ERR;
226  if ( ( unsigned short )colour_pair_number > COLORS )
227  return ERR;
228 
229  slks->attrs = ( (unsigned short)colour_pair_number << CPAIR_SHIFT )
230  | ( slks->attrs & A_ATTRIBUTES );
231 
232  return OK;
233 }
#define A_ATTRIBUTES
Definition: curses.h:146
attr_t attrs
Definition: slk.c:37
#define COLORS
Definition: curses.h:207
Definition: sis900.h:208
#define ERR
Definition: curses.h:18
static struct _softlabelkeys * slks
Definition: slk.c:55
#define CPAIR_SHIFT
Definition: curses.h:115
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References A_ATTRIBUTES, _softlabelkeys::attrs, COLORS, CPAIR_SHIFT, ERR, NULL, OK, and slks.

◆ slk_init()

int slk_init ( int  fmt)

Initialise the soft function keys.

Parameters
fmtformat of keys
Return values
rcreturn status code

Definition at line 241 of file slk.c.

241  {
242  unsigned short nmaj, nmin, nblocks, available_width;
243 
244  if ( (unsigned)fmt > 3 ) {
245  return ERR;
246  }
247 
248  /* There seems to be no API call to free this data structure... */
249  if ( ! slks )
250  slks = calloc(1,sizeof(*slks));
251  if ( ! slks )
252  return ERR;
253 
254  slks->attrs = A_DEFAULT;
255  slks->fmt = fmt;
256  switch(fmt) {
257  case 0:
258  nblocks = 8; nmaj = 2; nmin = 5;
259  slks->spaces[0] = 2; slks->spaces[1] = 4;
260  break;
261  case 1:
262  nblocks = 8; nmaj = 1; nmin = 6;
263  slks->spaces[0] = 3;
264  break;
265  case 2:
266  // same allocations as format 3
267  case 3:
268  nblocks = 12; nmaj = 2; nmin = 9;
269  slks->spaces[0] = 3; slks->spaces[1] = 7;
270  break;
271  default:
272  return ERR;
273  }
274 
275  // determine maximum label length and major space size
276  available_width = COLS - ( ( MIN_SPACE_SIZE * nmaj ) + nmin );
277  slks->max_label_len = available_width / nblocks;
279  ( available_width % nblocks ) / nmaj;
280  slks->num_spaces = nmaj;
281  slks->num_labels = nblocks;
282 
283  // strip a line from the screen
284  LINES -= 1;
285 
286  return OK;
287 }
unsigned int maj_space_len
Definition: slk.c:46
unsigned int num_labels
Definition: slk.c:47
attr_t attrs
Definition: slk.c:37
#define A_DEFAULT
Definition: curses.h:135
#define LINES(...)
Define inline lines.
Definition: linebuf_test.c:44
Definition: sis900.h:208
unsigned int num_spaces
Definition: slk.c:48
unsigned int max_label_len
Definition: slk.c:45
#define ERR
Definition: curses.h:18
static void *__malloc calloc(size_t nmemb, size_t size)
Allocate cleared memory.
Definition: stdlib.h:45
#define COLS
Definition: vga.h:27
static struct _softlabelkeys * slks
Definition: slk.c:55
unsigned int spaces[SLK_MAX_NUM_SPACES]
Definition: slk.c:49
#define MIN_SPACE_SIZE
Definition: slk.c:16
int ssize_t const char * fmt
Definition: vsprintf.h:72
unsigned int fmt
Definition: slk.c:44

References A_DEFAULT, _softlabelkeys::attrs, calloc(), COLS, ERR, _softlabelkeys::fmt, fmt, LINES, _softlabelkeys::maj_space_len, _softlabelkeys::max_label_len, MIN_SPACE_SIZE, _softlabelkeys::num_labels, _softlabelkeys::num_spaces, OK, slks, and _softlabelkeys::spaces.

◆ slk_label()

char* slk_label ( int  labnum)

Return the label for the specified soft key.

Parameters
labnumsoft key identifier
Return values
labelreturn label

Definition at line 295 of file slk.c.

295  {
296  if ( slks == NULL )
297  return NULL;
298 
299  return slks->fkeys[labnum].label;
300 }
struct _softlabel fkeys[SLK_MAX_NUM_LABELS]
Definition: slk.c:36
char label[SLK_MAX_LABEL_LEN]
Definition: slk.c:26
static struct _softlabelkeys * slks
Definition: slk.c:55
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References _softlabelkeys::fkeys, _softlabel::label, NULL, and slks.

◆ slk_restore()

int slk_restore ( void  )

Restore soft function key labels to the screen.

Return values
rcreturn status code

Definition at line 307 of file slk.c.

307  {
308  unsigned int i, j, pos_x,
309  *next_space, *last_space;
310  chtype space_ch;
311 
312  if ( slks == NULL )
313  return ERR;
314 
315  pos_x = 0;
316 
317  _enter_slk();
318 
319  space_ch = (chtype)' ' | slks->attrs;
320  next_space = &(slks->spaces[0]);
321  last_space = &(slks->spaces[slks->num_spaces-1]);
322 
323  for ( i = 0; i < slks->num_labels ; i++ ) {
324  _print_label( slks->fkeys[i] );
325  pos_x += slks->max_label_len;
326 
327  if ( i == *next_space ) {
328  for ( j = 0; j < slks->maj_space_len; j++, pos_x++ )
329  _wputch ( stdscr, space_ch, NOWRAP );
330  if ( next_space < last_space )
331  next_space++;
332  } else {
333  if ( pos_x < COLS )
334  _wputch ( stdscr, space_ch, NOWRAP );
335  pos_x++;
336  }
337  }
338 
339  _leave_slk();
340 
341  return OK;
342 }
unsigned int maj_space_len
Definition: slk.c:46
unsigned int num_labels
Definition: slk.c:47
struct _softlabel fkeys[SLK_MAX_NUM_LABELS]
Definition: slk.c:36
static void _leave_slk(void)
Definition: slk.c:72
attr_t attrs
Definition: slk.c:37
Definition: sis900.h:208
unsigned int num_spaces
Definition: slk.c:48
unsigned int max_label_len
Definition: slk.c:45
#define ERR
Definition: curses.h:18
#define COLS
Definition: vga.h:27
static void _print_label(struct _softlabel sl)
Definition: slk.c:78
static struct _softlabelkeys * slks
Definition: slk.c:55
#define stdscr
Definition: curses.h:110
#define NOWRAP
Definition: mucurses.h:13
static void _enter_slk(void)
Definition: slk.c:64
unsigned int spaces[SLK_MAX_NUM_SPACES]
Definition: slk.c:49
void _wputch(WINDOW *win, chtype ch, int wrap) __nonnull
Write a single character rendition to a window.
Definition: mucurses.c:50
uint32_t chtype
Definition: curses.h:29
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References _enter_slk(), _leave_slk(), _print_label(), _wputch(), _softlabelkeys::attrs, COLS, ERR, _softlabelkeys::fkeys, _softlabelkeys::maj_space_len, _softlabelkeys::max_label_len, NOWRAP, NULL, _softlabelkeys::num_labels, _softlabelkeys::num_spaces, OK, slks, _softlabelkeys::spaces, and stdscr.

Referenced by slk_refresh().

◆ slk_set()

int slk_set ( int  labnum,
const char *  label,
int  fmt 
)

Configure specified soft key.

Parameters
labnumsoft label position to configure
*labelstring to use as soft key label
fmtjustification format of label
Return values
rcreturn status code

Definition at line 352 of file slk.c.

352  {
353  if ( slks == NULL )
354  return ERR;
355  if ( (unsigned short)labnum >= slks->num_labels )
356  return ERR;
357  if ( (unsigned short)fmt >= 3 )
358  return ERR;
359 
360  strncpy(slks->fkeys[labnum].label, label,
361  (sizeof(slks->fkeys[labnum].label) - 1));
362  slks->fkeys[labnum].fmt = fmt;
363 
364  return OK;
365 }
A text label widget.
Definition: label.h:16
unsigned int num_labels
Definition: slk.c:47
struct _softlabel fkeys[SLK_MAX_NUM_LABELS]
Definition: slk.c:36
char label[SLK_MAX_LABEL_LEN]
Definition: slk.c:26
Definition: sis900.h:208
char * strncpy(char *dest, const char *src, size_t max)
Copy string.
Definition: string.c:360
#define ERR
Definition: curses.h:18
static struct _softlabelkeys * slks
Definition: slk.c:55
unsigned int fmt
Definition: slk.c:32
int ssize_t const char * fmt
Definition: vsprintf.h:72
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References ERR, _softlabelkeys::fkeys, _softlabel::fmt, fmt, _softlabel::label, NULL, _softlabelkeys::num_labels, OK, slks, and strncpy().

Variable Documentation

◆ slks

struct _softlabelkeys* slks
static