a8753a1fc8736c052b290998e1fcfa70cd40071c
[platform/upstream/libsolv.git] / tools / appdata2solv.c
1 /*
2  * Copyright (c) 2013, Novell Inc.
3  *
4  * This program is licensed under the BSD license, read LICENSE.BSD
5  * for further information
6  */
7
8 /*
9  * appdata2solv.c
10  * 
11  * parse AppStream appdata type xml and write out .solv 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 <unistd.h>
24
25 #include "pool.h"
26 #include "repo.h"
27 #include "repo_appdata.h"
28 #include "common_write.h"
29
30 int
31 main(int argc, char **argv)
32 {
33   Pool *pool = pool_create();
34   Repo *repo;
35   int c;
36   const char *appdatadir = 0;
37   const char *root = 0;
38
39   while ((c = getopt(argc, argv, "hd:r:")) >= 0)
40     {
41       switch (c)
42         {
43         case 'd':
44           appdatadir = optarg;
45           break;
46         case 'r':
47           root = optarg;
48           break;
49         default:
50           fprintf(stderr, "usage: appdata2solv [-d appdatadir]");
51           exit(c == 'h' ? 0 : 1);
52         }
53     }
54
55   if (root)
56     pool_set_rootdir(pool, root);
57     
58   repo = repo_create(pool, "<stdin>");
59   if (!appdatadir)
60     {
61       if (repo_add_appdata(repo, stdin, 0))
62         {
63           fprintf(stderr, "appdata2solv: %s\n", pool_errstr(pool));
64           exit(1);
65         }
66     }
67   else
68     {
69       if (repo_add_appdata_dir(repo, appdatadir, REPO_USE_ROOTDIR))
70         {
71           fprintf(stderr, "appdata2solv: %s\n", pool_errstr(pool));
72           exit(1);
73         }
74     }
75   tool_write(repo, 0, 0);
76   pool_free(pool);
77   exit(0);
78 }