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;
18 int range = 0, wantleast = 0, argismax = 0;
19 char *minpkg = 0, *maxpkg = 0;
26 dbfile = getenv("ZPMDB");
28 dbfile = "/var/lib/zpm/local.db";
31 include = sqlite3_str_new(NULL);
32 exclude = sqlite3_str_new(NULL);
34 while ((opt = getopt(ac, av, "f:s:S:Imrl")) != -1) {
36 case 'f': dbfile = optarg; break;
37 case 's': sqlite3_str_appendf(include,",%Q", optarg);
39 case 'S': sqlite3_str_appendf(exclude,",%Q", optarg);
41 case 'I': sqlite3_str_appendall(include,",'installed'");
43 case 'l': wantleast = 1; break;
44 case 'r': range = 1; break;
45 case 'm': argismax = 1; range = 1; break;
59 pkgstr = minpkg = av[argn];
69 fprintf(stderr, "must specify db\n");
73 query = sqlite3_str_new(NULL);
75 if (zpm_open(&zpm, dbfile)) {
76 char *excludes, *includes;
78 excludes = sqlite3_str_value(exclude);
79 includes = sqlite3_str_value(include);
82 sqlite3_str_appendf(query, "status in (%s)", includes+1);
85 sqlite3_str_appendf(query, "%sstatus not in (%s)",
86 includes ? " and " : "",
90 sql = sqlite3_str_value(query);
94 /* swap the sense of the arguments */
98 pkgid = zpm_findpkg_range(&zpm, minpkg, maxpkg, sql, wantleast);
100 pkgid = zpm_findpkg(&zpm, pkgstr, sql);
105 printf("%s\n", pkgid);
109 return pkgid ? 0 : 1;