Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/cleanupdelta.c26
-rw-r--r--src/util/pactree.c169
-rw-r--r--src/util/testdb.c58
-rw-r--r--src/util/testpkg.c27
-rw-r--r--src/util/vercmp.c6
5 files changed, 139 insertions, 147 deletions
diff --git a/src/util/cleanupdelta.c b/src/util/cleanupdelta.c
index 71ba3a47..98291706 100644
--- a/src/util/cleanupdelta.c
+++ b/src/util/cleanupdelta.c
@@ -29,9 +29,11 @@
#define BASENAME "cleanupdelta"
+pmhandle_t *handle = NULL;
+
static void cleanup(int signum) {
- if(alpm_release() == -1) {
- fprintf(stderr, "error releasing alpm: %s\n", alpm_strerrorlast());
+ if(handle && alpm_release(handle) == -1) {
+ fprintf(stderr, "error releasing alpm\n");
}
exit(signum);
@@ -65,7 +67,7 @@ static void checkpkgs(alpm_list_t *pkglist)
}
}
-static void checkdbs(char *dbpath, alpm_list_t *dbnames) {
+static void checkdbs(const char *dbpath, alpm_list_t *dbnames) {
char syncdbpath[PATH_MAX];
pmdb_t *db = NULL;
alpm_list_t *i;
@@ -73,10 +75,10 @@ static void checkdbs(char *dbpath, alpm_list_t *dbnames) {
for(i = dbnames; i; i = alpm_list_next(i)) {
char *dbname = alpm_list_getdata(i);
snprintf(syncdbpath, PATH_MAX, "%s/sync/%s", dbpath, dbname);
- db = alpm_db_register_sync(dbname);
+ db = alpm_db_register_sync(handle, dbname);
if(db == NULL) {
fprintf(stderr, "error: could not register sync database (%s)\n",
- alpm_strerrorlast());
+ alpm_strerror(alpm_errno(handle)));
return;
}
checkpkgs(alpm_db_get_pkgcache(db));
@@ -93,7 +95,8 @@ static void usage(void) {
int main(int argc, char *argv[])
{
- char *dbpath = DBPATH;
+ const char *dbpath = DBPATH;
+ enum _pmerrno_t err;
int a = 1;
alpm_list_t *dbnames = NULL;
@@ -117,15 +120,14 @@ int main(int argc, char *argv[])
usage();
}
- if(alpm_initialize() == -1) {
- fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerrorlast());
- return(1);
+ handle = alpm_initialize(ROOTDIR, dbpath, &err);
+ if(!handle) {
+ fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerror(err));
+ return 1;
}
/* let us get log messages from libalpm */
- alpm_option_set_logcb(output_cb);
-
- alpm_option_set_dbpath(dbpath);
+ alpm_option_set_logcb(handle, output_cb);
checkdbs(dbpath,dbnames);
alpm_list_free(dbnames);
diff --git a/src/util/pactree.c b/src/util/pactree.c
index 6a10006f..1dee61bf 100644
--- a/src/util/pactree.c
+++ b/src/util/pactree.c
@@ -27,63 +27,66 @@
#include <alpm_list.h>
/* output */
-char *provides = " provides";
-char *unresolvable = " [unresolvable]";
-char *branch_tip1 = "|--";
-char *branch_tip2 = "+--";
-int indent_size = 3;
-
-/* color */
-char *branch1_color = "\033[0;33m"; /* yellow */
-char *branch2_color = "\033[0;37m"; /* white */
-char *leaf1_color = "\033[1;32m"; /* bold green */
-char *leaf2_color = "\033[0;32m"; /* green */
-char *color_off = "\033[0m";
+struct graph_style {
+ const char *provides;
+ const char *tip1;
+ const char *tip2;
+ int indent;
+};
+
+static struct graph_style graph_default = {
+ " provides",
+ "|--",
+ "+--",
+ 3
+};
+
+static struct graph_style graph_linear = {
+ "",
+ "",
+ "",
+ 0
+};
+
+/* color choices */
+struct color_choices {
+ const char *branch1;
+ const char *branch2;
+ const char *leaf1;
+ const char *leaf2;
+ const char *off;
+};
+
+static struct color_choices use_color = {
+ "\033[0;33m", /* yellow */
+ "\033[0;37m", /* white */
+ "\033[1;32m", /* bold green */
+ "\033[0;32m", /* green */
+ "\033[0m"
+};
+
+static struct color_choices no_color = {
+ "",
+ "",
+ "",
+ "",
+ ""
+};
/* globals */
+pmhandle_t *handle = NULL;
pmdb_t *db_local;
alpm_list_t *walked = NULL;
alpm_list_t *provisions = NULL;
/* options */
-int color = 0;
+struct color_choices *color = &no_color;
+struct graph_style *style = &graph_default;
int graphviz = 0;
-int linear = 0;
int max_depth = -1;
int reverse = 0;
int unique = 0;
-char *dbpath = NULL;
-
-static int alpm_local_init(void)
-{
- int ret;
-
- ret = alpm_initialize();
- if(ret != 0) {
- return(ret);
- }
-
- ret = alpm_option_set_root(ROOTDIR);
- if(ret != 0) {
- return(ret);
- }
-
- if(dbpath) {
- ret = alpm_option_set_dbpath(dbpath);
- } else {
- ret = alpm_option_set_dbpath(DBPATH);
- }
- if(ret != 0) {
- return(ret);
- }
-
- db_local = alpm_option_get_localdb();
- if(!db_local) {
- return(1);
- }
-
- return(0);
-}
+const char *dbpath = DBPATH;
static int parse_options(int argc, char *argv[])
{
@@ -109,10 +112,10 @@ static int parse_options(int argc, char *argv[])
switch(opt) {
case 'b':
- dbpath = strdup(optarg);
+ dbpath = optarg;
break;
case 'c':
- color = 1;
+ color = &use_color;
break;
case 'd':
/* validate depth */
@@ -126,40 +129,27 @@ static int parse_options(int argc, char *argv[])
graphviz = 1;
break;
case 'l':
- linear = 1;
+ style = &graph_linear;
break;
case 'r':
reverse = 1;
break;
case 'u':
- unique = linear = 1;
+ unique = 1;
+ style = &graph_linear;
break;
case 'h':
case '?':
default:
- return(1);
+ return 1;
}
}
if(!argv[optind]) {
- return(1);
- }
-
- if(!color) {
- branch1_color = "";
- branch2_color = "";
- leaf1_color = "";
- leaf2_color = "";
- color_off = "";
- }
- if(linear) {
- provides = "";
- branch_tip1 = "";
- branch_tip2 = "";
- indent_size = 0;
+ return 1;
}
- return(0);
+ return 0;
}
static void usage(void)
@@ -178,19 +168,15 @@ static void usage(void)
static void cleanup(void)
{
- if(dbpath) {
- free(dbpath);
- }
-
alpm_list_free(walked);
alpm_list_free(provisions);
- alpm_release();
+ alpm_release(handle);
}
/* pkg provides provision */
static void print_text(const char *pkg, const char *provision, int depth)
{
- int indent_sz = (depth + 1) * indent_size;
+ int indent_sz = (depth + 1) * style->indent;
if(!pkg && !provision) {
/* not much we can do */
@@ -199,17 +185,17 @@ static void print_text(const char *pkg, const char *provision, int depth)
if(!pkg && provision) {
/* we failed to resolve provision */
- printf("%s%*s%s%s%s%s%s\n", branch1_color, indent_sz, branch_tip1,
- leaf1_color, provision, branch1_color, unresolvable, color_off);
+ printf("%s%*s%s%s%s [unresolvable]%s\n", color->branch1, indent_sz,
+ style->tip1, color->leaf1, provision, color->branch1, color->off);
} else if(provision && strcmp(pkg, provision) != 0) {
/* pkg provides provision */
- printf("%s%*s%s%s%s%s %s%s%s\n", branch2_color, indent_sz, branch_tip2,
- leaf1_color, pkg, leaf2_color, provides, leaf1_color, provision,
- color_off);
+ printf("%s%*s%s%s%s%s %s%s%s\n", color->branch2, indent_sz, style->tip2,
+ color->leaf1, pkg, color->leaf2, style->provides, color->leaf1, provision,
+ color->off);
} else {
/* pkg is a normal package */
- printf("%s%*s%s%s%s\n", branch1_color, indent_sz, branch_tip1, leaf1_color,
- pkg, color_off);
+ printf("%s%*s%s%s%s\n", color->branch1, indent_sz, style->tip1, color->leaf1,
+ pkg, color->off);
}
}
@@ -267,7 +253,7 @@ static void walk_reverse_deps(pmpkg_t *pkg, int depth)
return;
}
- walked = alpm_list_add(walked, (void*)alpm_pkg_get_name(pkg));
+ walked = alpm_list_add(walked, (void *)alpm_pkg_get_name(pkg));
required_by = alpm_pkg_compute_requiredby(pkg);
for(i = required_by; i; i = alpm_list_next(i)) {
@@ -299,7 +285,7 @@ static void walk_deps(pmpkg_t *pkg, int depth)
return;
}
- walked = alpm_list_add(walked, (void*)alpm_pkg_get_name(pkg));
+ walked = alpm_list_add(walked, (void *)alpm_pkg_get_name(pkg));
for(i = alpm_pkg_get_depends(pkg); i; i = alpm_list_next(i)) {
pmdepend_t *depend = alpm_list_getdata(i);
@@ -328,22 +314,27 @@ static void walk_deps(pmpkg_t *pkg, int depth)
int main(int argc, char *argv[])
{
- int ret;
+ int ret = 0;
+ enum _pmerrno_t err;
const char *target_name;
pmpkg_t *pkg;
- ret = parse_options(argc, argv);
- if(ret != 0) {
+ if(parse_options(argc, argv) != 0) {
usage();
+ ret = 1;
goto finish;
}
- ret = alpm_local_init();
- if(ret != 0) {
- fprintf(stderr, "error: cannot initialize alpm: %s\n", alpm_strerrorlast());
+ handle = alpm_initialize(ROOTDIR, dbpath, &err);
+ if(!handle) {
+ fprintf(stderr, "error: cannot initialize alpm: %s\n",
+ alpm_strerror(err));
+ ret = 1;
goto finish;
}
+ db_local = alpm_option_get_localdb(handle);
+
/* we only care about the first non option arg for walking */
target_name = argv[optind];
@@ -366,7 +357,7 @@ int main(int argc, char *argv[])
finish:
cleanup();
- return(ret);
+ return ret;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/src/util/testdb.c b/src/util/testdb.c
index 0436a23f..0bd78202 100644
--- a/src/util/testdb.c
+++ b/src/util/testdb.c
@@ -31,9 +31,11 @@
#define BASENAME "testdb"
+pmhandle_t *handle = NULL;
+
static void cleanup(int signum) {
- if(alpm_release() == -1) {
- fprintf(stderr, "error releasing alpm: %s\n", alpm_strerrorlast());
+ if(handle && alpm_release(handle) == -1) {
+ fprintf(stderr, "error releasing alpm\n");
}
exit(signum);
@@ -59,14 +61,14 @@ static int check_localdb_files(void)
int ret = 0;
DIR *dir;
- dbpath = alpm_option_get_dbpath();
+ dbpath = alpm_option_get_dbpath(handle);
snprintf(path, sizeof(path), "%slocal", dbpath);
if(!(dir = opendir(path))) {
fprintf(stderr, "error : %s : %s\n", path, strerror(errno));
- return(1);
+ return 1;
}
- while ((ent = readdir(dir)) != NULL) {
+ while((ent = readdir(dir)) != NULL) {
if(strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0
|| ent->d_name[0] == '.') {
continue;
@@ -85,10 +87,10 @@ static int check_localdb_files(void)
}
if(closedir(dir)) {
fprintf(stderr, "error closing dbpath : %s\n", strerror(errno));
- return(1);
+ return 1;
}
- return(ret);
+ return ret;
}
static int checkdeps(alpm_list_t *pkglist)
@@ -96,7 +98,7 @@ static int checkdeps(alpm_list_t *pkglist)
alpm_list_t *data, *i;
int ret = 0;
/* check dependencies */
- data = alpm_checkdeps(pkglist, 0, NULL, pkglist);
+ data = alpm_checkdeps(handle, pkglist, NULL, pkglist, 0);
for(i = data; i; i = alpm_list_next(i)) {
pmdepmissing_t *miss = alpm_list_getdata(i);
pmdepend_t *dep = alpm_miss_get_dep(miss);
@@ -107,7 +109,7 @@ static int checkdeps(alpm_list_t *pkglist)
ret++;
}
FREELIST(data);
- return(ret);
+ return ret;
}
static int checkconflicts(alpm_list_t *pkglist)
@@ -115,7 +117,7 @@ static int checkconflicts(alpm_list_t *pkglist)
alpm_list_t *data, *i;
int ret = 0;
/* check conflicts */
- data = alpm_checkconflicts(pkglist);
+ data = alpm_checkconflicts(handle, pkglist);
for(i = data; i; i = i->next) {
pmconflict_t *conflict = alpm_list_getdata(i);
printf("%s conflicts with %s\n", alpm_conflict_get_package1(conflict),
@@ -123,7 +125,7 @@ static int checkconflicts(alpm_list_t *pkglist)
ret++;
}
FREELIST(data);
- return(ret);
+ return ret;
}
static int check_localdb(void) {
@@ -133,19 +135,14 @@ static int check_localdb(void) {
ret = check_localdb_files();
if(ret) {
- return(ret);
+ return ret;
}
- db = alpm_option_get_localdb();
- if(db == NULL) {
- fprintf(stderr, "error: could not register 'local' database (%s)\n",
- alpm_strerrorlast());
- cleanup(EXIT_FAILURE);
- }
+ db = alpm_option_get_localdb(handle);
pkglist = alpm_db_get_pkgcache(db);
ret += checkdeps(pkglist);
ret += checkconflicts(pkglist);
- return(ret);
+ return ret;
}
static int check_syncdbs(alpm_list_t *dbnames) {
@@ -155,10 +152,10 @@ static int check_syncdbs(alpm_list_t *dbnames) {
for(i = dbnames; i; i = alpm_list_next(i)) {
char *dbname = alpm_list_getdata(i);
- db = alpm_db_register_sync(dbname);
+ db = alpm_db_register_sync(handle, dbname);
if(db == NULL) {
fprintf(stderr, "error: could not register sync database (%s)\n",
- alpm_strerrorlast());
+ alpm_strerror(alpm_errno(handle)));
ret = 1;
goto cleanup;
}
@@ -169,7 +166,7 @@ static int check_syncdbs(alpm_list_t *dbnames) {
cleanup:
alpm_list_free(syncpkglist);
- return(ret);
+ return ret;
}
static void usage(void) {
@@ -184,7 +181,8 @@ static void usage(void) {
int main(int argc, char *argv[])
{
int ret = 0;
- char *dbpath = DBPATH;
+ enum _pmerrno_t err;
+ const char *dbpath = DBPATH;
int a = 1;
alpm_list_t *dbnames = NULL;
@@ -204,18 +202,14 @@ int main(int argc, char *argv[])
a++;
}
- if(alpm_initialize() == -1) {
- fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerrorlast());
- return(EXIT_FAILURE);
+ handle = alpm_initialize(ROOTDIR, dbpath, &err);
+ if(!handle) {
+ fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerror(err));
+ return EXIT_FAILURE;
}
/* let us get log messages from libalpm */
- alpm_option_set_logcb(output_cb);
-
- if(alpm_option_set_dbpath(dbpath) != 0) {
- fprintf(stderr, "cannot set dbpath: %s\n", alpm_strerrorlast());
- return(EXIT_FAILURE);
- }
+ alpm_option_set_logcb(handle, output_cb);
if(!dbnames) {
ret = check_localdb();
diff --git a/src/util/testpkg.c b/src/util/testpkg.c
index d0d9cac1..c6f02e34 100644
--- a/src/util/testpkg.c
+++ b/src/util/testpkg.c
@@ -40,23 +40,28 @@ static void output_cb(pmloglevel_t level, const char *fmt, va_list args)
int main(int argc, char *argv[])
{
int retval = 1; /* default = false */
+ pmhandle_t *handle;
+ enum _pmerrno_t err;
pmpkg_t *pkg = NULL;
if(argc != 2) {
fprintf(stderr, "usage: %s <package file>\n", BASENAME);
- return(1);
+ return 1;
}
- if(alpm_initialize() == -1) {
- fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerrorlast());
- return(1);
+ handle = alpm_initialize(ROOTDIR, DBPATH, &err);
+ if(!handle) {
+ fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerror(err));
+ return 1;
}
/* let us get log messages from libalpm */
- alpm_option_set_logcb(output_cb);
+ alpm_option_set_logcb(handle, output_cb);
- if(alpm_pkg_load(argv[1], 1, &pkg) == -1 || pkg == NULL) {
- switch(pm_errno) {
+ if(alpm_pkg_load(handle, argv[1], 1, PM_PGP_VERIFY_OPTIONAL, &pkg) == -1
+ || pkg == NULL) {
+ enum _pmerrno_t err = alpm_errno(handle);
+ switch(err) {
case PM_ERR_PKG_OPEN:
printf("Cannot open the given file.\n");
break;
@@ -65,7 +70,7 @@ int main(int argc, char *argv[])
printf("Package is invalid.\n");
break;
default:
- printf("libalpm error: %s\n", alpm_strerrorlast());
+ printf("libalpm error: %s\n", alpm_strerror(err));
break;
}
retval = 1;
@@ -75,9 +80,9 @@ int main(int argc, char *argv[])
retval = 0;
}
- if(alpm_release() == -1) {
- fprintf(stderr, "error releasing alpm: %s\n", alpm_strerrorlast());
+ if(alpm_release(handle) == -1) {
+ fprintf(stderr, "error releasing alpm\n");
}
- return(retval);
+ return retval;
}
diff --git a/src/util/vercmp.c b/src/util/vercmp.c
index adb5a42a..88cf49a6 100644
--- a/src/util/vercmp.c
+++ b/src/util/vercmp.c
@@ -45,13 +45,13 @@ int main(int argc, char *argv[])
if(argc == 1) {
usage();
- return(2);
+ return 2;
}
if(argc > 1 &&
(strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0
|| strcmp(argv[1], "--usage") == 0)) {
usage();
- return(0);
+ return 0;
}
if(argc > 2) {
s2 = argv[2];
@@ -62,5 +62,5 @@ int main(int argc, char *argv[])
ret = alpm_pkg_vercmp(s1, s2);
printf("%d\n", ret);
- return(EXIT_SUCCESS);
+ return EXIT_SUCCESS;
}