* Initial import of chkver (compare version and package strings)
* Oops. update-index for Makefile in / and utils/ --HG-- extra : convert_revision : 2e3132bd594600b63febf11a01bc1fd63da73398
This commit is contained in:
parent
af3fe4c94c
commit
86d787a276
8
Makefile
8
Makefile
|
@ -1,8 +1,2 @@
|
|||
all:
|
||||
mkdir -p utils
|
||||
cd xbps-digest && make
|
||||
cp -f xbps-digest/xbps-digest utils/
|
||||
cd xbps-pkgdb && make
|
||||
cp -f xbps-pkgdb/xbps-pkgdb utils/
|
||||
cd xbps-digest && make clean
|
||||
cd xbps-pkgdb && make clean
|
||||
cd utils && make
|
||||
|
|
|
@ -1,10 +1,16 @@
|
|||
CFLAGS += -Wall -Werror -O3 -funroll-all-loops -ftree-loop-linear
|
||||
PREFIX ?= /usr/local
|
||||
PKGDB_CFLAGS += -Wall -Werror -I$(PREFIX)/include
|
||||
PKGDB_LDFLAGS += -lprop
|
||||
|
||||
all: xbps-digest
|
||||
all: xbps-digest xbps-pkgdb
|
||||
|
||||
xbps-digest: xbps-digest.o
|
||||
$(CC) $(CFLAGS) $< -o $@
|
||||
|
||||
clean:
|
||||
-rm -rf *.o xbps-digest
|
||||
xbps-pkgdb: xbps-pkgdb.o
|
||||
$(CC) $(PKGDB_CFLAGS) $(CFLAGS) $(PKGDB_LDFLAGS) $< -o $@
|
||||
|
||||
clean:
|
||||
-rm -rf *.o xbps-digest xbps-pkgdb
|
||||
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Compare package and version strings
|
||||
*
|
||||
* Author: pancake <youterm.com>
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static int chkchr(char *ch)
|
||||
{
|
||||
if (*ch>='0' && *ch<='9')
|
||||
return *ch-'0';
|
||||
switch(*ch) {
|
||||
case 'a': if (ch[1]=='l')
|
||||
return 0xa;
|
||||
return -1;
|
||||
case 'b': return 0xb;
|
||||
case 'r': return 0xc;
|
||||
}
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
static int ver2int(const char *a0, int *pow, int mpow)
|
||||
{
|
||||
int r,ret = 0;
|
||||
int pos = 0;
|
||||
const char *a = a0+strlen(a0)-1;
|
||||
for(*pow=0;a>=a0;a=a-1) {
|
||||
if (*a=='.') {
|
||||
*pow=*pow+1;
|
||||
} else {
|
||||
r = chkchr(a);
|
||||
if (r != -1)
|
||||
ret+=((r+1)*((*pow)+1))<<pos++;
|
||||
}
|
||||
if (mpow>0 && *pow > mpow)
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int chkver(const char *a0, const char *a1)
|
||||
{
|
||||
int p0,p1;
|
||||
int v0 = ver2int(a0, &p0, 0);
|
||||
int v1 = ver2int(a1, &p1, p0);
|
||||
return v1-v0;
|
||||
}
|
||||
|
||||
int chkpkg(const char *a0, const char *b0)
|
||||
{
|
||||
char *a = strchr(a0, '-');
|
||||
char *b = strchr(b0, '-');
|
||||
|
||||
if (a == NULL || b== NULL) {
|
||||
eprintf("Invalid package names\n");
|
||||
return 0;
|
||||
}
|
||||
return chkver(a+1, b+1);
|
||||
}
|
||||
|
||||
#if UNIT_TEST
|
||||
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"));
|
||||
}
|
||||
}
|
||||
#endif
|
Loading…
Reference in New Issue