]> pd.if.org Git - zpackage/commitdiff
cleanup foreach-path
authorNathan Wagner <nw@hydaspes.if.org>
Mon, 3 Dec 2018 08:18:03 +0000 (08:18 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Mon, 3 Dec 2018 08:18:03 +0000 (08:18 +0000)
lib/foreach_path.c
zpm-foreach-path.c

index 561e24f089b1674e88de4991b2a8e1ddd919f213..ec6e07ed77866dd9984d5dc0180e806b1b19810b 100644 (file)
@@ -18,7 +18,7 @@ void *data, char **errmsg) {
        if (!zpm || zpm->error || !callback) return 0;
 
        s = sqlite3_str_new(zpm->db);
-       sqlite3_str_appendall(s, "select * from packagefiles_pkgid where ");
+       sqlite3_str_appendall(s, "select * from packagefiles_status where ");
 
        if (where) {
                sqlite3_str_appendf(s, "%s", where);
@@ -30,7 +30,6 @@ void *data, char **errmsg) {
                sqlite3_str_appendf(s, " and printf('%%s-%%s-%%s', package, version, release) = %Q", pkgid);
        }
 
-
        sql = sqlite3_str_value(s);
        if (!sql) {
                sqlite3_str_finish(s);
index cad19282b603b0eb619867df1b10291d77f959c8..41fb1c6e62ac069705a043ce359301cf450ed59f 100644 (file)
@@ -18,6 +18,7 @@ struct config {
        char *program;
        char *pkgid;
        char *nullstr;
+       char *filter;
        int errcontinue;
        int errors;
        int (*callback)(void*,int,char**,char**);
@@ -123,12 +124,12 @@ static int printpaths(void *f, int ncols, char **vals, char **cols) {
 
        /* suppress unused warnings */
 
-       if (ncols < 4) {
+       if (ncols < 6) {
                fprintf(stderr, "can't find path names\n");
                return 1;
        }
 //     printf("path cols %d %p %p\n", ncols, vals, cols);
-       fprintf(stdout, "%s\n", vals[3]);
+       fprintf(stdout, "%s\n", vals[5]);
 #if 0
        cols = 0;
        f = 0;
@@ -144,51 +145,6 @@ static int printpaths(void *f, int ncols, char **vals, char **cols) {
        return 0;
 }
 
-void parse_package(char *pstr, char *name, char *ver, int *rel) {
-       if (name) *name = 0;
-       if (ver) *ver = 0;
-       if (rel) *rel = -1;
-
-       /* string - ver - rel */
-       /* rel is all digits */
-       /* possible forms:
-        * ^(.+)-([0-9][^-]*)-([\d+])$
-        * ^(.+)-([0-9][^-]*)$
-        * ^(.+)$
-        * The main problem in parsing is that the package name itself
-        * can contain a '-', so you can't just split on '-'
-        * Also, the version can be just digits.
-        */
-
-       /* everything up to the first '-' is in the name */
-       while (*pstr) {
-               if (*pstr == '-' && isdigit(*(pstr+1))) {
-                       break;
-               }
-               if (name) {
-                       *name++ = *pstr;
-               }
-               pstr++;
-       }
-       if (name) *name = 0;
-       if (*pstr == '-') {
-               pstr++;
-       }
-       while (*pstr && *pstr != '-') {
-               if (ver) {
-                       *ver++ = *pstr;
-               }
-               pstr++;
-       }
-       if (ver) *ver = 0;
-       if (*pstr == '-') {
-               pstr++;
-       }
-       if (rel && *pstr) {
-               *rel = atoi(pstr);
-       }
-}
-
 #ifdef PATH_MAX
 #define PATHLEN PATH_MAX
 #else
@@ -197,15 +153,16 @@ void parse_package(char *pstr, char *name, char *ver, int *rel) {
 
 int main(int ac, char **av){
        struct zpm pkg;
-       char *s;
        int opt;
 
-       struct config conf = { "/var/lib/zpm/local.db", 0, 0, 0, "", 0, 0, printpaths
-       };
+       struct config conf = { 0 };
+
+       conf.dbfile = getenv("ZPMDB");
+       conf.callback = printpaths;
+       conf.nullstr = "";
 
-       if ((s = getenv("ZPMDB"))) {
-               /* TODO does this need to be copied ? */
-               conf.dbfile = s;
+       if (!conf.dbfile) {
+               conf.dbfile = "/var/lib/zpm/local.db";
        }
 
        /*
@@ -218,7 +175,7 @@ int main(int ac, char **av){
         *  otherwise' 
         */
 
-       while ((opt = getopt(ac, av, "f:c:n:C")) != -1) {
+       while ((opt = getopt(ac, av, "f:c:n:Cp:F:")) != -1) {
                switch (opt) {
                        case 'f': conf.dbfile = optarg;
                                  break;
@@ -231,6 +188,11 @@ int main(int ac, char **av){
                        case 'n':
                                  conf.nullstr = optarg;
                                  break;
+                       case 'p':
+                                 conf.pkgid = optarg;
+                                 break;
+                       case 'F': conf.filter = optarg;
+                                 break;
                        default:
                                  usage();
                                  exit(EXIT_FAILURE);
@@ -245,16 +207,6 @@ int main(int ac, char **av){
        }
        char *errmsg = 0;
 
-       if (argn < ac) {
-               conf.pkgid = av[argn];
-       //      fprintf(stderr, "set pkgid to %s\n", conf.pkgid);
-               argn++;
-       } else {
-               fprintf(stderr, "must specify pkgid\n");
-               usage();
-               exit(EXIT_FAILURE);
-       }
-
        /* TODO lookup pkgid via zpm-findpkg equivalent */
 
        if (argn < ac) {
@@ -264,10 +216,7 @@ int main(int ac, char **av){
                /* TODO set conf.args to remaining arguments */
        }
 
-       /* install a collation function */
-       // zpm_addvercmp(&pkg);
-
-       if (!zpm_foreach_path(&pkg, conf.pkgid, 0, conf.callback, &conf, &errmsg)) {
+       if (!zpm_foreach_path(&pkg, conf.pkgid, conf.filter, conf.callback, &conf, &errmsg)) {
                if (errmsg) {
                        fprintf(stderr, "database error: %s\n", errmsg);
                        exit(EXIT_FAILURE);