From 17eca54b321e4eed63cd27bfa3dbf960b0c96901 Mon Sep 17 00:00:00 2001 From: Nagy Gabor Date: Sat, 1 Mar 2008 14:01:40 +0100 Subject: testpkg rework * mainly code cosmetics (indent fixes) * remove debug message "spam" * print also user friendly result Signed-off-by: Nagy Gabor [Dan: a few more whitespace/linebreak cleanups added] Signed-off-by: Dan McGee --- src/util/testpkg.c | 48 +++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/src/util/testpkg.c b/src/util/testpkg.c index e32b013d..64056ce4 100644 --- a/src/util/testpkg.c +++ b/src/util/testpkg.c @@ -29,44 +29,58 @@ static void output_cb(pmloglevel_t level, char *fmt, va_list args) { - if(strlen(fmt)) { - switch(level) { - case PM_LOG_ERROR: printf("error: "); break; - case PM_LOG_WARNING: printf("warning: "); break; - default: break; - } - vprintf(fmt, args); - } + if(fmt[0] == '\0') { + return; + } + switch(level) { + case PM_LOG_ERROR: printf("error: "); break; + case PM_LOG_WARNING: printf("warning: "); break; + default: return; /* skip other messages */ + } + vprintf(fmt, args); } int main(int argc, char **argv) { - int retval = 1; /* default = false */ - pmpkg_t *pkg = NULL; + int retval = 1; /* default = false */ + pmpkg_t *pkg = NULL; - if(argc != 2) { + if(argc != 2) { fprintf(stderr, "usage: %s \n", BASENAME); return(1); } if(alpm_initialize() == -1) { - fprintf(stderr, "cannot initilize alpm: %s\n", alpm_strerrorlast()); - return(1); + fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerrorlast()); + return(1); } - /* let us get log messages from libalpm */ + /* let us get log messages from libalpm */ alpm_option_set_logcb(output_cb); if(alpm_pkg_load(argv[1], 1, &pkg) == -1 || pkg == NULL) { - retval = 1; + switch(pm_errno) { + case PM_ERR_PKG_OPEN: + printf("Cannot open the given file.\n"); + break; + case PM_ERR_LIBARCHIVE_ERROR: + case PM_ERR_PKG_INVALID: + printf("Package is invalid.\n"); + break; + default: + printf("libalpm error: %s\n", alpm_strerrorlast()); + break; + } + retval = 1; } else { alpm_pkg_free(pkg); - retval = 0; + printf("Package is valid.\n"); + retval = 0; } if(alpm_release() == -1) { fprintf(stderr, "error releasing alpm: %s\n", alpm_strerrorlast()); } - return(retval); + return(retval); } -- cgit v1.2.3-70-g09d2