- allow repositories that don't consist of a single block of solvables
[platform/upstream/libsolv.git] / tools / rpmdb2solv.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  * rpmdb2solv
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
20 #include "pool.h"
21 #include "repo_rpmdb.h"
22 #include "repo_solv.h"
23 #include "repo_write.h"
24
25 int
26 main(int argc, char **argv)
27 {
28   Pool *pool = pool_create();
29   Repo *repo, *ref = 0;
30   FILE *fp;
31
32   if (argc != 1)
33     {
34       Pool *refpool = pool;
35       if ((fp = fopen(argv[1], "r")) == NULL)
36         {
37           perror(argv[1]);
38           exit(0);
39         }
40       ref = repo_create(refpool, "ref");
41       repo_add_solv(ref, fp);
42       fclose(fp);
43     }
44
45   repo = repo_create(pool, "installed");
46   repo_add_rpmdb(repo, ref);
47   if (ref)
48     {
49       if (ref->pool != pool)
50         pool_free(ref->pool);
51       else
52         repo_free(ref, 1);
53       ref = 0;
54     }
55
56   repo_write(repo, stdout);
57   pool_free(pool);
58
59   exit(0);
60 }