iPXE
Data Structures | Functions
editstring.h File Reference

Editable strings. More...

Go to the source code of this file.

Data Structures

struct  edit_string
 An editable string. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static void init_editstring (struct edit_string *string, char *buf, size_t len)
 Initialise editable string. More...
 
void replace_string (struct edit_string *string, const char *replacement) __nonnull
 Replace editable string. More...
 
int edit_string (struct edit_string *string, int key) __nonnull
 Edit editable string. More...
 

Detailed Description

Editable strings.

Definition in file editstring.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ init_editstring()

static void init_editstring ( struct edit_string string,
char *  buf,
size_t  len 
)
inlinestatic

Initialise editable string.

Parameters
stringEditable string
bufBuffer for string
lenLength of buffer

Definition at line 38 of file editstring.h.

39  {
40  string->buf = buf;
41  string->len = len;
42 }
uint32_t len
Length.
Definition: ena.h:14

References len.

Referenced by init_editbox(), and readline_history().

◆ replace_string()

void replace_string ( struct edit_string string,
const char *  replacement 
)

Replace editable string.

Parameters
stringEditable string
replacementReplacement string

Definition at line 173 of file editstring.c.

173  {
174  string->cursor = 0;
175  insert_delete ( string, ~( ( size_t ) 0 ), replacement );
176 }
static void insert_delete(struct edit_string *string, size_t delete_len, const char *insert_text) __attribute__((nonnull(1)))
Insert and/or delete text within an editable string.
Definition: editstring.c:57

References insert_delete().

Referenced by readline_history().

◆ edit_string()

int edit_string ( struct edit_string string,
int  key 
)

Edit editable string.

Parameters
stringEditable string
keyKey pressed by user
Return values
keyKey returned to application, or zero

Handles keypresses and updates the content of the editable string. Basic line editing facilities (delete/insert/cursor) are supported. If edit_string() understands and uses the keypress it will return zero, otherwise it will return the original key.

This function does not update the display in any way.

The string's edit history will be updated to allow the caller to efficiently bring the display into sync with the string content.

Definition at line 195 of file editstring.c.

195  {
196  int retval = 0;
197  size_t len = strlen ( string->buf );
198 
199  /* Prepare edit history */
200  string->last_cursor = string->cursor;
201  string->mod_start = string->cursor;
202  string->mod_end = string->cursor;
203 
204  /* Interpret key */
205  if ( ( key >= 0x20 ) && ( key <= 0x7e ) ) {
206  /* Printable character; insert at current position */
207  insert_character ( string, key );
208  } else switch ( key ) {
209  case KEY_BACKSPACE:
210  /* Backspace */
211  backspace ( string );
212  break;
213  case KEY_DC:
214  case CTRL_D:
215  /* Delete character */
216  delete_character ( string );
217  break;
218  case CTRL_W:
219  /* Delete word */
220  kill_word ( string );
221  break;
222  case CTRL_U:
223  /* Delete to start of line */
224  kill_sol ( string );
225  break;
226  case CTRL_K:
227  /* Delete to end of line */
228  kill_eol ( string );
229  break;
230  case KEY_HOME:
231  case CTRL_A:
232  /* Start of line */
233  string->cursor = 0;
234  break;
235  case KEY_END:
236  case CTRL_E:
237  /* End of line */
238  string->cursor = len;
239  break;
240  case KEY_LEFT:
241  case CTRL_B:
242  /* Cursor left */
243  if ( string->cursor > 0 )
244  string->cursor--;
245  break;
246  case KEY_RIGHT:
247  case CTRL_F:
248  /* Cursor right */
249  if ( string->cursor < len )
250  string->cursor++;
251  break;
252  default:
253  retval = key;
254  break;
255  }
256 
257  return retval;
258 }
#define CTRL_B
Definition: keys.h:19
#define CTRL_E
Definition: keys.h:22
uint32_t string
Definition: multiboot.h:14
#define KEY_HOME
Home.
Definition: keys.h:70
static void backspace(struct edit_string *string) __nonnull
Delete character to left of current cursor position.
Definition: editstring.c:113
#define CTRL_K
Definition: keys.h:28
#define CTRL_W
Definition: keys.h:40
#define KEY_END
End.
Definition: keys.h:69
size_t strlen(const char *src)
Get length of string.
Definition: string.c:243
#define CTRL_F
Definition: keys.h:23
static void insert_character(struct edit_string *string, unsigned int character) __nonnull
Insert character at current cursor position.
Definition: editstring.c:93
#define CTRL_A
Definition: keys.h:18
#define CTRL_U
Definition: keys.h:38
static void kill_eol(struct edit_string *string) __nonnull
Delete to end of line.
Definition: editstring.c:163
unsigned long retval
Definition: xen.h:45
#define KEY_DC
Delete.
Definition: keys.h:72
static void kill_sol(struct edit_string *string) __nonnull
Delete to start of line.
Definition: editstring.c:152
uint32_t len
Length.
Definition: ena.h:14
#define KEY_RIGHT
Right arrow.
Definition: keys.h:67
#define CTRL_D
Definition: keys.h:21
#define KEY_BACKSPACE
Definition: keys.h:87
static void kill_word(struct edit_string *string) __nonnull
Delete to end of previous word.
Definition: editstring.c:141
#define KEY_LEFT
Left arrow.
Definition: keys.h:68
union @382 key
Sense key.
Definition: scsi.h:18
static void delete_character(struct edit_string *string) __nonnull
Delete character at current cursor position.
Definition: editstring.c:104

References backspace(), CTRL_A, CTRL_B, CTRL_D, CTRL_E, CTRL_F, CTRL_K, CTRL_U, CTRL_W, delete_character(), insert_character(), key, KEY_BACKSPACE, KEY_DC, KEY_END, KEY_HOME, KEY_LEFT, KEY_RIGHT, kill_eol(), kill_sol(), kill_word(), len, retval, string, and strlen().

Referenced by edit_editbox(), and readline_history().