- new program
[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
37   while ((c = getopt(argc, argv, "m:")) >= 0)
38     {
39       switch(c)
40         {
41         case 'm':
42           manifest = optarg;
43           break;
44         default:
45           exit(1);
46         }
47     }
48   if (manifest)
49     {
50       if ((fp = fopen(manifest, "r")) == 0)
51         {
52           perror(manifest);
53           exit(1);
54         }
55       while(fgets(buf, sizeof(buf), fp))
56         {
57           if ((p = strchr(buf, '\n')) != 0)
58             *p = 0;
59           rpms = sat_extend(rpms, nrpms, 1, sizeof(char *), 15);
60           rpms[nrpms++] = strdup(buf);
61         }
62       fclose(fp);
63     }
64   while (optind < argc)
65     {
66       rpms = sat_extend(rpms, nrpms, 1, sizeof(char *), 15);
67       rpms[nrpms++] = strdup(argv[optind++]);
68     }
69   repo = repo_create(pool, "rpms2solv");
70   repo_add_rpms(repo, rpms, nrpms);
71   tool_write(repo, 0, 0);
72   pool_free(pool);
73   for (c = 0; c < nrpms; c++)
74     free((char *)rpms[c]);
75   sat_free(rpms);
76   exit(0);
77 }
78