Browse Source

Use symbolic key names, and avoid moving beyond end of string

tags/v0.9.3
Michael Brown 18 years ago
parent
commit
4b2b8b02ab
1 changed files with 17 additions and 9 deletions
  1. 17
    9
      src/hci/editstring.c

+ 17
- 9
src/hci/editstring.c View File

18
 
18
 
19
 #include <assert.h>
19
 #include <assert.h>
20
 #include <string.h>
20
 #include <string.h>
21
+#include <gpxe/keys.h>
21
 #include <gpxe/editstring.h>
22
 #include <gpxe/editstring.h>
22
 
23
 
23
 /** @file
24
 /** @file
124
  */
125
  */
125
 int edit_string ( struct edit_string *string, int key ) {
126
 int edit_string ( struct edit_string *string, int key ) {
126
 	int retval = 0;
127
 	int retval = 0;
128
+	size_t len = strlen ( string->buf );
127
 
129
 
128
 	/* Prepare edit history */
130
 	/* Prepare edit history */
129
 	string->last_cursor = string->cursor;
131
 	string->last_cursor = string->cursor;
135
 		/* Printable character; insert at current position */
137
 		/* Printable character; insert at current position */
136
 		insert_character ( string, key );
138
 		insert_character ( string, key );
137
 	} else switch ( key ) {
139
 	} else switch ( key ) {
138
-	case 0x08: /* Ctrl-H */
140
+	case KEY_BACKSPACE:
139
 		/* Backspace */
141
 		/* Backspace */
140
 		backspace ( string );
142
 		backspace ( string );
141
 		break;
143
 		break;
142
-	case 0x04: /* Ctrl-D */
144
+	case KEY_DC:
145
+	case CTRL_D:
143
 		/* Delete character */
146
 		/* Delete character */
144
 		delete_character ( string );
147
 		delete_character ( string );
145
 		break;
148
 		break;
146
-	case 0x0b: /* Ctrl-K */
149
+	case CTRL_K:
150
+		/* Delete to end of line */
147
 		kill_eol ( string );
151
 		kill_eol ( string );
148
 		break;
152
 		break;
149
-	case 0x01: /* Ctrl-A */
153
+	case KEY_HOME:
154
+	case CTRL_A:
150
 		/* Start of line */
155
 		/* Start of line */
151
 		string->cursor = 0;
156
 		string->cursor = 0;
152
 		break;
157
 		break;
153
-	case 0x05: /* Ctrl-E */
158
+	case KEY_END:
159
+	case CTRL_E:
154
 		/* End of line */
160
 		/* End of line */
155
-		string->cursor = strlen ( string->buf );
161
+		string->cursor = len;
156
 		break;
162
 		break;
157
-	case 0x02: /* Ctrl-B */
163
+	case KEY_LEFT:
164
+	case CTRL_B:
158
 		/* Cursor left */
165
 		/* Cursor left */
159
 		if ( string->cursor > 0 )
166
 		if ( string->cursor > 0 )
160
 			string->cursor--;
167
 			string->cursor--;
161
 		break;
168
 		break;
162
-	case 0x06: /* Ctrl-F */
169
+	case KEY_RIGHT:
170
+	case CTRL_F:
163
 		/* Cursor right */
171
 		/* Cursor right */
164
-		if ( string->cursor < ( string->len - 1 ) )
172
+		if ( string->cursor < len )
165
 			string->cursor++;
173
 			string->cursor++;
166
 		break;
174
 		break;
167
 	default:
175
 	default:

Loading…
Cancel
Save