From bf9a7bf08ee190de523a653f541318df0bce34d4 Mon Sep 17 00:00:00 2001 From: Nagy Gabor Date: Fri, 23 Nov 2007 22:32:40 +0100 Subject: [PATCH] Unify dump_pkg_full in pacman [-Si, -Qip, -Qi and -Qii] dump_pkg_sync is now a trivial wrapper for dump_pkg_full Some smaller changes: * string_display function added to util.c [prints None in case of empty string] * Filename field added to -Qip * rename License to Licenses * 'Compressed Size' used instead of 'Download Size' for -Qip Signed-off-by: Nagy Gabor --- src/pacman/package.c | 98 ++++++++++++++++++++++--------------------------- src/pacman/util.c | 10 +++++ src/pacman/util.h | 1 + 3 files changed, 55 insertions(+), 54 deletions(-) diff --git a/src/pacman/package.c b/src/pacman/package.c index b9a323b..48211a5 100644 --- a/src/pacman/package.c +++ b/src/pacman/package.c @@ -34,17 +34,18 @@ #include "package.h" #include "util.h" -/* Display the content of an installed package +/* Display the content of a package * - * level: <1 - omits N/A info for file query (-Qp) - * 1 - normal level - * >1 - extra information (backup files) + * level: <0 - sync package [-Si] + * =0 - file query [-Qip] + * 1 - localdb query, normal level [-Qi] + * >1 - localdb query, extra information (backup files) [-Qii] */ void dump_pkg_full(pmpkg_t *pkg, int level) { const char *reason, *descheader; time_t bdate, idate; - char bdatestr[50], idatestr[50]; + char bdatestr[50] = "", idatestr[50] = ""; const alpm_list_t *i; alpm_list_t *depstrings = NULL; @@ -54,9 +55,13 @@ void dump_pkg_full(pmpkg_t *pkg, int level) /* set variables here, do all output below */ bdate = alpm_pkg_get_builddate(pkg); - strftime(bdatestr, 50, "%c", localtime(&bdate)); + if(bdate) { + strftime(bdatestr, 50, "%c", localtime(&bdate)); + } idate = alpm_pkg_get_installdate(pkg); - strftime(idatestr, 50, "%c", localtime(&idate)); + if(idate) { + strftime(idatestr, 50, "%c", localtime(&idate)); + } switch((long)alpm_pkg_get_reason(pkg)) { case PM_PKG_REASON_EXPLICIT: @@ -79,10 +84,13 @@ void dump_pkg_full(pmpkg_t *pkg, int level) descheader = _("Description : "); /* actual output */ - printf(_("Name : %s\n"), (char *)alpm_pkg_get_name(pkg)); - printf(_("Version : %s\n"), (char *)alpm_pkg_get_version(pkg)); - printf(_("URL : %s\n"), (char *)alpm_pkg_get_url(pkg)); - list_display(_("License :"), alpm_pkg_get_licenses(pkg)); + if(level == 0) { + string_display(_("Filename :"), (char *)alpm_pkg_get_filename(pkg)); + } + string_display(_("Name :"), (char *)alpm_pkg_get_name(pkg)); + string_display(_("Version :"), (char *)alpm_pkg_get_version(pkg)); + string_display(_("URL :"), (char *)alpm_pkg_get_url(pkg)); + list_display(_("Licenses :"), alpm_pkg_get_licenses(pkg)); list_display(_("Groups :"), alpm_pkg_get_groups(pkg)); list_display(_("Provides :"), alpm_pkg_get_provides(pkg)); list_display(_("Depends On :"), depstrings); @@ -95,23 +103,39 @@ void dump_pkg_full(pmpkg_t *pkg, int level) } list_display(_("Conflicts With :"), alpm_pkg_get_conflicts(pkg)); list_display(_("Replaces :"), alpm_pkg_get_replaces(pkg)); + if(level < 0) { + printf(_("Download Size : %6.2f K\n"), + (float)alpm_pkg_get_size(pkg) / 1024.0); + } + if(level == 0) { + printf(_("Compressed Size: %6.2f K\n"), + (float)alpm_pkg_get_size(pkg) / 1024.0); + } + printf(_("Installed Size : %6.2f K\n"), (float)alpm_pkg_get_isize(pkg) / 1024.0); - printf(_("Packager : %s\n"), (char *)alpm_pkg_get_packager(pkg)); - printf(_("Architecture : %s\n"), (char *)alpm_pkg_get_arch(pkg)); - printf(_("Build Date : %s\n"), bdatestr); + string_display(_("Packager :"), (char *)alpm_pkg_get_packager(pkg)); + string_display(_("Architecture :"), (char *)alpm_pkg_get_arch(pkg)); + string_display(_("Build Date :"), bdatestr); if(level > 0) { - printf(_("Install Date : %s\n"), idatestr); - printf(_("Install Reason : %s\n"), reason); + string_display(_("Install Date :"), idatestr); + string_display(_("Install Reason :"), reason); + } + if(level >= 0) { + string_display(_("Install Script :"), + alpm_pkg_has_scriptlet(pkg) ? _("Yes") : _("No")); } - printf(_("Install Script : %s\n"), - alpm_pkg_has_scriptlet(pkg) ? _("Yes") : _("No")); /* printed using a variable to make i18n safe */ printf("%s", descheader); indentprint(alpm_pkg_get_desc(pkg), mbstowcs(NULL, descheader, 0)); printf("\n"); + /* MD5 Sum for sync package */ + if(level < 0) { + string_display(_("MD5 Sum :"), (char *)alpm_pkg_get_md5sum(pkg)); + } + /* Print additional package info if info flag passed more than once */ if(level > 1) { /* call new backup function */ @@ -127,45 +151,11 @@ void dump_pkg_full(pmpkg_t *pkg, int level) */ void dump_pkg_sync(pmpkg_t *pkg, const char *treename) { - const char *descheader, *md5sum; - const alpm_list_t *i; - alpm_list_t *depstrings = NULL; if(pkg == NULL) { return; } - - /* turn depends list into a text list */ - for(i = alpm_pkg_get_depends(pkg); i; i = alpm_list_next(i)) { - pmdepend_t *dep = (pmdepend_t*)alpm_list_getdata(i); - depstrings = alpm_list_add(depstrings, alpm_dep_get_string(dep)); - } - - descheader = _("Description : "); - - md5sum = alpm_pkg_get_md5sum(pkg); - - printf(_("Repository : %s\n"), treename); - printf(_("Name : %s\n"), (char *)alpm_pkg_get_name(pkg)); - printf(_("Version : %s\n"), (char *)alpm_pkg_get_version(pkg)); - list_display(_("Groups :"), alpm_pkg_get_groups(pkg)); - list_display(_("Provides :"), alpm_pkg_get_provides(pkg)); - list_display(_("Depends On :"), depstrings); - list_display(_("Conflicts With :"), alpm_pkg_get_conflicts(pkg)); - list_display(_("Replaces :"), alpm_pkg_get_replaces(pkg)); - printf(_("Download Size : %6.2f K\n"), (float)alpm_pkg_get_size(pkg) / 1024.0); - printf(_("Installed Size : %6.2f K\n"), (float)alpm_pkg_get_isize(pkg) / 1024.0); - - /* printed using a variable to make i18n safe */ - printf("%s", descheader); - indentprint(alpm_pkg_get_desc(pkg), mbstowcs(NULL, descheader, 0)); - printf("\n"); - - if (md5sum != NULL && md5sum[0] != '\0') { - printf(_("MD5 Sum : %s"), md5sum); - } - printf("\n"); - - FREELIST(depstrings); + string_display(_("Repository :"), treename); + dump_pkg_full(pkg, -1); } /* Display list of backup files and their modification states diff --git a/src/pacman/util.c b/src/pacman/util.c index 77773bf..1d35af0 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -327,6 +327,16 @@ alpm_list_t *strsplit(const char *str, const char splitchar) return(list); } +void string_display(const char *title, const char *string) +{ + printf("%s ", title); + if(string == NULL || string[0] == '\0') { + printf(_("None\n")); + } else { + printf("%s\n", string); + } +} + void list_display(const char *title, const alpm_list_t *list) { const alpm_list_t *i; diff --git a/src/pacman/util.h b/src/pacman/util.h index 931b456..c4a7ae1 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -47,6 +47,7 @@ char *strtoupper(char *str); char *strtrim(char *str); char *strreplace(const char *str, const char *needle, const char *replace); alpm_list_t *strsplit(const char *str, const char splitchar); +void string_display(const char *title, const char *string); void list_display(const char *title, const alpm_list_t *list); void display_targets(const alpm_list_t *syncpkgs, pmdb_t *db_local); int yesno(char *fmt, ...); -- 1.5.3.6