1 #define _POSIX_C_SOURCE 2
11 fprintf(stderr, "zpm-findpkg [-I] [-s <status> ...] [-S <status>] [package]\n");
14 int main(int ac, char **av){
17 char *dbfile = 0, *pkgstr = 0, *pkgid = 0;
24 dbfile = getenv("ZPMDB");
26 dbfile = "/var/lib/zpm/local.db";
29 include = sqlite3_str_new(NULL);
30 exclude = sqlite3_str_new(NULL);
32 while ((opt = getopt(ac, av, "f:s:S:I")) != -1) {
34 case 'f': dbfile = optarg; break;
35 case 's': sqlite3_str_appendf(include,",%Q", optarg);
37 case 'S': sqlite3_str_appendf(exclude,",%Q", optarg);
39 case 'I': sqlite3_str_appendall(include,",'installed'");
50 fprintf(stderr, "must specify db\n");
54 query = sqlite3_str_new(NULL);
56 if (zpm_open(&zpm, dbfile)) {
57 char *excludes, *includes;
59 excludes = sqlite3_str_value(exclude);
60 includes = sqlite3_str_value(include);
63 sqlite3_str_appendf(query, "status in (%s)", includes+1);
66 sqlite3_str_appendf(query, "%sstatus not in (%s)",
67 includes ? " and " : "",
75 sql = sqlite3_str_value(query);
77 pkgid = zpm_findpkg(&zpm, pkgstr, sql);
81 printf("%s\n", pkgid);