Imported Upstream version 0.6.27
[platform/upstream/libsolv.git] / tools / updateinfoxml2solv.c
index 6d88995..6a97b0d 100644 (file)
@@ -6,11 +6,10 @@
  */
 
 #include <sys/types.h>
-#include <limits.h>
-#include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 
 #include "pool.h"
 #include "repo.h"
 #include "common_write.h"
 
 static void
-usage(const char *err)
+usage(int status)
 {
-  if (err)
-    fprintf(stderr, "\n** Error:\n  %s\n", err);
   fprintf(stderr, "\nUsage:\n"
-          "updateinfoxml2solv [-a][-h][-k][-n <attrname>]\n"
+          "updateinfoxml2solv [-h][-n <attrname>]\n"
          "  reads a 'updateinfo.xml' file from <stdin> and writes a .solv file to <stdout>\n"
          "  -h : print help & exit\n"
-         "  -k : don't mix kinds (experimental!)\n"
          "  -n <name>: save attributes as <name>.attr\n"
         );
-   exit(0);
+  exit(status);
 }
 
 int
 main(int argc, char **argv)
 {
-  int flags = 0;
+  int c, flags = 0;
   char *attrname = 0;
   
   Pool *pool = pool_create();
   Repo *repo = repo_create(pool, "<stdin>");
 
-  argv++;
-  argc--;
-  while (argc--)
+  while ((c = getopt(argc, argv, "hn:")) >= 0)
     {
-      const char *s = argv[0];
-      if (*s++ == '-')
-        while (*s)
-          switch (*s++)
-           {
-             case 'h': usage(NULL); break;
-             case 'n':
-               if (argc)
-                 {
-                   attrname = argv[1];
-                   argv++;
-                   argc--;
-                 }
-               else
-                 usage("argument required for '-n'");
-               break;
-             case 'k':
-               flags |= UPDATEINFOXML_KINDS_SEPARATELY;
-             break;
-             default : break;
-           }
-      argv++;
+      switch(c)
+       {
+       case 'h':
+         usage(0);
+         break;
+       case 'n':
+         attrname = optarg;
+         break;
+       default:
+         usage(1);
+         break;
+       }
     }
-
-  repo_add_updateinfoxml(repo, stdin, flags);
-  tool_write(repo, 0, 0);
+  if (repo_add_updateinfoxml(repo, stdin, flags))
+    {
+      fprintf(stderr, "updateinfoxml2solv: %s\n", pool_errstr(pool));
+      exit(1);
+    }
+  tool_write(repo, 0, attrname);
   pool_free(pool);
   exit(0);
 }