X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=zpm-findpkg.c;fp=zpm-findpkg.c;h=0000000000000000000000000000000000000000;hb=5dd3c3e64a9574112dda77a5afc167f5daa53fd8;hp=4ee3f120e9131d84efd401fd5c9b9dd1b8ce6981;hpb=bd21f0a1265b43ad5f05353a39db31c16826f05c;p=zpackage diff --git a/zpm-findpkg.c b/zpm-findpkg.c deleted file mode 100644 index 4ee3f12..0000000 --- a/zpm-findpkg.c +++ /dev/null @@ -1,86 +0,0 @@ -#define _POSIX_C_SOURCE 2 - -#include -#include -#include -#include - -#include "zpm.h" - -void usage(void) { - fprintf(stderr, "zpm-findpkg [-I] [-s ...] [-S ] [package]\n"); -} - -int main(int ac, char **av){ - int opt, argn; - struct zpm zpm; - char *dbfile = 0, *pkgstr = 0, *pkgid = 0; - - char *sql; - sqlite3_str *include; - sqlite3_str *exclude; - sqlite3_str *query; - - dbfile = getenv("ZPMDB"); - if (!dbfile) { - dbfile = "/var/lib/zpm/local.db"; - } - - include = sqlite3_str_new(NULL); - exclude = sqlite3_str_new(NULL); - - while ((opt = getopt(ac, av, "f:s:S:I")) != -1) { - switch (opt) { - case 'f': dbfile = optarg; break; - case 's': sqlite3_str_appendf(include,",%Q", optarg); - break; - case 'S': sqlite3_str_appendf(exclude,",%Q", optarg); - break; - case 'I': sqlite3_str_appendall(include,",'installed'"); - break; - default: - usage(); - exit(EXIT_FAILURE); - break; - } - } - argn = optind; - - if (!dbfile) { - fprintf(stderr, "must specify db\n"); - return 1; - } - - query = sqlite3_str_new(NULL); - - if (zpm_open(&zpm, dbfile)) { - char *excludes, *includes; - - excludes = sqlite3_str_value(exclude); - includes = sqlite3_str_value(include); - - if (includes) { - sqlite3_str_appendf(query, "status in (%s)", includes+1); - } - if (excludes) { - sqlite3_str_appendf(query, "%sstatus not in (%s)", - includes ? " and " : "", - excludes+1); - } - - if (ac >= argn) { - pkgstr = av[argn]; - } - - sql = sqlite3_str_value(query); - - pkgid = zpm_findpkg(&zpm, pkgstr, sql); - - sqlite3_free(sql); - if (pkgid) { - printf("%s\n", pkgid); - } - zpm_close(&zpm); - } - return pkgid ? 0 : 1; -}