Imported Upstream version 0.6.29
[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 <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <unistd.h>
22
23 #include "pool.h"
24 #include "repo.h"
25 #include "repo_mdk.h"
26 #include "solv_xfopen.h"
27 #include "common_write.h"
28
29
30 static void
31 usage(int status)
32 {
33   fprintf(stderr, "\nUsage:\n"
34           "mdk2solv [-i <infoxml>]\n"
35           "  reads a 'synthesis' repository from <stdin> and writes a .solv file to <stdout>\n"
36           "  -i : info.xml file for extra attributes\n"
37           "  -f : files.xml file for extra attributes\n"
38           "  -h : print help & exit\n"
39          );
40    exit(status);
41 }
42
43 int
44 main(int argc, char **argv)
45 {
46   Pool *pool;
47   Repo *repo;
48   char *infofile = 0, *filesfile = 0;
49   int c;
50
51   while ((c = getopt(argc, argv, "hi:f:")) >= 0)
52     {
53       switch(c)
54         {
55         case 'h':
56           usage(0);
57           break;
58         case 'i':
59           infofile = optarg;
60           break;
61         case 'f':
62           filesfile = optarg;
63           break;
64         default:
65           usage(1);
66           break;
67         }
68     }
69   pool = pool_create();
70   repo = repo_create(pool, "<stdin>");
71   if (repo_add_mdk(repo, stdin, REPO_NO_INTERNALIZE))
72     {
73       fprintf(stderr, "mdk2solv: %s\n", pool_errstr(pool));
74       exit(1);
75     }
76   if (infofile)
77     {
78       FILE *fp = solv_xfopen(infofile, "r");
79       if (!fp)
80         {
81           perror(infofile);
82           exit(1);
83         }
84       if (repo_add_mdk_info(repo, fp, REPO_EXTEND_SOLVABLES | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE))
85         {
86           fprintf(stderr, "mdk2solv: %s\n", pool_errstr(pool));
87           exit(1);
88         }
89       fclose(fp);
90     }
91   if (filesfile)
92     {
93       FILE *fp = solv_xfopen(filesfile, "r");
94       if (!fp)
95         {
96           perror(filesfile);
97           exit(1);
98         }
99       if (repo_add_mdk_info(repo, fp, REPO_EXTEND_SOLVABLES | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE))
100         {
101           fprintf(stderr, "mdk2solv: %s\n", pool_errstr(pool));
102           exit(1);
103         }
104       fclose(fp);
105     }
106   repo_internalize(repo);
107   tool_write(repo, 0, 0);
108   pool_free(pool);
109   exit(0);
110 }