Imported Upstream version 0.6.29
[platform/upstream/libsolv.git] / tools / deltainfoxml2solv.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 <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <unistd.h>
13
14 #include "pool.h"
15 #include "repo.h"
16 #include "repo_deltainfoxml.h"
17 #include "common_write.h"
18
19 static void
20 usage(int status)
21 {
22   fprintf(stderr, "\nUsage:\n"
23           "deltainfoxml2solv [-a][-h][-n <attrname>]\n"
24           "  reads a 'deltainfo.xml' file from <stdin> and writes a .solv file to <stdout>\n"
25           "  -h : print help & exit\n"
26           "  -n <name>: save attributes as <name>.attr\n"
27          );
28   exit(status);
29 }
30
31 int
32 main(int argc, char **argv)
33 {
34   int c, flags = 0;
35   char *attrname = 0;
36   
37   Pool *pool = pool_create();
38   Repo *repo = repo_create(pool, "<stdin>");
39
40   while ((c = getopt(argc, argv, "hn:")) >= 0)
41     {   
42       switch(c)
43         {
44         case 'h':
45           usage(0);
46           break;
47         case 'n':
48           attrname = optarg;
49           break;
50         default:
51           usage(1);
52           break;
53         }
54     }
55   if (repo_add_deltainfoxml(repo, stdin, flags))
56     {
57       fprintf(stderr, "deltainfoxml2solv: %s\n", pool_errstr(pool));
58       exit(1);
59     }
60   tool_write(repo, 0, attrname);
61   pool_free(pool);
62   exit(0);
63 }