Imported Upstream version 0.7.5
[platform/upstream/libsolv.git] / tools / conda2solv.c
1 /*
2  * Copyright (c) 2019, SUSE LLC
3  *
4  * This program is licensed under the BSD license, read LICENSE.BSD
5  * for further information
6  */
7
8 /*
9  * conda2solv.c
10  *
11  * parse a conda repository 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_conda.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           "conda2solv\n"
35           "  reads a 'synthesis' repository from <stdin> and writes a .solv file to <stdout>\n"
36           "  -h : print help & exit\n"
37          );
38    exit(status);
39 }
40
41 int
42 main(int argc, char **argv)
43 {
44   Pool *pool;
45   Repo *repo;
46   int c;
47
48   while ((c = getopt(argc, argv, "h")) >= 0)
49     {
50       switch(c)
51         {
52         case 'h':
53           usage(0);
54           break;
55         default:
56           usage(1);
57           break;
58         }
59     }
60   pool = pool_create();
61   repo = repo_create(pool, "<stdin>");
62   if (repo_add_conda(repo, stdin, 0))
63     {
64       fprintf(stderr, "conda2solv: %s\n", pool_errstr(pool));
65       exit(1);
66     }
67   repo_internalize(repo);
68   tool_write(repo, stdout);
69   pool_free(pool);
70   exit(0);
71 }