浏览代码

[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 年前
父节点
当前提交
6a6dd5c452
共有 3 个文件被更改,包括 15 次插入4 次删除
  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 查看文件

@@ -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 查看文件

@@ -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 查看文件

@@ -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 */

正在加载...
取消
保存