From 961be77c93b487987600cd041bef3aa656949724 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Thu, 26 Apr 2007 15:28:54 -0400 Subject: Remove MSG output macro (#define and in code) This is the first step of converting output to standard functions such as printf, and eventually allowing compiliation with the -pedantic flag as is done on the libalpm side. Signed-off-by: Dan McGee --- src/pacman/add.c | 31 +++++----- src/pacman/callback.c | 72 ++++++++++-------------- src/pacman/deptest.c | 2 +- src/pacman/output.c | 6 -- src/pacman/output.h | 1 - src/pacman/pacman.c | 11 +--- src/pacman/query.c | 22 ++++---- src/pacman/remove.c | 20 +++---- src/pacman/sync.c | 153 +++++++++++++++++++++++++------------------------- src/pacman/util.c | 23 ++++---- 10 files changed, 158 insertions(+), 183 deletions(-) (limited to 'src') diff --git a/src/pacman/add.c b/src/pacman/add.c index ae32596d..20c7fd68 100644 --- a/src/pacman/add.c +++ b/src/pacman/add.c @@ -94,26 +94,27 @@ int pacman_add(alpm_list_t *targets) /* TODO: error messages should be in the front end, not the back */ ERR(NL, "%s\n", alpm_strerror(pm_errno)); if(pm_errno == PM_ERR_HANDLE_LOCK) { - MSG(NL, _(" if you're sure a package manager is not already running,\n" - " you can remove %s%s\n"), alpm_option_get_root(), PM_LOCK); + /* TODO this and the 2 other places should probably be on stderr */ + printf(_(" if you're sure a package manager is not already\n" + " running, you can remove %s%s.\n"), + alpm_option_get_root(), PM_LOCK); } return(1); } /* add targets to the created transaction */ - MSG(NL, _("loading package data... ")); + printf(_("loading package data... ")); for(i = targets; i; i = alpm_list_next(i)) { char *targ = alpm_list_getdata(i); if(alpm_trans_addtarget(targ) == -1) { /* TODO: glad this output is hacky */ - MSG(NL, "\n"); ERR(NL, _("failed to add target '%s' (%s)"), targ, alpm_strerror(pm_errno)); retval = 1; goto cleanup; } } - MSG(CL, _("done.\n")); + printf(_("done.\n")); /* Step 2: "compute" the transaction based on targets and flags */ /* TODO: No, compute nothing. This is stupid. */ @@ -129,28 +130,28 @@ int pacman_add(alpm_list_t *targets) /* TODO indicate if the error was a virtual package or not: * :: %s: requires %s, provided by %s */ - MSG(NL, _(":: %s: requires %s"), alpm_dep_get_target(miss), + printf(_(":: %s: requires %s"), alpm_dep_get_target(miss), alpm_dep_get_name(miss)); switch(alpm_dep_get_mod(miss)) { case PM_DEP_MOD_ANY: break; case PM_DEP_MOD_EQ: - MSG(CL, "=%s", alpm_dep_get_version(miss)); + printf("=%s", alpm_dep_get_version(miss)); break; case PM_DEP_MOD_GE: - MSG(CL, ">=%s", alpm_dep_get_version(miss)); + printf(">=%s", alpm_dep_get_version(miss)); break; case PM_DEP_MOD_LE: - MSG(CL, "<=%s", alpm_dep_get_version(miss)); + printf("<=%s", alpm_dep_get_version(miss)); break; } - MSG(CL, "\n"); + printf("\n"); } break; case PM_ERR_CONFLICTING_DEPS: for(i = data; i; i = alpm_list_next(i)) { pmdepmissing_t *miss = alpm_list_getdata(i); - MSG(NL, _(":: %s: conflicts with %s"), + printf(_(":: %s: conflicts with %s"), alpm_dep_get_target(miss), alpm_dep_get_name(miss)); } break; @@ -159,19 +160,19 @@ int pacman_add(alpm_list_t *targets) pmconflict_t *conflict = alpm_list_getdata(i); switch(alpm_conflict_get_type(conflict)) { case PM_CONFLICT_TYPE_TARGET: - MSG(NL, _("%s exists in both '%s' and '%s'\n"), + printf(_("%s exists in both '%s' and '%s'\n"), alpm_conflict_get_file(conflict), alpm_conflict_get_target(conflict), alpm_conflict_get_ctarget(conflict)); break; case PM_CONFLICT_TYPE_FILE: - MSG(NL, _("%s: %s exists in filesystem\n"), + printf(_("%s: %s exists in filesystem\n"), alpm_conflict_get_target(conflict), alpm_conflict_get_file(conflict)); break; } } - MSG(NL, _("\nerrors occurred, no packages were upgraded.\n")); + printf(_("\nerrors occurred, no packages were upgraded.\n")); break; /* TODO This is gross... we should not return these values in the same * list we would get conflicts and such with... it's just silly @@ -181,7 +182,7 @@ int pacman_add(alpm_list_t *targets) pkgsize = alpm_list_getdata(i); i = alpm_list_next(i); freespace = alpm_list_getdata(i); - MSG(NL, _(":: %.1f MB required, have %.1f MB"), + printf(_(":: %.1f MB required, have %.1f MB"), (double)(*pkgsize / (1024.0*1024.0)), (double)(*freespace / (1024.0*1024.0))); break; diff --git a/src/pacman/callback.c b/src/pacman/callback.c index abb47049..2c4923b4 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -129,43 +129,43 @@ void cb_trans_evt(pmtransevt_t event, void *data1, void *data2) switch(event) { case PM_TRANS_EVT_CHECKDEPS_START: - MSG(NL, _("checking dependencies... ")); + printf(_("checking dependencies... ")); break; case PM_TRANS_EVT_FILECONFLICTS_START: if(config->noprogressbar) { - MSG(NL, _("checking for file conflicts... ")); + printf(_("checking for file conflicts... ")); } break; case PM_TRANS_EVT_CLEANUP_START: - MSG(NL, _("cleaning up... ")); + printf(_("cleaning up... ")); break; case PM_TRANS_EVT_RESOLVEDEPS_START: - MSG(NL, _("resolving dependencies... ")); + printf(_("resolving dependencies... ")); break; case PM_TRANS_EVT_INTERCONFLICTS_START: - MSG(NL, _("looking for inter-conflicts... ")); + printf(_("looking for inter-conflicts... ")); break; case PM_TRANS_EVT_FILECONFLICTS_DONE: if(config->noprogressbar) { - MSG(CL, _("done.\n")); + printf(_("done.\n")); } break; case PM_TRANS_EVT_CHECKDEPS_DONE: case PM_TRANS_EVT_CLEANUP_DONE: case PM_TRANS_EVT_RESOLVEDEPS_DONE: case PM_TRANS_EVT_INTERCONFLICTS_DONE: - MSG(CL, _("done.\n")); + printf(_("done.\n")); break; case PM_TRANS_EVT_EXTRACT_DONE: break; case PM_TRANS_EVT_ADD_START: if(config->noprogressbar) { - MSG(NL, _("installing %s... "), alpm_pkg_get_name(data1)); + printf(_("installing %s... "), alpm_pkg_get_name(data1)); } break; case PM_TRANS_EVT_ADD_DONE: if(config->noprogressbar) { - MSG(CL, _("done.\n")); + printf(_("done.\n")); } snprintf(str, LOG_STR_LEN, _("installed %s (%s)"), alpm_pkg_get_name(data1), @@ -174,12 +174,12 @@ void cb_trans_evt(pmtransevt_t event, void *data1, void *data2) break; case PM_TRANS_EVT_REMOVE_START: if(config->noprogressbar) { - MSG(NL, _("removing %s... "), alpm_pkg_get_name(data1)); + printf(_("removing %s... "), alpm_pkg_get_name(data1)); } break; case PM_TRANS_EVT_REMOVE_DONE: if(config->noprogressbar) { - MSG(CL, _("done.\n")); + printf(_("done.\n")); } snprintf(str, LOG_STR_LEN, _("removed %s (%s)"), alpm_pkg_get_name(data1), @@ -188,12 +188,12 @@ void cb_trans_evt(pmtransevt_t event, void *data1, void *data2) break; case PM_TRANS_EVT_UPGRADE_START: if(config->noprogressbar) { - MSG(NL, _("upgrading %s... "), alpm_pkg_get_name(data1)); + printf(_("upgrading %s... "), alpm_pkg_get_name(data1)); } break; case PM_TRANS_EVT_UPGRADE_DONE: if(config->noprogressbar) { - MSG(CL, _("done.\n")); + printf(_("done.\n")); } snprintf(str, LOG_STR_LEN, _("upgraded %s (%s -> %s)"), (char *)alpm_pkg_get_name(data1), @@ -202,30 +202,30 @@ void cb_trans_evt(pmtransevt_t event, void *data1, void *data2) alpm_logaction(str); break; case PM_TRANS_EVT_INTEGRITY_START: - MSG(NL, _("checking package integrity... ")); + printf(_("checking package integrity... ")); break; case PM_TRANS_EVT_INTEGRITY_DONE: - MSG(CL, _("done.\n")); + printf(_("done.\n")); break; case PM_TRANS_EVT_SCRIPTLET_INFO: - MSG(NL, "%s\n", (char*)data1); + printf("%s\n", (char*)data1); break; case PM_TRANS_EVT_SCRIPTLET_START: - MSG(NL, (char*)data1); - MSG(CL, "..."); + printf((char*)data1); + printf("..."); break; case PM_TRANS_EVT_SCRIPTLET_DONE: if(!(long)data1) { - MSG(CL, _("done.\n")); + printf(_("done.\n")); } else { - MSG(CL, _("failed.\n")); + printf(_("failed.\n")); } break; case PM_TRANS_EVT_PRINTURI: - MSG(NL, "%s/%s\n", (char*)data1, (char*)data2); + printf("%s/%s\n", (char*)data1, (char*)data2); break; case PM_TRANS_EVT_RETRIEVE_START: - MSG(NL, _(":: Retrieving packages from %s...\n"), (char*)data1); + printf(_(":: Retrieving packages from %s...\n"), (char*)data1); fflush(stdout); break; } @@ -372,13 +372,9 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent, return; } - /* XXX: big fat hack: due to the fact that we switch out printf/pm_fprintf, - * not everything honors our 'neednl' newline hackery. This forces a newline - * if we need one before drawing the progress bar */ - MSG(NL,NULL); - if(percent == 0) { - set_output_padding(1); /* turn on output padding with ' ' */ + /* print a newline before we start our progressbar */ + printf("\n"); timediff = get_update_timediff(1); } else { timediff = get_update_timediff(0); @@ -452,10 +448,6 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent, /* call refactored fill progress function */ fill_progress(percent, getcols() - infolen); - - if(percent >= 100) { - set_output_padding(0); /* restore padding */ - } } /* callback to handle display of download progress */ @@ -473,13 +465,10 @@ void cb_dl_progress(const char *filename, int xfered, int total) return; } - /* XXX: big fat hack: due to the fact that we switch out printf/pm_fprintf, - * not everything honors our 'neednl' newline hackery. This forces a newline - * if we need one before drawing the progress bar */ - MSG(NL,NULL); - /* this is basically a switch on xferred: 0, total, and anything else */ if(xfered == 0) { + /* print a newline before we start our progressbar */ + printf("\n"); /* set default starting values */ gettimeofday(&initial_time, NULL); xfered_last = 0; @@ -487,7 +476,6 @@ void cb_dl_progress(const char *filename, int xfered, int total) timediff = get_update_timediff(1); rate = 0.0; eta_s = 0; - set_output_padding(1); /* we need padding from pm_fprintf output */ } else if(xfered == total) { /* compute final values */ struct timeval current_time; @@ -501,8 +489,6 @@ void cb_dl_progress(const char *filename, int xfered, int total) /* round elapsed time to the nearest second */ eta_s = (int)floorf(timediff + 0.5); - - set_output_padding(0); /* shut off padding */ } else { /* compute current average values */ timediff = get_update_timediff(0); @@ -615,12 +601,12 @@ void cb_log(unsigned short level, char *msg) strftime(timestr, 9, "%H:%M:%S", tmp); timestr[8] = '\0'; - MSG(NL, "[%s] %s: %s", timestr, str, msg); + printf("[%s] %s: %s", timestr, str, msg); } else { - MSG(NL, "%s: %s", str, msg); + printf("%s: %s", str, msg); } #else - MSG(NL, "%s: %s", str, msg); + printf("%s: %s", str, msg); #endif } diff --git a/src/pacman/deptest.c b/src/pacman/deptest.c index 409cc25b..120c8a00 100644 --- a/src/pacman/deptest.c +++ b/src/pacman/deptest.c @@ -79,7 +79,7 @@ int pacman_deptest(alpm_list_t *targets) } if(!found) { - MSG(NL, "%s", saved_target); + printf("%s", saved_target); retval = 1; } free(saved_target); diff --git a/src/pacman/output.c b/src/pacman/output.c index 23b03373..85defaa2 100644 --- a/src/pacman/output.c +++ b/src/pacman/output.c @@ -41,12 +41,6 @@ extern config_t *config; static int neednl = 0; /* for cleaner message output */ static int needpad = 0; /* pad blanks to terminal width */ -/* simple helper for needpad */ -void set_output_padding(int on) -{ - needpad = on; -} - /* Wrapper to fprintf() that allows to choose if we want the output * to be appended on the current line, or written to a new one */ diff --git a/src/pacman/output.h b/src/pacman/output.h index c116502a..b74a1dbf 100644 --- a/src/pacman/output.h +++ b/src/pacman/output.h @@ -25,7 +25,6 @@ /* TODO these are illegal in ISO C, thus the reason -pedantic was never used * as a compile flag for the pacman side of things (named variadic macros) */ -#define MSG(line, fmt, args...) pm_fprintf(stdout, line, fmt, ##args) #define ERR(line, fmt, args...) do { \ pm_fprintf(stderr, line, _("error: ")); \ pm_fprintf(stderr, CL, fmt, ##args); \ diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index d240263d..c4dc848f 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -202,17 +202,13 @@ static void cleanup(int signum) { if(signum==SIGSEGV) { - fprintf(stderr, "Internal pacman error: Segmentation fault\n" - "Please submit a full bug report, with the given package if appropriate.\n"); + fprintf(stderr, "Internal pacman error: Segmentation fault.\n" + "Please submit a full bug report with --debug if appropriate.\n"); exit(signum); } else if((signum == SIGINT) && (alpm_trans_release() == -1) && (pm_errno == PM_ERR_TRANS_COMMITING)) { return; } - if(signum != 0) { - /* TODO why is this here? */ - fprintf(stderr, "\n"); - } /* free alpm library resources */ if(alpm_release() == -1) { @@ -226,9 +222,6 @@ static void cleanup(int signum) config = NULL; } - /* This fixes up any missing newlines (neednl) */ - MSG(NL, ""); - exit(signum); } diff --git a/src/pacman/query.c b/src/pacman/query.c index bfe51af3..3f46da34 100644 --- a/src/pacman/query.c +++ b/src/pacman/query.c @@ -171,14 +171,14 @@ int pacman_query(alpm_list_t *targets) } if(config->op_q_upgrade) { - MSG(NL, _("Checking for package upgrades...")); + printf(_("Checking for package upgrades...")); alpm_list_t *syncpkgs; if((syncpkgs = alpm_get_upgrades()) != NULL) { display_targets(syncpkgs); return(0); } else { - MSG(NL, _("no upgrades found")); + printf(_("no upgrades found")); return(1); } } @@ -205,7 +205,7 @@ int pacman_query(alpm_list_t *targets) pkgnames = alpm_grp_get_pkgs(grp); for(p = pkgnames; p; p = alpm_list_next(p)) { - MSG(NL, "%s %s\n", grpname, (char *)alpm_list_getdata(p)); + printf("%s %s\n", grpname, (char *)alpm_list_getdata(p)); } } } else { @@ -213,7 +213,7 @@ int pacman_query(alpm_list_t *targets) if(grp) { alpm_list_t *p, *pkgnames = alpm_grp_get_pkgs(grp); for(p = pkgnames; p; p = alpm_list_next(p)) { - MSG(NL, "%s %s\n", package, (char *)alpm_list_getdata(p)); + printf("%s %s\n", package, (char *)alpm_list_getdata(p)); } } else { ERR(NL, _("group \"%s\" was not found\n"), package); @@ -241,8 +241,8 @@ int pacman_query(alpm_list_t *targets) dump_pkg_files(info); } if(!config->op_q_info && !config->op_q_list) { - MSG(NL, "%s %s\n", alpm_pkg_get_name(info), - alpm_pkg_get_version(info)); + printf("%s %s\n", alpm_pkg_get_name(info), + alpm_pkg_get_version(info)); } alpm_pkg_free(info); info = NULL; @@ -285,17 +285,17 @@ int pacman_query(alpm_list_t *targets) } } if(match==0) { - MSG(NL, "%s %s\n", pkgname, pkgver); + printf("%s %s\n", pkgname, pkgver); } } else if(config->op_q_list) { dump_pkg_files(info); } else if(config->op_q_orphans) { if(alpm_pkg_get_requiredby(info) == NULL && (long)alpm_pkg_get_reason(info) == PM_PKG_REASON_DEPEND) { - MSG(NL, "%s %s\n", pkgname, pkgver); + printf("%s %s\n", pkgname, pkgver); } } else { - MSG(NL, "%s %s\n", pkgname, pkgver); + printf("%s %s\n", pkgname, pkgver); } } } else { @@ -313,8 +313,8 @@ int pacman_query(alpm_list_t *targets) dump_pkg_files(info); } if(!config->op_q_info && !config->op_q_list) { - MSG(NL, "%s %s\n", alpm_pkg_get_name(info), - alpm_pkg_get_version(info)); + printf("%s %s\n", alpm_pkg_get_name(info), + alpm_pkg_get_version(info)); } if(config->op_q_changelog) { char changelog[PATH_MAX]; diff --git a/src/pacman/remove.c b/src/pacman/remove.c index bb1ea0d1..32570927 100644 --- a/src/pacman/remove.c +++ b/src/pacman/remove.c @@ -64,7 +64,7 @@ int pacman_remove(alpm_list_t *targets) int all; alpm_list_t *pkgnames = alpm_grp_get_pkgs(grp); - MSG(NL, _(":: group %s:\n"), alpm_grp_get_name(grp)); + printf(_(":: group %s:\n"), alpm_grp_get_name(grp)); list_display(" ", pkgnames); all = yesno(_(" Remove whole content? [Y/n] ")); @@ -85,20 +85,20 @@ int pacman_remove(alpm_list_t *targets) cb_trans_evt, cb_trans_conv, cb_trans_progress) == -1) { ERR(NL, _("failed to init transaction (%s)\n"), alpm_strerror(pm_errno)); if(pm_errno == PM_ERR_HANDLE_LOCK) { - MSG(NL, _(" if you're sure a package manager is not already running,\n" - " you can remove %s%s\n"), alpm_option_get_root(), PM_LOCK); + printf(_(" if you're sure a package manager is not already\n" + " running, you can remove %s%s.\n"), + alpm_option_get_root(), PM_LOCK); } FREELIST(finaltargs); return(1); } /* add targets to the created transaction */ - MSG(NL, _("loading package data... ")); + printf(_("loading package data... ")); for(i = finaltargs; i; i = alpm_list_next(i)) { char *targ = alpm_list_getdata(i); if(alpm_trans_addtarget(targ) == -1) { - /* TODO: glad this output is hacky */ - MSG(NL, "\n"); + printf("failed.\n"); ERR(NL, _("failed to add target '%s' (%s)\n"), targ, alpm_strerror(pm_errno)); retval = 1; @@ -113,8 +113,8 @@ int pacman_remove(alpm_list_t *targets) case PM_ERR_UNSATISFIED_DEPS: for(i = data; i; i = alpm_list_next(i)) { pmdepmissing_t *miss = alpm_list_getdata(i); - MSG(NL, _(":: %s is required by %s\n"), alpm_dep_get_target(miss), - alpm_dep_get_name(miss)); + printf(_(":: %s is required by %s\n"), alpm_dep_get_target(miss), + alpm_dep_get_name(miss)); } alpm_list_free(data); break; @@ -135,7 +135,7 @@ int pacman_remove(alpm_list_t *targets) pmpkg_t *pkg = alpm_list_getdata(i); lst = alpm_list_add(lst, strdup(alpm_pkg_get_name(pkg))); } - MSG(NL, "\n"); + printf("\n"); list_display(_("Targets:"), lst); FREELIST(lst); /* get confirmation */ @@ -143,7 +143,7 @@ int pacman_remove(alpm_list_t *targets) retval = 1; goto cleanup; } - MSG(NL, "\n"); + printf("\n"); } /* Step 3: actually perform the removal */ diff --git a/src/pacman/sync.c b/src/pacman/sync.c index 730aadde..b2a8958e 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -106,7 +106,7 @@ static int sync_cleancache(int level) if(!yesno(_("Do you want to remove old packages from cache? [Y/n] "))) return(0); - MSG(NL, _("removing old packages from cache... ")); + printf(_("removing old packages from cache... ")); dir = opendir(dirpath); if(dir == NULL) { ERR(NL, _("could not access cache directory\n")); @@ -172,7 +172,7 @@ static int sync_cleancache(int level) /* full cleanup */ if(!yesno(_("Do you want to remove all packages from cache? [Y/n] "))) return(0); - MSG(NL, _("removing all packages from cache... ")); + printf(_("removing all packages from cache... ")); if(rmrf(dirpath)) { ERR(NL, _("could not remove cache directory\n")); @@ -185,7 +185,7 @@ static int sync_cleancache(int level) } } - MSG(CL, _("done.\n")); + printf(_("done.\n")); return(0); } @@ -212,7 +212,7 @@ static int sync_synctree(int level, alpm_list_t *syncs) ERR(NL, _("failed to update %s (%s)\n"), alpm_db_get_name(db), alpm_strerror(pm_errno)); } } else if(ret == 1) { - MSG(NL, _(" %s is up to date\n"), alpm_db_get_name(db)); + printf(_(" %s is up to date\n"), alpm_db_get_name(db)); success++; } else { success++; @@ -287,7 +287,7 @@ static int sync_group(int level, alpm_list_t *syncs, alpm_list_t *targets) if(grp) { /* TODO this should be a lot cleaner, why two outputs? */ - MSG(NL, "%s\n", (char *)alpm_grp_get_name(grp)); + printf("%s\n", (char *)alpm_grp_get_name(grp)); list_display(" ", alpm_grp_get_pkgs(grp)); } } @@ -299,7 +299,7 @@ static int sync_group(int level, alpm_list_t *syncs, alpm_list_t *targets) for(j = alpm_db_getgrpcache(db); j; j = alpm_list_next(j)) { pmgrp_t *grp = alpm_list_getdata(j); - MSG(NL, "%s\n", (char *)alpm_grp_get_name(grp)); + printf("%s\n", (char *)alpm_grp_get_name(grp)); if(grp && level > 1) { list_display(" ", alpm_grp_get_pkgs(grp)); } @@ -347,7 +347,7 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets) if(strcmp(alpm_pkg_get_name(pkg), pkgstr) == 0) { dump_pkg_sync(pkg, alpm_db_get_name(db)); - MSG(NL, "\n"); + printf("\n"); foundpkg = 1; break; } @@ -367,7 +367,7 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets) if(strcmp(alpm_pkg_get_name(pkg), pkgstr) == 0) { dump_pkg_sync(pkg, alpm_db_get_name(db)); - MSG(NL, "\n"); + printf("\n"); foundpkg = 1; break; } @@ -384,7 +384,7 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets) for(j = alpm_db_getpkgcache(db); j; j = alpm_list_next(j)) { dump_pkg_sync(alpm_list_getdata(j), alpm_db_get_name(db)); - MSG(NL, "\n"); + printf("\n"); } } } @@ -427,7 +427,8 @@ static int sync_list(alpm_list_t *syncs, alpm_list_t *targets) for(j = alpm_db_getpkgcache(db); j; j = alpm_list_next(j)) { pmpkg_t *pkg = alpm_list_getdata(j); - MSG(NL, "%s %s %s\n", alpm_db_get_name(db), alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg)); + printf("%s %s %s\n", alpm_db_get_name(db), alpm_pkg_get_name(pkg), + alpm_pkg_get_version(pkg)); } } @@ -470,20 +471,20 @@ int pacman_sync(alpm_list_t *targets) return(sync_list(sync_dbs, targets)); } - /* Step 1: create a new transaction... - */ + /* Step 1: create a new transaction... */ if(alpm_trans_init(PM_TRANS_TYPE_SYNC, config->flags, cb_trans_evt, cb_trans_conv, cb_trans_progress) == -1) { ERR(NL, _("failed to init transaction (%s)\n"), alpm_strerror(pm_errno)); if(pm_errno == PM_ERR_HANDLE_LOCK) { - MSG(NL, _(" if you're sure a package manager is not already running,\n" - " you can remove %s%s\n"), alpm_option_get_root(), PM_LOCK); + printf(_(" if you're sure a package manager is not already\n" + " running, you can remove %s%s.\n"), + alpm_option_get_root(), PM_LOCK); } return(1); } if(config->op_s_sync) { /* grab a fresh package list */ - MSG(NL, _(":: Synchronizing package databases...\n")); + printf(_(":: Synchronizing package databases...\n")); alpm_logaction(_("synchronizing package lists")); if(!sync_synctree(config->op_s_sync, sync_dbs)) { ERR(NL, _("failed to synchronize any databases")); @@ -492,7 +493,7 @@ int pacman_sync(alpm_list_t *targets) } if(config->op_s_upgrade) { - MSG(NL, _(":: Starting full system upgrade...\n")); + printf(_(":: Starting full system upgrade...\n")); alpm_logaction(_("starting full system upgrade")); if(alpm_trans_sysupgrade() == -1) { ERR(NL, "%s\n", alpm_strerror(pm_errno)); @@ -500,9 +501,7 @@ int pacman_sync(alpm_list_t *targets) goto cleanup; } - /* check if pacman itself is one of the packages to upgrade. If so, we - * we should upgrade ourselves first and then re-exec as the new version. - * + /* check if pacman itself is one of the packages to upgrade. * this can prevent some of the "syntax error" problems users can have * when sysupgrade'ing with an older version of pacman. */ @@ -510,23 +509,27 @@ int pacman_sync(alpm_list_t *targets) for(i = data; i; i = alpm_list_next(i)) { pmsyncpkg_t *sync = alpm_list_getdata(i); pmpkg_t *spkg = alpm_sync_get_pkg(sync); - if(strcmp("pacman", alpm_pkg_get_name(spkg)) == 0 && alpm_list_count(data) > 1) { - MSG(NL, _("\n:: pacman has detected a newer version of the \"pacman\" package.\n")); - MSG(NL, _(":: It is recommended that you allow pacman to upgrade itself\n")); - MSG(NL, _(":: first, then you can re-run the operation with the newer version.\n")); - MSG(NL, "::\n"); - if(yesno(_(":: Upgrade pacman first? [Y/n] "))) { + /* TODO pacman name should probably not be hardcoded. In addition, we + * have problems on an -Syu if pacman has to pull in deps, so recommend + * an '-S pacman' operation */ + if(strcmp("pacman", alpm_pkg_get_name(spkg)) == 0) { + printf("\n"); + printf(_(":: pacman has detected a newer version of itself.\n" + ":: It is recommended that you upgrade pacman by itself\n" + ":: using 'pacman -S pacman', and then rerun the current\n" + ":: operation. If you wish to continue the operation and\n" + ":: not upgrade pacman seperately, answer no.\n")); + if(yesno(_(":: Cancel current operation? [Y/n] "))) { if(alpm_trans_release() == -1) { - ERR(NL, _("failed to release transaction (%s)\n"), alpm_strerror(pm_errno)); + ERR(NL, _("failed to release transaction (%s)\n"), + alpm_strerror(pm_errno)); retval = 1; goto cleanup; } - if(alpm_trans_init(PM_TRANS_TYPE_SYNC, config->flags, cb_trans_evt, cb_trans_conv, cb_trans_progress) == -1) { - ERR(NL, _("failed to init transaction (%s)\n"), alpm_strerror(pm_errno)); - if(pm_errno == PM_ERR_HANDLE_LOCK) { - MSG(NL, _(" if you're sure a package manager is not already running,\n" - " you can remove %s%s\n"), alpm_option_get_root(), PM_LOCK); - } + if(alpm_trans_init(PM_TRANS_TYPE_SYNC, config->flags, + cb_trans_evt, cb_trans_conv, cb_trans_progress) == -1) { + ERR(NL, _("failed to init transaction (%s)\n"), + alpm_strerror(pm_errno)); return(1); } if(alpm_trans_addtarget("pacman") == -1) { @@ -561,7 +564,7 @@ int pacman_sync(alpm_list_t *targets) grp = alpm_db_readgrp(db, targ); if(grp) { found++; - MSG(NL, _(":: group %s:\n"), targ); + printf(_(":: group %s:\n"), targ); /* remove dupe entries in case a package exists in multiple repos */ alpm_list_t *pkgs = alpm_list_remove_dupes(alpm_grp_get_pkgs(grp)); list_display(" ", pkgs); @@ -605,8 +608,7 @@ int pacman_sync(alpm_list_t *targets) } } - /* Step 2: "compute" the transaction based on targets and flags - */ + /* Step 2: "compute" the transaction based on targets and flags */ if(alpm_trans_prepare(&data) == -1) { long long *pkgsize, *freespace; ERR(NL, _("failed to prepare transaction (%s)\n"), alpm_strerror(pm_errno)); @@ -614,36 +616,36 @@ int pacman_sync(alpm_list_t *targets) case PM_ERR_UNSATISFIED_DEPS: for(i = data; i; i = alpm_list_next(i)) { pmdepmissing_t *miss = alpm_list_getdata(i); - MSG(NL, ":: %s %s %s", alpm_dep_get_target(miss), _("requires"), + printf(":: %s %s %s", alpm_dep_get_target(miss), _("requires"), alpm_dep_get_name(miss)); switch(alpm_dep_get_mod(miss)) { case PM_DEP_MOD_ANY: break; case PM_DEP_MOD_EQ: - MSG(CL, "=%s", alpm_dep_get_version(miss)); + printf("=%s", alpm_dep_get_version(miss)); break; case PM_DEP_MOD_GE: - MSG(CL, ">=%s", alpm_dep_get_version(miss)); + printf(">=%s", alpm_dep_get_version(miss)); break; case PM_DEP_MOD_LE: - MSG(CL, "<=%s", alpm_dep_get_version(miss)); + printf("<=%s", alpm_dep_get_version(miss)); break; } - MSG(CL, "\n"); + printf("\n"); } break; case PM_ERR_CONFLICTING_DEPS: for(i = data; i; i = alpm_list_next(i)) { pmdepmissing_t *miss = alpm_list_getdata(i); - MSG(NL, _(":: %s: conflicts with %s"), + printf(_(":: %s: conflicts with %s"), alpm_dep_get_target(miss), alpm_dep_get_name(miss)); } break; case PM_ERR_DISK_FULL: pkgsize = alpm_list_getdata(data); freespace = alpm_list_getdata(alpm_list_next(data)); - MSG(NL, _(":: %.1f MB required, have %.1f MB"), + printf(_(":: %.1f MB required, have %.1f MB"), (double)(*pkgsize / 1048576.0), (double)(*freespace / 1048576.0)); break; default: @@ -656,19 +658,19 @@ int pacman_sync(alpm_list_t *targets) packages = alpm_trans_get_pkgs(); if(packages == NULL) { /* nothing to do: just exit without complaining */ - MSG(NL, _(" local database is up to date\n")); + printf(_(" local database is up to date\n")); goto cleanup; } if(!(alpm_trans_get_flags() & PM_TRANS_FLAG_PRINTURIS)) { display_targets(packages); + printf("\n"); if(config->op_s_downloadonly) { if(config->noconfirm) { - MSG(NL, _("\nBeginning download...\n")); + printf(_("Beginning download...\n")); confirm = 1; } else { - MSG(NL, "\n"); confirm = yesno(_("Proceed with download? [Y/n] ")); } } else { @@ -677,10 +679,9 @@ int pacman_sync(alpm_list_t *targets) confirm = 1; } else { if(config->noconfirm) { - MSG(NL, _("\nBeginning upgrade process...\n")); + printf(_("Beginning upgrade process...\n")); confirm = 1; } else { - MSG(NL, "\n"); confirm = yesno(_("Proceed with installation? [Y/n] ")); } } @@ -690,45 +691,43 @@ int pacman_sync(alpm_list_t *targets) } }/* else 'print uris' requested. We're done at this point */ - /* Step 3: actually perform the installation - */ + /* Step 3: actually perform the installation */ if(alpm_trans_commit(&data) == -1) { ERR(NL, _("failed to commit transaction (%s)\n"), alpm_strerror(pm_errno)); switch(pm_errno) { - case PM_ERR_FILE_CONFLICTS: - for(i = data; i; i = alpm_list_next(i)) { - pmconflict_t *conflict = alpm_list_getdata(i); - switch(alpm_conflict_get_type(conflict)) { - case PM_CONFLICT_TYPE_TARGET: - MSG(NL, _("%s exists in both '%s' and '%s'\n"), - alpm_conflict_get_file(conflict), - alpm_conflict_get_target(conflict), - alpm_conflict_get_ctarget(conflict)); - break; - case PM_CONFLICT_TYPE_FILE: - MSG(NL, _("%s: %s exists in filesystem\n"), - alpm_conflict_get_target(conflict), - alpm_conflict_get_file(conflict)); - break; + case PM_ERR_FILE_CONFLICTS: + for(i = data; i; i = alpm_list_next(i)) { + pmconflict_t *conflict = alpm_list_getdata(i); + switch(alpm_conflict_get_type(conflict)) { + case PM_CONFLICT_TYPE_TARGET: + printf(_("%s exists in both '%s' and '%s'\n"), + alpm_conflict_get_file(conflict), + alpm_conflict_get_target(conflict), + alpm_conflict_get_ctarget(conflict)); + break; + case PM_CONFLICT_TYPE_FILE: + printf(_("%s: %s exists in filesystem\n"), + alpm_conflict_get_target(conflict), + alpm_conflict_get_file(conflict)); + break; + } } - } - MSG(NL, _("\nerrors occurred, no packages were upgraded.\n")); - break; - case PM_ERR_PKG_CORRUPTED: - for(i = data; i; i = alpm_list_next(i)) { - MSG(NL, "%s", (char*)alpm_list_getdata(i)); - } - MSG(NL, _("\nerrors occurred, no packages were upgraded.\n")); - break; - default: - break; + break; + case PM_ERR_PKG_CORRUPTED: + for(i = data; i; i = alpm_list_next(i)) { + printf("%s", (char*)alpm_list_getdata(i)); + } + break; + default: + break; } + /* TODO: stderr? */ + printf(_("Errors occurred, no packages were upgraded.\n")); retval = 1; goto cleanup; } - /* Step 4: release transaction resources - */ + /* Step 4: release transaction resources */ cleanup: if(data) { alpm_list_free(data); diff --git a/src/pacman/util.c b/src/pacman/util.c index 94274da5..3c623cd4 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -257,6 +257,7 @@ void list_display(const char *title, alpm_list_t *list) * `pkgs` should be a list of pmsyncpkg_t's, * retrieved from a transaction object */ +/* TODO move to output.c? or just combine util and output */ void display_targets(alpm_list_t *syncpkgs) { char *str; @@ -299,35 +300,37 @@ void display_targets(alpm_list_t *syncpkgs) mbisize = (double)(isize) / (1024.0 * 1024.0); mbrsize = (double)(rsize) / (1024.0 * 1024.0); + /* start displaying information */ + printf("\n"); + if(to_remove) { - MSG(NL, "\n"); /* TODO ugly hack. printing a single NL should be easy */ list_display(_("Remove:"), to_remove); + printf("\n"); FREELIST(to_remove); - if(mbrsize > 0) { - /* round up if size is really small */ - if(mbrsize < 0.1) { - mbrsize = 0.1; - } - MSG(NL, _("\nTotal Removed Size: %.2f MB\n"), mbrsize); + /* round up if size is really small */ + if(mbrsize < 0.1) { + mbrsize = 0.1; } + printf(_("Total Removed Size: %.2f MB\n"), mbrsize); } - MSG(NL, "\n"); /* TODO ugly hack. printing a single NL should be easy */ list_display(_("Targets:"), targets); + printf("\n"); /* round up if size is really small */ if(mbsize < 0.1) { mbsize = 0.1; } - MSG(NL, _("\nTotal Package Size: %.2f MB\n"), mbsize); + printf(_("Total Package Size: %.2f MB\n"), mbsize); + /* TODO because all pkgs don't include isize, this is a crude hack */ if(mbisize > mbsize) { /*round up if size is really small */ if(mbisize < 0.1) { mbisize = 0.1; } - MSG(NL, _("Total Installed Size: %.2f MB\n"), mbisize); + printf(_("Total Installed Size: %.2f MB\n"), mbisize); } FREELIST(targets); -- cgit v1.2.3-24-g4f1b