summaryrefslogtreecommitdiffstats
path: root/src/pacman/util.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2007-04-27 01:20:46 +0200
committerDan McGee <dan@archlinux.org>2007-04-27 01:20:46 +0200
commit63588aff191f5bf982cc0c8ee8af2b46de084c4b (patch)
tree63e5f1fd1f2bef649c0ffb32efcad5053a3706cd /src/pacman/util.c
parentb39aba99f922d3e4451d6be09ea9201ea20ba102 (diff)
downloadpacman-63588aff191f5bf982cc0c8ee8af2b46de084c4b.tar.gz
pacman-63588aff191f5bf982cc0c8ee8af2b46de084c4b.tar.xz
Remove output.c and output.h
One function was left in this set of files after the earlier cleansing, so I moved yesno to util.c. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'src/pacman/util.c')
-rw-r--r--src/pacman/util.c35
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: */