mirror of
https://github.com/moparisthebest/pacman
synced 2024-12-23 00:08:50 -05:00
Improve yesno function.
Add a preset paramater to yesno function saying which answer should be the default. Ref: http://www.archlinux.org/pipermail/pacman-dev/2007-June/008470.html This allows us to answer no by default to some questions, like the -Scc one mentioned in the above thread, and implemented by this patch. Another advantage is that we don't have to repeat the [Y/n] in every questions. It's only put once in yesno function. This highly reduces the chances that YES and NO strings are translated, but not some questions, which lead to obvious confusions. Finally, the noconfirm variable only needs to be used in that yesno function. So all other usages of it were removed. Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
This commit is contained in:
parent
ca1a187131
commit
143135e666
@ -251,41 +251,33 @@ void cb_trans_conv(pmtransconv_t event, void *data1, void *data2,
|
|||||||
case PM_TRANS_CONV_INSTALL_IGNOREPKG:
|
case PM_TRANS_CONV_INSTALL_IGNOREPKG:
|
||||||
if(data2) {
|
if(data2) {
|
||||||
/* TODO we take this route based on data2 being not null? WTF */
|
/* TODO we take this route based on data2 being not null? WTF */
|
||||||
*response = yesno(_(":: %s requires installing %s from IgnorePkg/IgnoreGroup. Install anyway? [Y/n] "),
|
*response = yesno(1, _(":: %s requires installing %s from IgnorePkg/IgnoreGroup. Install anyway?"),
|
||||||
alpm_pkg_get_name(data1),
|
alpm_pkg_get_name(data1),
|
||||||
alpm_pkg_get_name(data2));
|
alpm_pkg_get_name(data2));
|
||||||
} else {
|
} else {
|
||||||
*response = yesno(_(":: %s is in IgnorePkg/IgnoreGroup. Install anyway? [Y/n] "),
|
*response = yesno(1, _(":: %s is in IgnorePkg/IgnoreGroup. Install anyway?"),
|
||||||
alpm_pkg_get_name(data1));
|
alpm_pkg_get_name(data1));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PM_TRANS_CONV_REMOVE_HOLDPKG:
|
case PM_TRANS_CONV_REMOVE_HOLDPKG:
|
||||||
*response = yesno(_(":: %s is designated as a HoldPkg. Remove anyway? [Y/n] "),
|
*response = yesno(1, _(":: %s is designated as a HoldPkg. Remove anyway?"),
|
||||||
alpm_pkg_get_name(data1));
|
alpm_pkg_get_name(data1));
|
||||||
break;
|
break;
|
||||||
case PM_TRANS_CONV_REPLACE_PKG:
|
case PM_TRANS_CONV_REPLACE_PKG:
|
||||||
if(!config->noconfirm) {
|
*response = yesno(1, _(":: Replace %s with %s/%s?"),
|
||||||
*response = yesno(_(":: Replace %s with %s/%s? [Y/n] "),
|
|
||||||
alpm_pkg_get_name(data1),
|
alpm_pkg_get_name(data1),
|
||||||
(char *)data3,
|
(char *)data3,
|
||||||
alpm_pkg_get_name(data2));
|
alpm_pkg_get_name(data2));
|
||||||
} else {
|
|
||||||
printf(_("Replacing %s with %s/%s\n"),
|
|
||||||
alpm_pkg_get_name(data1),
|
|
||||||
(char *)data3,
|
|
||||||
alpm_pkg_get_name(data2));
|
|
||||||
*response = 1;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case PM_TRANS_CONV_CONFLICT_PKG:
|
case PM_TRANS_CONV_CONFLICT_PKG:
|
||||||
*response = yesno(_(":: %s conflicts with %s. Remove %s? [Y/n] "),
|
*response = yesno(1, _(":: %s conflicts with %s. Remove %s?"),
|
||||||
(char *)data1,
|
(char *)data1,
|
||||||
(char *)data2,
|
(char *)data2,
|
||||||
(char *)data2);
|
(char *)data2);
|
||||||
break;
|
break;
|
||||||
case PM_TRANS_CONV_LOCAL_NEWER:
|
case PM_TRANS_CONV_LOCAL_NEWER:
|
||||||
if(!config->op_s_downloadonly) {
|
if(!config->op_s_downloadonly) {
|
||||||
*response = yesno(_(":: %s-%s: local version is newer. Upgrade anyway? [Y/n] "),
|
*response = yesno(1, _(":: %s-%s: local version is newer. Upgrade anyway?"),
|
||||||
alpm_pkg_get_name(data1),
|
alpm_pkg_get_name(data1),
|
||||||
alpm_pkg_get_version(data1));
|
alpm_pkg_get_version(data1));
|
||||||
} else {
|
} else {
|
||||||
@ -293,12 +285,8 @@ void cb_trans_conv(pmtransconv_t event, void *data1, void *data2,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PM_TRANS_CONV_CORRUPTED_PKG:
|
case PM_TRANS_CONV_CORRUPTED_PKG:
|
||||||
if(!config->noconfirm) {
|
*response = yesno(1, _(":: File %s is corrupted. Do you want to delete it?"),
|
||||||
*response = yesno(_(":: File %s is corrupted. Do you want to delete it? [Y/n] "),
|
|
||||||
(char *)data1);
|
(char *)data1);
|
||||||
} else {
|
|
||||||
*response = 1;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,11 +75,11 @@ int pacman_remove(alpm_list_t *targets)
|
|||||||
|
|
||||||
printf(_(":: group %s:\n"), alpm_grp_get_name(grp));
|
printf(_(":: group %s:\n"), alpm_grp_get_name(grp));
|
||||||
list_display(" ", pkgnames);
|
list_display(" ", pkgnames);
|
||||||
all = yesno(_(" Remove whole content? [Y/n] "));
|
all = yesno(1, _(" Remove whole content?"));
|
||||||
|
|
||||||
for(p = pkgnames; p; p = alpm_list_next(p)) {
|
for(p = pkgnames; p; p = alpm_list_next(p)) {
|
||||||
char *pkg = alpm_list_getdata(p);
|
char *pkg = alpm_list_getdata(p);
|
||||||
if(all || yesno(_(":: Remove %s from group %s? [Y/n] "), pkg, (char *)alpm_list_getdata(i))) {
|
if(all || yesno(1, _(":: Remove %s from group %s?"), pkg, (char *)alpm_list_getdata(i))) {
|
||||||
finaltargs = alpm_list_add(finaltargs, strdup(pkg));
|
finaltargs = alpm_list_add(finaltargs, strdup(pkg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -155,7 +155,7 @@ int pacman_remove(alpm_list_t *targets)
|
|||||||
list_display(_("Targets:"), lst);
|
list_display(_("Targets:"), lst);
|
||||||
FREELIST(lst);
|
FREELIST(lst);
|
||||||
/* get confirmation */
|
/* get confirmation */
|
||||||
if(yesno(_("\nDo you want to remove these packages? [Y/n] ")) == 0) {
|
if(yesno(1, _("\nDo you want to remove these packages?")) == 0) {
|
||||||
remove_cleanup();
|
remove_cleanup();
|
||||||
FREELIST(finaltargs);
|
FREELIST(finaltargs);
|
||||||
return(1);
|
return(1);
|
||||||
|
@ -89,7 +89,7 @@ static int sync_cleandb(const char *dbpath, int keep_used) {
|
|||||||
/* We have a directory that doesn't match any syncdb.
|
/* We have a directory that doesn't match any syncdb.
|
||||||
* Ask the user if he wants to remove it. */
|
* Ask the user if he wants to remove it. */
|
||||||
if(!found) {
|
if(!found) {
|
||||||
if(!yesno(_("Do you want to remove %s? [Y/n] "), path)) {
|
if(!yesno(1, _("Do you want to remove %s?"), path)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ static int sync_cleandb_all(void) {
|
|||||||
char newdbpath[PATH_MAX];
|
char newdbpath[PATH_MAX];
|
||||||
|
|
||||||
printf(_("Database directory: %s\n"), dbpath);
|
printf(_("Database directory: %s\n"), dbpath);
|
||||||
if(!yesno(_("Do you want to remove unused repositories? [Y/n] "))) {
|
if(!yesno(1, _("Do you want to remove unused repositories?"))) {
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
/* The sync dbs were previously put in dbpath/, but are now in dbpath/sync/,
|
/* The sync dbs were previously put in dbpath/, but are now in dbpath/sync/,
|
||||||
@ -138,7 +138,7 @@ static int sync_cleancache(int level)
|
|||||||
* package and see if it has an entry in the local DB; if not, delete it.
|
* package and see if it has an entry in the local DB; if not, delete it.
|
||||||
*/
|
*/
|
||||||
printf(_("Cache directory: %s\n"), cachedir);
|
printf(_("Cache directory: %s\n"), cachedir);
|
||||||
if(!yesno(_("Do you want to remove uninstalled packages from cache? [Y/n] "))) {
|
if(!yesno(1, _("Do you want to remove uninstalled packages from cache?"))) {
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
printf(_("removing old packages from cache... "));
|
printf(_("removing old packages from cache... "));
|
||||||
@ -185,7 +185,7 @@ static int sync_cleancache(int level)
|
|||||||
} else {
|
} else {
|
||||||
/* full cleanup */
|
/* full cleanup */
|
||||||
printf(_("Cache directory: %s\n"), cachedir);
|
printf(_("Cache directory: %s\n"), cachedir);
|
||||||
if(!yesno(_("Do you want to remove ALL packages from cache? [Y/n] "))) {
|
if(!yesno(0, _("Do you want to remove ALL packages from cache?"))) {
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
printf(_("removing all packages from cache... "));
|
printf(_("removing all packages from cache... "));
|
||||||
@ -545,8 +545,8 @@ static int sync_trans(alpm_list_t *targets)
|
|||||||
if(strcmp("pacman", alpm_pkg_get_name(spkg)) == 0) {
|
if(strcmp("pacman", alpm_pkg_get_name(spkg)) == 0) {
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf(_(":: pacman has detected a newer version of itself.\n"));
|
printf(_(":: pacman has detected a newer version of itself.\n"));
|
||||||
if(yesno(_(":: Do you want to cancel the current operation\n"
|
if(yesno(1, _(":: Do you want to cancel the current operation\n"
|
||||||
":: and install the new pacman version now? [Y/n] "))) {
|
":: and install the new pacman version now?"))) {
|
||||||
if(sync_trans_release() == -1) {
|
if(sync_trans_release() == -1) {
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
@ -597,14 +597,14 @@ static int sync_trans(alpm_list_t *targets)
|
|||||||
const alpm_list_t *grppkgs = alpm_grp_get_pkgs(grp);
|
const alpm_list_t *grppkgs = alpm_grp_get_pkgs(grp);
|
||||||
alpm_list_t *pkgs = alpm_list_remove_dupes(grppkgs);
|
alpm_list_t *pkgs = alpm_list_remove_dupes(grppkgs);
|
||||||
list_display(" ", pkgs);
|
list_display(" ", pkgs);
|
||||||
if(yesno(_(":: Install whole content? [Y/n] "))) {
|
if(yesno(1, _(":: Install whole content?"))) {
|
||||||
for(k = pkgs; k; k = alpm_list_next(k)) {
|
for(k = pkgs; k; k = alpm_list_next(k)) {
|
||||||
targets = alpm_list_add(targets, strdup(alpm_list_getdata(k)));
|
targets = alpm_list_add(targets, strdup(alpm_list_getdata(k)));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for(k = pkgs; k; k = alpm_list_next(k)) {
|
for(k = pkgs; k; k = alpm_list_next(k)) {
|
||||||
char *pkgname = alpm_list_getdata(k);
|
char *pkgname = alpm_list_getdata(k);
|
||||||
if(yesno(_(":: Install %s from group %s? [Y/n] "), pkgname, targ)) {
|
if(yesno(1, _(":: Install %s from group %s?"), pkgname, targ)) {
|
||||||
targets = alpm_list_add(targets, strdup(pkgname));
|
targets = alpm_list_add(targets, strdup(pkgname));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -693,19 +693,9 @@ static int sync_trans(alpm_list_t *targets)
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
if(config->op_s_downloadonly) {
|
if(config->op_s_downloadonly) {
|
||||||
if(config->noconfirm) {
|
confirm = yesno(1, _("Proceed with download?"));
|
||||||
printf(_("Beginning download...\n"));
|
|
||||||
confirm = 1;
|
|
||||||
} else {
|
} else {
|
||||||
confirm = yesno(_("Proceed with download? [Y/n] "));
|
confirm = yesno(1, _("Proceed with installation?"));
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if(config->noconfirm) {
|
|
||||||
printf(_("Beginning upgrade process...\n"));
|
|
||||||
confirm = 1;
|
|
||||||
} else {
|
|
||||||
confirm = yesno(_("Proceed with installation? [Y/n] "));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if(!confirm) {
|
if(!confirm) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -527,28 +527,44 @@ void display_targets(const alpm_list_t *syncpkgs, pmdb_t *db_local)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* presents a prompt and gets a Y/N answer */
|
/* presents a prompt and gets a Y/N answer */
|
||||||
/* TODO there must be a better way */
|
int yesno(short preset, char *fmt, ...)
|
||||||
int yesno(char *fmt, ...)
|
|
||||||
{
|
{
|
||||||
char response[32];
|
char response[32];
|
||||||
va_list args;
|
va_list args;
|
||||||
|
FILE *stream;
|
||||||
|
|
||||||
if(config->noconfirm) {
|
if(config->noconfirm) {
|
||||||
return(1);
|
stream = stdout;
|
||||||
|
} else {
|
||||||
|
/* Use stderr so questions are always displayed when redirecting output */
|
||||||
|
stream = stderr;
|
||||||
}
|
}
|
||||||
|
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
/* Use stderr so questions are always displayed when redirecting output */
|
vfprintf(stream, fmt, args);
|
||||||
vfprintf(stderr, fmt, args);
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
if(fgets(response, 32, stdin)) {
|
if(preset) {
|
||||||
if(strlen(response) != 0) {
|
fprintf(stream, " %s ", _("[Y/n]"));
|
||||||
strtrim(response);
|
} else {
|
||||||
|
fprintf(stream, " %s ", _("[y/N]"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!strcasecmp(response, _("Y")) || !strcasecmp(response, _("YES")) || strlen(response) == 0) {
|
if(config->noconfirm) {
|
||||||
|
fprintf(stream, "\n");
|
||||||
|
return(preset);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(fgets(response, 32, stdin)) {
|
||||||
|
strtrim(response);
|
||||||
|
if(strlen(response) == 0) {
|
||||||
|
return(preset);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!strcasecmp(response, _("Y")) || !strcasecmp(response, _("YES"))) {
|
||||||
return(1);
|
return(1);
|
||||||
|
} else if (!strcasecmp(response, _("N")) || !strcasecmp(response, _("NO"))) {
|
||||||
|
return(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return(0);
|
return(0);
|
||||||
|
@ -50,7 +50,7 @@ alpm_list_t *strsplit(const char *str, const char splitchar);
|
|||||||
void string_display(const char *title, const char *string);
|
void string_display(const char *title, const char *string);
|
||||||
void list_display(const char *title, const alpm_list_t *list);
|
void list_display(const char *title, const alpm_list_t *list);
|
||||||
void display_targets(const alpm_list_t *syncpkgs, pmdb_t *db_local);
|
void display_targets(const alpm_list_t *syncpkgs, pmdb_t *db_local);
|
||||||
int yesno(char *fmt, ...);
|
int yesno(short preset, char *fmt, ...);
|
||||||
int pm_printf(pmloglevel_t level, const char *format, ...) __attribute__((format(printf,2,3)));
|
int pm_printf(pmloglevel_t level, const char *format, ...) __attribute__((format(printf,2,3)));
|
||||||
int pm_fprintf(FILE *stream, pmloglevel_t level, const char *format, ...) __attribute__((format(printf,3,4)));
|
int pm_fprintf(FILE *stream, pmloglevel_t level, const char *format, ...) __attribute__((format(printf,3,4)));
|
||||||
int pm_vfprintf(FILE *stream, pmloglevel_t level, const char *format, va_list args) __attribute__((format(printf,3,0)));
|
int pm_vfprintf(FILE *stream, pmloglevel_t level, const char *format, va_list args) __attribute__((format(printf,3,0)));
|
||||||
|
Loading…
Reference in New Issue
Block a user