From 2dd53e50de4f80cef84cd90140c4b43633360372 Mon Sep 17 00:00:00 2001 From: Xavier Chantry Date: Sun, 17 Oct 2010 17:18:36 +0200 Subject: 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 --- src/pacman/callback.c | 1 - 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); } -- cgit v1.2.3-70-g09d2