diff -ur pacman-4.2.0.old/src/pacman/callback.c pacman-4.2.0/src/pacman/callback.c --- pacman-4.2.0.old/src/pacman/callback.c 2014-09-30 09:02:37.000000000 +0530 +++ pacman-4.2.0/src/pacman/callback.c 2014-12-29 17:43:25.580454965 +0530 @@ -369,7 +369,7 @@ { alpm_question_install_ignorepkg_t *q = &question->install_ignorepkg; if(!config->op_s_downloadonly) { - q->install = yesno(_("%s is in IgnorePkg/IgnoreGroup. Install anyway?"), + q->install = yesno(1, 0, _("%s is in IgnorePkg/IgnoreGroup. Install anyway?"), alpm_pkg_get_name(q->pkg)); } else { q->install = 1; @@ -379,7 +379,7 @@ case ALPM_QUESTION_REPLACE_PKG: { alpm_question_replace_t *q = &question->replace; - q->replace = yesno(_("Replace %s with %s/%s?"), + q->replace = yesno(1, 1, _("Replace %s with %s/%s?"), alpm_pkg_get_name(q->oldpkg), alpm_db_get_name(q->newdb), alpm_pkg_get_name(q->newpkg)); @@ -391,12 +391,12 @@ /* print conflict only if it contains new information */ if(strcmp(q->conflict->package1, q->conflict->reason->name) == 0 || strcmp(q->conflict->package2, q->conflict->reason->name) == 0) { - q->remove = noyes(_("%s and %s are in conflict. Remove %s?"), + q->remove = yesno(0, 0, _("%s and %s are in conflict. Remove %s?"), q->conflict->package1, q->conflict->package2, q->conflict->package2); } else { - q->remove = noyes(_("%s and %s are in conflict (%s). Remove %s?"), + q->remove = yesno(0, 0, _("%s and %s are in conflict (%s). Remove %s?"), q->conflict->package1, q->conflict->package2, q->conflict->reason->name, @@ -420,7 +420,7 @@ count)); list_display(" ", namelist, getcols()); printf("\n"); - q->skip = noyes(_n( + q->skip = yesno(0, 0, _n( "Do you want to skip the above package for this upgrade?", "Do you want to skip the above packages for this upgrade?", count)); @@ -442,7 +442,7 @@ case ALPM_QUESTION_CORRUPTED_PKG: { alpm_question_corrupted_t *q = &question->corrupted; - q->remove = yesno(_("File %s is corrupted (%s).\n" + q->remove = yesno(1, 0, _("File %s is corrupted (%s).\n" "Do you want to delete it?"), q->filepath, alpm_strerror(q->reason)); @@ -456,10 +456,10 @@ strftime(created, 12, "%Y-%m-%d", localtime(&time)); if(q->key->revoked) { - q->import = yesno(_("Import PGP key %d%c/%s, \"%s\", created: %s (revoked)?"), + q->import = yesno(1, 1, _("Import PGP key %d%c/%s, \"%s\", created: %s (revoked)?"), q->key->length, q->key->pubkey_algo, q->key->fingerprint, q->key->uid, created); } else { - q->import = yesno(_("Import PGP key %d%c/%s, \"%s\", created: %s?"), + q->import = yesno(1, 1, _("Import PGP key %d%c/%s, \"%s\", created: %s?"), q->key->length, q->key->pubkey_algo, q->key->fingerprint, q->key->uid, created); } } diff -ur pacman-4.2.0.old/src/pacman/conf.c pacman-4.2.0/src/pacman/conf.c --- pacman-4.2.0.old/src/pacman/conf.c 2014-12-19 09:18:00.000000000 +0530 +++ pacman-4.2.0/src/pacman/conf.c 2014-12-29 17:43:25.580454965 +0530 @@ -101,6 +101,7 @@ newconfig->op = PM_OP_MAIN; newconfig->logmask = ALPM_LOG_ERROR | ALPM_LOG_WARNING; newconfig->configfile = strdup(CONFFILE); + newconfig->default_answer = PM_DEFAULT_ANSWER_SMART; newconfig->deltaratio = 0.0; if(alpm_capabilities() & ALPM_CAPABILITY_SIGNATURES) { newconfig->siglevel = ALPM_SIG_PACKAGE | ALPM_SIG_PACKAGE_OPTIONAL | @@ -519,6 +520,23 @@ if(!config->arch) { config_set_arch(value); } + } else if(strcmp(key, "DefaultAnswer") == 0) { + if (strncasecmp(value, "smart", 5) == 0) { + config->default_answer = PM_DEFAULT_ANSWER_SMART; + } + else if(strncasecmp(value, "safe", 4) == 0) { + config->default_answer = PM_DEFAULT_ANSWER_SAFER; + } + else if(strcasecmp(value, "nodefault") == 0) { + config->default_answer = PM_DEFAULT_ANSWER_NODEFAULT; + } + else { + pm_printf(ALPM_LOG_ERROR, + _("config file %s, line %d: invalid value for '%s' : '%s'\n"), + file, linenum, "DefaultAnswer", value); + return 1; + } + pm_printf(ALPM_LOG_DEBUG, "config: defaultanswer = %s\n", value); } else if(strcmp(key, "UseDelta") == 0) { double ratio; char *endptr; diff -ur pacman-4.2.0.old/src/pacman/conf.h pacman-4.2.0/src/pacman/conf.h --- pacman-4.2.0.old/src/pacman/conf.h 2014-10-14 06:14:20.000000000 +0530 +++ pacman-4.2.0/src/pacman/conf.h 2014-12-29 17:43:25.580454965 +0530 @@ -47,6 +47,7 @@ unsigned short checkspace; unsigned short usesyslog; unsigned short color; + unsigned short default_answer; /* see enum below */ double deltaratio; char *arch; char *print_format; @@ -201,6 +202,12 @@ PM_COLOR_ON }; +enum { + PM_DEFAULT_ANSWER_SMART = 0, + PM_DEFAULT_ANSWER_SAFER, /* Use safer (conservative) defaults */ + PM_DEFAULT_ANSWER_NODEFAULT /* Neither 'yes' nor 'no' is default */ +}; + /* global config variable */ extern config_t *config; diff -ur pacman-4.2.0.old/src/pacman/remove.c pacman-4.2.0/src/pacman/remove.c --- pacman-4.2.0.old/src/pacman/remove.c 2014-09-16 10:25:59.000000000 +0530 +++ pacman-4.2.0/src/pacman/remove.c 2014-12-29 17:43:25.580454965 +0530 @@ -145,7 +145,7 @@ holdpkg = 1; } } - if(holdpkg && (noyes(_("HoldPkg was found in target list. Do you want to continue?")) == 0)) { + if(holdpkg && (yesno(0, 0, _("HoldPkg was found in target list. Do you want to continue?")) == 0)) { retval = 1; goto cleanup; } @@ -165,7 +165,7 @@ /* print targets and ask user confirmation */ display_targets(); printf("\n"); - if(yesno(_("Do you want to remove these packages?")) == 0) { + if(yesno(1, 0, _("Do you want to remove these packages?")) == 0) { retval = 1; goto cleanup; } diff -ur pacman-4.2.0.old/src/pacman/sync.c pacman-4.2.0/src/pacman/sync.c --- pacman-4.2.0.old/src/pacman/sync.c 2014-12-19 09:18:00.000000000 +0530 +++ pacman-4.2.0/src/pacman/sync.c 2014-12-29 17:43:25.580454965 +0530 @@ -145,7 +145,7 @@ dbpath = alpm_option_get_dbpath(config->handle); printf(_("Database directory: %s\n"), dbpath); - if(!yesno(_("Do you want to remove unused repositories?"))) { + if(!yesno(1, 0, _("Do you want to remove unused repositories?"))) { return 0; } printf(_("removing unused sync repositories...\n")); @@ -196,13 +196,13 @@ printf(_("Cache directory: %s\n"), (const char *)i->data); if(level == 1) { - if(!yesno(_("Do you want to remove all other packages from cache?"))) { + if(!yesno(1, 0, _("Do you want to remove all other packages from cache?"))) { printf("\n"); continue; } printf(_("removing old packages from cache...\n")); } else { - if(!noyes(_("Do you want to remove ALL files from cache?"))) { + if(!yesno(0, 0, _("Do you want to remove ALL files from cache?"))) { printf("\n"); continue; } @@ -822,9 +822,9 @@ int confirm; if(config->op_s_downloadonly) { - confirm = yesno(_("Proceed with download?")); + confirm = yesno(1, 0, _("Proceed with download?")); } else { - confirm = yesno(_("Proceed with installation?")); + confirm = yesno(1, 0, _("Proceed with installation?")); } if(!confirm) { retval = 1; diff -ur pacman-4.2.0.old/src/pacman/util.c pacman-4.2.0/src/pacman/util.c --- pacman-4.2.0.old/src/pacman/util.c 2014-10-01 17:23:10.000000000 +0530 +++ pacman-4.2.0/src/pacman/util.c 2014-12-29 17:43:25.583788392 +0530 @@ -1498,6 +1498,7 @@ char response[32]; FILE *stream; int fd_in = fileno(stdin); + const char *yesnostr = "[y/n]"; if(config->noconfirm) { stream = stdout; @@ -1513,11 +1514,10 @@ fputs(config->colstr.colon, stream); vfprintf(stream, format, args); - if(preset) { - fprintf(stream, " %s ", _("[Y/n]")); - } else { - fprintf(stream, " %s ", _("[y/N]")); + if (config->noconfirm || config->default_answer != PM_DEFAULT_ANSWER_NODEFAULT) { + yesnostr = (preset ? "[Y/n]" : "[y/N]"); } + fprintf(stream, " %s ", _(yesnostr)); fputs(config->colstr.nocolor, stream); fflush(stream); @@ -1529,9 +1529,9 @@ flush_term_input(fd_in); - if(safe_fgets(response, sizeof(response), stdin)) { + while(safe_fgets(response, sizeof(response), stdin)) { size_t len = strtrim(response); - if(len == 0) { + if(len == 0 && config->default_answer != PM_DEFAULT_ANSWER_NODEFAULT) { return preset; } @@ -1546,29 +1546,26 @@ } else if(strcasecmp(response, _("N")) == 0 || strcasecmp(response, _("NO")) == 0) { return 0; } + else { + fputs(config->colstr.colon, stream); + fprintf(stream, "%s %s ", _("You must specify Yes or No"), _(yesnostr)); + fputs(config->colstr.nocolor, stream); + fflush(stream); + } } return 0; } -int yesno(const char *format, ...) -{ - int ret; - va_list args; - - va_start(args, format); - ret = question(1, format, args); - va_end(args); - - return ret; -} - -int noyes(const char *format, ...) +int yesno(short preset, short safepreset, const char *format, ...) { int ret; va_list args; + if(!config->noconfirm && config->default_answer == PM_DEFAULT_ANSWER_SAFER) { + preset = safepreset; + } va_start(args, format); - ret = question(0, format, args); + ret = question(preset ? 1 : 0, format, args); va_end(args); return ret; diff -ur pacman-4.2.0.old/src/pacman/util.h pacman-4.2.0/src/pacman/util.h --- pacman-4.2.0.old/src/pacman/util.h 2014-09-16 10:25:59.000000000 +0530 +++ pacman-4.2.0/src/pacman/util.h 2014-12-29 17:43:25.583788392 +0530 @@ -73,8 +73,7 @@ int select_question(int count); int multiselect_question(char *array, int count); int colon_printf(const char *format, ...) __attribute__((format(printf, 1, 2))); -int yesno(const char *format, ...) __attribute__((format(printf, 1, 2))); -int noyes(const char *format, ...) __attribute__((format(printf, 1, 2))); +int yesno(short preset, short safepreset, const char *format, ...) __attribute__((format(printf, 3, 4))); int pm_printf(alpm_loglevel_t level, const char *format, ...) __attribute__((format(printf,2,3))); int pm_asprintf(char **string, const char *format, ...) __attribute__((format(printf,2,3)));