summaryrefslogtreecommitdiff
path: root/tools/appdata2solv.c
blob: a8753a1fc8736c052b290998e1fcfa70cd40071c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
 * Copyright (c) 2013, Novell Inc.
 *
 * This program is licensed under the BSD license, read LICENSE.BSD
 * for further information
 */

/*
 * appdata2solv.c
 * 
 * parse AppStream appdata type xml and write out .solv file
 *
 * reads from stdin
 * writes to stdout
 */

#include <sys/types.h>
#include <limits.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "pool.h"
#include "repo.h"
#include "repo_appdata.h"
#include "common_write.h"

int
main(int argc, char **argv)
{
  Pool *pool = pool_create();
  Repo *repo;
  int c;
  const char *appdatadir = 0;
  const char *root = 0;

  while ((c = getopt(argc, argv, "hd:r:")) >= 0)
    {
      switch (c)
	{
	case 'd':
	  appdatadir = optarg;
	  break;
	case 'r':
	  root = optarg;
	  break;
	default:
	  fprintf(stderr, "usage: appdata2solv [-d appdatadir]");
	  exit(c == 'h' ? 0 : 1);
	}
    }

  if (root)
    pool_set_rootdir(pool, root);
    
  repo = repo_create(pool, "<stdin>");
  if (!appdatadir)
    {
      if (repo_add_appdata(repo, stdin, 0))
	{
	  fprintf(stderr, "appdata2solv: %s\n", pool_errstr(pool));
	  exit(1);
	}
    }
  else
    {
      if (repo_add_appdata_dir(repo, appdatadir, REPO_USE_ROOTDIR))
	{
	  fprintf(stderr, "appdata2solv: %s\n", pool_errstr(pool));
	  exit(1);
	}
    }
  tool_write(repo, 0, 0);
  pool_free(pool);
  exit(0);
}