- add a license
[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 *ref = NULL;
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 = pool_addrepo_solv(refpool, fp, "rpmdb");
41       fclose(fp);
42     }
43
44   Repo *repo = pool_addrepo_rpmdb(pool, ref);
45   if (ref)
46     {
47       if (ref->pool != pool)
48         pool_free(ref->pool);
49       else
50         pool_freerepo(pool, ref);
51       ref = NULL;
52     }
53
54   pool_writerepo(pool, repo, stdout);
55   pool_free(pool);
56
57   exit(0);
58 }