- support -b option
[platform/upstream/libsolv.git] / tools / rpms2solv.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  * rpms2solv - create a solv file from multiple rpms
10  * 
11  */
12
13 #include <sys/types.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <unistd.h>
17 #include <string.h>
18
19 #include "util.h"
20 #include "pool.h"
21 #include "repo.h"
22 #include "repo_rpmdb.h"
23 #include "repo_solv.h"
24 #include "common_write.h"
25
26 int
27 main(int argc, char **argv)
28 {
29   const char **rpms = 0;
30   char *manifest = 0;
31   int c, nrpms = 0;
32   Pool *pool = pool_create();
33   Repo *repo;
34   FILE *fp;
35   char buf[4096], *p;
36   const char *basefile = 0;
37
38   while ((c = getopt(argc, argv, "b:m:")) >= 0)
39     {
40       switch(c)
41         {
42         case 'b':
43           basefile = optarg;
44           break;
45         case 'm':
46           manifest = optarg;
47           break;
48         default:
49           exit(1);
50         }
51     }
52   if (manifest)
53     {
54       if ((fp = fopen(manifest, "r")) == 0)
55         {
56           perror(manifest);
57           exit(1);
58         }
59       while(fgets(buf, sizeof(buf), fp))
60         {
61           if ((p = strchr(buf, '\n')) != 0)
62             *p = 0;
63           rpms = sat_extend(rpms, nrpms, 1, sizeof(char *), 15);
64           rpms[nrpms++] = strdup(buf);
65         }
66       fclose(fp);
67     }
68   while (optind < argc)
69     {
70       rpms = sat_extend(rpms, nrpms, 1, sizeof(char *), 15);
71       rpms[nrpms++] = strdup(argv[optind++]);
72     }
73   repo = repo_create(pool, "rpms2solv");
74   repo_add_rpms(repo, rpms, nrpms);
75   tool_write(repo, basefile, 0);
76   pool_free(pool);
77   for (c = 0; c < nrpms; c++)
78     free((char *)rpms[c]);
79   sat_free(rpms);
80   exit(0);
81 }
82