- add '-d' option to susetags2solv, reads all packages files
[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 #include <unistd.h>
20
21 #include "pool.h"
22 #include "repo.h"
23 #include "repo_rpmdb.h"
24 #include "repo_solv.h"
25 #include "common_write.h"
26
27 int
28 main(int argc, char **argv)
29 {
30   Pool *pool = pool_create();
31   Repo *repo, *ref = 0;
32   FILE *fp;
33   Pool *refpool;
34   int c;
35   const char *root = "/";
36   const char *basefile = 0;
37
38   while ((c = getopt (argc, argv, "b:r:")) >= 0)
39     switch (c)
40       {
41       case 'r':
42         root = optarg;
43         break;
44       case 'b':
45         basefile = optarg;
46         break;
47       default:
48         exit(1);
49       }
50   
51   if (optind < argc)
52     {
53       refpool = pool;
54       if ((fp = fopen(argv[optind], "r")) == NULL)
55         {
56           perror(argv[optind]);
57           exit(1);
58         }
59       ref = repo_create(refpool, "ref");
60       repo_add_solv(ref, fp);
61       fclose(fp);
62     }
63
64   repo = repo_create(pool, "installed");
65   repo_add_rpmdb(repo, ref, root);
66   if (ref)
67     {
68       if (ref->pool != pool)
69         pool_free(ref->pool);
70       else
71         repo_free(ref, 1);
72       ref = 0;
73     }
74
75   tool_write(repo, basefile, 0);
76   pool_free(pool);
77
78   exit(0);
79 }