c8d6f62da5fa2e51706ebf895fb6c36cc3662b41
[platform/upstream/libsolv.git] / tools / mergesolv.c
1 /*
2  * Copyright (c) 2007, Novell Inc.
3  *
4  * This program is licensed under the BSD license, read LICENSE.BSD
5  * for further information
6  */
7
8 /*
9  * mergesolv
10  * 
11  */
12
13 #include <sys/types.h>
14 #include <limits.h>
15 #include <fcntl.h>
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <assert.h>
20
21 #include "pool.h"
22 #include "repo_solv.h"
23 #include "repo_write.h"
24
25 static char *verticals[] = {
26   "authors",
27   "description",
28   "messagedel",
29   "messageins",
30   "eula",
31   "diskusage",
32   0
33 };
34
35 static unsigned char *filter;
36 static int nfilter;
37
38 static void
39 create_filter(Pool *pool)
40 {
41   char **s;
42   Id id;
43   for (s = verticals; *s; s++)
44     {
45       id = str2id(pool, *s, 1);
46       if (id >= nfilter)
47         {
48           filter = sat_realloc(filter, id + 16);
49           memset(filter + nfilter, 0, id + 16 - nfilter);
50           nfilter = id + 16;
51         }
52       filter[id] = 1;
53     }
54 }
55
56 static int
57 keyfilter(Repo *data, Repokey *key, void *kfdata)
58 {
59   if (key->name < nfilter && filter[key->name])
60     return KEY_STORAGE_VERTICAL_OFFSET;
61   return KEY_STORAGE_INCORE;
62 }
63
64 int
65 main(int argc, char **argv)
66 {
67   Pool *pool = pool_create();
68   Repo *repo;
69
70   repo = repo_create(pool, "");
71   while (argc-- > 1)
72     {
73       FILE *fp;
74       argv++;
75       if ((fp = fopen(*argv, "r")) == NULL)
76         {
77           perror(argv[1]);
78           exit(0);
79         }
80       repo_add_solv(repo, fp);
81       fclose(fp);
82     }
83
84   create_filter(pool);
85   repo_write(repo, stdout, keyfilter, 0, 0, 0);
86   pool_free(pool);
87
88   return 0;
89 }