Imported Upstream version 0.6.7
[platform/upstream/libsolv.git] / tools / mdk2solv.c
1 /*
2  * Copyright (c) 2012, Novell Inc.
3  *
4  * This program is licensed under the BSD license, read LICENSE.BSD
5  * for further information
6  */
7
8 /*
9  * mdk2solv.c
10  *
11  * parse Mandriva/Mageie synthesis file
12  *
13  * reads from stdin
14  * writes to stdout
15  */
16
17 #include <sys/types.h>
18 #include <limits.h>
19 #include <fcntl.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <getopt.h>
24
25 #include "pool.h"
26 #include "repo.h"
27 #include "repo_mdk.h"
28 #include "solv_xfopen.h"
29 #include "common_write.h"
30
31
32 static void
33 usage(int status)
34 {
35   fprintf(stderr, "\nUsage:\n"
36           "mdk2solv [-i <infoxml>]\n"
37           "  reads a 'synthesis' repository from <stdin> and writes a .solv file to <stdout>\n"
38           "  -i : info.xml file for extra attributes\n"
39           "  -f : files.xml file for extra attributes\n"
40           "  -h : print help & exit\n"
41          );
42    exit(status);
43 }
44
45 int
46 main(int argc, char **argv)
47 {
48   Pool *pool;
49   Repo *repo;
50   char *infofile = 0, *filesfile = 0;
51   int c;
52
53   while ((c = getopt(argc, argv, "hi:f:")) >= 0)
54     {
55       switch(c)
56         {
57         case 'h':
58           usage(0);
59           break;
60         case 'i':
61           infofile = optarg;
62           break;
63         case 'f':
64           filesfile = optarg;
65           break;
66         default:
67           usage(1);
68           break;
69         }
70     }
71   pool = pool_create();
72   repo = repo_create(pool, "<stdin>");
73   if (repo_add_mdk(repo, stdin, REPO_NO_INTERNALIZE))
74     {
75       fprintf(stderr, "mdk2solv: %s\n", pool_errstr(pool));
76       exit(1);
77     }
78   if (infofile)
79     {
80       FILE *fp = solv_xfopen(infofile, "r");
81       if (!fp)
82         {
83           perror(infofile);
84           exit(1);
85         }
86       if (repo_add_mdk_info(repo, fp, REPO_EXTEND_SOLVABLES | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE))
87         {
88           fprintf(stderr, "mdk2solv: %s\n", pool_errstr(pool));
89           exit(1);
90         }
91       fclose(fp);
92     }
93   if (filesfile)
94     {
95       FILE *fp = solv_xfopen(filesfile, "r");
96       if (!fp)
97         {
98           perror(filesfile);
99           exit(1);
100         }
101       if (repo_add_mdk_info(repo, fp, REPO_EXTEND_SOLVABLES | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE))
102         {
103           fprintf(stderr, "mdk2solv: %s\n", pool_errstr(pool));
104           exit(1);
105         }
106       fclose(fp);
107     }
108   repo_internalize(repo);
109   tool_write(repo, 0, 0);
110   pool_free(pool);
111   exit(0);
112 }