From: Nathan Wagner Date: Sat, 29 Sep 2018 21:47:06 +0000 (+0000) Subject: separate parse from findpkg X-Git-Tag: v0.1.7~15 X-Git-Url: https://pd.if.org/git/?a=commitdiff_plain;h=38b4e690c9910cde05ff97b7ebb32d5590328894;hp=4a6ff66a5868ab54ec03f240d8160b7c87dd23f7;p=zpackage separate parse from findpkg --- diff --git a/Makefile b/Makefile index c52fc24..9c3a63c 100644 --- 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) diff --git a/lib/findpkg.c b/lib/findpkg.c index 900b6cb..072f9f1 100644 --- a/lib/findpkg.c +++ b/lib/findpkg.c @@ -11,66 +11,6 @@ #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 index 0000000..5009c01 --- /dev/null +++ b/lib/parse.c @@ -0,0 +1,72 @@ +#define _POSIX_C_SOURCE 200809L + +#include +#include +#include +#include + +#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; +}