Support for generating separate sub files and bugfixes in the reader
[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.h"
22 #include "repo_rpmdb.h"
23 #include "repo_solv.h"
24 #include "repo_write.h"
25
26 int
27 main(int argc, char **argv)
28 {
29   Pool *pool = pool_create();
30   Repo *repo, *ref = 0;
31   FILE *fp;
32
33   if (argc != 1)
34     {
35       Pool *refpool = pool;
36       if ((fp = fopen(argv[1], "r")) == NULL)
37         {
38           perror(argv[1]);
39           exit(0);
40         }
41       ref = repo_create(refpool, "ref");
42       repo_add_solv(ref, fp);
43       fclose(fp);
44     }
45
46   repo = repo_create(pool, "installed");
47   repo_add_rpmdb(repo, ref, "/");
48   if (ref)
49     {
50       if (ref->pool != pool)
51         pool_free(ref->pool);
52       else
53         repo_free(ref, 1);
54       ref = 0;
55     }
56
57   repo_write(repo, stdout, 0, 0, 0, 0);
58   pool_free(pool);
59
60   exit(0);
61 }