From 5e8118e21314ab3da8a459974dc4beba004b0bcc Mon Sep 17 00:00:00 2001 From: Alexey Tourbin Date: Sat, 11 Sep 2010 02:07:19 +0400 Subject: [PATCH] tools/mkset.c, tools/setcmp.c: command-line helpers --- rpm-4_0.spec | 3 +++ tools/Makefile.am | 5 ++++- tools/mkset.c | 30 ++++++++++++++++++++++++++++++ tools/setcmp.c | 27 +++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 tools/mkset.c create mode 100644 tools/setcmp.c diff --git a/rpm-4_0.spec b/rpm-4_0.spec index 9a055d5..923661c 100644 --- a/rpm-4_0.spec +++ b/rpm-4_0.spec @@ -445,6 +445,9 @@ fi %rpmattr %_rpmlibdir/symlinks.* %rpmattr %_rpmlibdir/verify-elf %rpmattr %_rpmlibdir/*.awk +# set-version helpers +%rpmattr %_rpmlibdir/mkset +%rpmattr %_rpmlibdir/setcmp %_mandir/man?/gendiff.* %_man8dir/rpmbuild.* diff --git a/tools/Makefile.am b/tools/Makefile.am index 9297de1..f01c435 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -28,7 +28,7 @@ noinst_PROGRAMS = \ dump dumpdb rpmarchive rpmheader rpmlead rpmsignature pkgbindir = @RPMCONFIGDIR@ -pkgbin_PROGRAMS = javadeps filesize dump_ld_config relative pdeath_execute +pkgbin_PROGRAMS = javadeps filesize dump_ld_config relative pdeath_execute mkset setcmp bin_PROGRAMS = rpmvercmp rpmevrcmp javadeps_SOURCES = javadeps.c @@ -45,6 +45,9 @@ dump_ld_config_LDADD = pdeath_execute_SOURCES = pdeath_execute.c pdeath_execute_LDADD = +mkset_SOURCES = mkset.c +setcmp_SOURCES = setcmp.c + rpmvercmp_SOURCES = rpmvercmp.c rpmevrcmp_SOURCES = rpmevrcmp.c diff --git a/tools/mkset.c b/tools/mkset.c new file mode 100644 index 0000000..1b87f0e --- /dev/null +++ b/tools/mkset.c @@ -0,0 +1,30 @@ +#include +#include +#include +#include "set.h" + +int main(int argc, const char **argv) +{ + assert(argc == 2); + int bpp = atoi(argv[1]); + assert(bpp >= 10); + assert(bpp <= 32); + struct set *set = set_new(); + char *line = NULL; + size_t alloc_size = 0; + ssize_t len; + int added = 0; + while ((len = getline(&line, &alloc_size, stdin)) >= 0) { + if (len > 0 && line[len-1] == '\n') + line[--len] = '\0'; + if (len == 0) + continue; + set_add(set, line); + added++; + } + assert(added > 0); + const char *str = set_fini(set, bpp); + assert(str); + printf("set:%s\n", str); + return 0; +} diff --git a/tools/setcmp.c b/tools/setcmp.c new file mode 100644 index 0000000..8c74bd6 --- /dev/null +++ b/tools/setcmp.c @@ -0,0 +1,27 @@ +#include +#include +#include "set.h" + +int main(int argc, const char **argv) +{ + assert(argc == 3); + int cmp = rpmsetcmp(argv[1], argv[2]); + switch (cmp) { + case 1: + case 0: + case -1: + case -2: + printf("%d\n", cmp); + return 0; + case -3: + fprintf(stderr, "%s: set1 error\n", __FILE__); + break; + case -4: + fprintf(stderr, "%s: set2 error\n", __FILE__); + break; + default: + fprintf(stderr, "%s: unknown error\n", __FILE__); + break; + } + return 1; +}