diff options
Diffstat (limited to 'src/pacman/util.c')
-rw-r--r-- | src/pacman/util.c | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/src/pacman/util.c b/src/pacman/util.c index 8d7be69b..780434cd 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -27,6 +27,7 @@ #include <stdio.h> #include <stdlib.h> +#include <stdarg.h> #include <string.h> #include <errno.h> #include <fcntl.h> @@ -40,7 +41,8 @@ /* pacman */ #include "util.h" #include "conf.h" -#include "output.h" + +#define LOG_STR_LEN 256 extern config_t *config; @@ -336,4 +338,35 @@ void display_targets(alpm_list_t *syncpkgs) FREELIST(targets); } +/* presents a prompt and gets a Y/N answer */ +/* TODO there must be a better way */ +int yesno(char *fmt, ...) +{ + char str[LOG_STR_LEN]; + char response[32]; + va_list args; + + if(config->noconfirm) { + return(1); + } + + va_start(args, fmt); + vsnprintf(str, LOG_STR_LEN, fmt, args); + va_end(args); + + /* Use stderr so questions are always displayed when redirecting output */ + fprintf(stderr, str); + + if(fgets(response, 32, stdin)) { + if(strlen(response) != 0) { + strtrim(response); + } + + if(!strcasecmp(response, _("Y")) || !strcasecmp(response, _("YES")) || strlen(response) == 0) { + return(1); + } + } + return(0); +} + /* vim: set ts=2 sw=2 noet: */ |