- add repo_mdk_add_info() function to parse the M&M info.xml file
[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           "  -h : print help & exit\n"
40          );
41    exit(status);
42 }
43
44 int
45 main(int argc, char **argv)
46 {
47   Pool *pool;
48   Repo *repo;
49   char *infofile;
50   int c;
51
52   while ((c = getopt(argc, argv, "i:")) >= 0)
53     {
54       switch(c)
55         {
56         case 'h':
57           usage(0);
58           break;
59         case 'i':
60           infofile = optarg;
61           break;
62         default:
63           usage(1);
64           break;
65         }
66     }
67   pool = pool_create();
68   repo = repo_create(pool, "<stdin>");
69   repo_add_mdk(repo, stdin, REPO_NO_INTERNALIZE);
70   if (infofile)
71     {
72       FILE *fp = solv_xfopen(infofile, "r");
73       if (!fp)
74         {
75           perror(infofile);
76           exit(1);
77         }
78       repo_add_mdk_info(repo, fp, REPO_EXTEND_SOLVABLES | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE);
79       fclose(fp);
80     }
81   repo_internalize(repo);
82   tool_write(repo, 0, 0);
83   pool_free(pool);
84   exit(0);
85 }