kconfig: lxdialog: clean string input with whitespace
PATCH 1/1 kconfig: lxdialog: clean string input with whitespace
From: yuan linyu <[email protected]>
remove leading/trailing whitespace and all whitespace
Signed-off-by yuan linyu <[email protected]>
--- scripts/kconfig/lxdialog/inputbox.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
scripts/kconfig/lxdialog/inputbox.c +27 -0
@@ -38,6 +38,31 @@ static void print_buttons(WINDOW * dialog, int height, int width, int selected)wrefresh (dialog); } +static void dialog_input_clean (void ) +{ +char *instr = dialog_input_result; +int l, s, e; + + l =strlen (instr); +if (l ==0 ) +return ; +for (s =0 ; s < l; s++) { +if (instr[s] !=' ' ) +break ; + instr[s] ='\0' ; + } +if (s == l) +return ; +for (e = l -1 ; e >0 ; e--) { +if (instr[e] !=' ' ) +break ; + instr[e] ='\0' ; + } +if (s ==0 ) +return ; +memmove (instr, instr + s, e - s +2 ); +} +/* * Display a dialog box for inputing a string */
@@ -234,6 +259,7 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int widthcase 'O' :case 'o' :delwin (dialog); +dialog_input_clean ();return 0 ;case 'H' :case 'h' :
@@ -281,6 +307,7 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int widthcase ' ' :case '\n' :delwin (dialog); +dialog_input_clean ();return (button ==-1 ?0 : button);case 'X' :case 'x' :
Signature · 1 line
2.14.1