backup
[platform/upstream/libsolv.git] / tools / updateinfoxml2solv.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
15 #include "pool.h"
16 #include "repo.h"
17 #include "repo_updateinfoxml.h"
18 #include "common_write.h"
19
20 static void
21 usage(const char *err)
22 {
23   if (err)
24     fprintf(stderr, "\n** Error:\n  %s\n", err);
25   fprintf(stderr, "\nUsage:\n"
26           "updateinfoxml2solv [-a][-h][-k][-n <attrname>]\n"
27           "  reads a 'updateinfo.xml' file from <stdin> and writes a .solv file to <stdout>\n"
28           "  -h : print help & exit\n"
29           "  -k : don't mix kinds (experimental!)\n"
30           "  -n <name>: save attributes as <name>.attr\n"
31          );
32    exit(0);
33 }
34
35 int
36 main(int argc, char **argv)
37 {
38   int flags = 0;
39   char *attrname = 0;
40   
41   Pool *pool = pool_create();
42   Repo *repo = repo_create(pool, "<stdin>");
43
44   argv++;
45   argc--;
46   while (argc--)
47     {
48       const char *s = argv[0];
49       if (*s++ == '-')
50         while (*s)
51           switch (*s++)
52             {
53               case 'h': usage(NULL); break;
54               case 'n':
55                 if (argc)
56                   {
57                     attrname = argv[1];
58                     argv++;
59                     argc--;
60                   }
61                 else
62                   usage("argument required for '-n'");
63                 break;
64               case 'k':
65                 flags |= UPDATEINFOXML_KINDS_SEPARATELY;
66               break;
67               default : break;
68             }
69       argv++;
70     }
71
72   repo_add_updateinfoxml(repo, stdin, flags);
73   tool_write(repo, 0, 0);
74   pool_free(pool);
75   exit(0);
76 }