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))
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 $@ $<
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)
#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
--- /dev/null
+#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;
+}