diff options
author | Xavier Chantry <chantry.xavier@gmail.com> | 2010-10-17 17:18:36 +0200 |
---|---|---|
committer | Xavier Chantry <chantry.xavier@gmail.com> | 2011-01-29 19:40:07 +0100 |
commit | 2dd53e50de4f80cef84cd90140c4b43633360372 (patch) | |
tree | 0d3ec35706cd07e87b105c5c4a036b68d79a2626 | |
parent | 00fec5e2503a8272ebac9f240e03d655131ec216 (diff) |
pacman: improve select-question
Make use of parseindex like in multiselect, and loop until we get a
valid answer like in multiselect.
Signed-off-by: Xavier Chantry <chantry.xavier@gmail.com>
-rw-r--r-- | src/pacman/callback.c | 1 | ||||
-rw-r--r-- | src/pacman/util.c | 31 |
2 files changed, 16 insertions, 16 deletions
diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 43c56d00..53a56817 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -311,7 +311,6 @@ void cb_trans_conv(pmtransconv_t event, void *data1, void *data2, depstring); free(depstring); select_display(providers); - printf("\n"); *response = select_question(count); } break; diff --git a/src/pacman/util.c b/src/pacman/util.c index 51abbf4d..37f28528 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -815,27 +815,28 @@ int select_question(int count) stream = stderr; } - fprintf(stream, _("Enter a number (default=%d)"), preset); - fprintf(stream, ": "); - - if(config->noconfirm) { + while(1) { fprintf(stream, "\n"); - return(preset-1); - } + fprintf(stream, _("Enter a number (default=%d)"), preset); + fprintf(stream, ": "); - if(fgets(response, sizeof(response), stdin)) { - strtrim(response); - if(strlen(response) > 0) { - char *endptr = NULL; - int n = strtol(response, &endptr, 10); - if(*endptr == '\0' && n >= 1 && n <= count) { + if(config->noconfirm) { + fprintf(stream, "\n"); + break; + } + + if(fgets(response, sizeof(response), stdin)) { + strtrim(response); + if(strlen(response) > 0) { + int n; + if(parseindex(response, &n, 1, count) != 0) + continue; return(n-1); - } else { - fprintf(stream, _("Invalid number: %s\n"), response); - return(-1); } } + break; } + return(preset-1); } |