]> pd.if.org Git - zpackage/commitdiff
move vercmp into zpm library
authorNathan Wagner <nw@hydaspes.if.org>
Wed, 8 Mar 2017 09:32:32 +0000 (03:32 -0600)
committerNathan Wagner <nw@hydaspes.if.org>
Wed, 8 Mar 2017 09:32:32 +0000 (03:32 -0600)
Makefile
lib/vercmp.c [moved from vercmp.c with 83% similarity]
zpm.h

index ffb3f5baad52ac382af52c8aee53b89e30b5c887..5352872d3d5097a61c08b10194592452d4426bb4 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -67,11 +67,12 @@ $(LZMAOBJ):
 
 lib/zpm.o: newdb.c
 
-zpm-vercmp: vercmp.o
-       $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $
+zpm-vercmp: zpm-vercmp.o lib/vercmp.o
+       $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $+
        
 libzpm.a: lib/sha256.o lib/db.o lib/compress.o lib/uncompress.o lib/zpm.o \
        lib/sqlite3.o \
+       lib/vercmp.o \
        $(LZMAOBJ)
        ar rcuv $@ $?
 
similarity index 83%
rename from vercmp.c
rename to lib/vercmp.c
index 58053d9f46b68341accb86674ea2adb83396cc97..8cbad7354ec92035ab0264c9ebc4b35018b48b34 100644 (file)
--- a/vercmp.c
@@ -17,7 +17,7 @@ struct ver {
        char *relstr;
 };
 
-void init_ver(struct ver *v, char *s) {
+static void init_ver(struct ver *v, char *s) {
        strncpy(v->str, s, 1023);
        v->str[1023] = 0;
        v->s = 0;
@@ -43,7 +43,7 @@ void init_ver(struct ver *v, char *s) {
 
 }
 
-int ver_cmp(struct ver *a, struct ver *b) {
+static int ver_cmp(struct ver *a, struct ver *b) {
        if (a->type == 0 && b->type == 0) {
                return 0;
        }
@@ -65,7 +65,7 @@ int ver_cmp(struct ver *a, struct ver *b) {
        return 0;
 }
 
-int next_comp(struct ver *v) {
+static int next_comp(struct ver *v) {
        char *s;
 
        /* restore over-written character */
@@ -109,41 +109,34 @@ int next_comp(struct ver *v) {
 /*
  * alphabetic less than numeric
  */
-int main(int ac, char *av[]) {
+int zpm_vercmp(char *vsa, char *vsb) {
        struct ver a, b;
        int an, bn;
        int cmp;
 
-       if (ac < 2) return 1;
-
-       init_ver(&a, av[1]);
-       init_ver(&b, av[2]);
+       init_ver(&a, vsa);
+       init_ver(&b, vsb);
        do {
                an = next_comp(&a);
                bn = next_comp(&b);
                if (an != bn) {
                        if (an == 0 && a.type == 2 && b.sep == 0 && b.type == 1) {
-                               printf("1\n");
+                               return 1;
                        } else if (bn == 0 && b.type == 2 && a.sep == 0 && a.type == 1) {
-                               printf("-1\n");
-                       } else {
-                               printf("%s\n", an < bn ? "-1" : "1");
+                               return -1;
                        }
-                       exit(0);
+                       return an < bn ? -1 : 1;
                }
                cmp = ver_cmp(&a, &b);
                if (cmp != 0) {
-                       printf("%d\n", cmp);
-                       exit(0);
+                       return cmp;
                }
        } while (an && bn);
 
        /* if we've gotten here, and both have releases, check those */
        if (a.relstr && b.relstr && a.release != b.release) {
-               printf("%s\n", a.release < b.release ? "-1" : "1");
-               exit(0);
+               return a.release < b.release ? -1 : 1;
        }
        
-       printf("0\n");
        return 0;
 }
diff --git a/zpm.h b/zpm.h
index 7ed6cfefdcb900784abda2a794f9b6ae937b5a2f..ee807228048b5588dec76941bddeb37c690195ec 100644 (file)
--- a/zpm.h
+++ b/zpm.h
@@ -98,4 +98,5 @@ void *compresslzma(void *buf, size_t bufsize, size_t *len);
 int zpm_hash(char *path, char *hash, uint32_t flags);
 int zpm_readopts(struct zpm *pkg, int ac, char **av);
 
+int zpm_vercmp(char *a, char *b);
 #endif