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 include = sqlite3_str_new(NULL);
27 exclude = sqlite3_str_new(NULL);
29 while ((opt = getopt(ac, av, "f:s:S:I")) != -1) {
31 case 'f': dbfile = optarg; break;
32 case 's': sqlite3_str_appendf(include,",%Q", optarg);
34 case 'S': sqlite3_str_appendf(exclude,",%Q", optarg);
36 case 'I': sqlite3_str_appendall(include,",'installed'");
47 fprintf(stderr, "must specify db\n");
51 query = sqlite3_str_new(NULL);
53 if (zpm_open(&zpm, dbfile)) {
54 char *excludes, *includes;
56 excludes = sqlite3_str_value(exclude);
57 includes = sqlite3_str_value(include);
60 sqlite3_str_appendf(query, "status in (%s)", includes+1);
63 sqlite3_str_appendf(query, "%sstatus not in (%s)",
64 includes ? " and " : "",
72 sql = sqlite3_str_value(query);
74 pkgid = zpm_findpkg(&zpm, pkgstr, sql);
78 printf("%s\n", pkgid);