]> git.draconx.ca Git - upkg.git/commitdiff
Use gen-options script and help formatting from dxcommon.
authorNick Bowler <nbowler@draconx.ca>
Thu, 24 Feb 2022 03:06:32 +0000 (22:06 -0500)
committerNick Bowler <nbowler@draconx.ca>
Thu, 24 Feb 2022 03:10:35 +0000 (22:10 -0500)
These utilities make it easy to produce a much more useful help
output with descriptions and everything.

Makefile.am
src/.gitignore [new file with mode: 0644]
src/upkg.c
src/upkgopts.opt [new file with mode: 0644]

index 30cf7aee17cc31b92a30468daf64b3d79e3ef431..d6d99b0fc66251384bd636efa3fa31e137492154 100644 (file)
@@ -36,10 +36,11 @@ dist_man_MANS = doc/man/upkg.1
 have_orderonly = $(findstring order-only,$(.FEATURES))
 orderonly = $(have_orderonly:order-only=|)
 
-upkg_SOURCES  = src/upkg.c src/upkg.h
-upkg_LDFLAGS  = $(AM_LDFLAGS) -export-dynamic
-upkg_LDADD    = libuobject.la libupkg.la libgnu.la $(GLIB_LIBS)
-$(upkg_OBJECTS): $(gnulib_headers)
+upkg_SOURCES = src/upkg.c src/upkg.h src/upkgopts.h \
+               common/src/help.c common/src/help.h
+upkg_LDFLAGS = $(AM_LDFLAGS) -export-dynamic
+upkg_LDADD   = libuobject.la libupkg.la libgnu.la $(GLIB_LIBS)
+$(upkg_OBJECTS): $(gnulib_headers) src/upkgopts.h
 
 libupkg_la_SOURCES = src/libupkg.c common/src/pack.c common/src/pack.h
 
@@ -141,6 +142,14 @@ STAMP_RECOVER = \
 .gobstamp.c: ; $(STAMP_RECOVER)
 .gobstamp.h: ; $(STAMP_RECOVER)
 
+OPTFILES = src/upkgopts.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
+MAINTAINERCLEANFILES += $(OPTFILES:.opt=.h)
+EXTRA_DIST += $(DX_BASEDIR)/scripts/gen-options.awk $(OPTFILES)
+
 # The gob rules refrain from updating unchanged headers for the convenience of
 # developers, but the headers should be distributed with up-to-date timestamps.
 dist-hook: update-headers
diff --git a/src/.gitignore b/src/.gitignore
new file mode 100644 (file)
index 0000000..b5b19dd
--- /dev/null
@@ -0,0 +1 @@
+/upkgopts.h
index 55d13f8f37f71c1c0d7449ed3bb259f2edfbe9c2..6c8cbc10f48fbc95e13b1896cb8d44317ced00eb 100644 (file)
@@ -1,19 +1,19 @@
 /*
- *  upkg: tool for manipulating Unreal Tournament packages.
- *  Copyright © 2009-2011 Nick Bowler
+ * upkg: tool for manipulating Unreal Tournament packages.
+ * Copyright © 2009-2012, 2022 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
- *  the Free Software Foundation, either version 3 of the License, or
- *  (at your option) any later version.
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
  *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- *  You should have received a copy of the GNU General Public License
- *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
 #include <config.h>
@@ -34,6 +34,8 @@
 #include <uobject/package.h>
 #include <uobject/vfs.h>
 
+#include "help.h"
+
 enum {
        MODE_INFO,
        MODE_LIST,
@@ -44,50 +46,49 @@ enum {
 int verbose = 0;
 
 static const char *progname = "upkg";
-static const char *sopts = "ilxvf:VH";
-static const struct option lopts[] = {
-       { "info",     0, NULL, 'i' },
-       { "list",     0, NULL, 'l' },
-       { "export",   0, NULL, 'x' },
-       { "file",     1, NULL, 'f' },
-       { "verbose",  0, NULL, 'v' },
-       { "version",  0, NULL, 'V' },
-       { "help",     0, NULL, 'H' },
-       { 0 }
-};
 
-void print_version(void)
+#include "upkgopts.h"
+static const char sopts[] = SOPT_STRING;
+static const struct option lopts[] = { LOPTS_INITIALIZER, {0} };
+
+static void print_version(void)
 {
        printf("%s\n", PACKAGE_STRING);
-       puts("\
-Copyright (C) 2009 Nick Bowler.\n\
-License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n\
-This is free software: you are free to change and redistribute it.\n\
-There is NO WARRANTY, to the extent permitted by law."
-       );
+       puts("Copyright (C) 2022 Nick Bowler.");
+       puts("License GPLv3+: GNU GPL version 3 or any later version.");
+       puts("This is free software: you are free to change and redistribute it.");
+       puts("There is NO WARRANTY, to the extent permitted by law.");
 }
 
-void print_usage(FILE *f)
+static void print_usage(FILE *f)
 {
        fprintf(f, "Usage: %s [options] [object ...]\n", progname);
+       if (f != stdout)
+               fprintf(f, "Try %s --help for more information.\n", progname);
 }
 
-void print_help(void)
+static void print_help(void)
 {
+       const struct option *opt;
+
        print_usage(stdout);
-       puts("Detailed help coming soon.  Until then, I'll just list my options.");
-       for (unsigned i = 0; lopts[i].name; i++) {
-               const struct option *o = &lopts[i];
-               printf("\t--%s", o->name);
-
-               if (o->has_arg == 1) {
-                       printf("=val");
-               } else if (o->has_arg == 2) {
-                       printf("[=val]");
-               }
 
-               printf(" (-%c)\n", o->val);
+       putchar('\n');
+       puts("Options:");
+       for (opt = lopts; opt->name; opt++) {
+               struct lopt_help help;
+
+               if (!lopt_get_help(opt, &help))
+                       continue;
+
+               help_print_option(opt, help.arg, help.desc, 20);
        }
+       putchar('\n');
+
+       puts("For more information, see the upkg(1) man page.");
+       putchar('\n');
+
+       printf("Report bugs to <%s>.\n", PACKAGE_BUGREPORT);
 }
 
 static void print_upkg_flags(const char *prefix, unsigned long flags)
diff --git a/src/upkgopts.opt b/src/upkgopts.opt
new file mode 100644 (file)
index 0000000..2b19e98
--- /dev/null
@@ -0,0 +1,20 @@
+-i, --info
+Display information about the package.
+
+-l, --list
+List objects belonging to the package.
+
+-x, --export
+Export objects from the package.
+
+-v, --verbose
+Display additional information on standard output.
+
+-f, --file=PKG
+Load the specified package file.
+
+-V, --version
+Print a version message and then exit.
+
+-H, --help
+Print this message and then exit.