]> git.draconx.ca Git - liblbx.git/commitdiff
Convert tools to use option generator script from dxcommon.
authorNick Bowler <nbowler@draconx.ca>
Mon, 13 Sep 2021 17:49:40 +0000 (13:49 -0400)
committerNick Bowler <nbowler@draconx.ca>
Mon, 13 Sep 2021 17:56:09 +0000 (13:56 -0400)
This generator makes it simple to maintain long and short option lists,
as well as provide an actually useful --help output.

Makefile.am
common
configure.ac
doc/man/lbximg.1
doc/man/lbxtool.1
src/.gitignore [new file with mode: 0644]
src/imgopts.opt [new file with mode: 0644]
src/lbximg.c
src/lbxtool.c
src/toolopts.opt [new file with mode: 0644]

index fb85562931092adf02af0bc37809c350a8ad3b15..30a8c5ce52d82ed4359234bcdcaa492143341c1e 100644 (file)
@@ -14,7 +14,8 @@ EXTRA_LTLIBRARIES =
 EXTRA_DIST = bootstrap $(DX_BASEDIR)/scripts/fix-gnulib.pl m4/gnulib-cache.m4
 CLEANFILES = $(EXTRA_LTLIBRARIES)
 
-AM_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib -I$(top_srcdir)/src \
+AM_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib \
+              -I$(top_builddir)/src -I$(top_srcdir)/src \
               -I$(top_srcdir)/common/src
 AM_CFLAGS = $(LIBPNG_CFLAGS) $(GTK_CFLAGS)
 
@@ -23,7 +24,7 @@ dist_doc_DATA = doc/txt/moo2-data.txt
 
 lbxdir = $(includedir)/lbx
 lbx_HEADERS = src/lbx.h src/image.h src/error.h
-noinst_HEADERS = src/misc.h src/tools.h
+noinst_HEADERS = src/misc.h src/tools.h src/imgoutput.h common/src/help.h
 
 lib_LTLIBRARIES = liblbx.la
 liblbx_la_SOURCES = src/lbx.c src/fops.c src/image.c src/error.c \
@@ -35,13 +36,15 @@ if BUILD_LBXGUI
 bin_PROGRAMS += lbxgui
 endif
 
-lbxtool_SOURCES = src/lbxtool.c src/tools.c
+lbxtool_SOURCES = src/lbxtool.c src/tools.c common/src/help.c
 lbxtool_LDADD = liblbx.la libgnu.la
 $(lbxtool_OBJECTS): $(gnulib_headers)
+$(lbxtool_OBJECTS): src/toolopts.h
 
-lbximg_SOURCES = src/lbximg.c src/tools.c src/pnm.c src/imgoutput.h
+lbximg_SOURCES = src/lbximg.c src/tools.c src/pnm.c common/src/help.c
 lbximg_LDADD = liblbx.la libgnu.la $(LIBPNG_LIBS)
 $(lbximg_OBJECTS): $(gnulib_headers)
+$(lbximg_OBJECTS): src/imgopts.h
 
 if HAVE_LIBPNG
 lbximg_SOURCES += src/png.c
@@ -72,6 +75,14 @@ clean-testdirs:
        done
 .PHONY: clean-testdirs
 
+OPTFILES = src/toolopts.opt src/imgopts.opt
+.opt.h:
+       $(AM_V_GEN) $(AWK) -f $(DX_BASEDIR)/scripts/gen-options.awk $< >$@.tmp
+       $(AM_V_at) mv -f $@.tmp $@
+$(OPTFILES:.opt=.h): $(DX_BASEDIR)/scripts/gen-options.awk
+CLEANFILES += $(OPTFILES:.opt=.h)
+EXTRA_DIST += $(DX_BASEDIR)/scripts/gen-options.awk $(OPTFILES)
+
 .xml.c:
        $(AM_V_GEN) printf '%s\n' $(*F) | sed -e 's/[^[:alnum:]]/_/g' \
                -e 's/.*/const char &[] =/' > $@.tmp
