59ac79ad2e450587dfd96aa0d303394668b19219
[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 [-a][-h][-n <attrname>]\n"
26           "  reads a 'diskusage.xml' file from <stdin> and writes a .solv file to <stdout>\n"
27           "  -h : print help & exit\n"
28           "  -n <name>: save attributes as <name>.attr\n"
29          );
30   exit(status);
31 }
32
33 int
34 main(int argc, char **argv)
35 {
36   int c, flags = 0;
37   char *attrname = 0;
38   
39   Pool *pool = pool_create();
40   Repo *repo = repo_create(pool, "<stdin>");
41
42   while ((c = getopt(argc, argv, "hn:")) >= 0)
43     {   
44       switch(c)
45         {
46         case 'h':
47           usage(0);
48           break;
49         case 'n':
50           attrname = optarg;
51           break;
52         default:
53           usage(1);
54           break;
55         }
56     }
57   if (repo_add_diskusagexml(repo, stdin, flags))
58     {
59       fprintf(stderr, "diskusagexml2solv: %s\n", pool_errstr(pool));
60       exit(1);
61     }
62   tool_write(repo, 0, attrname);
63   pool_free(pool);
64   exit(0);
65 }