From 633c89b5327bbdb14d0d076cbab474c60dabab57 Mon Sep 17 00:00:00 2001 From: Aurelien Foret Date: Sat, 4 Feb 2006 10:34:27 +0000 Subject: - moved yesno() from util.c to log.c - fixed a missing line feed in yesno when printing the message --- src/pacman/log.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/pacman/log.c') 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: */ -- cgit v1.2.3