summaryrefslogtreecommitdiffstats
path: root/src/hci
diff options
context:
space:
mode:
authorMichael Brown2006-12-20 23:21:09 +0100
committerMichael Brown2006-12-20 23:21:09 +0100
commit4b2b8b02ab2b3c669e98fa9061a2d9f10dff546b (patch)
treef8018eb335703941713e24d2f8c13e1fc7aa960b /src/hci
parentFix definition of KEY_END (diff)
downloadipxe-4b2b8b02ab2b3c669e98fa9061a2d9f10dff546b.tar.gz
ipxe-4b2b8b02ab2b3c669e98fa9061a2d9f10dff546b.tar.xz
ipxe-4b2b8b02ab2b3c669e98fa9061a2d9f10dff546b.zip
Use symbolic key names, and avoid moving beyond end of string
Diffstat (limited to 'src/hci')
-rw-r--r--src/hci/editstring.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/hci/editstring.c b/src/hci/editstring.c
index f6a11617..32483334 100644
--- a/src/hci/editstring.c
+++ b/src/hci/editstring.c
@@ -18,6 +18,7 @@
#include <assert.h>
#include <string.h>
+#include <gpxe/keys.h>
#include <gpxe/editstring.h>
/** @file
@@ -124,6 +125,7 @@ static void kill_eol ( struct edit_string *string ) {
*/
int edit_string ( struct edit_string *string, int key ) {
int retval = 0;
+ size_t len = strlen ( string->buf );
/* Prepare edit history */
string->last_cursor = string->cursor;
@@ -135,33 +137,39 @@ int edit_string ( struct edit_string *string, int key ) {
/* Printable character; insert at current position */
insert_character ( string, key );
} else switch ( key ) {
- case 0x08: /* Ctrl-H */
+ case KEY_BACKSPACE:
/* Backspace */
backspace ( string );
break;
- case 0x04: /* Ctrl-D */
+ case KEY_DC:
+ case CTRL_D:
/* Delete character */
delete_character ( string );
break;
- case 0x0b: /* Ctrl-K */
+ case CTRL_K:
+ /* Delete to end of line */
kill_eol ( string );
break;
- case 0x01: /* Ctrl-A */
+ case KEY_HOME:
+ case CTRL_A:
/* Start of line */
string->cursor = 0;
break;
- case 0x05: /* Ctrl-E */
+ case KEY_END:
+ case CTRL_E:
/* End of line */
- string->cursor = strlen ( string->buf );
+ string->cursor = len;
break;
- case 0x02: /* Ctrl-B */
+ case KEY_LEFT:
+ case CTRL_B:
/* Cursor left */
if ( string->cursor > 0 )
string->cursor--;
break;
- case 0x06: /* Ctrl-F */
+ case KEY_RIGHT:
+ case CTRL_F:
/* Cursor right */
- if ( string->cursor < ( string->len - 1 ) )
+ if ( string->cursor < len )
string->cursor++;
break;
default: