From b33428b853d91ff15eee32fd1407ae0924a56bb7 Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Mon, 11 Feb 2008 02:38:58 +0000 Subject: [PATCH] Factor out the filter code in preparation for nicely configuring where to write which attributes. --- tools/CMakeLists.txt | 13 +++---- tools/common_write.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++ tools/common_write.h | 15 ++++++++ tools/content2solv.c | 4 +-- tools/helix2solv.c | 4 +-- tools/mergesolv.c | 44 ++--------------------- tools/patchxml2solv.c | 4 +-- tools/rpmdb2solv.c | 4 +-- tools/rpmmd2solv.c | 4 +-- tools/susetags2solv.c | 88 ++------------------------------------------- 10 files changed, 135 insertions(+), 143 deletions(-) create mode 100644 tools/common_write.c create mode 100644 tools/common_write.h diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index e854a72..65a9f6f 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -4,24 +4,25 @@ SET(rpmdb2solv_REPOS repo_rpmdb.h repo_rpmdb.c repo_write.c + common_write.c ) ADD_EXECUTABLE( rpmdb2solv ${rpmdb2solv_REPOS} ) TARGET_LINK_LIBRARIES( rpmdb2solv satsolver ${DB43_LIBRARY}) -SET(rpmmd2solv_REPOS rpmmd2solv.c repo_rpmmd.h repo_rpmmd.c repo_write.c ) +SET(rpmmd2solv_REPOS rpmmd2solv.c repo_rpmmd.h repo_rpmmd.c repo_write.c common_write.c ) ADD_EXECUTABLE( rpmmd2solv ${rpmmd2solv_REPOS} ) TARGET_LINK_LIBRARIES( rpmmd2solv satsolver ${EXPAT_LIBRARY}) -SET(helix2solv_REPOS helix2solv.c repo_helix.h repo_helix.c repo_write.c ) +SET(helix2solv_REPOS helix2solv.c repo_helix.h repo_helix.c repo_write.c common_write.c ) ADD_EXECUTABLE( helix2solv ${helix2solv_REPOS} ) TARGET_LINK_LIBRARIES( helix2solv satsolver ${EXPAT_LIBRARY}) -SET(susetags2solv_REPOS susetags2solv.c repo_susetags.h repo_susetags.c repo_write.c) +SET(susetags2solv_REPOS susetags2solv.c repo_susetags.h repo_susetags.c repo_write.c common_write.c) ADD_EXECUTABLE( susetags2solv ${susetags2solv_REPOS} ) TARGET_LINK_LIBRARIES( susetags2solv satsolver) -SET(patchxml2solv_REPOS patchxml2solv.c repo_patchxml.h repo_patchxml.c repo_write.c) +SET(patchxml2solv_REPOS patchxml2solv.c repo_patchxml.h repo_patchxml.c repo_write.c common_write.c) ADD_EXECUTABLE( patchxml2solv ${patchxml2solv_REPOS} ) TARGET_LINK_LIBRARIES( patchxml2solv satsolver ${EXPAT_LIBRARY}) @@ -30,7 +31,7 @@ SET(content2solv_REPOS content2solv.c repo_content.h repo_content.c - repo_write.c) + repo_write.c common_write.c) ADD_EXECUTABLE( content2solv ${content2solv_REPOS} ) TARGET_LINK_LIBRARIES( content2solv satsolver) @@ -39,7 +40,7 @@ SET(dumpsolv_REPOS dumpsolv.c) ADD_EXECUTABLE( dumpsolv ${dumpsolv_REPOS} ) TARGET_LINK_LIBRARIES( dumpsolv satsolver) -SET(mergesolv_REPOS mergesolv.c repo_write.c) +SET(mergesolv_REPOS mergesolv.c repo_write.c common_write.c) ADD_EXECUTABLE( mergesolv ${mergesolv_REPOS} ) TARGET_LINK_LIBRARIES( mergesolv satsolver) diff --git a/tools/common_write.c b/tools/common_write.c new file mode 100644 index 0000000..7862338 --- /dev/null +++ b/tools/common_write.c @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2007, Novell Inc. + * + * This program is licensed under the BSD license, read LICENSE.BSD + * for further information + */ + +#include +#include +#include +#include +#include +#include + +#include "pool.h" +#include "repo.h" +#include "repo_write.h" +#include "common_write.h" + +static char *verticals[] = { + "authors", + "description", + "messagedel", + "messageins", + "eula", + "diskusage", + 0 +}; + +static unsigned char *filter; +static int nfilter; + +static void +create_filter(Pool *pool) +{ + char **s; + Id id; + for (s = verticals; *s; s++) + { + id = str2id(pool, *s, 1); + if (id >= nfilter) + { + filter = sat_realloc(filter, id + 16); + memset(filter + nfilter, 0, id + 16 - nfilter); + nfilter = id + 16; + } + filter[id] = 1; + } +} + +static int test_separate = 0; + +static int +keyfilter_solv(Repo *data, Repokey *key, void *kfdata) +{ + if (test_separate && key->storage != KEY_STORAGE_SOLVABLE) + return KEY_STORAGE_DROPPED; + if (key->name < nfilter && filter[key->name]) + return KEY_STORAGE_VERTICAL_OFFSET; + return KEY_STORAGE_INCORE; +} + +static int +keyfilter_attr(Repo *data, Repokey *key, void *kfdata) +{ + if (key->storage == KEY_STORAGE_SOLVABLE) + return KEY_STORAGE_DROPPED; + if (key->name < nfilter && filter[key->name]) + return KEY_STORAGE_VERTICAL_OFFSET; + return KEY_STORAGE_INCORE; +} + +int +tool_write(Repo *repo, const char *basename, int separate) +{ + Pool *pool = repo->pool; + Repodatafile fileinfoa[1]; + Repodatafile *fileinfo = 0; + int nsubfiles = 0; + + create_filter(pool); + memset (fileinfoa, 0, sizeof fileinfoa); + if (separate) + { + test_separate = 1; + fileinfo = fileinfoa; + FILE *fp = fopen ("test.attr", "w"); + repo_write(repo, fp, keyfilter_attr, 0, fileinfo, 0); + fclose (fp); + fileinfo->location = strdup ("test.attr"); + fileinfo++; + + nsubfiles = fileinfo - fileinfoa; + fileinfo = fileinfoa; + } + repo_write(repo, stdout, keyfilter_solv, 0, fileinfo, nsubfiles); + return 0; +} diff --git a/tools/common_write.h b/tools/common_write.h new file mode 100644 index 0000000..d32e0f5 --- /dev/null +++ b/tools/common_write.h @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2007, Novell Inc. + * + * This program is licensed under the BSD license, read LICENSE.BSD + * for further information + */ + +#ifndef COMMON_WRITE_H +#define COMMON_WRITE_H + +#include "repo.h" + +int tool_write(Repo *repo, const char *basename, int separate); + +#endif diff --git a/tools/content2solv.c b/tools/content2solv.c index c29958f..fca1757 100644 --- a/tools/content2solv.c +++ b/tools/content2solv.c @@ -15,7 +15,7 @@ #include "pool.h" #include "repo.h" #include "repo_content.h" -#include "repo_write.h" +#include "common_write.h" int main(int argc, char **argv) @@ -23,7 +23,7 @@ main(int argc, char **argv) Pool *pool = pool_create(); Repo *repo = repo_create(pool, ""); repo_add_content(repo, stdin); - repo_write(repo, stdout, 0, 0, 0, 0); + tool_write(repo, 0, 0); pool_free(pool); return 0; } diff --git a/tools/helix2solv.c b/tools/helix2solv.c index 764f195..f02b620 100644 --- a/tools/helix2solv.c +++ b/tools/helix2solv.c @@ -23,7 +23,7 @@ #include "pool.h" #include "repo_helix.h" -#include "repo_write.h" +#include "common_write.h" int main(int argc, char **argv) @@ -31,7 +31,7 @@ main(int argc, char **argv) Pool *pool = pool_create(); Repo *repo = repo_create(pool, ""); repo_add_helix(repo, stdin); - repo_write(repo, stdout, 0, 0, 0, 0); + tool_write(repo, 0, 0); pool_free(pool); exit(0); } diff --git a/tools/mergesolv.c b/tools/mergesolv.c index c8d6f62..14a466a 100644 --- a/tools/mergesolv.c +++ b/tools/mergesolv.c @@ -20,46 +20,7 @@ #include "pool.h" #include "repo_solv.h" -#include "repo_write.h" - -static char *verticals[] = { - "authors", - "description", - "messagedel", - "messageins", - "eula", - "diskusage", - 0 -}; - -static unsigned char *filter; -static int nfilter; - -static void -create_filter(Pool *pool) -{ - char **s; - Id id; - for (s = verticals; *s; s++) - { - id = str2id(pool, *s, 1); - if (id >= nfilter) - { - filter = sat_realloc(filter, id + 16); - memset(filter + nfilter, 0, id + 16 - nfilter); - nfilter = id + 16; - } - filter[id] = 1; - } -} - -static int -keyfilter(Repo *data, Repokey *key, void *kfdata) -{ - if (key->name < nfilter && filter[key->name]) - return KEY_STORAGE_VERTICAL_OFFSET; - return KEY_STORAGE_INCORE; -} +#include "common_write.h" int main(int argc, char **argv) @@ -81,8 +42,7 @@ main(int argc, char **argv) fclose(fp); } - create_filter(pool); - repo_write(repo, stdout, keyfilter, 0, 0, 0); + tool_write(repo, 0, 0); pool_free(pool); return 0; diff --git a/tools/patchxml2solv.c b/tools/patchxml2solv.c index 68b478e..987bf23 100644 --- a/tools/patchxml2solv.c +++ b/tools/patchxml2solv.c @@ -15,7 +15,7 @@ #include "pool.h" #include "repo.h" #include "repo_patchxml.h" -#include "repo_write.h" +#include "common_write.h" int main(int argc, char **argv) @@ -23,7 +23,7 @@ main(int argc, char **argv) Pool *pool = pool_create(); Repo *repo = repo_create(pool, ""); repo_add_patchxml(repo, stdin); - repo_write(repo, stdout, 0, 0, 0, 0); + tool_write(repo, 0, 0); pool_free(pool); exit(0); } diff --git a/tools/rpmdb2solv.c b/tools/rpmdb2solv.c index 8bd134a..50f65de 100644 --- a/tools/rpmdb2solv.c +++ b/tools/rpmdb2solv.c @@ -21,7 +21,7 @@ #include "repo.h" #include "repo_rpmdb.h" #include "repo_solv.h" -#include "repo_write.h" +#include "common_write.h" int main(int argc, char **argv) @@ -54,7 +54,7 @@ main(int argc, char **argv) ref = 0; } - repo_write(repo, stdout, 0, 0, 0, 0); + tool_write(repo, 0, 0); pool_free(pool); exit(0); diff --git a/tools/rpmmd2solv.c b/tools/rpmmd2solv.c index 1351c47..eee17ee 100644 --- a/tools/rpmmd2solv.c +++ b/tools/rpmmd2solv.c @@ -15,7 +15,7 @@ #include "pool.h" #include "repo.h" #include "repo_rpmmd.h" -#include "repo_write.h" +#include "common_write.h" int main(int argc, char **argv) @@ -23,7 +23,7 @@ main(int argc, char **argv) Pool *pool = pool_create(); Repo *repo = repo_create(pool, ""); repo_add_rpmmd(repo, stdin); - repo_write(repo, stdout, 0, 0, 0, 0); + tool_write(repo, 0, 0); pool_free(pool); exit(0); } diff --git a/tools/susetags2solv.c b/tools/susetags2solv.c index a7a8b81..db302a9 100644 --- a/tools/susetags2solv.c +++ b/tools/susetags2solv.c @@ -15,73 +15,13 @@ #include "pool.h" #include "repo.h" #include "repo_susetags.h" -#include "repo_write.h" -#if 0 -#include "attr_store.h" - -extern Attrstore *attr; -#endif - -static char *verticals[] = { - "authors", - "description", - "messagedel", - "messageins", - "eula", - "diskusage", - 0 -}; - -static unsigned char *filter; -static int nfilter; - -static void -create_filter(Pool *pool) -{ - char **s; - Id id; - for (s = verticals; *s; s++) - { - id = str2id(pool, *s, 1); - if (id >= nfilter) - { - filter = sat_realloc(filter, id + 16); - memset(filter + nfilter, 0, id + 16 - nfilter); - nfilter = id + 16; - } - filter[id] = 1; - } -} - -static int test_separate = 0; - -static int -keyfilter_solv(Repo *data, Repokey *key, void *kfdata) -{ - if (test_separate && key->storage != KEY_STORAGE_SOLVABLE) - return KEY_STORAGE_DROPPED; - if (key->name < nfilter && filter[key->name]) - return KEY_STORAGE_VERTICAL_OFFSET; - return KEY_STORAGE_INCORE; -} - -static int -keyfilter_attr(Repo *data, Repokey *key, void *kfdata) -{ - if (key->storage == KEY_STORAGE_SOLVABLE) - return KEY_STORAGE_DROPPED; - if (key->name < nfilter && filter[key->name]) - return KEY_STORAGE_VERTICAL_OFFSET; - return KEY_STORAGE_INCORE; -} +#include "common_write.h" int main(int argc, char **argv) { - Repodatafile fileinfoa[1]; - Repodatafile *fileinfo = 0; - int nsubfiles = 0; int with_attr = 0; + int test_separate = 0; argv++; argc--; while (argc--) @@ -100,29 +40,7 @@ main(int argc, char **argv) Pool *pool = pool_create(); Repo *repo = repo_create(pool, ""); repo_add_susetags(repo, stdin, 0, with_attr); - create_filter(pool); - memset (fileinfoa, 0, sizeof fileinfoa); - if (with_attr && test_separate) - { - fileinfo = fileinfoa; - FILE *fp = fopen ("test.attr", "w"); - repo_write(repo, fp, keyfilter_attr, 0, fileinfo, 0); - fclose (fp); - fileinfo->location = strdup ("test.attr"); - fileinfo++; - - nsubfiles = fileinfo - fileinfoa; - fileinfo = fileinfoa; - } - repo_write(repo, stdout, keyfilter_solv, 0, fileinfo, nsubfiles); -#if 0 - if (with_attr && attr) - { - FILE *fp = fopen ("test.attr", "w"); - write_attr_store (fp, attr); - fclose (fp); - } -#endif + tool_write(repo, 0, with_attr && test_separate); pool_free(pool); exit(0); } -- 2.7.4