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>
This commit is contained in:
Xavier Chantry 2010-10-17 17:18:36 +02:00
parent 00fec5e250
commit 2dd53e50de
2 changed files with 16 additions and 16 deletions

View File

@ -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;

View File

@ -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);
}