- grr, why on earth do the bindings have a loadcallback?
[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 <unistd.h>
15 #include <limits.h>
16 #include <fcntl.h>
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <assert.h>
21
22 #include "pool.h"
23 #include "repo_solv.h"
24 #include "common_write.h"
25
26 static void
27 usage()
28 {
29   fprintf(stderr, "\nUsage:\n"
30           "mergesolv [file] [file] [...]\n"
31           "  merges multiple solv files into one and writes it to stdout\n"
32           );
33   exit(0);
34 }
35
36 static FILE *
37 loadcallback (Pool *pool, Repodata *data, void *vdata)
38 {
39   FILE *fp = 0;
40   const char *location = repodata_lookup_str(data, REPOENTRY_META, REPOSITORY_LOCATION);
41   if (location)
42     {
43       fprintf(stderr, "Loading SOLV file %s\n", location);
44       fp = fopen (location, "r");
45       if (!fp)
46         perror(location);
47     }
48   return fp;
49 }
50
51 int
52 main(int argc, char **argv)
53 {
54   Pool *pool;
55   Repo *repo;
56   const char *basefile = 0;
57   int with_attr = 0;
58   int c;
59
60   pool = pool_create();
61   repo = repo_create(pool, "<mergesolv>");
62   
63   while ((c = getopt(argc, argv, "ahb:")) >= 0)
64     {
65       switch (c)
66       {
67         case 'h':
68           usage();
69           break;
70         case 'a':
71           with_attr = 1;
72           break;
73         case 'b':
74           basefile = optarg;
75           break;
76         default:
77           exit(1);
78       }
79     }
80   if (with_attr)
81     pool_setloadcallback(pool, loadcallback, 0);
82
83   for (; optind < argc; optind++)
84     {
85       FILE *fp;
86       if ((fp = fopen(argv[optind], "r")) == NULL)
87         {
88           perror(argv[optind]);
89           exit(1);
90         }
91       repo_add_solv(repo, fp);
92       fclose(fp);
93     }
94   tool_write(repo, basefile, 0);
95   pool_free(pool);
96   return 0;
97 }