Browse Source

[readline] Add init_editstring() wrapper function

Standardise on using init_editstring() to initialise an embedded
editable string, to match the coding style used by other embedded
objects.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 13 years ago
parent
commit
6a6dd5c452
3 changed files with 15 additions and 4 deletions
  1. 1
    2
      src/hci/mucurses/widgets/editbox.c
  2. 1
    2
      src/hci/readline.c
  3. 13
    0
      src/include/ipxe/editstring.h

+ 1
- 2
src/hci/mucurses/widgets/editbox.c View File

@@ -46,8 +46,7 @@ void init_editbox ( struct edit_box *box, char *buf, size_t len,
46 46
 		    WINDOW *win, unsigned int row, unsigned int col,
47 47
 		    unsigned int width, unsigned int flags ) {
48 48
 	memset ( box, 0, sizeof ( *box ) );
49
-	box->string.buf = buf;
50
-	box->string.len = len;
49
+	init_editstring ( &box->string, buf, len );
51 50
 	box->string.cursor = strlen ( buf );
52 51
 	box->win = ( win ? win : stdscr );
53 52
 	box->row = row;

+ 1
- 2
src/hci/readline.c View File

@@ -93,8 +93,7 @@ char * readline ( const char *prompt ) {
93 93
 		printf ( "%s", prompt );
94 94
 
95 95
 	memset ( &string, 0, sizeof ( string ) );
96
-	string.buf = buf;
97
-	string.len = sizeof ( buf );
96
+	init_editstring ( &string, buf, sizeof ( buf ) );
98 97
 	buf[0] = '\0';
99 98
 
100 99
 	while ( 1 ) {

+ 13
- 0
src/include/ipxe/editstring.h View File

@@ -28,6 +28,19 @@ struct edit_string {
28 28
 	unsigned int mod_end;
29 29
 };
30 30
 
31
+/**
32
+ * Initialise editable string
33
+ *
34
+ * @v string		Editable string
35
+ * @v buf		Buffer for string
36
+ * @v len		Length of buffer
37
+ */
38
+static inline void init_editstring ( struct edit_string *string, char *buf,
39
+				     size_t len ) {
40
+	string->buf = buf;
41
+	string->len = len;
42
+}
43
+
31 44
 extern int edit_string ( struct edit_string *string, int key ) __nonnull;
32 45
 
33 46
 #endif /* _IPXE_EDITSTRING_H */

Loading…
Cancel
Save