From 73121d6a9327147a3e2b706f0dd10e2e8cd6800f Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Wed, 23 Feb 2022 22:06:32 -0500 Subject: [PATCH] Use gen-options script and help formatting from dxcommon. These utilities make it easy to produce a much more useful help output with descriptions and everything. --- Makefile.am | 17 +++++++--- src/.gitignore | 1 + src/upkg.c | 87 ++++++++++++++++++++++++------------------------ src/upkgopts.opt | 20 +++++++++++ 4 files changed, 78 insertions(+), 47 deletions(-) create mode 100644 src/.gitignore create mode 100644 src/upkgopts.opt diff --git a/Makefile.am b/Makefile.am index 30cf7ae..d6d99b0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 index 0000000..b5b19dd --- /dev/null +++ b/src/.gitignore @@ -0,0 +1 @@ +/upkgopts.h diff --git a/src/upkg.c b/src/upkg.c index 55d13f8..6c8cbc1 100644 --- a/src/upkg.c +++ b/src/upkg.c @@ -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 . + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include @@ -34,6 +34,8 @@ #include #include +#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 .\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 index 0000000..2b19e98 --- /dev/null +++ b/src/upkgopts.opt @@ -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. -- 2.43.2