From a4f4fde9cfca71ba10c0f7b2b888b1c4e6c011e3 Mon Sep 17 00:00:00 2001 From: pancake Date: Tue, 28 Oct 2008 16:51:58 +0100 Subject: [PATCH] Initial import of xbps-cmpver --HG-- extra : convert_revision : 57260b5d7bfc45cb2e2c877fad2fdcae155c0a75 --- utils/Makefile | 8 +++++--- utils/{chkver.c => xbps-cmpver.c} | 32 ++++++++++++++++--------------- 2 files changed, 22 insertions(+), 18 deletions(-) rename utils/{chkver.c => xbps-cmpver.c} (60%) 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