Mailinglist Archive: zypp-commit (301 mails)

< Previous Next >
[zypp-commit] r7528 - in /trunk/sat-solver: src/source_solv.c tools/Makefile.am tools/mergesolv.c
  • From: matz@xxxxxxxxxxxxxxxx
  • Date: Mon, 15 Oct 2007 01:59:13 -0000
  • Message-id: <20071015015913.34EFD45628@xxxxxxxxxxxxxxxx>
Author: matz
Date: Mon Oct 15 03:59:12 2007
New Revision: 7528

URL: http://svn.opensuse.org/viewcvs/zypp?rev=7528&view=rev
Log:
I have use for a tool to merge .solv files.

Added:
    trunk/sat-solver/tools/mergesolv.c
Modified:
    trunk/sat-solver/src/source_solv.c
    trunk/sat-solver/tools/Makefile.am

Modified: trunk/sat-solver/src/source_solv.c
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/src/source_solv.c?rev=7528&r1=7527&r2=7528&view=diff
==============================================================================
--- trunk/sat-solver/src/source_solv.c (original)
+++ trunk/sat-solver/src/source_solv.c Mon Oct 15 03:59:12 2007
@@ -464,6 +464,7 @@
     }
   if (size_idarray)
     source->idarraydata = (Id *)xmalloc(sizeof(Id) * size_idarray);
+  source->idarraysize = size_idarray;
   idarraydatap = source->idarraydata;
 
   /* alloc solvables */

Modified: trunk/sat-solver/tools/Makefile.am
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/tools/Makefile.am?rev=7528&r1=7527&r2=7528&view=diff
==============================================================================
--- trunk/sat-solver/tools/Makefile.am (original)
+++ trunk/sat-solver/tools/Makefile.am Mon Oct 15 03:59:12 2007
@@ -1,9 +1,9 @@
-noinst_PROGRAMS = rpmdb2solv rpmmd2solv helix2solv susetags2solv patchxml2solv dumpsolv
+noinst_PROGRAMS = rpmdb2solv rpmmd2solv helix2solv susetags2solv patchxml2solv dumpsolv mergesolv
 
 INCLUDES =  \
        -I$(top_srcdir)/src
 
-LIBS = \
+LDADD = \
        $(top_builddir)/src/libsatsolver.la
 
 noinst_HEADERS = source_write.h
@@ -49,3 +49,6 @@
 dumpsolv_SOURCES = \
        dumpsolv.c
 
+mergesolv_SOURCES = \
+       mergesolv.c \
+       source_write.c

Added: trunk/sat-solver/tools/mergesolv.c
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/tools/mergesolv.c?rev=7528&view=auto
==============================================================================
--- trunk/sat-solver/tools/mergesolv.c (added)
+++ trunk/sat-solver/tools/mergesolv.c Mon Oct 15 03:59:12 2007
@@ -0,0 +1,97 @@
+/*
+ * mergesolv
+ * 
+ */
+
+#include <sys/types.h>
+#include <limits.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "pool.h"
+#include "source_solv.h"
+#include "source_write.h"
+
+static void
+adjust (Id **val, Id * new_id, Source *source)
+{
+  if (!*val)
+    return;
+  assert (source->idarraydata <= *val);
+  assert (*val < source->idarraydata + source->idarraysize);
+  *val = new_id + (*val - source->idarraydata);
+}
+
+int
+main(int argc, char **argv)
+{
+  Pool *pool = pool_create();
+  int i;
+  int new_id_size;
+  Id *new_id;
+
+  while (argc-- > 1)
+    {
+      FILE *fp;
+      argv++;
+      if ((fp = fopen(*argv, "r")) == NULL)
+       {
+         perror(argv[1]);
+         exit(0);
+       }
+      pool_addsource_solv(pool, fp, "");
+      fclose(fp);
+    }
+  if (!pool->nsources)
+    return 0;
+
+  new_id_size = 0;
+  for (i = 0; i < pool->nsources; i++)
+    new_id_size += pool->sources[i]->idarraysize;
+  new_id = (Id*) malloc (sizeof (Id) * new_id_size);
+  new_id_size = 0;
+  for (i = 0; i < pool->nsources; i++)
+    {
+      Source *source = pool->sources[i];
+      int si;
+      memcpy (new_id + new_id_size, source->idarraydata,
+             source->idarraysize * sizeof (new_id[0]));
+      for (si = source->start; si < source->start + source->nsolvables; si++)
+        {
+         Solvable *s = pool->solvables + si;
+         adjust (&s->provides, new_id + new_id_size, source);
+         adjust (&s->obsoletes, new_id + new_id_size, source);
+         adjust (&s->conflicts, new_id + new_id_size, source);
+         adjust (&s->requires, new_id + new_id_size, source);
+         adjust (&s->recommends, new_id + new_id_size, source);
+         adjust (&s->suggests, new_id + new_id_size, source);
+         adjust (&s->supplements, new_id + new_id_size, source);
+         adjust (&s->enhances, new_id + new_id_size, source);
+         adjust (&s->freshens, new_id + new_id_size, source);
+       }
+      new_id_size += source->idarraysize;
+      if (i > 0)
+        {
+         pool->sources[0]->nsolvables += source->nsolvables;
+         source->nsolvables = 0;
+         source->start = pool->nsolvables;
+         free (source->idarraydata);
+         source->idarraydata = 0;
+       }
+    }
+  while (pool->nsources > 1)
+    {
+      pool_freesource (pool, pool->sources[1]);
+    }
+  free (pool->sources[0]->idarraydata);
+  pool->sources[0]->idarraydata = new_id;
+  pool->sources[0]->idarraysize = new_id_size;
+
+  pool_writesource(pool, pool->sources[0], stdout);
+  pool_free(pool);
+
+  return 0;
+}

--
To unsubscribe, e-mail: zypp-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages