[pacman-dev] [PATCH] pacman/util.c: flush output once for questions

Allan McRae allan at archlinux.org
Sat Apr 6 03:24:54 EDT 2013


On 03/04/13 09:53, Andrew Gregory wrote:
> Convert a couple random tabs inside fprintf to spaces.
> 

That commit subject and message really made me read through the patch...
How about:


pacman/util.c: fix issue with flushing output in questions

Flush stream before taking input in select_question() and only flush
once during question().  Also fix some tabs inside related fprintf
statements.



> Signed-off-by: Andrew Gregory <andrew.gregory.8 at gmail.com>
> ---
>  src/pacman/util.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/src/pacman/util.c b/src/pacman/util.c
> index 862c8e8..7b7dace 100644
> --- a/src/pacman/util.c
> +++ b/src/pacman/util.c
> @@ -1384,15 +1384,15 @@ int multiselect_question(char *array, int count)
>  	*lastchar = 1;
>  
>  	while(1) {
>  		memset(array, 1, count);
>  
>  		fprintf(stream, "\n");
>  		fprintf(stream, _("Enter a selection (default=all)"));
> -		fprintf(stream,	": ");
> +		fprintf(stream, ": ");
>  		fflush(stream);
>  
>  		if(config->noconfirm) {
>  			fprintf(stream, "\n");
>  			break;
>  		}
>  
> @@ -1448,15 +1448,16 @@ int select_question(int count)
>  		/* Use stderr so questions are always displayed when redirecting output */
>  		stream = stderr;
>  	}
>  
>  	while(1) {
>  		fprintf(stream, "\n");
>  		fprintf(stream, _("Enter a number (default=%d)"), preset);
> -		fprintf(stream,	": ");
> +		fprintf(stream, ": ");
> +		fflush(stream);
>  
>  		if(config->noconfirm) {
>  			fprintf(stream, "\n");
>  			break;
>  		}
>  
>  		flush_term_input(fileno(stdin));
> @@ -1509,15 +1510,14 @@ static int question(short preset, const char *format, va_list args)
>  	fflush(stream);
>  
>  	if(config->noconfirm) {
>  		fprintf(stream, "\n");
>  		return preset;
>  	}
>  
> -	fflush(stream);
>  	flush_term_input(fd_in);
>  
>  	if(fgets(response, sizeof(response), stdin)) {
>  		size_t len = strtrim(response);
>  		if(len == 0) {
>  			return preset;
>  		}
> 



More information about the pacman-dev mailing list