diff --git a/common b/common
index aa6ab453c6ff523a4d8538554c068117f2de3aca..843799dbec995b276a7d017bb32c053747b55400 160000 (submodule)
--- a/common
+++ b/common
@@ -1 +1 @@
-Subproject commit aa6ab453c6ff523a4d8538554c068117f2de3aca
+Subproject commit 843799dbec995b276a7d017bb32c053747b55400
index 22e7ceeb90f3db73bf381d07d2bd0d41edfbecf8..c054f51f6d3f6d40d5efba70b6ea3cc05cbdeae4 100644 (file)
@@ -5,7 +5,7 @@ dnl This is free software: you are free to do what the fuck you want to.
 dnl There is NO WARRANTY, to the extent permitted by law.
 
 AC_PREREQ([2.68])
-AC_INIT([liblbx], [0.1], [toom-devel@lists.sourceforge.net])
+AC_INIT([liblbx], [0.1], [nbowler@draconx.ca])
 AC_CONFIG_SRCDIR([src/lbx.c])
 AC_CONFIG_HEADER([config.h])
 
index 5f0c6ee0aa5e036a1ef07ede7a414f78e5610177..e3a91c12cef552c928b9a5c226601c3829df3bf5 100644 (file)
@@ -1,4 +1,4 @@
-.Dd June 14, 2013
+.Dd September 12, 2021
 .Os liblbx
 .Dt LBXIMG \&1 "2ooM Reference Manual"
 .Sh NAME
@@ -125,10 +125,12 @@ Decodes an image of a red star fortress.
 .Sh AUTHORS
 Nick Bowler <nbowler@draconx.ca>
 .Sh COPYRIGHT
