Imported Upstream version 0.7.19
[platform/upstream/libsolv.git] / tools / rpmmd2solv.c
1 /*
2  * Copyright (c) 2007, Novell Inc.
3  *
4  * This program is licensed under the BSD license, read LICENSE.BSD
5  * for further information
6  */
7
8 #define _GNU_SOURCE
9
10 #include <sys/types.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <unistd.h>
15
16 #include "pool.h"
17 #include "repo.h"
18 #include "repo_rpmmd.h"
19 #ifdef SUSE
20 #include "repo_autopattern.h"
21 #endif
22 #include "common_write.h"
23 #include "solv_xfopen.h"
24
25
26 static void
27 usage(int status)
28 {
29   fprintf(stderr, "\nUsage:\n"
30           "rpmmd2solv [-h]\n"
31           "  reads 'primary' from a 'rpmmd' repository from <stdin> and writes a .solv file to <stdout>\n"
32           "  -h : print help & exit\n"
33          );
34    exit(status);
35 }
36
37 int
38 main(int argc, char **argv)
39 {
40   int c;
41 #ifdef SUSE
42   int add_auto = 0;
43 #endif
44   
45   Pool *pool = pool_create();
46   Repo *repo = repo_create(pool, "<stdin>");
47
48   while ((c = getopt (argc, argv, "hX")) >= 0)
49     {
50       switch (c)
51         {
52         case 'h':
53           usage(0);
54           break;
55         case 'X':
56 #ifdef SUSE
57           add_auto = 1;
58 #endif
59           break;
60         default:
61           usage(1);
62           break;
63         }
64     }
65   if (repo_add_rpmmd(repo, stdin, 0, 0))
66     {
67       fprintf(stderr, "rpmmd2solv: %s\n", pool_errstr(pool));
68       exit(1);
69     }
70 #ifdef SUSE
71   if (add_auto)
72     repo_add_autopattern(repo, 0);
73 #endif
74   tool_write(repo, stdout);
75   pool_free(pool);
76   exit(0);
77 }