Imported Upstream version 0.6.27
[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 <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_arch.h"
26 #include "solv_xfopen.h"
27 #include "common_write.h"
28
29
30 static void
31 usage(int status)
32 {
33   fprintf(stderr, "\nUsage:\n"
34           "archrepo2solv\n"
35           "  reads a repository from <stdin> and writes a .solv file to <stdout>\n"
36           "  -l <dbdir> : read local database\n"
37           "  -h : print help & exit\n"
38          );
39    exit(status);
40 }
41
42 int
43 main(int argc, char **argv)
44 {
45   Pool *pool;
46   Repo *repo;
47   int c, ret;
48   const char *localdb = 0;
49
50   while ((c = getopt(argc, argv, "hl:")) >= 0)
51     {
52       switch(c)
53         {
54         case 'h':
55           usage(0);
56           break;
57         case 'l':
58           localdb = optarg;
59           break;
60         default:
61           usage(1);
62           break;
63         }
64     }
65   pool = pool_create();
66   repo = repo_create(pool, "<stdin>");
67   if (localdb)
68     ret = repo_add_arch_local(repo, localdb, 0);
69   else
70     ret = repo_add_arch_repo(repo, stdin, 0);
71   if (ret)
72     {
73       fprintf(stderr, "archrepo2solv: %s\n", pool_errstr(pool));
74       exit(1);
75     }
76   tool_write(repo, 0, 0);
77   pool_free(pool);
78   exit(0);
79 }