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.
void replace_string (struct edit_string *string, const char *replacement) __nonnull
 Replace editable string.
int edit_string (struct edit_string *string, int key) __nonnull
 Edit editable string.

Detailed Description

Editable strings.

Definition in file editstring.h.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static void init_editstring ( struct edit_string string,
char *  buf,
size_t  len 
) [inline, static]

Initialise editable string.

Parameters:
stringEditable string
bufBuffer for string
lenLength of buffer

Definition at line 38 of file editstring.h.

References len.

Referenced by init_editbox(), and readline_history().

                                                  {
        string->buf = buf;
        string->len = len;
}
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.

References insert_delete().

Referenced by readline_history().

                                                                            {
        string->cursor = 0;
        insert_delete ( string, ~( ( size_t ) 0 ), replacement );
}
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.

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

Referenced by edit_editbox(), and readline_history().

                                                        {
        int retval = 0;
        size_t len = strlen ( string->buf );

        /* Prepare edit history */
        string->last_cursor = string->cursor;
        string->mod_start = string->cursor;
        string->mod_end = string->cursor;

        /* Interpret key */
        if ( ( key >= 0x20 ) && ( key <= 0x7e ) ) {
                /* Printable character; insert at current position */
                insert_character ( string, key );
        } else switch ( key ) {
        case KEY_BACKSPACE:
                /* Backspace */
                backspace ( string );
                break;
        case KEY_DC:
        case CTRL_D:
                /* Delete character */
                delete_character ( string );
                break;
        case CTRL_W:
                /* Delete word */
                kill_word ( string );
                break;
        case CTRL_U:
                /* Delete to start of line */
                kill_sol ( string );
                break;
        case CTRL_K:
                /* Delete to end of line */
                kill_eol ( string );
                break;
        case KEY_HOME:
        case CTRL_A:
                /* Start of line */
                string->cursor = 0;
                break;
        case KEY_END:
        case CTRL_E:
                /* End of line */
                string->cursor = len;
                break;
        case KEY_LEFT:
        case CTRL_B:
                /* Cursor left */
                if ( string->cursor > 0 )
                        string->cursor--;
                break;
        case KEY_RIGHT:
        case CTRL_F:
                /* Cursor right */
                if ( string->cursor < len )
                        string->cursor++;
                break;
        default:
                retval = key;
                break;
        }

        return retval;
}