This will make it considerably easier to add colors properly to pacman down the road. --- src/pacman/callback.c | 24 ++++++++++++------------ src/pacman/remove.c | 2 +- src/pacman/sync.c | 14 +++++++------- src/pacman/util.c | 14 ++++++++++++++ src/pacman/util.h | 2 ++ 5 files changed, 36 insertions(+), 20 deletions(-) diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 01c6b61..c0bb074 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -232,7 +232,7 @@ void cb_event(alpm_event_t event, void *data1, void *data2) fputs((const char *)data1, stdout); break; case ALPM_EVENT_RETRIEVE_START: - printf(_(":: Retrieving packages ...\n")); + msg_printf(_("Retrieving packages ...\n")); break; case ALPM_EVENT_DISKSPACE_START: if(config->noprogressbar) { @@ -266,14 +266,14 @@ void cb_question(alpm_question_t event, void *data1, void *data2, switch(event) { case ALPM_QUESTION_INSTALL_IGNOREPKG: if(!config->op_s_downloadonly) { - *response = yesno(_(":: %s is in IgnorePkg/IgnoreGroup. Install anyway?"), + *response = yesno(_("%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(_("Replace %s with %s/%s?"), alpm_pkg_get_name(data1), (char *)data3, alpm_pkg_get_name(data2)); @@ -282,12 +282,12 @@ void cb_question(alpm_question_t event, void *data1, void *data2, /* 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 = 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?"), + *response = noyes(_("%s and %s are in conflict (%s). Remove %s?"), (char *)data1, (char *)data2, (char *)data3, @@ -304,9 +304,9 @@ void cb_question(alpm_question_t event, void *data1, void *data2, (char *)alpm_pkg_get_name(i->data)); count++; } - printf(_n( - ":: The following package cannot be upgraded due to unresolvable dependencies:\n", - ":: The following packages cannot be upgraded due to unresolvable dependencies:\n", + msg_printf(_n( + "The following package cannot be upgraded due to unresolvable dependencies:\n", + "The following packages cannot be upgraded due to unresolvable dependencies:\n", count)); list_display(" ", namelist, getcols(fileno(stdout))); printf("\n"); @@ -322,7 +322,7 @@ void cb_question(alpm_question_t event, void *data1, void *data2, alpm_list_t *providers = data1; size_t count = alpm_list_count(providers); char *depstring = alpm_dep_compute_string((alpm_depend_t *)data2); - printf(_(":: There are %zd providers available for %s:\n"), count, + msg_printf(_("There are %zd providers available for %s:\n"), count, depstring); free(depstring); select_display(providers); @@ -331,7 +331,7 @@ void cb_question(alpm_question_t event, void *data1, void *data2, break; case ALPM_QUESTION_LOCAL_NEWER: if(!config->op_s_downloadonly) { - *response = yesno(_(":: %s-%s: local version is newer. Upgrade anyway?"), + *response = yesno(_("%s-%s: local version is newer. Upgrade anyway?"), alpm_pkg_get_name(data1), alpm_pkg_get_version(data1)); } else { @@ -339,7 +339,7 @@ void cb_question(alpm_question_t event, void *data1, void *data2, } break; case ALPM_QUESTION_CORRUPTED_PKG: - *response = yesno(_(":: File %s is corrupted (%s).\n" + *response = yesno(_("File %s is corrupted (%s).\n" "Do you want to delete it?"), (char *)data1, alpm_strerror(*(alpm_errno_t *)data2)); @@ -356,7 +356,7 @@ void cb_question(alpm_question_t event, void *data1, void *data2, revoked = " (revoked)"; } - *response = yesno(_(":: Import PGP key %d%c/%s, \"%s\", created: %s%s?"), + *response = yesno(_("Import PGP key %d%c/%s, \"%s\", created: %s%s?"), key->length, key->pubkey_algo, key->fingerprint, key->uid, created, revoked); } break; diff --git a/src/pacman/remove.c b/src/pacman/remove.c index 472adb5..ebe4692 100644 --- a/src/pacman/remove.c +++ b/src/pacman/remove.c @@ -119,7 +119,7 @@ int pacman_remove(alpm_list_t *targets) for(i = data; i; i = alpm_list_next(i)) { alpm_depmissing_t *miss = i->data; char *depstring = alpm_dep_compute_string(miss->depend); - printf(_(":: %s: requires %s\n"), miss->target, depstring); + msg_printf(_("%s: requires %s\n"), miss->target, depstring); free(depstring); } break; diff --git a/src/pacman/sync.c b/src/pacman/sync.c index 532a667..34e7330 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -661,7 +661,7 @@ static int process_group(alpm_list_t *dbs, const char *group, int error) } if(config->print == 0) { - printf(_(":: There are %d members in group %s:\n"), count, + msg_printf(_("There are %d members in group %s:\n"), count, group); select_display(pkgs); char *array = malloc(count); @@ -786,7 +786,7 @@ static int sync_trans(alpm_list_t *targets) } if(config->op_s_upgrade) { - printf(_(":: Starting full system upgrade...\n")); + msg_printf(_("Starting full system upgrade...\n")); alpm_logaction(config->handle, "starting full system upgrade\n"); if(alpm_sync_sysupgrade(config->handle, config->op_s_upgrade >= 2) == -1) { pm_printf(ALPM_LOG_ERROR, "%s\n", alpm_strerror(alpm_errno(config->handle))); @@ -812,14 +812,14 @@ int sync_prepare_execute(void) case ALPM_ERR_PKG_INVALID_ARCH: for(i = data; i; i = alpm_list_next(i)) { const char *pkg = i->data; - printf(_(":: package %s does not have a valid architecture\n"), pkg); + msg_printf(_("package %s does not have a valid architecture\n"), pkg); } break; case ALPM_ERR_UNSATISFIED_DEPS: for(i = data; i; i = alpm_list_next(i)) { alpm_depmissing_t *miss = i->data; char *depstring = alpm_dep_compute_string(miss->depend); - printf(_(":: %s: requires %s\n"), miss->target, depstring); + msg_printf(_("%s: requires %s\n"), miss->target, depstring); free(depstring); } break; @@ -828,11 +828,11 @@ int sync_prepare_execute(void) alpm_conflict_t *conflict = i->data; /* only print reason if it contains new information */ if(conflict->reason->mod == ALPM_DEP_MOD_ANY) { - printf(_(":: %s and %s are in conflict\n"), + msg_printf(_("%s and %s are in conflict\n"), conflict->package1, conflict->package2); } else { char *reason = alpm_dep_compute_string(conflict->reason); - printf(_(":: %s and %s are in conflict (%s)\n"), + msg_printf(_("%s and %s are in conflict (%s)\n"), conflict->package1, conflict->package2, reason); free(reason); } @@ -953,7 +953,7 @@ int pacman_sync(alpm_list_t *targets) if(config->op_s_sync) { /* grab a fresh package list */ - printf(_(":: Synchronizing package databases...\n")); + msg_printf(_("Synchronizing package databases...\n")); alpm_logaction(config->handle, "synchronizing package lists\n"); if(!sync_synctree(config->op_s_sync, sync_dbs)) { return 1; diff --git a/src/pacman/util.c b/src/pacman/util.c index 5ed450e..e980e5d 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1491,6 +1491,7 @@ static int question(short preset, char *fmt, va_list args) fflush(stdout); fflush(stderr); + fprintf(stream, ":: "); vfprintf(stream, fmt, args); if(preset) { @@ -1552,6 +1553,19 @@ int noyes(char *fmt, ...) return ret; } +int msg_printf(const char *fmt, ...) +{ + int ret; + va_list args; + + printf(":: "); + va_start(args, fmt); + ret = vprintf(fmt, args); + va_end(args); + + return ret; +} + int pm_printf(alpm_loglevel_t level, const char *format, ...) { int ret; diff --git a/src/pacman/util.h b/src/pacman/util.h index 0dfdc85..644dcc4 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -75,6 +75,8 @@ int multiselect_question(char *array, int count); int yesno(char *fmt, ...); int noyes(char *fmt, ...); +int msg_printf(const char *fmt, ...); + int pm_printf(alpm_loglevel_t level, const char *format, ...) __attribute__((format(printf,2,3))); int pm_asprintf(char **string, const char *format, ...); int pm_vfprintf(FILE *stream, alpm_loglevel_t level, const char *format, va_list args) __attribute__((format(printf,3,0))); -- 1.8.0.1