diff -ur pacman-4.1.2.old/src/pacman/callback.c pacman-4.1.2/src/pacman/callback.c --- pacman-4.1.2.old/src/pacman/callback.c 2013-06-18 09:14:25.000000000 +0530 +++ pacman-4.1.2/src/pacman/callback.c 2014-05-10 12:39:24.432471953 +0530 @@ -314,14 +314,14 @@ switch(event) { case ALPM_QUESTION_INSTALL_IGNOREPKG: if(!config->op_s_downloadonly) { - *response = yesno(_("%s is in IgnorePkg/IgnoreGroup. Install anyway?"), + *response = yesno(1, 0, _("%s is in IgnorePkg/IgnoreGroup. Install anyway?"), alpm_pkg_get_name(data1)); } else { *response = 1; } break; case ALPM_QUESTION_REPLACE_PKG: - *response = yesno(_("Replace %s with %s/%s?"), + *response = yesno(1, 0, _("Replace %s with %s/%s?"), alpm_pkg_get_name(data1), (char *)data3, alpm_pkg_get_name(data2)); @@ -330,12 +330,12 @@ /* data parameters: target package, local package, conflict (strings) */ /* print conflict only if it contains new information */ if(strcmp(data1, data3) == 0 || strcmp(data2, data3) == 0) { - *response = noyes(_("%s and %s are in conflict. Remove %s?"), + *response = yesno(0, 0, _("%s and %s are in conflict. Remove %s?"), (char *)data1, (char *)data2, (char *)data2); } else { - *response = noyes(_("%s and %s are in conflict (%s). Remove %s?"), + *response = yesno(0, 0, _("%s and %s are in conflict (%s). Remove %s?"), (char *)data1, (char *)data2, (char *)data3, @@ -358,7 +358,7 @@ count)); list_display(" ", namelist, getcols(fileno(stdout))); printf("\n"); - *response = noyes(_n( + *response = 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)); @@ -379,7 +379,7 @@ break; case ALPM_QUESTION_LOCAL_NEWER: if(!config->op_s_downloadonly) { - *response = yesno(_("%s-%s: local version is newer. Upgrade anyway?"), + *response = yesno(1, 0, _("%s-%s: local version is newer. Upgrade anyway?"), alpm_pkg_get_name(data1), alpm_pkg_get_version(data1)); } else { @@ -387,7 +387,7 @@ } break; case ALPM_QUESTION_CORRUPTED_PKG: - *response = yesno(_("File %s is corrupted (%s).\n" + *response = yesno(1, 0, _("File %s is corrupted (%s).\n" "Do you want to delete it?"), (char *)data1, alpm_strerror(*(alpm_errno_t *)data2)); @@ -400,10 +400,10 @@ strftime(created, 12, "%Y-%m-%d", localtime(&time)); if(key->revoked) { - *response = yesno(_("Import PGP key %d%c/%s, \"%s\", created: %s (revoked)?"), + *response = yesno(1, 1, _("Import PGP key %d%c/%s, \"%s\", created: %s (revoked)?"), key->length, key->pubkey_algo, key->fingerprint, key->uid, created); } else { - *response = yesno(_("Import PGP key %d%c/%s, \"%s\", created: %s?"), + *response = yesno(1, 1, _("Import PGP key %d%c/%s, \"%s\", created: %s?"), key->length, key->pubkey_algo, key->fingerprint, key->uid, created); } } diff -ur pacman-4.1.2.old/src/pacman/conf.c pacman-4.1.2/src/pacman/conf.c --- pacman-4.1.2.old/src/pacman/conf.c 2013-05-07 08:29:44.000000000 +0530 +++ pacman-4.1.2/src/pacman/conf.c 2014-05-10 12:21:34.217424625 +0530 @@ -92,6 +92,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 | @@ -514,6 +515,20 @@ 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 { + 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.1.2.old/src/pacman/conf.h pacman-4.1.2/src/pacman/conf.h --- pacman-4.1.2.old/src/pacman/conf.h 2013-04-30 16:35:45.000000000 +0530 +++ pacman-4.1.2/src/pacman/conf.h 2014-05-10 12:24:35.346126668 +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; @@ -168,6 +169,11 @@ PM_COLOR_ON }; +enum { + PM_DEFAULT_ANSWER_SMART = 0, + PM_DEFAULT_ANSWER_SAFER /* Use safer (conservative) defaults */ +}; + /* global config variable */ extern config_t *config; diff -ur pacman-4.1.2.old/src/pacman/remove.c pacman-4.1.2/src/pacman/remove.c --- pacman-4.1.2.old/src/pacman/remove.c 2013-04-30 16:35:45.000000000 +0530 +++ pacman-4.1.2/src/pacman/remove.c 2014-05-10 12:41:29.182836680 +0530 @@ -141,7 +141,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; } @@ -161,7 +161,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.1.2.old/src/pacman/sync.c pacman-4.1.2/src/pacman/sync.c --- pacman-4.1.2.old/src/pacman/sync.c 2013-06-18 09:14:25.000000000 +0530 +++ pacman-4.1.2/src/pacman/sync.c 2014-05-10 12:44:19.157869330 +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; } @@ -799,9 +799,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.1.2.old/src/pacman/util.c pacman-4.1.2/src/pacman/util.c --- pacman-4.1.2.old/src/pacman/util.c 2013-05-07 08:29:44.000000000 +0530 +++ pacman-4.1.2/src/pacman/util.c 2014-05-10 12:57:42.578274269 +0530 @@ -1538,25 +1538,16 @@ return 0; } -int yesno(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(1, format, args); - va_end(args); - - return ret; -} - -int noyes(const char *format, ...) -{ - int ret; - va_list args; - - 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.1.2.old/src/pacman/util.h pacman-4.1.2/src/pacman/util.h --- pacman-4.1.2.old/src/pacman/util.h 2013-04-30 16:35:45.000000000 +0530 +++ pacman-4.1.2/src/pacman/util.h 2014-05-10 12:06:38.394256161 +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)));