summaryrefslogtreecommitdiff
path: root/tools/mdk2solv.c
blob: 3a6cf9481241f11006cefd214c7d29562d356f89 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
 * Copyright (c) 2012, Novell Inc.);
 *
 * This program is licensed under the BSD license, read LICENSE.BSD
 * for further information
 */

/*
 * mdk2solv.c
 *
 * parse Mandriva/Mageie synthesis file
 *
 * reads from stdin
 * writes to stdout
 */

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

#include "pool.h"
#include "repo.h"
#include "repo_mdk.h"
#include "solv_xfopen.h"
#include "common_write.h"


static void
usage(int status)
{
  fprintf(stderr, "\nUsage:\n"
          "mdk2solv [-i <infoxml>]\n"
          "  reads a 'synthesis' repository from <stdin> and writes a .solv file to <stdout>\n"
          "  -i : info.xml file for extra attributes\n"
          "  -f : files.xml file for extra attributes\n"
          "  -h : print help & exit\n"
         );
   exit(status);
}

int
main(int argc, char **argv)
{
  Pool *pool;
  Repo *repo;
  char *infofile = 0, *filesfile = 0;
  int c;

  while ((c = getopt(argc, argv, "hi:f:")) >= 0)
    {
      switch(c)
	{
	case 'h':
	  usage(0);
	  break;
	case 'i':
	  infofile = optarg;
	  break;
	case 'f':
	  filesfile = optarg;
	  break;
	default:
	  usage(1);
	  break;
	}
    }
  pool = pool_create();
  repo = repo_create(pool, "<stdin>");
  if (repo_add_mdk(repo, stdin, REPO_NO_INTERNALIZE))
    {
      fprintf(stderr, "mdk2solv: %s\n", pool_errstr(pool));
      exit(1);
    }
  if (infofile)
    {
      FILE *fp = solv_xfopen(infofile, "r");
      if (!fp)
	{
	  perror(infofile);
	  exit(1);
	}
      if (repo_add_mdk_info(repo, fp, REPO_EXTEND_SOLVABLES | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE))
	{
	  fprintf(stderr, "mdk2solv: %s\n", pool_errstr(pool));
	  exit(1);
	}
      fclose(fp);
    }
  if (filesfile)
    {
      FILE *fp = solv_xfopen(filesfile, "r");
      if (!fp)
	{
	  perror(filesfile);
	  exit(1);
	}
      if (repo_add_mdk_info(repo, fp, REPO_EXTEND_SOLVABLES | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE))
	{
	  fprintf(stderr, "mdk2solv: %s\n", pool_errstr(pool));
	  exit(1);
	}
      fclose(fp);
    }
  repo_internalize(repo);
  tool_write(repo, stdout);
  pool_free(pool);
  exit(0);
}