- also free attrs array when freeing a solvable
[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   repo_add_mdk(repo, stdin, REPO_NO_INTERNALIZE);
74   if (infofile)
75     {
76       FILE *fp = solv_xfopen(infofile, "r");
77       if (!fp)
78         {
79           perror(infofile);
80           exit(1);
81         }
82       repo_add_mdk_info(repo, fp, REPO_EXTEND_SOLVABLES | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE);
83       fclose(fp);
84     }
85   if (filesfile)
86     {
87       FILE *fp = solv_xfopen(filesfile, "r");
88       if (!fp)
89         {
90           perror(filesfile);
91           exit(1);
92         }
93       repo_add_mdk_info(repo, fp, REPO_EXTEND_SOLVABLES | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE);
94       fclose(fp);
95     }
96   repo_internalize(repo);
97   tool_write(repo, 0, 0);
98   pool_free(pool);
99   exit(0);
100 }