summaryrefslogtreecommitdiffstats
path: root/src/pacman/log.c
diff options
context:
space:
mode:
authorAurelien Foret <aurelien@archlinux.org>2006-02-04 11:34:27 +0100
committerAurelien Foret <aurelien@archlinux.org>2006-02-04 11:34:27 +0100
commit633c89b5327bbdb14d0d076cbab474c60dabab57 (patch)
tree6d6294f69393fbecdc276665ea7ad87288c71bae /src/pacman/log.c
parentfe0b4cccb2539165657b7f06bb0a6a1123377798 (diff)
downloadpacman-633c89b5327bbdb14d0d076cbab474c60dabab57.tar.gz
pacman-633c89b5327bbdb14d0d076cbab474c60dabab57.tar.xz
- moved yesno() from util.c to log.c
- fixed a missing line feed in yesno when printing the message
Diffstat (limited to 'src/pacman/log.c')
-rw-r--r--src/pacman/log.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/pacman/log.c b/src/pacman/log.c
index dd70492f..caa0410b 100644
--- a/src/pacman/log.c
+++ b/src/pacman/log.c
@@ -113,4 +113,44 @@ void vprint(char *fmt, ...)
}
}
+/* presents a prompt and gets a Y/N answer
+ */
+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);
+ MSG(NL, str);
+
+ if(fgets(response, 32, stdin)) {
+ /* trim whitespace and newlines */
+ char *pch = response;
+ while(isspace(*pch)) {
+ pch++;
+ }
+ if(pch != response) {
+ memmove(response, pch, strlen(pch) + 1);
+ }
+ pch = response + strlen(response) - 1;
+ while(isspace(*pch)) {
+ pch--;
+ }
+ *++pch = 0;
+ strtrim(response);
+
+ if(!strcasecmp(response, "Y") || !strcasecmp(response, "YES") || !strlen(response)) {
+ return(1);
+ }
+ }
+ return(0);
+}
+
/* vim: set ts=2 sw=2 noet: */