diff options
| author | Dirk Gouders <dirk@gouders.net> | 2013-05-08 11:29:42 -0400 |
|---|---|---|
| committer | Yann E. MORIN <yann.morin.1998@free.fr> | 2013-06-18 17:58:57 -0400 |
| commit | 1376391621654cc369c5e8b60497f7c184f0ed47 (patch) | |
| tree | 0a4b91e6aae28dd794218386a337c38b3f7fa1e5 /scripts/kconfig/lxdialog | |
| parent | ff7b0c2c2430b5b116108441cbd0680efbef68d1 (diff) | |
kconfig/lxdialog: handle newline characters in print_autowrap()
When exiting menuconfig with unsaved changes, a dialog like
the following is shown:
Do you wish to save your new configuration ? <ESC><ESC>
to continue.
The author of the dialog text specified a newline after the '?',
and probably expected it to be processed, so let print_autowrap()
handle newlines propperly.
Also, reword that dialog's second phrase with a real sentence.
Signed-off-by: Dirk Gouders <dirk@gouders.net>
Tested-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Reviewed-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
[yann.morin.1998@free.fr: very slightly tweak the commit message]
Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
Diffstat (limited to 'scripts/kconfig/lxdialog')
| -rw-r--r-- | scripts/kconfig/lxdialog/util.c | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/scripts/kconfig/lxdialog/util.c b/scripts/kconfig/lxdialog/util.c index 78fe4e9d8778..0fa567eb68c6 100644 --- a/scripts/kconfig/lxdialog/util.c +++ b/scripts/kconfig/lxdialog/util.c | |||
| @@ -371,27 +371,19 @@ void print_title(WINDOW *dialog, const char *title, int width) | |||
| 371 | /* | 371 | /* |
| 372 | * Print a string of text in a window, automatically wrap around to the | 372 | * Print a string of text in a window, automatically wrap around to the |
| 373 | * next line if the string is too long to fit on one line. Newline | 373 | * next line if the string is too long to fit on one line. Newline |
| 374 | * characters '\n' are replaced by spaces. We start on a new line | 374 | * characters '\n' are propperly processed. We start on a new line |
| 375 | * if there is no room for at least 4 nonblanks following a double-space. | 375 | * if there is no room for at least 4 nonblanks following a double-space. |
| 376 | */ | 376 | */ |
| 377 | void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x) | 377 | void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x) |
| 378 | { | 378 | { |
| 379 | int newl, cur_x, cur_y; | 379 | int newl, cur_x, cur_y; |
| 380 | int i, prompt_len, room, wlen; | 380 | int prompt_len, room, wlen; |
| 381 | char tempstr[MAX_LEN + 1], *word, *sp, *sp2; | 381 | char tempstr[MAX_LEN + 1], *word, *sp, *sp2, *newline_separator = 0; |
| 382 | 382 | ||
| 383 | strcpy(tempstr, prompt); | 383 | strcpy(tempstr, prompt); |
| 384 | 384 | ||
| 385 | prompt_len = strlen(tempstr); | 385 | prompt_len = strlen(tempstr); |
| 386 | 386 | ||
| 387 | /* | ||
| 388 | * Remove newlines | ||
| 389 | */ | ||
| 390 | for (i = 0; i < prompt_len; i++) { | ||
| 391 | if (tempstr[i] == '\n') | ||
| 392 | tempstr[i] = ' '; | ||
| 393 | } | ||
| 394 | |||
| 395 | if (prompt_len <= width - x * 2) { /* If prompt is short */ | 387 | if (prompt_len <= width - x * 2) { /* If prompt is short */ |
| 396 | wmove(win, y, (width - prompt_len) / 2); | 388 | wmove(win, y, (width - prompt_len) / 2); |
| 397 | waddstr(win, tempstr); | 389 | waddstr(win, tempstr); |
| @@ -401,7 +393,10 @@ void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x) | |||
| 401 | newl = 1; | 393 | newl = 1; |
| 402 | word = tempstr; | 394 | word = tempstr; |
| 403 | while (word && *word) { | 395 | while (word && *word) { |
| 404 | sp = strchr(word, ' '); | 396 | sp = strpbrk(word, "\n "); |
| 397 | if (sp && *sp == '\n') | ||
| 398 | newline_separator = sp; | ||
| 399 | |||
| 405 | if (sp) | 400 | if (sp) |
| 406 | *sp++ = 0; | 401 | *sp++ = 0; |
| 407 | 402 | ||
| @@ -413,7 +408,7 @@ void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x) | |||
| 413 | if (wlen > room || | 408 | if (wlen > room || |
| 414 | (newl && wlen < 4 && sp | 409 | (newl && wlen < 4 && sp |
| 415 | && wlen + 1 + strlen(sp) > room | 410 | && wlen + 1 + strlen(sp) > room |
| 416 | && (!(sp2 = strchr(sp, ' ')) | 411 | && (!(sp2 = strpbrk(sp, "\n ")) |
| 417 | || wlen + 1 + (sp2 - sp) > room))) { | 412 | || wlen + 1 + (sp2 - sp) > room))) { |
| 418 | cur_y++; | 413 | cur_y++; |
| 419 | cur_x = x; | 414 | cur_x = x; |
| @@ -421,7 +416,15 @@ void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x) | |||
| 421 | wmove(win, cur_y, cur_x); | 416 | wmove(win, cur_y, cur_x); |
| 422 | waddstr(win, word); | 417 | waddstr(win, word); |
| 423 | getyx(win, cur_y, cur_x); | 418 | getyx(win, cur_y, cur_x); |
| 424 | cur_x++; | 419 | |
| 420 | /* Move to the next line if the word separator was a newline */ | ||
| 421 | if (newline_separator) { | ||
| 422 | cur_y++; | ||
| 423 | cur_x = x; | ||
| 424 | newline_separator = 0; | ||
| 425 | } else | ||
| 426 | cur_x++; | ||
| 427 | |||
| 425 | if (sp && *sp == ' ') { | 428 | if (sp && *sp == ' ') { |
| 426 | cur_x++; /* double space */ | 429 | cur_x++; /* double space */ |
| 427 | while (*++sp == ' ') ; | 430 | while (*++sp == ' ') ; |
