From adc4078b8743a1437d44557dafea8619b1ce0fb1 Mon Sep 17 00:00:00 2001 From: Xavier Chantry Date: Wed, 20 Aug 2008 22:08:11 +0200 Subject: split yesno() into yesno() and noyes() functions. The yesno function had a preset argument for specifying the default answer : yes or no. However, in all our calls to yesno, only one used the default "no" answer. Having to specify preset==1 for all the other cases was rather cumbersome. To make this easier, this commit adds a noyes function, with the following behavior : yesno() : default answer is yes noyes() : default answer is no Signed-off-by: Xavier Chantry Signed-off-by: Dan McGee --- src/pacman/util.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'src/pacman/util.c') diff --git a/src/pacman/util.c b/src/pacman/util.c index 8c4aeab8..1fc67145 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -619,10 +619,9 @@ void display_optdepends(pmpkg_t *pkg) } /* presents a prompt and gets a Y/N answer */ -int yesno(short preset, char *fmt, ...) +static int question(short preset, char *fmt, va_list args) { char response[32]; - va_list args; FILE *stream; if(config->noconfirm) { @@ -632,9 +631,7 @@ int yesno(short preset, char *fmt, ...) stream = stderr; } - va_start(args, fmt); vfprintf(stream, fmt, args); - va_end(args); if(preset) { fprintf(stream, " %s ", _("[Y/n]")); @@ -662,6 +659,30 @@ int yesno(short preset, char *fmt, ...) return(0); } +int yesno(char *fmt, ...) +{ + int ret; + va_list args; + + va_start(args, fmt); + ret = question(1, fmt, args); + va_end(args); + + return(ret); +} + +int noyes(char *fmt, ...) +{ + int ret; + va_list args; + + va_start(args, fmt); + ret = question(0, fmt, args); + va_end(args); + + return(ret); +} + int pm_printf(pmloglevel_t level, const char *format, ...) { int ret; -- cgit v1.2.3