Imported Upstream version 0.7.18
[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 <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_appdata.h"
26 #include "common_write.h"
27
28 int
29 main(int argc, char **argv)
30 {
31   Pool *pool = pool_create();
32   Repo *repo;
33   int c;
34   const char *appdatadir = 0;
35   const char *root = 0;
36
37   while ((c = getopt(argc, argv, "hd:r:")) >= 0)
38     {
39       switch (c)
40         {
41         case 'd':
42           appdatadir = optarg;
43           break;
44         case 'r':
45           root = optarg;
46           break;
47         default:
48           fprintf(stderr, "usage: appdata2solv [-d appdatadir]");
49           exit(c == 'h' ? 0 : 1);
50         }
51     }
52
53   if (root)
54     pool_set_rootdir(pool, root);
55     
56   repo = repo_create(pool, "<stdin>");
57   if (!appdatadir)
58     {
59       if (repo_add_appdata(repo, stdin, 0))
60         {
61           fprintf(stderr, "appdata2solv: %s\n", pool_errstr(pool));
62           exit(1);
63         }
64     }
65   else
66     {
67       if (repo_add_appdata_dir(repo, appdatadir, REPO_USE_ROOTDIR))
68         {
69           fprintf(stderr, "appdata2solv: %s\n", pool_errstr(pool));
70           exit(1);
71         }
72     }
73   tool_write(repo, stdout);
74   pool_free(pool);
75   exit(0);
76 }