2007-02-11 20:30:02 -05:00
|
|
|
/*
|
|
|
|
* testpkg.c : Test a pacman package for validity
|
|
|
|
*
|
|
|
|
* Copyright (c) 2007 by Aaron Griffin <aaronmgriffin@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|
|
|
* USA.
|
|
|
|
*/
|
|
|
|
|
2007-03-05 17:13:33 -05:00
|
|
|
#include "config.h"
|
|
|
|
|
2007-08-15 20:16:46 -04:00
|
|
|
#include <stdio.h> /* printf */
|
|
|
|
#include <stdarg.h> /* va_list */
|
|
|
|
#include <string.h> /* strlen */
|
2007-02-11 20:30:02 -05:00
|
|
|
|
|
|
|
#include <alpm.h>
|
|
|
|
|
2007-09-10 20:13:38 -04:00
|
|
|
static void output_cb(pmloglevel_t level, char *fmt, va_list args)
|
2007-02-11 20:30:02 -05:00
|
|
|
{
|
2007-06-07 20:55:13 -04:00
|
|
|
if(strlen(fmt)) {
|
2007-02-11 20:30:02 -05:00
|
|
|
switch(level) {
|
|
|
|
case PM_LOG_ERROR: printf("error: "); break;
|
|
|
|
case PM_LOG_WARNING: printf("warning: "); break;
|
2007-04-26 18:59:02 -04:00
|
|
|
default: break;
|
2007-02-11 20:30:02 -05:00
|
|
|
}
|
2007-06-07 20:55:13 -04:00
|
|
|
vprintf(fmt, args);
|
2007-02-11 20:30:02 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int retval = 1; /* default = false */
|
|
|
|
pmpkg_t *pkg = NULL;
|
|
|
|
|
|
|
|
if(argc != 2) {
|
|
|
|
fprintf(stderr, "usage: %s <package file>\n", basename(argv[0]));
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(alpm_initialize() == -1) {
|
2007-09-08 12:41:45 -04:00
|
|
|
fprintf(stderr, "cannot initilize alpm: %s\n", alpm_strerrorlast());
|
2007-02-11 20:30:02 -05:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* let us get log messages from libalpm */
|
|
|
|
alpm_option_set_logcb(output_cb);
|
|
|
|
|
2007-09-28 00:39:37 -04:00
|
|
|
if(alpm_pkg_load(argv[1], 1, &pkg) == -1 || pkg == NULL) {
|
2007-02-11 20:30:02 -05:00
|
|
|
retval = 1;
|
|
|
|
} else {
|
|
|
|
alpm_pkg_free(pkg);
|
|
|
|
retval = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(alpm_release() == -1) {
|
2007-09-08 12:41:45 -04:00
|
|
|
fprintf(stderr, "error releasing alpm: %s\n", alpm_strerrorlast());
|
2007-02-11 20:30:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return(retval);
|
|
|
|
}
|