summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNagy Gabor <ngaba@bibl.u-szeged.hu>2008-03-01 14:01:40 +0100
committerDan McGee <dan@archlinux.org>2008-03-01 16:32:06 -0600
commit17eca54b321e4eed63cd27bfa3dbf960b0c96901 (patch)
treec859d242345a5dc011ef87cd37b91bf5b34649a7
parentaecc2fd19037d0580df9600628acace93cb0dd46 (diff)
downloadpacman-17eca54b321e4eed63cd27bfa3dbf960b0c96901.tar.xz
testpkg rework
* mainly code cosmetics (indent fixes) * remove debug message "spam" * print also user friendly result Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu> [Dan: a few more whitespace/linebreak cleanups added] Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--src/util/testpkg.c48
1 files 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 <package file>\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);
}