Imported Upstream version 0.7.4
[platform/upstream/libsolv.git] / tools / diskusagexml2solv.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 #include <sys/types.h>
9 #include <limits.h>
10 #include <fcntl.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_diskusagexml.h"
19 #include "common_write.h"
20
21 static void
22 usage(int status)
23 {
24   fprintf(stderr, "\nUsage:\n"
25           "diskusagexml2solv [-h]\n"
26           "  reads a 'diskusage.xml' file from <stdin> and writes a .solv file to <stdout>\n"
27           "  -h : print help & exit\n"
28          );
29   exit(status);
30 }
31
32 int
33 main(int argc, char **argv)
34 {
35   int c, flags = 0;
36   
37   Pool *pool = pool_create();
38   Repo *repo = repo_create(pool, "<stdin>");
39
40   while ((c = getopt(argc, argv, "h")) >= 0)
41     {   
42       switch(c)
43         {
44         case 'h':
45           usage(0);
46           break;
47         default:
48           usage(1);
49           break;
50         }
51     }
52   if (repo_add_diskusagexml(repo, stdin, flags))
53     {
54       fprintf(stderr, "diskusagexml2solv: %s\n", pool_errstr(pool));
55       exit(1);
56     }
57   tool_write(repo, stdout);
58   pool_free(pool);
59   exit(0);
60 }