]> pd.if.org Git - zpackage/commitdiff
separate parse from findpkg
authorNathan Wagner <nw@hydaspes.if.org>
Sat, 29 Sep 2018 21:47:06 +0000 (21:47 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Sat, 29 Sep 2018 21:47:06 +0000 (21:47 +0000)
Makefile
lib/findpkg.c
lib/parse.c [new file with mode: 0644]

index c52fc24b83dd8a1ffef6dadf62a52e2116b46985..9c3a63c6b38d7761d128c91ec773a466fde7a4a9 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -19,7 +19,8 @@ lib/jsw/jsw_rbtree.c
 
 JSWOBJ=$(JSWSRC:%.c=%.o)
 LIBZPMSRC=sha256.c db.c compress.c uncompress.c zpm.c zpm_hash.c \
-         foreach_path.c vercmp.o findpkg.c quote.c dbquery.c script_hash.c
+         foreach_path.c vercmp.c findpkg.c quote.c dbquery.c script_hash.c \
+         parse.c
 
 LIBZPMOBJ=$(addprefix lib/, $(LIBZPMSRC:%.c=%.o))
 
@@ -136,8 +137,8 @@ zpm-findpkg: zpm-findpkg.o libzpm.a
 zpm-syncfs: zpm-syncfs.o libzpm.a libelf.a
        $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf -lm -ldl
 
-zpm-parse: zpm-parse.o libzpm.a
-       $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -lzpm -lelf
+zpm-parse: zpm-parse.o lib/parse.o
+       $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $+
 
 zpm-quote: zpm-quote.o
        $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<
@@ -175,4 +176,4 @@ clean:
        rm -f *.o sqlite/*.o lib/*.o $(LZMAOBJ) liblzma.a \
                libelf.a libzpm.a zpm-addfile soname \
                *.xz \
-               local.db t/ctap/prove.o
+               local.db t/ctap/prove.o $(ZPKGBIN)
index 900b6cbc74ebd51bfb5ce0184d95715793e72c60..072f9f1cbd21745259eeb1c0b59e412424bd490a 100644 (file)
 
 #define DMARK fprintf(stderr, "mark %s %s:%d\n", __FILE__, __func__, __LINE__)
 
-int zpm_parse_package(char *pstr, char *name, char *ver, int *rel) {
-       if (name) *name = 0;
-       if (ver) *ver = 0;
-       if (rel) *rel = 0;
-       int havename = 0;
-       int havever = 0;
-       int haverel = 0;
-
-       /* 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 == '\'' || !isgraph(*pstr)) {
-                       return 0;
-               }
-               if (*pstr == '-' && isdigit(*(pstr+1))) {
-                       break;
-               }
-               if (name) {
-                       *name++ = *pstr;
-               }
-               pstr++;
-               havename = 1;
-       }
-       if (name) *name = 0;
-       if (*pstr == '-') {
-               pstr++;
-       }
-       while (*pstr && *pstr != '-') {
-               if (*pstr == '\'' || !isgraph(*pstr)) {
-                       return 0;
-               }
-               if (ver) {
-                       *ver++ = *pstr;
-               }
-               pstr++;
-               havever = 1;
-       }
-       if (ver) *ver = 0;
-       if (*pstr == '-') {
-               pstr++;
-       }
-       /* TODO use strtol */
-       if (rel && *pstr) {
-               haverel = 1;
-               *rel = atoi(pstr);
-       }
-
-       return havename + havever + haverel;
-}
-
 /*
  * flags 0 = find installed
  * flags 1 = skip installed
diff --git a/lib/parse.c b/lib/parse.c
new file mode 100644 (file)
index 0000000..5009c01
--- /dev/null
@@ -0,0 +1,72 @@
+#define _POSIX_C_SOURCE 200809L
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "zpm.h"
+
+#include "sqlite3.h"
+
+#define DMARK fprintf(stderr, "mark %s %s:%d\n", __FILE__, __func__, __LINE__)
+
+int zpm_parse_package(char *pstr, char *name, char *ver, int *rel) {
+       if (name) *name = 0;
+       if (ver) *ver = 0;
+       if (rel) *rel = 0;
+       int havename = 0;
+       int havever = 0;
+       int haverel = 0;
+
+       /* 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 == '\'' || !isgraph(*pstr)) {
+                       return 0;
+               }
+               if (*pstr == '-' && isdigit(*(pstr+1))) {
+                       break;
+               }
+               if (name) {
+                       *name++ = *pstr;
+               }
+               pstr++;
+               havename = 1;
+       }
+       if (name) *name = 0;
+       if (*pstr == '-') {
+               pstr++;
+       }
+       while (*pstr && *pstr != '-') {
+               if (*pstr == '\'' || !isgraph(*pstr)) {
+                       return 0;
+               }
+               if (ver) {
+                       *ver++ = *pstr;
+               }
+               pstr++;
+               havever = 1;
+       }
+       if (ver) *ver = 0;
+       if (*pstr == '-') {
+               pstr++;
+       }
+       /* TODO use strtol */
+       if (rel && *pstr) {
+               haverel = 1;
+               *rel = atoi(pstr);
+       }
+
+       return havename + havever + haverel;
+}