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>
|
2007-11-16 21:18:45 -05:00
|
|
|
*
|
2007-02-11 20:30:02 -05:00
|
|
|
* 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
|
2007-12-10 23:55:22 -05:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2007-02-11 20:30:02 -05:00
|
|
|
*/
|
|
|
|
|
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-10-31 12:43:04 -04:00
|
|
|
#define BASENAME "testpkg"
|
|
|
|
|
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) {
|
2007-10-31 12:43:04 -04:00
|
|
|
fprintf(stderr, "usage: %s <package file>\n", BASENAME);
|
2007-02-11 20:30:02 -05:00
|
|
|
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;
|
|
|
|
}
|
2007-11-16 21:18:45 -05:00
|
|
|
|
2007-02-11 20:30:02 -05:00
|
|
|
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);
|
|
|
|
}
|