Factor out the filter code in preparation for nicely configuring where
authorMichael Matz <matz@suse.de>
Mon, 11 Feb 2008 02:38:58 +0000 (02:38 +0000)
committerMichael Matz <matz@suse.de>
Mon, 11 Feb 2008 02:38:58 +0000 (02:38 +0000)
to write which attributes.

tools/CMakeLists.txt
tools/common_write.c [new file with mode: 0644]
tools/common_write.h [new file with mode: 0644]
tools/content2solv.c
tools/helix2solv.c
tools/mergesolv.c
tools/patchxml2solv.c
tools/rpmdb2solv.c
tools/rpmmd2solv.c
tools/susetags2solv.c

index e854a72..65a9f6f 100644 (file)
@@ -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 (file)
index 0000000..7862338
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2007, Novell Inc.
+ *
+ * This program is licensed under the BSD license, read LICENSE.BSD
+ * for further information
+ */
+
+#include <sys/types.h>
+#include <limits.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#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 (file)
index 0000000..d32e0f5
--- /dev/null
@@ -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
index c29958f..fca1757 100644 (file)
@@ -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, "<stdin>");
   repo_add_content(repo, stdin);
-  repo_write(repo, stdout, 0, 0, 0, 0);
+  tool_write(repo, 0, 0);
   pool_free(pool);
   return 0;
 }
index 764f195..f02b620 100644 (file)
@@ -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, "<stdin>");
   repo_add_helix(repo, stdin);
-  repo_write(repo, stdout, 0, 0, 0, 0);
+  tool_write(repo, 0, 0);
   pool_free(pool);
   exit(0);
 }
index c8d6f62..14a466a 100644 (file)
 
 #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;
index 68b478e..987bf23 100644 (file)
@@ -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, "<stdin>");
   repo_add_patchxml(repo, stdin);
-  repo_write(repo, stdout, 0, 0, 0, 0);
+  tool_write(repo, 0, 0);
   pool_free(pool);
   exit(0);
 }
index 8bd134a..50f65de 100644 (file)
@@ -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);
index 1351c47..eee17ee 100644 (file)
@@ -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, "<stdin>");
   repo_add_rpmmd(repo, stdin);
-  repo_write(repo, stdout, 0, 0, 0, 0);
+  tool_write(repo, 0, 0);
   pool_free(pool);
   exit(0);
 }
index a7a8b81..db302a9 100644 (file)
 #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, "<stdin>");
   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);
 }