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 ++++++++++++++++++++++++++++++++++++++++ src/pacman/log.h | 8 ++------ src/pacman/util.c | 40 ---------------------------------------- src/pacman/util.h | 1 - 4 files changed, 42 insertions(+), 47 deletions(-) (limited to 'src') 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: */ diff --git a/src/pacman/log.h b/src/pacman/log.h index 28999fd3..6cd5b346 100644 --- a/src/pacman/log.h +++ b/src/pacman/log.h @@ -26,11 +26,6 @@ pm_fprintf(stderr, line, "error: "); \ pm_fprintf(stderr, CL, fmt, ##args); \ } while(0) -#define DBG(line, fmt, args...) do { \ - char str[256]; \ - snprintf(str, 256, fmt, ##args); \ - cb_log(PM_LOG_DEBUG, str); \ -} while(0) enum { NL, /* new line */ @@ -41,9 +36,10 @@ enum { void cb_log(unsigned short level, char *msg); void pm_fprintf(FILE *file, unsigned short line, char *fmt, ...); - void vprint(char *fmt, ...); +int yesno(char *fmt, ...); + #endif /* _PM_LOG_H */ /* vim: set ts=2 sw=2 noet: */ diff --git a/src/pacman/util.c b/src/pacman/util.c index 16939099..757244a5 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -40,7 +40,6 @@ #include "conf.h" extern int maxcols; -extern int neednl; extern config_t *config; /* does the same thing as 'mkdir -p' */ @@ -189,45 +188,6 @@ char *strtrim(char *str) return str; } -/* presents a prompt and gets a Y/N answer - */ -int yesno(char *fmt, ...) -{ - char response[32]; - va_list args; - - if(config->noconfirm) { - return(1); - } - - va_start(args, fmt); - vprintf(fmt, args); - va_end(args); - fflush(stdout); - neednl = 1; - 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); -} - /* match a string against a regular expression */ int reg_match(char *string, char *pattern) { diff --git a/src/pacman/util.h b/src/pacman/util.h index f9d8d847..3cce4d3d 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -45,7 +45,6 @@ int rmrf(char *path); void indentprint(char *str, int indent); char *strtrim(char *str); char *strtoupper(char *str); -int yesno(char *fmt, ...); int reg_match(char *string, char *pattern); #endif /* _PM_UTIL_H */ -- cgit v1.2.3-70-g09d2