From d8d89d8d27794d493ed2aa9eba4649e6e3ff4a9d Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 1 Apr 2011 15:16:26 -0500 Subject: Ensure stdout/stderr are flushed when asking questions Addresses FS#23492, where the question was shown without knowing what one was answering to. Ensure we flush our output streams before printing the question, and flush the stream on which we ask the question before waiting for an answer. Signed-off-by: Dan McGee --- src/pacman/util.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/pacman/util.c b/src/pacman/util.c index 83368085..c7d98540 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -878,6 +878,10 @@ static int question(short preset, char *fmt, va_list args) stream = stderr; } + /* ensure all text makes it to the screen before we prompt the user */ + fflush(stdout); + fflush(stderr); + vfprintf(stream, fmt, args); if(preset) { @@ -891,6 +895,7 @@ static int question(short preset, char *fmt, va_list args) return(preset); } + fflush(stream); if(fgets(response, sizeof(response), stdin)) { strtrim(response); if(strlen(response) == 0) { -- cgit v1.2.3-70-g09d2 From 6a8b1c4f8433e95e713e3c6f152ba717c90d1dc9 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sat, 2 Apr 2011 13:51:25 -0500 Subject: Coding style cleanups Signed-off-by: Dan McGee --- src/pacman/util.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/pacman/util.c b/src/pacman/util.c index c7d98540..3d268031 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -746,8 +746,9 @@ static int multiselect_parse(char *array, int count, char *response) char *ends = NULL; char *starts = strtok_r(str, " ", &saveptr); - if (starts == NULL) + if (starts == NULL) { break; + } strtrim(starts); int len = strlen(starts); if(len == 0) @@ -765,9 +766,9 @@ static int multiselect_parse(char *array, int count, char *response) if(len > 1) { /* check for range */ char *p; - if((p = strchr(starts+1, '-'))) { + if((p = strchr(starts + 1, '-'))) { *p = 0; - ends = p+1; + ends = p + 1; } } @@ -777,9 +778,11 @@ static int multiselect_parse(char *array, int count, char *response) if(!ends) { array[start-1] = include; } else { - if(parseindex(ends, &end, start, count) != 0) + int d; + if(parseindex(ends, &end, start, count) != 0) { return(-1); - for(int d = start; d <= end; d++) { + } + for(d = start; d <= end; d++) { array[d-1] = include; } } -- cgit v1.2.3-70-g09d2