From 2397144294c496fe17c3a8b7ae2eaa45f2898b93 Mon Sep 17 00:00:00 2001 From: Michael Schroeder Date: Fri, 7 Jan 2011 15:32:09 +0100 Subject: [PATCH] - kill stillborn KINDS_SEPARATELY, use getopt() in tools --- ext/repo_rpmmd.h | 2 -- ext/repo_susetags.c | 48 ++++++++++------------------------------- ext/repo_susetags.h | 1 - ext/repo_zyppdb.c | 14 ++++-------- tools/deltainfoxml2solv.c | 54 +++++++++++++++++----------------------------- tools/diskusagexml2solv.c | 54 +++++++++++++++++----------------------------- tools/dumpsolv.c | 53 +++++++++++++++++++++------------------------ tools/rpmmd2solv.c | 8 ++----- tools/susetags2solv.c | 8 ++----- tools/updateinfoxml2solv.c | 52 ++++++++++++++++---------------------------- 10 files changed, 103 insertions(+), 191 deletions(-) diff --git a/ext/repo_rpmmd.h b/ext/repo_rpmmd.h index 9b021b2..931a7f3 100644 --- a/ext/repo_rpmmd.h +++ b/ext/repo_rpmmd.h @@ -5,6 +5,4 @@ * for further information */ -#define RPMMD_KINDS_SEPARATELY (1 << 2) - extern void repo_add_rpmmd(Repo *repo, FILE *fp, const char *language, int flags); diff --git a/ext/repo_susetags.c b/ext/repo_susetags.c index d8daa7f..b5fff0c 100644 --- a/ext/repo_susetags.c +++ b/ext/repo_susetags.c @@ -567,11 +567,6 @@ repo_add_susetags(Repo *repo, FILE *fp, Id defvendor, const char *language, int cummulate = 0; switch (tag_from_string(line)) /* check if accumulation is needed */ { - case CTAG('+', 'P', 'r', 'q'): - case CTAG('+', 'P', 'r', 'c'): - case CTAG('+', 'P', 's', 'g'): - if (!pd.kind || !(flags & SUSETAGS_KINDS_SEPARATELY)) - break; case CTAG('+', 'D', 'e', 's'): case CTAG('+', 'E', 'u', 'l'): case CTAG('+', 'I', 'n', 's'): @@ -579,6 +574,9 @@ repo_add_susetags(Repo *repo, FILE *fp, Id defvendor, const char *language, int case CTAG('+', 'A', 'u', 't'): if (line[4] == ':') cummulate = 1; + break; + default: + break; } line[0] = '='; /* handle lines between +Key:/-Key: as =Key: */ line[intag + keylen - 1] = ' '; @@ -706,10 +704,7 @@ repo_add_susetags(Repo *repo, FILE *fp, Id defvendor, const char *language, int case CTAG('=', 'P', 'r', 'q'): /* pre-requires / packages required */ if (pd.kind) { - if (flags & SUSETAGS_KINDS_SEPARATELY) - repodata_set_poolstr(data, handle, str2id(pool, "solvable:must", 1), line + 6); - else - s->requires = adddep(pool, &pd, s->requires, line, 0, 0); /* patterns: a required package */ + s->requires = adddep(pool, &pd, s->requires, line, 0, 0); /* patterns: a required package */ } else s->requires = adddep(pool, &pd, s->requires, line, SOLVABLE_PREREQMARKER, 0); /* package: pre-requires */ @@ -736,46 +731,25 @@ repo_add_susetags(Repo *repo, FILE *fp, Id defvendor, const char *language, int freshens = adddep(pool, &pd, freshens, line, 0, pd.kind); continue; case CTAG('=', 'P', 'r', 'c'): /* packages recommended */ - if (flags & SUSETAGS_KINDS_SEPARATELY) - repodata_set_poolstr(data, handle, str2id(pool, "solvable:should", 1), line + 6); - else - s->recommends = adddep(pool, &pd, s->recommends, line, 0, 0); + s->recommends = adddep(pool, &pd, s->recommends, line, 0, 0); continue; case CTAG('=', 'P', 's', 'g'): /* packages suggested */ - if (flags & SUSETAGS_KINDS_SEPARATELY) - repodata_set_poolstr(data, handle, str2id(pool, "solvable:may", 1), line + 6); - else - s->suggests = adddep(pool, &pd, s->suggests, line, 0, 0); + s->suggests = adddep(pool, &pd, s->suggests, line, 0, 0); continue; case CTAG('=', 'P', 'c', 'n'): /* pattern: package conflicts */ - if (flags & SUSETAGS_KINDS_SEPARATELY) - fprintf(stderr, "Unsupported: pattern -> package conflicts\n"); - else - s->conflicts = adddep(pool, &pd, s->conflicts, line, 0, 0); + s->conflicts = adddep(pool, &pd, s->conflicts, line, 0, 0); continue; case CTAG('=', 'P', 'o', 'b'): /* pattern: package obsoletes */ - if (flags & SUSETAGS_KINDS_SEPARATELY) - fprintf(stderr, "Unsupported: pattern -> package obsoletes\n"); - else - s->obsoletes = adddep(pool, &pd, s->obsoletes, line, 0, 0); + s->obsoletes = adddep(pool, &pd, s->obsoletes, line, 0, 0); continue; case CTAG('=', 'P', 'f', 'r'): /* pattern: package freshens */ - if (flags & SUSETAGS_KINDS_SEPARATELY) - fprintf(stderr, "Unsupported: pattern -> package freshens\n"); - else - freshens = adddep(pool, &pd, freshens, line, 0, 0); + freshens = adddep(pool, &pd, freshens, line, 0, 0); continue; case CTAG('=', 'P', 's', 'p'): /* pattern: package supplements */ - if (flags & SUSETAGS_KINDS_SEPARATELY) - fprintf(stderr, "Unsupported: pattern -> package supplements\n"); - else - s->supplements = adddep(pool, &pd, s->supplements, line, 0, 0); + s->supplements = adddep(pool, &pd, s->supplements, line, 0, 0); continue; case CTAG('=', 'P', 'e', 'n'): /* pattern: package enhances */ - if (flags & SUSETAGS_KINDS_SEPARATELY) - fprintf(stderr, "Unsupported: pattern -> package enhances\n"); - else - s->enhances = adddep(pool, &pd, s->enhances, line, 0, 0); + s->enhances = adddep(pool, &pd, s->enhances, line, 0, 0); continue; case CTAG('=', 'V', 'e', 'r'): /* - version - */ last_found_pack = 0; diff --git a/ext/repo_susetags.h b/ext/repo_susetags.h index 91acd2a..f922dbf 100644 --- a/ext/repo_susetags.h +++ b/ext/repo_susetags.h @@ -9,7 +9,6 @@ * if given, write attributes as '.attr' */ -#define SUSETAGS_KINDS_SEPARATELY (1 << 8) #define SUSETAGS_EXTEND (1 << 9) extern void repo_add_susetags(Repo *repo, FILE *fp, Id defvendor, const char *language, int flags); diff --git a/ext/repo_zyppdb.c b/ext/repo_zyppdb.c index f69c7bf..b4f7b90 100644 --- a/ext/repo_zyppdb.c +++ b/ext/repo_zyppdb.c @@ -141,7 +141,7 @@ startElement(void *userData, const char *name, const char **atts) struct stateswitch *sw; #if 0 - fprintf(stderr, "start: [%d]%s\n", pd->state, name); + fprintf(stderr, "start: [%d]%s\n", pd->state, name); #endif if (pd->depth != pd->statedepth) { @@ -214,7 +214,7 @@ endElement(void *userData, const char *name) Solvable *s = pd->solvable; #if 0 - fprintf(stderr, "end: [%d]%s\n", pd->state, name); + fprintf(stderr, "end: [%d]%s\n", pd->state, name); #endif if (pd->depth != pd->statedepth) { @@ -262,7 +262,7 @@ endElement(void *userData, const char *name) pd->docontent = 0; #if 0 - fprintf(stderr, "end: [%s] -> %d\n", name, pd->state); + fprintf(stderr, "end: [%s] -> %d\n", name, pd->state); #endif } @@ -273,14 +273,8 @@ characterData(void *userData, const XML_Char *s, int len) struct parsedata *pd = userData; int l; char *c; - if (!pd->docontent) { -#if 0 - char *dup = strndup( s, len ); - fprintf(stderr, "Content: [%d]'%s'\n", pd->state, dup ); - free( dup ); -#endif + if (!pd->docontent) return; - } l = pd->lcontent + len + 1; if (l > pd->acontent) { diff --git a/tools/deltainfoxml2solv.c b/tools/deltainfoxml2solv.c index a0fe6c2..1528df2 100644 --- a/tools/deltainfoxml2solv.c +++ b/tools/deltainfoxml2solv.c @@ -11,6 +11,7 @@ #include #include #include +#include #include "pool.h" #include "repo.h" @@ -18,58 +19,43 @@ #include "common_write.h" static void -usage(const char *err) +usage(int status) { - if (err) - fprintf(stderr, "\n** Error:\n %s\n", err); fprintf(stderr, "\nUsage:\n" - "deltainfoxml2solv [-a][-h][-k][-n ]\n" + "deltainfoxml2solv [-a][-h][-n ]\n" " reads a 'deltainfo.xml' file from and writes a .solv file to \n" " -h : print help & exit\n" - " -k : don't mix kinds (experimental!)\n" " -n : save attributes as .attr\n" ); - exit(0); + exit(status); } int main(int argc, char **argv) { - int flags = 0; + int c, flags = 0; char *attrname = 0; Pool *pool = pool_create(); Repo *repo = repo_create(pool, ""); - argv++; - argc--; - while (argc--) - { - const char *s = argv[0]; - if (*s++ == '-') - while (*s) - switch (*s++) - { - case 'h': usage(NULL); break; - case 'n': - if (argc) - { - attrname = argv[1]; - argv++; - argc--; - } - else - usage("argument required for '-n'"); - break; - case 'k': - break; - default : break; - } - argv++; + while ((c = getopt(argc, argv, "hn:")) >= 0) + { + switch(c) + { + case 'h': + usage(0); + break; + case 'n': + attrname = optarg; + break; + default: + usage(1); + break; + } } - repo_add_deltainfoxml(repo, stdin, flags); - tool_write(repo, 0, 0); + tool_write(repo, 0, attrname); pool_free(pool); exit(0); } diff --git a/tools/diskusagexml2solv.c b/tools/diskusagexml2solv.c index fd9e564..bfc775f 100644 --- a/tools/diskusagexml2solv.c +++ b/tools/diskusagexml2solv.c @@ -11,6 +11,7 @@ #include #include #include +#include #include "pool.h" #include "repo.h" @@ -18,58 +19,43 @@ #include "common_write.h" static void -usage(const char *err) +usage(int status) { - if (err) - fprintf(stderr, "\n** Error:\n %s\n", err); fprintf(stderr, "\nUsage:\n" - "diskusagexml2solv [-a][-h][-k][-n ]\n" + "diskusagexml2solv [-a][-h][-n ]\n" " reads a 'diskusage.xml' file from and writes a .solv file to \n" " -h : print help & exit\n" - " -k : don't mix kinds (experimental!)\n" " -n : save attributes as .attr\n" ); - exit(0); + exit(status); } int main(int argc, char **argv) { - int flags = 0; + int c, flags = 0; char *attrname = 0; Pool *pool = pool_create(); Repo *repo = repo_create(pool, ""); - argv++; - argc--; - while (argc--) - { - const char *s = argv[0]; - if (*s++ == '-') - while (*s) - switch (*s++) - { - case 'h': usage(NULL); break; - case 'n': - if (argc) - { - attrname = argv[1]; - argv++; - argc--; - } - else - usage("argument required for '-n'"); - break; - case 'k': - break; - default : break; - } - argv++; + while ((c = getopt(argc, argv, "hn:")) >= 0) + { + switch(c) + { + case 'h': + usage(0); + break; + case 'n': + attrname = optarg; + break; + default: + usage(1); + break; + } } - repo_add_diskusagexml(repo, stdin, flags); - tool_write(repo, 0, 0); + tool_write(repo, 0, attrname); pool_free(pool); exit(0); } diff --git a/tools/dumpsolv.c b/tools/dumpsolv.c index 061f3d0..77a5a35 100644 --- a/tools/dumpsolv.c +++ b/tools/dumpsolv.c @@ -200,15 +200,13 @@ printf("loc %s\n", location); static void -usage( const char *err ) +usage(int status) { - if (err) - fprintf (stderr, "\n** Error:\n %s\n", err); fprintf( stderr, "\nUsage:\n" "dumpsolv [-a] []\n" " -a read attributes.\n" ); - exit(0); + exit(status); } #if 0 @@ -247,40 +245,39 @@ int main(int argc, char **argv) { Repo *repo; Pool *pool; - int i, j, n; + int c, i, j, n; Solvable *s; pool = pool_create(); pool_setdebuglevel(pool, 1); pool_setloadcallback(pool, loadcallback, 0); - argv++; - argc--; - while (argc--) + while ((c = getopt(argc, argv, "ha")) >= 0) { - const char *s = argv[0]; - if (*s++ == '-') - while (*s) - switch (*s++) - { - case 'h': usage(NULL); break; - case 'a': with_attr = 1; break; - default : break; - } - else + switch(c) { - if (freopen (argv[0], "r", stdin) == 0) - { - perror(argv[0]); - exit(1); - } - repo = repo_create(pool, argv[0]); - if (repo_add_solv(repo, stdin)) - printf("could not read repository\n"); + case 'h': + usage(0); + break; + case 'a': + with_attr = 1; + break; + default: + usage(1); + break; } - argv++; } - + for (; optind < argc; optind++) + { + if (freopen(argv[optind], "r", stdin) == 0) + { + perror(argv[optind]); + exit(1); + } + repo = repo_create(pool, argv[optind]); + if (repo_add_solv(repo, stdin)) + printf("could not read repository\n"); + } if (!pool->nrepos) { repo = repo_create(pool, argc != 1 ? argv[1] : ""); diff --git a/tools/rpmmd2solv.c b/tools/rpmmd2solv.c index f08bbe8..e5c2c84 100644 --- a/tools/rpmmd2solv.c +++ b/tools/rpmmd2solv.c @@ -59,10 +59,9 @@ static void usage(int status) { fprintf(stderr, "\nUsage:\n" - "rpmmd2solv [-a][-h][-k][-n ][-l ]\n" + "rpmmd2solv [-a][-h][-n ][-l ]\n" " reads 'primary' from a 'rpmmd' repository from and writes a .solv file to \n" " -h : print help & exit\n" - " -k : don't mix kinds (experimental!)\n" " -n : save attributes as .attr\n" " -l : parse localization data for \n" ); @@ -81,16 +80,13 @@ main(int argc, char **argv) Pool *pool = pool_create(); Repo *repo = repo_create(pool, ""); - while ((c = getopt (argc, argv, "hkn:b:d:l:")) >= 0) + while ((c = getopt (argc, argv, "hn:b:d:l:")) >= 0) { switch(c) { case 'h': usage(0); break; - case 'k': - flags |= RPMMD_KINDS_SEPARATELY; /* do not use! */ - break; case 'n': attrname = optarg; break; diff --git a/tools/susetags2solv.c b/tools/susetags2solv.c index daf7249..a0fd08e 100644 --- a/tools/susetags2solv.c +++ b/tools/susetags2solv.c @@ -27,13 +27,12 @@ static void usage(int status) { fprintf(stderr, "\nUsage:\n" - "susetags2solv [-b ][-c ][-d ][-h][-k][-n ]\n" + "susetags2solv [-b ][-c ][-d ][-h][-n ]\n" " reads a 'susetags' repository from and writes a .solv file to \n" " -b : save as multiple files starting with \n" " -c : parse given contentfile (for product information)\n" " -d : do not read from stdin, but use data in descrdir\n" " -h : print help & exit\n" - " -k : don't mix kinds (experimental!)\n" " -n : save attributes as .attr\n" ); exit(status); @@ -101,16 +100,13 @@ main(int argc, char **argv) int flags = 0; int c; - while ((c = getopt(argc, argv, "hkn:c:d:b:q:")) >= 0) + while ((c = getopt(argc, argv, "hn:c:d:b:q:")) >= 0) { switch (c) { case 'h': usage(0); break; - case 'k': - flags |= SUSETAGS_KINDS_SEPARATELY; /* do not use! */ - break; case 'n': attrname = optarg; break; diff --git a/tools/updateinfoxml2solv.c b/tools/updateinfoxml2solv.c index e893c1b..921538f 100644 --- a/tools/updateinfoxml2solv.c +++ b/tools/updateinfoxml2solv.c @@ -11,6 +11,7 @@ #include #include #include +#include #include "pool.h" #include "repo.h" @@ -18,58 +19,43 @@ #include "common_write.h" static void -usage(const char *err) +usage(int status) { - if (err) - fprintf(stderr, "\n** Error:\n %s\n", err); fprintf(stderr, "\nUsage:\n" - "updateinfoxml2solv [-a][-h][-k][-n ]\n" + "updateinfoxml2solv [-h][-n ]\n" " reads a 'updateinfo.xml' file from and writes a .solv file to \n" " -h : print help & exit\n" - " -k : don't mix kinds (experimental!)\n" " -n : save attributes as .attr\n" ); - exit(0); + exit(status); } int main(int argc, char **argv) { - int flags = 0; + int c, flags = 0; char *attrname = 0; Pool *pool = pool_create(); Repo *repo = repo_create(pool, ""); - argv++; - argc--; - while (argc--) + while ((c = getopt(argc, argv, "hn:")) >= 0) { - const char *s = argv[0]; - if (*s++ == '-') - while (*s) - switch (*s++) - { - case 'h': usage(NULL); break; - case 'n': - if (argc) - { - attrname = argv[1]; - argv++; - argc--; - } - else - usage("argument required for '-n'"); - break; - case 'k': - break; - default : break; - } - argv++; + switch(c) + { + case 'h': + usage(0); + break; + case 'n': + attrname = optarg; + break; + default: + usage(1); + break; + } } - repo_add_updateinfoxml(repo, stdin, flags); - tool_write(repo, 0, 0); + tool_write(repo, 0, attrname); pool_free(pool); exit(0); } -- 2.7.4