summaryrefslogtreecommitdiffstats
path: root/src/pacman/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pacman/util.c')
-rw-r--r--src/pacman/util.c31
1 files changed, 16 insertions, 15 deletions
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);
}