diff --git a/utils/Makefile b/utils/Makefile index 35c38cb8acb..ed95d2d09aa 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -3,8 +3,11 @@ PREFIX ?= /usr/local PKGDB_CFLAGS += -Wall -Werror -I$(PREFIX)/include PKGDB_LDFLAGS += -lprop -all: xbps-digest xbps-pkgdb +all: xbps-digest xbps-pkgdb xbps-cmpver +xbps-cmpver: xbps-cmpver.o + $(CC) $(CFLAGS) $< -o $@ + xbps-digest: xbps-digest.o $(CC) $(CFLAGS) $< -o $@ @@ -15,5 +18,4 @@ clean_objs: -rm -f *.o clean: clean_objs - -rm -f xbps-digest xbps-pkgdb - + -rm -f xbps-digest xbps-pkgdb xbps-cmpver diff --git a/utils/chkver.c b/utils/xbps-cmpver.c similarity index 60% rename from utils/chkver.c rename to utils/xbps-cmpver.c index 51f11b19852..a0954cac177 100644 --- a/utils/chkver.c +++ b/utils/xbps-cmpver.c @@ -1,12 +1,12 @@ /* * Compare package and version strings - * + * @ 2008 * Author: pancake */ #include #include -static int chkchr(char *ch) +static int chkchr(const char *ch) { if (*ch>='0' && *ch<='9') return *ch-'0'; @@ -54,26 +54,28 @@ int chkpkg(const char *a0, const char *b0) char *b = strchr(b0, '-'); if (a == NULL || b== NULL) { - eprintf("Invalid package names\n"); + fprintf(stderr, "Invalid package names\n"); return 0; } return chkver(a+1, b+1); } #if UNIT_TEST + printf("1.2 2.2 = %d\n", chkver("1.2", "2.2")); + printf("1.0 10.3 = %d\n", chkver("1.0", "10.3")); + printf("1.0 1.0 = %d\n", chkver("1.0", "1.0")); + printf("1.0 1.2 = %d\n", chkver("1.0", "1.2")); + printf("1.0.1 1.0.2 = %d\n", chkver("1.0.1", "1.0.2")); + printf("1.0beta 1.0rc1 = %d\n", chkver("1.0beta", "1.0rc1")); +#endif + int main(int argc, char **argv) { - if (argc>2) { - printf("%s %s = %d\n", - argv[1], argv[2], - chkver(argv[1], argv[2])); - } else { - printf("1.2 2.2 = %d\n", chkver("1.2", "2.2")); - printf("1.0 10.3 = %d\n", chkver("1.0", "10.3")); - printf("1.0 1.0 = %d\n", chkver("1.0", "1.0")); - printf("1.0 1.2 = %d\n", chkver("1.0", "1.2")); - printf("1.0.1 1.0.2 = %d\n", chkver("1.0.1", "1.0.2")); - printf("1.0beta 1.0rc1 = %d\n", chkver("1.0beta", "1.0rc1")); + if (argc<3) { + printf("Usage: ./xbps-cmpver [old] [new]\n"); + printf(" ./xbpks-cmpver foo-1.2 foo-2.2 # $? = 1\n"); + printf(" ./xbpks-cmpver foo-1.2 foo-1.2 # $? = 0\n"); + return 1; } + return (chkpkg(argv[1], argv[2]) > 0)?1:0; } -#endif