1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-08-13 17:03:46 -04:00

- moved yesno() from util.c to log.c

- fixed a missing line feed in yesno when printing the message
This commit is contained in:
Aurelien Foret 2006-02-04 10:34:27 +00:00
parent fe0b4cccb2
commit 633c89b532
4 changed files with 42 additions and 47 deletions

View File

@ -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: */

View File

@ -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: */

View File

@ -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)
{

View File

@ -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 */