diff --git a/Makefile b/Makefile index 5bb3010..e662a79 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,14 @@ testinput: run.py - ./run.py > testinput + ./run.py /var/lib/apt/lists/ftp.debian.org_debian_dists_sid_main_binary-amd64_Packages > testinput + +testinput.1000: run.py + ./run.py /var/lib/apt/lists/ftp.debian.org_debian_dists_sid_main_binary-amd64_Packages | awk 'NR % 1000 == 1' > testinput.1000 + +testinput.unequal: testinput inequalityfilter + ./inequalityfilter < testinput > testinput.unequal + +testinput.unequal.1000: testinput inequalityfilter + ./inequalityfilter < testinput | awk 'NR % 1000 == 1' > testinput.unequal.1000 testdpkg: testdpkg.c gcc testdpkg.c -ldpkg -o testdpkg @@ -10,12 +19,31 @@ testapt: testapt.cc testdose: testdose.ml ocamlfind ocamlc -package dose3 -linkpkg testdose.ml -o testdose +inequalityfilter: inequalityfilter.cc + g++ inequalityfilter.cc -lapt-pkg -o inequalityfilter + .PHONY: test -test: testinput testdpkg testapt +test: testinput testdpkg testapt testdose rundpkg.sh ./rundpkg.sh < testinput | md5sum ./testapt < testinput | md5sum ./testdose < testinput | md5sum +.PHONY: test.1000 +test.1000: testinput.1000 testdpkg testapt testdose rundpkg.sh + ./rundpkg.sh < testinput.1000 | md5sum + ./testapt < testinput.1000 | md5sum + ./testdose < testinput.1000 | md5sum + +.PHONY: testsort +testsort: testinput.unequal testapt testsort.sh + ./testapt < testinput.unequal | md5sum + ./testsort.sh < testinput.unequal | md5sum + +.PHONY: testsort.1000 +testsort.1000: testinput.unequal.1000 testapt testsort.sh + ./testapt < testinput.unequal.1000 | md5sum + ./testsort.sh < testinput.unequal.1000 | md5sum + .PHONY: clean clean: - rm -f testapt testdose testdose.cmi testdose.cmo testdpkg testinput + rm -f testapt testdose testdose.cmi testdose.cmo testdpkg testinput inequalityfilter diff --git a/inequalityfilter.cc b/inequalityfilter.cc new file mode 100644 index 0000000..eaeaabf --- /dev/null +++ b/inequalityfilter.cc @@ -0,0 +1,41 @@ +#include +#include +#include +#include + +int main() +{ + char *line = NULL; + char *token; + char *orig1; + char *orig2; + char *ver1; + char *ver2; + size_t len = 0; + size_t read; + int ret; + while ((read = getline(&line, &len, stdin)) != -1) { + //fprintf(stderr, "%s", line); + orig1 = strdup(line); + orig2 = strdup(line); + token = orig1; + ver1 = strsep(&token, "\t"); + if (ver1 == NULL) { + fprintf(stderr, "cannot read token1"); + exit(EXIT_FAILURE); + } + ver2 = strsep(&token, "\n"); + if (ver2 == NULL) { + fprintf(stderr, "cannot read token2"); + exit(EXIT_FAILURE); + } + ret = debVS.CmpVersion(ver1, ver2); + if (ret != 0) { + fputs(orig2, stdout); + } + //fputs(orig2, stdout); + free(orig1); + free(orig2); + } + exit(EXIT_SUCCESS); +} diff --git a/run.py b/run.py index 2371938..22e92ab 100755 --- a/run.py +++ b/run.py @@ -1,10 +1,12 @@ #!/usr/bin/env python +from __future__ import print_function import deb822 +import sys versions = set() -with open("/home/josch/gsoc2012/bootstrap/Packages") as f: - for pkg in deb822.Deb822.iter_paragraphs(f, use_apt_pkg=False): +with open(sys.argv[1]) as f: + for pkg in deb822.Deb822.iter_paragraphs(f): ver = pkg.get('Version') if ver: versions.add(ver) @@ -13,6 +15,8 @@ with open("/home/josch/gsoc2012/bootstrap/Packages") as f: # through the list of versions and comparing every version with all that come # after it versions = sorted(versions) +l = len(versions) for i,v1 in enumerate(versions): + print("%f %%\r"%((i*100.0)/l), file=sys.stderr, end="") for v2 in versions[i+1:]: print("%s\t%s"%(v1,v2)) diff --git a/testapt.cc b/testapt.cc index 4f76fcf..8711591 100644 --- a/testapt.cc +++ b/testapt.cc @@ -37,6 +37,10 @@ int main() } else { fputc('<', stdout); } + /* + fputc(' ', stdout); + fputs(orig2, stdout); + */ //fputs(orig2, stdout); free(orig1); free(orig2); diff --git a/testsort.sh b/testsort.sh new file mode 100755 index 0000000..36e4f93 --- /dev/null +++ b/testsort.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +# some examples where `sort -V` does the wrong thing: +# 0.04-1-5 0.4-3 +# 0.1+20080921-2 0.1-1+b8 +# 0.1+dfsg-4 000.001-4 +# 0.1.0+20071012-1.2 0.1.0-1.1 +# 0.3.0+20091229-1 0.3.0-7.2 +# 0.6.0+git20130305-5 0.6.0-5+b1 +# 0:2009.10.04-1 1.0pre11-1 +# 0:2009.10.04-1 1.240-1 +# 0:2009.10.04-1 1.7.2.4-4.1 +# 0:2009.10.04-1 2.3-12 +# 0:2009.10.04-1 8.0.184.15484+dfsg-2 +# 1.0+dfsg-1 1.00-6 + +i=0 +while read line; do + printf "$i\r" >&2 + i=$((i+1)) + set -- $line + newest=$( ( echo "$1"; echo "$2" ) | sort -V | tail -n1) + if [ "$1" != "$newest" ]; then + printf "<" + else + printf ">" + fi + printf " %s\t%s\n" $1 $2 +done