]> git.draconx.ca Git - liblbx.git/blobdiff - src/lbxtool.c
Convert tools to use option generator script from dxcommon.
[liblbx.git] / src / lbxtool.c
index 3c4e436450caf0db09f6fe9f79cbbd653dd0add2..6629969a09583e2f2802f7a9ba5976184f282ffb 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *  2ooM: The Master of Orion II Reverse Engineering Project
  *  Simple command-line tool to extract LBX archive files.
- *  Copyright © 2006-2011, 2013 Nick Bowler
+ *  Copyright © 2006-2011, 2013-2014, 2021 Nick Bowler
  *
  *  This program is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -16,6 +16,7 @@
  *  You should have received a copy of the GNU General Public License
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
+
 #include <config.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <getopt.h>
 #include <fnmatch.h>
 
+#include "help.h"
+
 #include "tools.h"
 #include "lbx.h"
 #include "error.h"
 
-static void printusage(void)
+#include "toolopts.h"
+static const char sopts[] = SOPT_STRING;
+static const struct option lopts[] = { LOPTS_INITIALIZER, {0} };
+
+static void print_usage(FILE *f)
 {
-       puts("usage: lbxtool [-l|-x] [-v] [-f path] [file ...]");
+       const char *progname = tool_invocation();
+
+       fprintf(f, "Usage: %s [options] [-l|-x] [file ...]\n", progname);
+       if (f != stdout)
+               fprintf(f, "Try %s --help for more information.\n", progname);
 }
 
-static void printhelp(void)
+static void print_help(void)
 {
-       printusage();
-       puts("For now, see the man page for detailed help.");
+       const struct option *opt;
+
+       print_usage(stdout);
+
+       puts("This is \"lbxtool\": a command-line tool for manipulating the LBX archives\n"
+            "used in Moo2.");
+
+       putchar('\n');
+       puts("Options:");
+       for (opt = lopts; opt->name; opt++) {
+               struct lopt_help help;
+               int w;
+
+               if (!lopt_get_help(opt, &help))
+                       continue;
+
+               help_print_option(opt, help.arg, help.desc, 20);
+       }
+       putchar('\n');
+
+       puts("For more information, see the lbxtool(1) man page.");
+       putchar('\n');
+
+       printf("Report bugs to <%s>.\n", PACKAGE_BUGREPORT);
 }
 
 enum {
@@ -177,23 +210,6 @@ int main(int argc, char **argv)
        const char *file = NULL;
        struct lbx *lbx;
 
-       static const char         *sopts   = "lxf:i:vV";
-       static const struct option lopts[] = {
-               { "list",    0, NULL, 'l' },
-               { "extract", 0, NULL, 'x' },
-
-               { "file",    1, NULL, 'f' },
-               { "index",   1, NULL, 'i' },
-
-               { "verbose", 0, NULL, 'v' },
-
-               { "version", 0, NULL, 'V' },
-               { "usage",   0, NULL, 'U' },
-               { "help",    0, NULL, 'H' },
-
-               { 0 }
-       };
-
        tool_init("lbxtool", argc, argv);
        while ((opt = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
                switch(opt) {
@@ -206,20 +222,14 @@ int main(int argc, char **argv)
                case 'f':
                        file = optarg;
                        break;
-               case 'i':
-                       /* FIXME: Add index file support. */
-                       break;
                case 'v':
                        verbose = 1;
                        break;
                case 'V':
                        tool_version();
                        return EXIT_SUCCESS;
-               case 'U':
-                       printusage();
-                       return EXIT_SUCCESS;
                case 'H':
-                       printhelp();
+                       print_help();
                        return EXIT_SUCCESS;
                default:
                        return EXIT_FAILURE;