Imported Upstream version 0.6.7
[platform/upstream/libsolv.git] / tools / archrepo2solv.c
1 /*
2  * Copyright (c) 2012, Novell Inc.
3  *
4  * This program is licensed under the BSD license, read LICENSE.BSD
5  * for further information
6  */
7
8 /*
9  * archrepo2solv.c
10  *
11  * parse archlinux repo 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 <getopt.h>
24
25 #include "pool.h"
26 #include "repo.h"
27 #include "repo_arch.h"
28 #include "solv_xfopen.h"
29 #include "common_write.h"
30
31
32 static void
33 usage(int status)
34 {
35   fprintf(stderr, "\nUsage:\n"
36           "archrepo2solv\n"
37           "  reads a repository from <stdin> and writes a .solv file to <stdout>\n"
38           "  -l <dbdir> : read local database\n"
39           "  -h : print help & exit\n"
40          );
41    exit(status);
42 }
43
44 int
45 main(int argc, char **argv)
46 {
47   Pool *pool;
48   Repo *repo;
49   int c, ret;
50   const char *localdb = 0;
51
52   while ((c = getopt(argc, argv, "hl:")) >= 0)
53     {
54       switch(c)
55         {
56         case 'h':
57           usage(0);
58           break;
59         case 'l':
60           localdb = optarg;
61           break;
62         default:
63           usage(1);
64           break;
65         }
66     }
67   pool = pool_create();
68   repo = repo_create(pool, "<stdin>");
69   if (localdb)
70     ret = repo_add_arch_local(repo, localdb, 0);
71   else
72     ret = repo_add_arch_repo(repo, stdin, 0);
73   if (ret)
74     {
75       fprintf(stderr, "archrepo2solv: %s\n", pool_errstr(pool));
76       exit(1);
77     }
78   tool_write(repo, 0, 0);
79   pool_free(pool);
80   exit(0);
81 }