-Copyright \(co 2008\(en2010, 2013 Nick Bowler
+Copyright \(co 2008, 2010, 2013, 2021 Nick Bowler
 .Pp
 Permission is granted to copy, distribute and/or modify this manual under the
-terms of the Do What The Fuck You Want To Public License, version 2.
+terms of the GNU General Public License as published by the Free Software
+Foundation, either version 3 of the License, or (at your option) any later
+version.
 .Sh SEE ALSO
 .Xr lbxtool 1 ,
 .Xr lbxgui 1
index 458187860a81d87d6410dcc4f35eccc981aff0f6..63bd25459a5d90eda40a3b9c9e6a484f7fddd9b2 100644 (file)
@@ -1,9 +1,4 @@
-.\" Copyright (C) 2008-2010 Nick Bowler
-.\" Copying and distribution of this file, with or without modification,
-.\" are permitted in any medium without royalty provided the copyright
-.\" notice and this notice are preserved.  This file is offered as-is,
-.\" without any warranty.
-.Dd February 9, 2010
+.Dd September 12, 2021
 .Os liblbx
 .Dt LBXTOOL \&1 "2ooM Reference Manual"
 .Sh NAME
@@ -34,9 +29,7 @@ Read from the specified
 instead of standard input.
 .It Fl V , -version
 Print a version message and exit.
-.It Fl -usage
-Print a short usage message and exit.
-.It Fl -help
+.It Fl H , -help
 Print a help message and exit
 .It Ar
 Limit the operation to these files in the archive.  By default, all files are
@@ -46,3 +39,12 @@ selected.  Supports common shell globbing features.
 When extracting from an archive read from standard input, be sure to specify
 files in the order that they appear in the archive.  This limitation will
 hopefully be lifted in the future.
+.Sh AUTHORS
+Nick Bowler <nbowler@draconx.ca>
+.Sh COPYRIGHT
+Copyright \(co 2008, 2010, 2021 Nick Bowler
+.Pp
+Permission is granted to copy, distribute and/or modify this manual under the
+terms of the GNU General Public License as published by the Free Software
+Foundation, either version 3 of the License, or (at your option) any later
+version.
diff --git a/src/.gitignore b/src/.gitignore
new file mode 100644 (file)
index 0000000..34968f0
--- /dev/null
@@ -0,0 +1,2 @@
+/toolopts.h
+/imgopts.h
diff --git a/src/imgopts.opt b/src/imgopts.opt
new file mode 100644 (file)
index 0000000..05fdb18
--- /dev/null
@@ -0,0 +1,35 @@
+-i, --identify
+Display details about the image file.
+
+-d, --decode
+Convert frames to another image format.
+
+-v, --verbose
+Display additional information on standard output.
+
+-f, --file=FILE
+Read image data from FILE instead of standard input.
+
+-F, --format=FMT
+When decoding, set the output format to FMT.  One of png,
+pam, ppm or pbm.
+
+--output-prefix=NAME
+When decoding, output filenames will begin with NAME
+instead of "out".
+
+-n, --no-palette
+Instead of performing palette lookups, the palette index
+values for each pixel are used directly as grayscale level.
+
+-p, --palette=FILE
+Load FILE as the base image palette.
+
+-O, --override=FILE
+Load FILE as the override palette.
+
+-V, --version
+Print a version message and then exit.
+
+-H, --help
+Print a help message and then exit.
index 98d2676dea7294e2527f006172691b239c3e1302..5beaaaeb8f6af6275fa9a16f713fbfa52bd216f4 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *  2ooM: The Master of Orion II Reverse Engineering Project
  *  Simple command-line tool to convert an LBX image to other formats.
- *  Copyright © 2006-2011, 2013-2014 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
@@ -27,6 +27,8 @@
 #include <getopt.h>
 #include <errno.h>
 
+#include "help.h"
+
 #include "tools.h"
 #include "image.h"
 #include "error.h"
@@ -41,21 +43,42 @@ static int verbose = 0;
 static char *outname = "out";
 static int usepalette = 1;
 
-enum {
-       OPT_PREFIX = UCHAR_MAX+1,
-};
+#include "imgopts.h"
+static const char sopts[] = SOPT_STRING;
+static const struct option lopts[] = { LOPTS_INITIALIZER, {0} };
 
-static void printusage(void)
+static void print_usage(FILE *f)
 {
-       puts("usage: lbximg [-i|-d] [-v] [-p palette_file] [-O override_file]"
-                         " [-f path]");
-       puts("              [-F format] [frameno ...]");
+       const char *progname = tool_invocation();
+
+       fprintf(f, "Usage: %s [options] [-i|-d] [frame ...]\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);
+
+       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 lbximg(1) man page.");
+       putchar('\n');
+
+       printf("Report bugs to <%s>.\n", PACKAGE_BUGREPORT);
 }
 
 enum {
@@ -442,26 +465,6 @@ int main(int argc, char **argv)
        FILE *palf = NULL, *overf = NULL;
        struct lbx_image *img;
 
-       static const char sopts[] = "idnvF:f:p:O:VH";
-       static const struct option lopts[] = {
-               { "identify",      0, NULL, 'i' },
-               { "decode",        0, NULL, 'd' },
-               { "verbose",       0, NULL, 'v' },
-               { "file",          1, NULL, 'f' },
-               { "format",        1, NULL, 'F' },
-               { "palette",       1, NULL, 'p' },
-               { "override",      1, NULL, 'O' },
-               { "no-palette",    0, NULL, 'n' },
-
-               { "output-prefix", 1, NULL,  OPT_PREFIX },
-
-               { "version",       0, NULL, 'V' },
-               { "usage",         0, NULL, 'U' },
-               { "help",          0, NULL, 'H' },
-
-               { 0 }
-       };
-
        tool_init("lbximg", argc, argv);
        while ((opt = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
                switch(opt) {
@@ -490,17 +493,14 @@ int main(int argc, char **argv)
                case 'O':
                        ovr_palette = optarg;
                        break;
-               case OPT_PREFIX:
+               case LOPT_OUTPUT_PREFIX:
                        outname = optarg;
                        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;
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;
diff --git a/src/toolopts.opt b/src/toolopts.opt
new file mode 100644 (file)
index 0000000..813c9e1
--- /dev/null
@@ -0,0 +1,17 @@
+-l, --list
+Display files contained in the archive.
+
+-x, --extract
+Extract files from the archive.
+
+-f, --file=FILE
+Read archive data from FILE instead of standard input.
+
+-v, --verbose
+Display additional information on standard output.
+
+-V, --version
+Print a version message and then exit.
+
+-H, --help
+Print this message and then exit.