From 8551ba212214a075b6dbbb8081465b711274df79 Mon Sep 17 00:00:00 2001 From: Nathan Wagner Date: Sun, 23 Sep 2018 01:41:51 +0000 Subject: [PATCH] use ZPMDB as package database if needed exit non-zero if findpkg doesn't find a package --- zpm-findpkg.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/zpm-findpkg.c b/zpm-findpkg.c index a376fae..95085d5 100644 --- a/zpm-findpkg.c +++ b/zpm-findpkg.c @@ -4,6 +4,8 @@ #include "zpm.h" +static int found = 0; + static int prow(void *f, int ncols, char **vals, char **cols) { FILE *out = f; int i; @@ -16,6 +18,7 @@ static int prow(void *f, int ncols, char **vals, char **cols) { fprintf(out, "%s", vals[i]); } fprintf(out, "\n"); + found++; return 0; } @@ -66,6 +69,7 @@ void parse_package(char *pstr, char *name, char *ver, int *rel) { int main(int ac, char **av){ struct zpm pkg; + char *dbfile, *pkgstr; char *select = "select package, version, release, package||'-'||version||'-'||release as pkgid from packages"; char *group = "group by package having max( version||'-'||release collate vercmp) order by length(package), package, version||'-'||release collate vercmp"; @@ -78,20 +82,26 @@ int main(int ac, char **av){ return 1; } + dbfile = getenv("ZPMDB"); + + if (ac > 1) { + dbfile = av[1]; + } + /* given a package name, get the packages */ /* no package name, get all */ - if (zpm_open(&pkg, av[1])) { + if (zpm_open(&pkg, dbfile)) { char *errmsg; -// char where[1024] = ""; - /* TODO allow more args to nail down version and release */ - if (ac >= 3) { + if (ac >= 2) { int release; char version[32]; char package[32]; - parse_package(av[2], package, version, &release); + pkgstr = av[2]; + + parse_package(pkgstr, package, version, &release); if (release != -1) { /* all three */ sprintf(sql, "%s where package = '%s' and version = " @@ -111,15 +121,8 @@ int main(int ac, char **av){ sprintf(sql, "%s %s;", select, group); } - /* install a collation function */ - zpm_addvercmp(&pkg); - /* sqlite seems to need the columns in the result to - * do the sort right */ -// zpm_exec(&pkg, "select package, version, release, package||'-'||version||'-'||release as pkgid from packages order by package, version collate vercmp, cast(release as integer)", prow, stdout, &errmsg); -// fprintf(stdout, "\n"); - zpm_exec(&pkg, sql, prow, stdout, &errmsg); } zpm_close(&pkg); - return 0; + return found ? 0 : 1; } -- 2.40.0