to follow SUSE tools conventions
[platform/upstream/libsolv.git] / tools / mergesolv.c
1 /*
2  * mergesolv
3  * 
4  */
5
6 #include <sys/types.h>
7 #include <limits.h>
8 #include <fcntl.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <assert.h>
13
14 #include "pool.h"
15 #include "repo_solv.h"
16 #include "repo_write.h"
17
18 int
19 main(int argc, char **argv)
20 {
21   Pool *pool = pool_create();
22   int i;
23   int new_id_size;
24   Id *new_id;
25
26   while (argc-- > 1)
27     {
28       FILE *fp;
29       argv++;
30       if ((fp = fopen(*argv, "r")) == NULL)
31         {
32           perror(argv[1]);
33           exit(0);
34         }
35       pool_addrepo_solv(pool, fp, "");
36       fclose(fp);
37     }
38   if (!pool->nrepos)
39     return 0;
40
41   new_id_size = 0;
42   for (i = 0; i < pool->nrepos; i++)
43     new_id_size += pool->repos[i]->idarraysize;
44   new_id = (Id*) malloc (sizeof (Id) * new_id_size);
45   new_id_size = 0;
46   for (i = 0; i < pool->nrepos; i++)
47     {
48       Repo *repo = pool->repos[i];
49       int si;
50       memcpy (new_id + new_id_size, repo->idarraydata,
51               repo->idarraysize * sizeof (new_id[0]));
52       for (si = repo->start; si < repo->start + repo->nsolvables; si++)
53         {
54           Solvable *s = pool->solvables + si;
55           if (s->provides)
56             s->provides += new_id_size;
57           if (s->obsoletes)
58             s->obsoletes += new_id_size;
59           if (s->conflicts)
60             s->conflicts += new_id_size;
61           if (s->requires)
62             s->requires += new_id_size;
63           if (s->recommends)
64             s->recommends += new_id_size;
65           if (s->suggests)
66             s->suggests+= new_id_size;
67           if (s->supplements)
68             s->supplements += new_id_size;
69           if (s->enhances)
70             s->enhances += new_id_size;
71           if (s->freshens)
72             s->freshens += new_id_size;
73         }
74       new_id_size += repo->idarraysize;
75       if (i > 0)
76         {
77           pool->repos[0]->nsolvables += repo->nsolvables;
78           repo->nsolvables = 0;
79           repo->start = pool->nsolvables;
80           free (repo->idarraydata);
81           repo->idarraydata = 0;
82         }
83     }
84   while (pool->nrepos > 1)
85     {
86       pool_freerepo (pool, pool->repos[1]);
87     }
88   free (pool->repos[0]->idarraydata);
89   pool->repos[0]->idarraydata = new_id;
90   pool->repos[0]->idarraysize = new_id_size;
91
92   pool_writerepo(pool, pool->repos[0], stdout);
93   pool_free(pool);
94
95   return 0;
96 }