iPXE
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)
 FILE_SECBOOT (PERMITTED)
static __nonnull void init_editstring (struct edit_string *string, char **buf)
 Initialise editable string.
 __attribute__ ((nonnull(1))) int replace_string(struct edit_string *string
__nonnull int edit_string (struct edit_string *string, int key)
 Edit editable string.

Variables

const char * replacement

Detailed Description

Editable strings.

Definition in file editstring.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ init_editstring()

__nonnull void init_editstring ( struct edit_string * string,
char ** buf )
inlinestatic

Initialise editable string.

Parameters
stringEditable string
bufDynamically allocated string buffer

The buf parameter must be the address of a caller-provided pointer to a NUL-terminated string allocated using malloc() (or equivalent, such as strdup()). Any edits made to the string will realloc() the string buffer as needed.

The caller may choose leave the initial string buffer pointer as NULL, in which case it will be allocated upon the first attempt to insert a character into the buffer. If the caller does this, then it must be prepared to find the pointer still NULL after editing, since the user may never attempt to insert any characters.

Definition at line 47 of file editstring.h.

48 {
49
50 string->buf = buf;
51}

References __nonnull.

Referenced by editstring_okx(), init_editbox(), and readline_history().

◆ __attribute__()

__attribute__ ( (nonnull(1)) )
extern

◆ edit_string()

__nonnull int edit_string ( struct edit_string * string,
int key )
extern

Edit editable string.

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

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.

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

This function does not itself update the display in any way.

Errors may safely be ignored if it is deemed that subsequently failing to update the display will provide sufficient feedback to the user.

Definition at line 256 of file editstring.c.

256 {
257 const char *buf = *(string->buf);
258 size_t len = ( buf ? strlen ( buf ) : 0 );
259 int retval = 0;
260
261 /* Prepare edit history */
262 string->last_cursor = string->cursor;
263 string->mod_start = string->cursor;
264 string->mod_end = string->cursor;
265
266 /* Interpret key */
267 if ( ( key >= 0x20 ) && ( key <= 0x7e ) ) {
268 /* Printable character; insert at current position */
269 retval = insert_character ( string, key );
270 } else switch ( key ) {
271 case KEY_BACKSPACE:
272 /* Backspace */
273 backspace ( string );
274 break;
275 case KEY_DC:
276 case CTRL_D:
277 /* Delete character */
278 delete_character ( string );
279 break;
280 case CTRL_W:
281 /* Delete word */
282 kill_word ( string );
283 break;
284 case CTRL_U:
285 /* Delete to start of line */
286 kill_sol ( string );
287 break;
288 case CTRL_K:
289 /* Delete to end of line */
290 kill_eol ( string );
291 break;
292 case KEY_HOME:
293 case CTRL_A:
294 /* Start of line */
295 string->cursor = 0;
296 break;
297 case KEY_END:
298 case CTRL_E:
299 /* End of line */
300 string->cursor = len;
301 break;
302 case KEY_LEFT:
303 case CTRL_B:
304 /* Cursor left */
305 if ( string->cursor > 0 )
306 string->cursor--;
307 break;
308 case KEY_RIGHT:
309 case CTRL_F:
310 /* Cursor right */
311 if ( string->cursor < len )
312 string->cursor++;
313 break;
314 default:
315 retval = key;
316 break;
317 }
318
319 return retval;
320}
union @162305117151260234136356364136041353210355154177 key
Sense key.
Definition scsi.h:3
unsigned long retval
Definition xen.h:46
ring len
Length.
Definition dwmac.h:226
static void kill_eol(struct edit_string *string)
Delete to end of line.
Definition editstring.c:202
static void backspace(struct edit_string *string)
Delete character to left of current cursor position.
Definition editstring.c:143
static void delete_character(struct edit_string *string)
Delete character at current cursor position.
Definition editstring.c:131
static int insert_character(struct edit_string *string, unsigned int character)
Insert character at current cursor position.
Definition editstring.c:119
static void kill_sol(struct edit_string *string)
Delete to start of line.
Definition editstring.c:188
static void kill_word(struct edit_string *string)
Delete to end of previous word.
Definition editstring.c:174
#define KEY_RIGHT
Right arrow.
Definition keys.h:108
#define KEY_DC
Delete.
Definition keys.h:113
#define CTRL_E
Definition keys.h:23
#define KEY_BACKSPACE
Definition keys.h:128
#define CTRL_W
Definition keys.h:41
#define CTRL_B
Definition keys.h:20
#define CTRL_D
Definition keys.h:22
#define CTRL_F
Definition keys.h:24
#define CTRL_U
Definition keys.h:39
#define CTRL_K
Definition keys.h:29
#define KEY_END
End.
Definition keys.h:110
#define CTRL_A
Definition keys.h:19
#define KEY_LEFT
Left arrow.
Definition keys.h:109
#define KEY_HOME
Home.
Definition keys.h:111
uint32_t string
Definition multiboot.h:2
size_t strlen(const char *src)
Get length of string.
Definition string.c:244

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().

Variable Documentation

◆ replacement

const char* replacement

Definition at line 54 of file editstring.h.

Referenced by image_exec(), image_replace(), myri10ge_net_poll(), and replace_string().