summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorOlivier Brunel <jjk@jjacky.com>2014-06-15 19:42:40 +0200
committerAllan McRae <allan@archlinux.org>2014-06-24 13:52:15 +1000
commitf1fadecfb34555cfac1c47f217253a535d64a28b (patch)
tree4221201d464af1d0ca234ef05cfd629c00a466e8 /src
parentd06d993d56bda499be31042bd39aaea9b8b11e3d (diff)
downloadpacman-f1fadecfb34555cfac1c47f217253a535d64a28b.tar.xz
Update the question callback
Much like with events, instead of using a bunch of void* arguments for all questions, we now send one pointer to an alpm_question_t union. This contains the type of question that was triggered. With this information, a question-specific struct can be accessed in order to get additional arguments. Signed-off-by: Olivier Brunel <jjk@jjacky.com> Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'src')
-rw-r--r--src/pacman/callback.c110
-rw-r--r--src/pacman/callback.h3
2 files changed, 61 insertions, 52 deletions
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index 340a3a1c..e3de75dd 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -361,55 +361,62 @@ void cb_event(alpm_event_t *event)
}
/* callback to handle questions from libalpm transactions (yes/no) */
-/* TODO this is one of the worst ever functions written. void *data ? wtf */
-void cb_question(alpm_question_t event, void *data1, void *data2,
- void *data3, int *response)
+void cb_question(alpm_question_t *question)
{
if(config->print) {
- if(event == ALPM_QUESTION_INSTALL_IGNOREPKG) {
- *response = 1;
+ if(question->type == ALPM_QUESTION_INSTALL_IGNOREPKG) {
+ question->any.answer = 1;
} else {
- *response = 0;
+ question->any.answer = 0;
}
return;
}
- switch(event) {
+ switch(question->type) {
case ALPM_QUESTION_INSTALL_IGNOREPKG:
- if(!config->op_s_downloadonly) {
- *response = yesno(_("%s is in IgnorePkg/IgnoreGroup. Install anyway?"),
- alpm_pkg_get_name(data1));
- } else {
- *response = 1;
+ {
+ alpm_question_install_ignorepkg_t *q = &question->install_ignorepkg;
+ if(!config->op_s_downloadonly) {
+ q->install = yesno(_("%s is in IgnorePkg/IgnoreGroup. Install anyway?"),
+ alpm_pkg_get_name(q->pkg));
+ } else {
+ q->install = 1;
+ }
}
break;
case ALPM_QUESTION_REPLACE_PKG:
- *response = yesno(_("Replace %s with %s/%s?"),
- alpm_pkg_get_name(data1),
- (char *)data3,
- alpm_pkg_get_name(data2));
+ {
+ alpm_question_replace_t *q = &question->replace;
+ q->replace = yesno(_("Replace %s with %s/%s?"),
+ alpm_pkg_get_name(q->oldpkg),
+ alpm_db_get_name(q->newdb),
+ alpm_pkg_get_name(q->newpkg));
+ }
break;
case ALPM_QUESTION_CONFLICT_PKG:
- /* 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?"),
- (char *)data1,
- (char *)data2,
- (char *)data2);
- } else {
- *response = noyes(_("%s and %s are in conflict (%s). Remove %s?"),
- (char *)data1,
- (char *)data2,
- (char *)data3,
- (char *)data2);
+ {
+ alpm_question_conflict_t *q = &question->conflict;
+ /* 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->conflict->package1,
+ q->conflict->package2,
+ q->conflict->package2);
+ } else {
+ q->remove = noyes(_("%s and %s are in conflict (%s). Remove %s?"),
+ q->conflict->package1,
+ q->conflict->package2,
+ q->conflict->reason->name,
+ q->conflict->package2);
+ }
}
break;
case ALPM_QUESTION_REMOVE_PKGS:
{
- alpm_list_t *unresolved = data1;
+ alpm_question_remove_pkgs_t *q = &question->remove_pkgs;
alpm_list_t *namelist = NULL, *i;
size_t count = 0;
- for(i = unresolved; i; i = i->next) {
+ for(i = q->packages; i; i = i->next) {
namelist = alpm_list_add(namelist,
(char *)alpm_pkg_get_name(i->data));
count++;
@@ -420,7 +427,7 @@ void cb_question(alpm_question_t event, void *data1, void *data2,
count));
list_display(" ", namelist, getcols(fileno(stdout)));
printf("\n");
- *response = noyes(_n(
+ q->skip = noyes(_n(
"Do you want to skip the above package for this upgrade?",
"Do you want to skip the above packages for this upgrade?",
count));
@@ -429,43 +436,46 @@ void cb_question(alpm_question_t event, void *data1, void *data2,
break;
case ALPM_QUESTION_SELECT_PROVIDER:
{
- alpm_list_t *providers = data1;
- size_t count = alpm_list_count(providers);
- char *depstring = alpm_dep_compute_string((alpm_depend_t *)data2);
+ alpm_question_select_provider_t *q = &question->select_provider;
+ size_t count = alpm_list_count(q->providers);
+ char *depstring = alpm_dep_compute_string(q->depend);
colon_printf(_("There are %zd providers available for %s:\n"), count,
depstring);
free(depstring);
- select_display(providers);
- *response = select_question(count);
+ select_display(q->providers);
+ q->use_index = select_question(count);
}
break;
case ALPM_QUESTION_CORRUPTED_PKG:
- *response = yesno(_("File %s is corrupted (%s).\n"
- "Do you want to delete it?"),
- (char *)data1,
- alpm_strerror(*(alpm_errno_t *)data2));
+ {
+ alpm_question_corrupted_t *q = &question->corrupted;
+ q->remove = yesno(_("File %s is corrupted (%s).\n"
+ "Do you want to delete it?"),
+ q->filepath,
+ alpm_strerror(q->reason));
+ }
break;
case ALPM_QUESTION_IMPORT_KEY:
{
- alpm_pgpkey_t *key = data1;
+ alpm_question_import_key_t *q = &question->import_key;
char created[12];
- time_t time = (time_t)key->created;
+ time_t time = (time_t)q->key->created;
strftime(created, 12, "%Y-%m-%d", localtime(&time));
- if(key->revoked) {
- *response = yesno(_("Import PGP key %d%c/%s, \"%s\", created: %s (revoked)?"),
- key->length, key->pubkey_algo, key->fingerprint, key->uid, created);
+ if(q->key->revoked) {
+ q->import = yesno(_("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 {
- *response = yesno(_("Import PGP key %d%c/%s, \"%s\", created: %s?"),
- key->length, key->pubkey_algo, key->fingerprint, key->uid, created);
+ q->import = yesno(_("Import PGP key %d%c/%s, \"%s\", created: %s?"),
+ q->key->length, q->key->pubkey_algo, q->key->fingerprint, q->key->uid, created);
}
}
break;
}
if(config->noask) {
- if(config->ask & event) {
+ if(config->ask & question->type) {
/* inverse the default answer */
- *response = !*response;
+ question->any.answer = !question->any.answer;
}
}
}
diff --git a/src/pacman/callback.h b/src/pacman/callback.h
index f16f7fc8..e4941fc7 100644
--- a/src/pacman/callback.h
+++ b/src/pacman/callback.h
@@ -28,8 +28,7 @@
void cb_event(alpm_event_t *event);
/* callback to handle questions from libalpm (yes/no) */
-void cb_question(alpm_question_t event, void *data1, void *data2,
- void *data3, int *response);
+void cb_question(alpm_question_t* question);
/* callback to handle display of progress */
void cb_progress(alpm_progress_t event, const char *pkgname, int percent,