From 73121d6a9327147a3e2b706f0dd10e2e8cd6800f Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Wed, 23 Feb 2022 22:06:32 -0500 Subject: [PATCH 01/16] 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.0 From 928139d581ba3b90e87683e3948db61193498fc5 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Wed, 23 Feb 2022 23:20:34 -0500 Subject: [PATCH 02/16] Ditch local orderonly trick. The orderonly trick used here is missing various updates in fix-gnulib that improve interoperability with various make implementations. We can just rely on the logic in $(gnulib_headers) to get its version of the order-only behaviour, particularly since every file including these ones should have gnulib header dependencies. --- Makefile.am | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Makefile.am b/Makefile.am index d6d99b0..57d8142 100644 --- a/Makefile.am +++ b/Makefile.am @@ -32,10 +32,6 @@ include_HEADERS = dist_man_MANS = doc/man/upkg.1 -# This trick should define orderonly to | iff we're using GNU make. -have_orderonly = $(findstring order-only,$(.FEATURES)) -orderonly = $(have_orderonly:order-only=|) - 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 @@ -76,7 +72,7 @@ engine_la_SOURCES = $(engine_GOBS:.gob=.c) $(engine_GOBS:.gob=.h) \ src/engine/pcx.h engine_la_LDFLAGS = $(AM_LDFLAGS) $(moduleflags) engine_la_LIBADD = $(GLIB_LIBS) -$(engine_la_OBJECTS): $(orderonly) $(engine_GOBS:.gob=.gobstamp) +$(engine_la_OBJECTS): $(gnulib_headers) $(engine_GOBS:.gob=.gobstamp) if USE_DUMMYMOD engine_la_SOURCES += src/engine/music-dummymod.c -- 2.43.0 From 18cf0058df91c5c0338c202b222ee3c5ea3fce75 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Sat, 26 Feb 2022 20:48:54 -0500 Subject: [PATCH 03/16] Update bootstrapping bits. Sync the bootstrap script to include updates from other packages, and pull in fix-gnulib and fix-ltdl updates from dxcommon. Stub out the silly warning flags configure test found in the latest gnulib. --- .gitignore | 37 +++++++++++++++++++------------------ bootstrap | 44 +++++++++++++++++++++++++++++++------------- common | 2 +- configure.ac | 3 +++ 4 files changed, 54 insertions(+), 32 deletions(-) diff --git a/.gitignore b/.gitignore index 15c133e..4231653 100644 --- a/.gitignore +++ b/.gitignore @@ -1,29 +1,30 @@ -*.o -*.lo -*.la *.gobstamp -Makefile -Makefile.in -.libs +*.la +*.lo +*.o .deps .dirstamp -/config.* -/configure +.libs +/INSTALL +/Makefile +/Makefile.in /aclocal.m4 /autom4te.cache -/libtool +/compile +/config.* +/configure +/depcomp +/exported.sh +/install-sh +/lib /libltdl +/libtool +/libuobject.pc /ltmain.sh -/install-sh -/depcomp /missing /mkinstalldirs -/stamp-h1 -/compile -/libuobject.pc -/lib /snippet -/upkg -/test-suite.log +/stamp-h1 /test-driver -/exported.sh +/test-suite.log +/upkg diff --git a/bootstrap b/bootstrap index d7e5087..19efbbd 100755 --- a/bootstrap +++ b/bootstrap @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright © 2011-2012, 2015 Nick Bowler +# Copyright © 2011-2012, 2015, 2021-2022 Nick Bowler # # Simple script to get started from a fresh git checkout. # @@ -10,17 +10,12 @@ scriptname=$0 -err() { - printf '%s: %s\n' "$scriptname" "$@" 1>&2 -} - -die() { - err "$@" - exit 1 -} +err() { printf '%s: %s\n' "$scriptname" "$*" 1>&2; } +die() { err "$@"; exit 1; } : ${LIBTOOLIZE=libtoolize} : ${AUTORECONF=autoreconf} +: ${AUTOMAKE=automake} : ${GNULIB=gnulib} : ${GIT=git} : ${PERL=perl} @@ -28,13 +23,25 @@ die() { $GIT submodule update --init || err "Failed to update submodules from git." if test -x $GNULIB/gnulib-tool; then - $GNULIB/gnulib-tool --update -S || die "Failed to update Gnulib." + $GNULIB/gnulib-tool --update -S || die "Failed to update Gnulib." else - die "Gnulib sources are not properly installed in gnulib/." + err "Gnulib sources are not properly installed in $GNULIB/" + cat >&2 <<'EOF' + +To bootstrap this package using an external Gnulib, you can set the GNULIB +environment variable to indicate the location of the Gnulib sources. +EOF + + test ! -f configure || cat >&2 <<'EOF' + +However, it seems this package is already bootstrapped. It should not +normally be necessary to run this script from a release tarball. +EOF + exit 1 fi $PERL common/scripts/fix-gnulib.pl -o lib/gnulib.mk -i lib/gnulib.mk.in \ - || die "Failed to fixup Gnulib makefile fragment." + || die "Failed to fixup Gnulib makefile fragment." # Frustratingly, libtoolize has changed the name of its nonrecursive ltdl # makefile output, which broke all packages depending on previous documented @@ -47,7 +54,18 @@ test ! -f libltdl/ltdl.mk || mv -f libltdl/ltdl.mk libltdl/ltdl.mk.in $PERL common/scripts/fix-ltdl.pl -o libltdl/ltdl.mk -i libltdl/ltdl.mk.in \ || die "Failed to fixup libltdl makefile fragment." +# Rewrite if ! ... construts produced by gnulib conditional dependencies +# as these fail in heirloom-sh. +sed 's/if ! *\(.*gnulib_enabled[^;]*\); then/if \1; then :; else/' \ + m4/gnulib-comp.m4 >m4/gnulib-comp.m4.new || exit +mv -f m4/gnulib-comp.m4.new m4/gnulib-comp.m4 || exit + # Punt some automake-generated files so that Gentoo's wrapper script doesn't # try to detect the automake version in use. rm -f Makefile.in aclocal.m4 -LIBTOOLIZE=true $AUTORECONF -fis +LIBTOOLIZE=true $AUTORECONF -fis || exit + +amdir=`$AUTOMAKE --print-libdir` +if test -f "$amdir/INSTALL"; then + ln -sf "$amdir/INSTALL" INSTALL +fi diff --git a/common b/common index 03a2675..a7cabb5 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 03a26752c80546ac8cf8fc81807bb5a153786599 +Subproject commit a7cabb5d0f067e78afd029d8ec41d14660d8f9e2 diff --git a/configure.ac b/configure.ac index 762de22..b5d8d3d 100644 --- a/configure.ac +++ b/configure.ac @@ -4,6 +4,9 @@ dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2. 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. +dnl remove pointless gnulib warning flag check +AC_DEFUN([gl_CC_GNULIB_WARNINGS]) + AC_INIT([upkg],[0.1],[nbowler@draconx.ca]) AC_CONFIG_SRCDIR([src/libupkg.c]) AC_CONFIG_HEADERS([config.h]) -- 2.43.0 From f6779008e58e8d3158555dca574e7bbdb15a55dd Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Sat, 26 Feb 2022 23:06:52 -0500 Subject: [PATCH 04/16] Port tests to Autotest. All my other projects use Autotest, which I like quite a lot better than the Automake test harness. So let's convert this project now, which has only a couple dead simple scripts to convert. --- .gitignore | 8 +++++ Makefile.am | 21 +++++------- configure.ac | 4 +++ test/decodeindex.c | 2 +- tests/engine-pcx-rlencode.sh | 27 --------------- tests/functions.at | 62 +++++++++++++++++++++++++++++++++++ tests/libupkg-index-decode.sh | 54 ------------------------------ testsuite.at | 21 ++++++++++++ 8 files changed, 105 insertions(+), 94 deletions(-) delete mode 100644 tests/engine-pcx-rlencode.sh create mode 100644 tests/functions.at delete mode 100644 tests/libupkg-index-decode.sh create mode 100644 testsuite.at diff --git a/.gitignore b/.gitignore index 4231653..f017110 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +*.a *.gobstamp *.la *.lo @@ -9,6 +10,8 @@ /Makefile /Makefile.in /aclocal.m4 +/atconfig +/atlocal /autom4te.cache /compile /config.* @@ -23,8 +26,13 @@ /ltmain.sh /missing /mkinstalldirs +/package.m4 /snippet /stamp-h1 /test-driver /test-suite.log +/testsuite +/testsuite.deps +/testsuite.dir +/testsuite.log /upkg diff --git a/Makefile.am b/Makefile.am index 57d8142..da9a395 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,7 +4,6 @@ # This is free software: you are free to do what the fuck you want to. # There is NO WARRANTY, to the extent permitted by law. -AUTOMAKE_OPTIONS = parallel-tests color-tests ACLOCAL_AMFLAGS = -I m4 -I common/m4 MAINTAINERCLEANFILES = MOSTLYCLEANFILES = @@ -39,6 +38,7 @@ 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 +$(libupkg_la_OBJECTS): $(gnulib_headers) uobjectdir = $(includedir)/uobject uobject_HEADERS = src/uobject/uobject.h src/uobject/exportable.h \ @@ -83,23 +83,19 @@ engine_la_SOURCES += src/engine/music-modplug.c src/engine/modplug-types.h engine_la_LIBADD += $(LIBMODPLUG_LIBS) endif -check_LTLIBRARIES = libtest.la check_PROGRAMS = test/decodeindex test/pcxrle +check_LIBRARIES = libtest.a -libtest_la_SOURCES = test/common.c test/common.h +libtest_a_SOURCES = test/common.c test/common.h +$(libtest_a_OBJECTS): $(gnulib_headers) -test_decodeindex_LDADD = libupkg.la libgnu.la libtest.la +TEST_LIBS = libtest.a libgnu.la + +test_decodeindex_LDADD = libupkg.la $(TEST_LIBS) $(test_decodeindex_OBJECTS): $(gnulib_headers) -test_pcxrle_LDADD = src/engine/pcx.lo libupkg.la libgnu.la libtest.la +test_pcxrle_LDADD = src/engine/pcx.lo libupkg.la $(TEST_LIBS) $(test_pcxrle_OBJECTS): $(gnulib_headers) -TESTS_ENVIRONMENT = SHELL='$(SHELL)' EXEEXT='$(EXEEXT)' -TEST_EXTENSIONS = .sh -SH_LOG_COMPILER = $(SHELL) - -TESTS = tests/libupkg-index-decode.sh tests/engine-pcx-rlencode.sh -EXTRA_DIST += $(TESTS) - # Supporting rules for GObject Builder GOB_V = $(GOB_V_@AM_V@) GOB_V_ = $(GOB_V_@AM_DEFAULT_V@) @@ -167,3 +163,4 @@ unfuck-distdir: include $(top_srcdir)/lib/gnulib.mk include $(top_srcdir)/libltdl/ltdl.mk +include $(top_srcdir)/common/snippet/autotest.mk diff --git a/configure.ac b/configure.ac index b5d8d3d..fef7121 100644 --- a/configure.ac +++ b/configure.ac @@ -78,5 +78,9 @@ CFLAGS=$save_CFLAGS LIBS=$save_LIBS]) ]) AM_CONDITIONAL([HAVE_GOB2_DYN], [test x"$dx_cv_gob2_dynamic_types" = x"yes"]) +AC_CONFIG_TESTDIR([.], [test:.]) +DX_PROG_AUTOTEST +AM_CONDITIONAL([HAVE_AUTOTEST], [test x"$dx_cv_autotest_works" = x"yes"]) + AC_CONFIG_FILES([Makefile libuobject.pc]) AC_OUTPUT diff --git a/test/decodeindex.c b/test/decodeindex.c index c072a07..1eef6a6 100644 --- a/test/decodeindex.c +++ b/test/decodeindex.c @@ -52,7 +52,7 @@ static void print_bytes(FILE *f, int indent, void *buf, size_t n) fprintf(f, "%*s", indent, ""); if (n == 0) { - printf("(empty)\n"); + fprintf(f, "(empty)\n"); return; } diff --git a/tests/engine-pcx-rlencode.sh b/tests/engine-pcx-rlencode.sh deleted file mode 100644 index 3a05444..0000000 --- a/tests/engine-pcx-rlencode.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh -# -# Check corner cases of the PCX run-length encoder. -# Copyright © 2012 Nick Bowler -# -# License WTFPL2: Do What The Fuck You Want To Public License, version 2. -# This is free software: you are free to do what the fuck you want to. -# There is NO WARRANTY, to the extent permitted by law. - -pcxrle=test/pcxrle$EXEEXT - -$pcxrle 00 || exit 1 -$pcxrle 0000 || exit 1 -$pcxrle c100 || exit 1 - -# Test RLE rollover -t1=00 -t2=$t1$t1 -t4=$t2$t2 -t8=$t4$t4 -t16=$t8$t8 -t32=$t16$t16 -t64=$t32$t32 - -$pcxrle "$t32$t16$t8$t4$t2$t1" || exit 1 # maximum possible run -$pcxrle "$t64" || exit 1 -$pcxrle "$t64$t64$t64" || exit 1 diff --git a/tests/functions.at b/tests/functions.at new file mode 100644 index 0000000..fe8632e --- /dev/null +++ b/tests/functions.at @@ -0,0 +1,62 @@ +# Copyright © 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 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 . + +AT_SETUP([upkg_decode_index]) +AT_KEYWORDS([core function]) + +# various encodings of zero +m4_foreach_w([INDEX], [00 4000 408000 40808000 4080808000], + [AT_CHECK([decodeindex INDEX], [0], [0 +]) +]) + +# truncated encodings of zero +m4_foreach_w([INDEX], ['' 40 4080 408080 40808080], + [AT_CHECK([decodeindex INDEX], [1], [ignore], [ignore]) +]) + +# overlong encoding of zero +AT_CHECK([decodeindex 408080808000], [1], [ignore], [ignore]) + +AT_CLEANUP + +AT_SETUP([pcx_write_scanline run-length encoding]) +AT_KEYWORDS([engine function]) + +AT_CHECK([pcxrle 00], [0], [00 +]) +AT_CHECK([pcxrle 0000], [0], [c200 +]) +AT_CHECK([pcxrle c100], [0], [c1c100 +]) + +zero1=00 +zero4=$zero1$zero1$zero1$zero1 +zero16=$zero4$zero4$zero4$zero4 +zero63=$zero16$zero16$zero16$zero4$zero4$zero4$zero1$zero1$zero1 +zero64=$zero16$zero16$zero16$zero16 +zero192=$zero64$zero64$zero64 + +AT_CHECK([# maximum possible run +pcxrle $zero63], [0], [ff00 +]) +AT_CHECK([# one more than maximum +pcxrle $zero64], [0], [ff0000 +]) +AT_CHECK([# consecutive runs +pcxrle $zero192], [0], [ff00ff00ff00c300 +]) + +AT_CLEANUP diff --git a/tests/libupkg-index-decode.sh b/tests/libupkg-index-decode.sh deleted file mode 100644 index 80b328d..0000000 --- a/tests/libupkg-index-decode.sh +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/sh -# -# Check various corner cases of upkg_decode_index. -# Copyright © 2012, 2022 Nick Bowler -# -# License WTFPL2: Do What The Fuck You Want To Public License, version 2. -# This is free software: you are free to do what the fuck you want to. -# There is NO WARRANTY, to the extent permitted by law. - -decodeindex=test/decodeindex$EXEEXT -scriptname=$0 - -test_index() { - decode_cmd=`exec 3>&1 - { $decodeindex "$1" 3>&- - echo decode_status=$? >&3 - } | { read val 3>&- - echo decode_val=\'$val\' >&3; - }` - eval "$decode_cmd" - - case $# in - 2) - (exit $decode_status) || return 1 - if test x"$decode_val" != x"$2"; then - printf '%s: result (%d) does not match expected (%d)\n' \ - "$scriptname" "$decode_val" "$2" - return 1 - fi - ;; - 1) - if (exit $decode_status); then - printf '%s: false positive on (%s), got (%d)\n' \ - "$scriptname" "$1" "$decode_val" - return 1 - fi - ;; - esac -} - -test_index 00 0 || exit 1 -test_index 4000 0 || exit 1 -test_index 408000 0 || exit 1 -test_index 40808000 0 || exit 1 -test_index 4080808000 0 || exit 1 - -# False positives -test_index '' || exit 1 -test_index 40 || exit 1 -test_index 4080 || exit 1 -test_index 408080 || exit 1 -test_index 40808080 || exit 1 -test_index 4080808080 || exit 1 -test_index 408080808000 || exit 1 diff --git a/testsuite.at b/testsuite.at new file mode 100644 index 0000000..74348cc --- /dev/null +++ b/testsuite.at @@ -0,0 +1,21 @@ +AT_COPYRIGHT([Copyright © 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 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 . + +AT_INIT +AT_COLOR_TESTS + +AT_TESTED([upkg]) + +m4_include([tests/functions.at]) -- 2.43.0 From b8058e7a9acc7b38fa3aa04e34422bb044f9406b Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Sun, 27 Feb 2022 00:14:52 -0500 Subject: [PATCH 05/16] Add a simple texture export testcase. --- tests/data/hatch2x2.pcx | Bin 0 -> 902 bytes tests/data/test0.utx | Bin 0 -> 1528 bytes tests/export.at | 26 ++++++++++++++++++++++++++ testsuite.at | 1 + 4 files changed, 27 insertions(+) create mode 100644 tests/data/hatch2x2.pcx create mode 100644 tests/data/test0.utx create mode 100644 tests/export.at diff --git a/tests/data/hatch2x2.pcx b/tests/data/hatch2x2.pcx new file mode 100644 index 0000000000000000000000000000000000000000..b5bead683b8e7df3676af509e45a459eddcf5f1f GIT binary patch literal 902 zcmb`F!L3k13T0QHov-Vmjt!C9# zR$ft{jWk*`^IA9OPG>UX8QoZ_cABZDItnh+NhY4?pm^(!Gxk_8(mLuWBafI0HDW+R z2^Mz@MjL6gXx16Jnv>S8&L3l`lE#hBE)-lkwQJ!XDBf17Tw#wqz@(cv@DBtIp+*d7 zD0vD8gV9DBEnRYVP0ewl3le{frLtp@D|VsaGIB(YBuxNt@tmM>OO)gRCf&pV6NYgJ zHDW;12^Jg-MjL6}itaVn)Eu!fg2W$VsmxFE{)V&r7R*L(pKnPA^>V-Uz9^6JrE}YU dh7b99xaB{rbMPi1jTT!XJUo5s_y0dl{{Z+@MAiTR literal 0 HcmV?d00001 diff --git a/tests/data/test0.utx b/tests/data/test0.utx new file mode 100644 index 0000000000000000000000000000000000000000..433c56c753a159c4e1d72935af62e1976daf2b3f GIT binary patch literal 1528 zcmd7Sv2W8r6vy%B)M=8Ik|HQ<3}x$7dV-aTP$7m=B-#$$OqFXQ(zr@osX|N?76$e= z(1DGe4GF>inBc!*2;X;!D*gnTysQ25`Rn$*}5_6;R<7vGAPrUcM|7teM{^eowSuyBV)hyq;ytB1koXzH9+U9Qe ztU4W~Uimy@ju{^ycOSkij>tKwcgk6h#@6tt@4rDBd22So-KnkWj;r-_xZsCJqw;jB zZuN@lu(xrxkuJ(+K1qK@t5l={C6kFqMq}hgZsbPp-IQE8P;w<#a=$f_NAk!?B#-1i zTp$nRfjkfda=sHG7jhvNa*^q@w8linpvC}3=R~0~Jch^c7@ow#V|WaY;W0dkjK}a8 z9>ZgJ($BzScnpu>F+Bd$43FV4Jch^cpi2^^RXmDE@uVfdqX3l2l!28&(z0+-IZ!-` zNAaYk!lQT;kK$20Y5DLd9>t@06pt^d;!!+`NAW10w9IK`T;rcWk^9o)iFhKOh$rGn z+kq$Ii69~qMg~t?#7&V7k&}og;z`?vC*p~CBA$rHw=&|1cp{#NC*n!ln|8@p#x?#S z_bta0@B};oPr#EN13Upwz!UHUJn7NE6YvB)0Z3rd^tdos;Ko3wKoIcorO5FFJONL@ zLrnP-daJGU2q`Mq9Qc0rUq@Hed&f9. + +AT_SETUP([export texture hatch2x2]) + +# Until we implement all properties we must ignore warnings printed to stderr +AT_CHECK([upkg -xf "$srcdir/tests/data/test0.utx" test0.testgroup.hatch2x2], +[0], [exporting test0.testgroup.hatch2x2 to hatch2x2.pcx +], [ignore]) + +dnl TODO make this independent of irrelevant file format details +AT_CHECK([cmp "$srcdir/tests/data/hatch2x2.pcx" hatch2x2.pcx]) + +AT_CLEANUP diff --git a/testsuite.at b/testsuite.at index 74348cc..fbdb0c6 100644 --- a/testsuite.at +++ b/testsuite.at @@ -19,3 +19,4 @@ AT_COLOR_TESTS AT_TESTED([upkg]) m4_include([tests/functions.at]) +m4_include([tests/export.at]) -- 2.43.0 From dc6cf2d7ff5aea68888bf648be23754ffe5b18ba Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Sun, 27 Feb 2022 00:18:04 -0500 Subject: [PATCH 06/16] uobject: Simplify lookup_module function. We don't need this function to double as a C compiler test case. Not doing weird things with flexible array members seems to be much simpler. --- src/uobject/module.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/uobject/module.c b/src/uobject/module.c index ff6bd5a..1d41d07 100644 --- a/src/uobject/module.c +++ b/src/uobject/module.c @@ -80,19 +80,16 @@ int u_object_module_exit(void) static int lookup_module(GTypeModule **out, const char *name) { - struct { GTypeModule pkg; char buf[]; } *search_key; - GTypeModule *result; + GTypeModule *result, key = {0}; + char *buf; - search_key = malloc(sizeof *search_key + strlen(name) + 1); - if (!search_key) + buf = malloc(strlen(name) + 1); + if (!buf) return -1; - search_key->pkg = (GTypeModule) { - .name = str_cpy_lower(search_key->buf, name), - }; - - result = avl_find(package_tree, search_key); - free(search_key); + key.name = str_cpy_lower(buf, name); + result = avl_find(package_tree, &key); + free(buf); *out = result; return 0; -- 2.43.0 From 5cc9122c07d7b903ff44369d6030c9e1c05315b9 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Sun, 27 Feb 2022 14:15:19 -0500 Subject: [PATCH 07/16] Fix distribution of test data. --- Makefile.am | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile.am b/Makefile.am index da9a395..8f98918 100644 --- a/Makefile.am +++ b/Makefile.am @@ -96,6 +96,8 @@ $(test_decodeindex_OBJECTS): $(gnulib_headers) test_pcxrle_LDADD = src/engine/pcx.lo libupkg.la $(TEST_LIBS) $(test_pcxrle_OBJECTS): $(gnulib_headers) +EXTRA_DIST += tests/data/test0.utx tests/data/hatch2x2.pcx + # Supporting rules for GObject Builder GOB_V = $(GOB_V_@AM_V@) GOB_V_ = $(GOB_V_@AM_DEFAULT_V@) -- 2.43.0 From ab9b40939aa8a68902e0fc38a7ba1db165d10788 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Sun, 27 Feb 2022 14:18:58 -0500 Subject: [PATCH 08/16] Don't use [static n] in prototypes. This modern C syntax is mostly useless and introduces compatibility problems for no real benefit. --- src/libupkg.c | 2 +- src/upkg.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libupkg.c b/src/libupkg.c index ed652ac..f6de123 100644 --- a/src/libupkg.c +++ b/src/libupkg.c @@ -132,7 +132,7 @@ size_t upkg_decode_index(long *val, const unsigned char *bytes, size_t n) return 0; } -static struct upkg_priv *init_upkg(unsigned char hdr[static UPKG_HDR_SIZE]) +static struct upkg_priv *init_upkg(const unsigned char *hdr) { struct upkg_priv *pkg; diff --git a/src/upkg.c b/src/upkg.c index 6c8cbc1..db9a747 100644 --- a/src/upkg.c +++ b/src/upkg.c @@ -171,7 +171,7 @@ static void print_upkg_object_flags(const char *prefix, unsigned long flags) printf("%sDebugDestroy\n", prefix); } -void print_guid(unsigned char guid[static 16]) +static void print_guid(unsigned char *guid) { for (unsigned i = 0; i < 16; i++) { printf("%02hhx", guid[i]); -- 2.43.0 From d2b086b113f4bc1d7a247cd1ec4301211f87964d Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Sun, 27 Feb 2022 14:39:52 -0500 Subject: [PATCH 09/16] Use gnulib flexmember module. For increased portability to older C compilers. --- m4/.gitignore | 2 ++ m4/gnulib-cache.m4 | 4 ++++ src/engine/texture.gob | 2 +- src/uobject/vfs.c | 26 +++++++++++++------------- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/m4/.gitignore b/m4/.gitignore index 9454b32..f49561a 100644 --- a/m4/.gitignore +++ b/m4/.gitignore @@ -6,6 +6,7 @@ exponentf.m4 exponentl.m4 extensions.m4 extern-inline.m4 +flexmember.m4 float_h.m4 fpieee.m4 getopt.m4 @@ -13,6 +14,7 @@ gnulib-common.m4 gnulib-comp.m4 gnulib-tool.m4 include_next.m4 +inline.m4 isnand.m4 isnanf.m4 isnanl.m4 diff --git a/m4/gnulib-cache.m4 b/m4/gnulib-cache.m4 index 988fa8e..5a3ed85 100644 --- a/m4/gnulib-cache.m4 +++ b/m4/gnulib-cache.m4 @@ -40,7 +40,9 @@ # --macro-prefix=gl \ # --no-vc-files \ # copysignf \ +# flexmember \ # getopt-gnu \ +# inline \ # ldexpf \ # strcase @@ -48,7 +50,9 @@ gl_LOCAL_DIR([]) gl_MODULES([ copysignf + flexmember getopt-gnu + inline ldexpf strcase ]) diff --git a/src/engine/texture.gob b/src/engine/texture.gob index 165f48a..cc6b271 100644 --- a/src/engine/texture.gob +++ b/src/engine/texture.gob @@ -40,7 +40,7 @@ struct engine_texture_data { unsigned long width, height; unsigned long datalen; - unsigned char data[]; + unsigned char data[FLEXIBLE_ARRAY_MEMBER]; }; %} diff --git a/src/uobject/vfs.c b/src/uobject/vfs.c index 819dbc2..ac73ca4 100644 --- a/src/uobject/vfs.c +++ b/src/uobject/vfs.c @@ -1,19 +1,19 @@ /* - * Functions for handling UObject package search paths. - * Copyright © 2009-2011 Nick Bowler + * Functions for handling UObject package search paths. + * Copyright © 2009-2011, 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 @@ -187,7 +187,7 @@ struct foreach_state { const char *name; struct upkg *f; size_t sz; - char buf[]; + char buf[FLEXIBLE_ARRAY_MEMBER]; }; static int foreachfile(const char *filename, void *_st) -- 2.43.0 From 84b8b056cfbc91dc6d8d29bb40b04afb3a282cbc Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Sun, 27 Feb 2022 14:44:11 -0500 Subject: [PATCH 10/16] Work around missing SIZE_MAX. Older library implementations lack this macro. Outside of an #if directive the expression (size_t)-1 is equivalent so we can define a fallback easily enough. --- src/engine/mesh.gob | 6 +++++- src/uobject/uobject.c | 27 +++++++++++++++------------ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/engine/mesh.gob b/src/engine/mesh.gob index 74b5b68..8e60828 100644 --- a/src/engine/mesh.gob +++ b/src/engine/mesh.gob @@ -23,10 +23,14 @@ %} %{ -#include +#include #include #include #include "pack.h" + +#ifndef SIZE_MAX +# define SIZE_MAX ((size_t)-1) +#endif %} %h{ diff --git a/src/uobject/uobject.c b/src/uobject/uobject.c index 3bada24..0fbcd8d 100644 --- a/src/uobject/uobject.c +++ b/src/uobject/uobject.c @@ -1,19 +1,19 @@ /* - * upkg: tool for manipulating Unreal Tournament packages. - * Copyright © 2009-2012, 2015, 2020 Nick Bowler + * upkg: tool for manipulating Unreal Tournament packages. + * Copyright © 2009-2012, 2015, 2020, 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 @@ -36,6 +36,9 @@ #define U_OBJECT_GET_PRIV(o) \ G_TYPE_INSTANCE_GET_PRIVATE(o, U_TYPE_OBJECT, struct u_object_priv) +#ifndef SIZE_MAX +# define SIZE_MAX ((size_t)-1) +#endif struct prop_head { const char *prop_name, *struct_name; -- 2.43.0 From 45969066e2f26f8b28787560c0b70d1c119982d7 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Sun, 27 Feb 2022 14:47:02 -0500 Subject: [PATCH 11/16] Avoid C99 stdbool. This is barely used at all, just another pointless library requirement. --- src/uobject/package.c | 4 ++-- src/uobject/package.h | 27 +++++++++++++-------------- src/uobject/uobject.c | 3 +-- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/uobject/package.c b/src/uobject/package.c index 7e42122..30a42cc 100644 --- a/src/uobject/package.c +++ b/src/uobject/package.c @@ -159,9 +159,9 @@ GTypeModule *u_pkg_open(const char *name) return mod; } -bool u_pkg_is_native(GTypeModule *m) +int u_pkg_is_native(GTypeModule *m) { struct upkg_priv *priv = U_PKG_GET_PRIV(m); - return priv->native; + return !!priv->native; } diff --git a/src/uobject/package.h b/src/uobject/package.h index eb217aa..74a0b9d 100644 --- a/src/uobject/package.h +++ b/src/uobject/package.h @@ -1,26 +1,25 @@ /* - * upkg: tool for manipulating Unreal Tournament packages. - * Copyright © 2009-2011 Nick Bowler + * upkg: tool for manipulating Unreal Tournament packages. + * Copyright © 2009-2011, 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 . */ #ifndef U_OBJECT_PACKAGE_H_ #define U_OBJECT_PACKAGE_H_ #include -#include #define U_PKG_TYPE (u_pkg_get_type()) #define U_PKG(obj) \ @@ -49,6 +48,6 @@ struct UPkgClass { GType u_pkg_get_type(void); GTypeModule *u_pkg_open(const char *name); -bool u_pkg_is_native(GTypeModule *pkg); +int u_pkg_is_native(GTypeModule *pkg); #endif diff --git a/src/uobject/uobject.c b/src/uobject/uobject.c index 0fbcd8d..cf07735 100644 --- a/src/uobject/uobject.c +++ b/src/uobject/uobject.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -43,7 +42,7 @@ struct prop_head { const char *prop_name, *struct_name; unsigned long size, array_idx; - bool tag_msb; + gboolean tag_msb; enum { PROPERTY_END, -- 2.43.0 From 7a7477c44a497ed04c9b677488bc42bce90b0831 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Sun, 27 Feb 2022 15:10:40 -0500 Subject: [PATCH 12/16] Simplify libupkg package header decoding. Not only is this way a bit more readable than the older version, it also avoids tripping over a designated initializer bug in HP-UX cc. --- src/libupkg.c | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/src/libupkg.c b/src/libupkg.c index f6de123..60dcab0 100644 --- a/src/libupkg.c +++ b/src/libupkg.c @@ -26,6 +26,16 @@ #define MIN(a, b) ((a) < (b) ? (a) : (b)) +#define UPKG_HDR_OFFSET_VERSION 4 +#define UPKG_HDR_OFFSET_LICENSE 6 +#define UPKG_HDR_OFFSET_FLAGS 8 +#define UPKG_HDR_OFFSET_NAME_COUNT 12 +#define UPKG_HDR_OFFSET_NAME_OFFSET 16 +#define UPKG_HDR_OFFSET_EXPORT_COUNT 20 +#define UPKG_HDR_OFFSET_EXPORT_OFFSET 24 +#define UPKG_HDR_OFFSET_IMPORT_COUNT 28 +#define UPKG_HDR_OFFSET_IMPORT_OFFSET 32 + /* * Print a message and execute some statement(s) if the expression evaluates * to zero. Intended to help verify that assumed constraints on the file @@ -134,26 +144,21 @@ size_t upkg_decode_index(long *val, const unsigned char *bytes, size_t n) static struct upkg_priv *init_upkg(const unsigned char *hdr) { - struct upkg_priv *pkg; + struct upkg_priv *pkg, tmp = {0}; + + tmp.pub.version = unpack_16_le(hdr+UPKG_HDR_OFFSET_VERSION); + tmp.pub.license = unpack_16_le(hdr+UPKG_HDR_OFFSET_LICENSE); + tmp.pub.flags = unpack_32_le(hdr+UPKG_HDR_OFFSET_FLAGS); + tmp.pub.name_count = unpack_32_le(hdr+UPKG_HDR_OFFSET_NAME_COUNT); + tmp.pub.export_count = unpack_32_le(hdr+UPKG_HDR_OFFSET_EXPORT_COUNT); + tmp.pub.import_count = unpack_32_le(hdr+UPKG_HDR_OFFSET_IMPORT_COUNT); + tmp.name_offset = unpack_32_le(hdr+UPKG_HDR_OFFSET_NAME_OFFSET); + tmp.export_offset = unpack_32_le(hdr+UPKG_HDR_OFFSET_EXPORT_OFFSET); + tmp.import_offset = unpack_32_le(hdr+UPKG_HDR_OFFSET_IMPORT_OFFSET); pkg = malloc(sizeof *pkg); - if (!pkg) - return NULL; - - *pkg = (struct upkg_priv) { - .pub = { - .version = unpack_16_le(hdr+4), - .license = unpack_16_le(hdr+6), - .flags = unpack_32_le(hdr+8), - .name_count = unpack_32_le(hdr+12), - .export_count = unpack_32_le(hdr+20), - .import_count = unpack_32_le(hdr+28), - }, - - .name_offset = unpack_32_le(hdr+16), - .export_offset = unpack_32_le(hdr+24), - .import_offset = unpack_32_le(hdr+32), - }; + if (pkg) + *pkg = tmp; return pkg; } -- 2.43.0 From b8fe472353dead42e203aefda5e8040ad41448a9 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Sun, 27 Feb 2022 15:38:15 -0500 Subject: [PATCH 13/16] tests: Add --version output to the common library. Just a slight simplification of the individual test apps. Let's also augment the --help output with a simple list of options (even though the current test apps have no useful options). --- Makefile.am | 2 +- test/common.c | 31 ++++++++++++++++++++++++++++--- test/common.h | 23 +++++++++++++++++++++++ test/decodeindex.c | 19 ++++++++----------- test/pcxrle.c | 17 +++++++---------- 5 files changed, 67 insertions(+), 25 deletions(-) diff --git a/Makefile.am b/Makefile.am index 8f98918..fa034c3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -86,7 +86,7 @@ endif check_PROGRAMS = test/decodeindex test/pcxrle check_LIBRARIES = libtest.a -libtest_a_SOURCES = test/common.c test/common.h +libtest_a_SOURCES = test/common.c test/common.h common/src/help.c $(libtest_a_OBJECTS): $(gnulib_headers) TEST_LIBS = libtest.a libgnu.la diff --git a/test/common.c b/test/common.c index c998624..9919b1b 100644 --- a/test/common.c +++ b/test/common.c @@ -1,6 +1,6 @@ /* * Helper functions for test programs. - * Copyright © 2012 Nick Bowler + * Copyright © 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 @@ -13,12 +13,17 @@ * 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 . + * along with this program. If not, see . */ + +#include +#include #include #include +#include #include "common.h" +#include "help.h" /* * Decode a hexadecimal string into a sequence of bytes. If there are an @@ -35,7 +40,7 @@ size_t test_decode_hex(const char *hex, unsigned char *buf, size_t n) char tmp[] = "00"; for (len = 0; hex[len]; len++) { - if (!isxdigit(hex[len])) + if (!isxdigit((unsigned char)hex[len])) return -1; } @@ -55,3 +60,23 @@ size_t test_decode_hex(const char *hex, unsigned char *buf, size_t n) return count; } + +void test_print_version(const char *program) +{ + printf("%s (%s) %s\n", program, PACKAGE_NAME, PACKAGE_VERSION); + 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 test_print_options(const struct option *lopts) +{ + const struct option *opt; + + puts("\nOptions:"); + for (opt = lopts; opt->val; opt++) { + if (help_print_optstring(opt, "ARG", 20)) + putchar('\n'); + } +} diff --git a/test/common.h b/test/common.h index 907ee5a..675ebe2 100644 --- a/test/common.h +++ b/test/common.h @@ -1,6 +1,29 @@ +/* + * Helper functions for test programs. + * Copyright © 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 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 . + */ + #ifndef TEST_COMMON_H_ #define TEST_COMMON_H_ +struct option; + +void test_print_version(const char *program); +void test_print_options(const struct option *lopts); + size_t test_decode_hex(const char *hex, unsigned char *buf, size_t n); #endif diff --git a/test/decodeindex.c b/test/decodeindex.c index 1eef6a6..1d4643b 100644 --- a/test/decodeindex.c +++ b/test/decodeindex.c @@ -1,6 +1,6 @@ /* * Tool for decoding compact index values for testing. - * Copyright © 2012 Nick Bowler + * Copyright © 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 @@ -13,7 +13,7 @@ * 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 . + * along with this program. If not, see . */ #include @@ -38,13 +38,10 @@ static void print_usage(FILE *f) fprintf(f, "Usage: %s [options] index [index ...]\n", progname); } -static void print_version(void) +static void print_help(void) { - printf("%s (%s) %s\n", PROGNAME, PACKAGE_NAME, PACKAGE_VERSION); - puts("Copyright (C) 2012 Nick Bowler."); - puts("License GPLv3+: GNU GPL version 3 or later ."); - puts("This is free software: you are free to change and redistribute it."); - puts("There is NO WARRANTY, to the extent permitted by law."); + print_usage(stdout); + test_print_options(lopts); } static void print_bytes(FILE *f, int indent, void *buf, size_t n) @@ -78,7 +75,7 @@ static int print_index(const char *hex) progname, hex); goto out; } - + rc = upkg_decode_index(&index, buf, n); if (rc == 0) { fprintf(stderr, "%s: invalid index encoding:\n", progname); @@ -106,10 +103,10 @@ int main(int argc, char **argv) while ((opt = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) { switch (opt) { case 'V': - print_version(); + test_print_version(PROGNAME); return EXIT_SUCCESS; case 'H': - print_usage(stdout); + print_help(); return EXIT_SUCCESS; default: print_usage(stderr); diff --git a/test/pcxrle.c b/test/pcxrle.c index 6824fd0..34c50ce 100644 --- a/test/pcxrle.c +++ b/test/pcxrle.c @@ -1,6 +1,6 @@ /* * Tool for testing PCX run-length encoding. - * Copyright © 2012 Nick Bowler + * Copyright © 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 @@ -13,7 +13,7 @@ * 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 . + * along with this program. If not, see . */ #include @@ -41,13 +41,10 @@ static void print_usage(FILE *f) fprintf(f, "Usage: %s [options] bytes [bytes ...]\n", progname); } -static void print_version(void) +static void print_help(void) { - printf("%s (%s) %s\n", PROGNAME, PACKAGE_NAME, PACKAGE_VERSION); - puts("Copyright (C) 2012 Nick Bowler."); - puts("License GPLv3+: GNU GPL version 3 or later ."); - puts("This is free software: you are free to change and redistribute it."); - puts("There is NO WARRANTY, to the extent permitted by law."); + print_usage(stdout); + test_print_options(lopts); } static void rle_error(const unsigned char *raw, size_t n, const char *str) @@ -163,10 +160,10 @@ int main(int argc, char **argv) while ((opt = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) { switch (opt) { case 'V': - print_version(); + test_print_version(PROGNAME); return EXIT_SUCCESS; case 'H': - print_usage(stdout); + print_help(); return EXIT_SUCCESS; default: print_usage(stderr); -- 2.43.0 From 07cf4b8fcf35643a0d566f8e8d10f123bb2e09d4 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Fri, 1 Dec 2023 01:12:24 -0500 Subject: [PATCH 14/16] Replace gnulib patches with new common helper macro. Using the new DX_PATCH_GNULIB macro allows m4 to implement the conditional dependency patches that were previously being done in bootstrap, as well as removing the gl_CC_GNULIB_WARNINGS stub. --- bootstrap | 8 +------- common | 2 +- configure.ac | 5 ++--- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/bootstrap b/bootstrap index 19efbbd..2ab4a58 100755 --- a/bootstrap +++ b/bootstrap @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright © 2011-2012, 2015, 2021-2022 Nick Bowler +# Copyright © 2011-2012, 2015, 2021-2023 Nick Bowler # # Simple script to get started from a fresh git checkout. # @@ -54,12 +54,6 @@ test ! -f libltdl/ltdl.mk || mv -f libltdl/ltdl.mk libltdl/ltdl.mk.in $PERL common/scripts/fix-ltdl.pl -o libltdl/ltdl.mk -i libltdl/ltdl.mk.in \ || die "Failed to fixup libltdl makefile fragment." -# Rewrite if ! ... construts produced by gnulib conditional dependencies -# as these fail in heirloom-sh. -sed 's/if ! *\(.*gnulib_enabled[^;]*\); then/if \1; then :; else/' \ - m4/gnulib-comp.m4 >m4/gnulib-comp.m4.new || exit -mv -f m4/gnulib-comp.m4.new m4/gnulib-comp.m4 || exit - # Punt some automake-generated files so that Gentoo's wrapper script doesn't # try to detect the automake version in use. rm -f Makefile.in aclocal.m4 diff --git a/common b/common index a7cabb5..262d3ea 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit a7cabb5d0f067e78afd029d8ec41d14660d8f9e2 +Subproject commit 262d3eaea39294df3f6172b28213e927e2f3b424 diff --git a/configure.ac b/configure.ac index fef7121..ebd7d4d 100644 --- a/configure.ac +++ b/configure.ac @@ -1,11 +1,10 @@ -dnl Copyright © 2009-2012, 2015, 2019-2020, 2022 Nick Bowler +dnl Copyright © 2009-2012, 2015, 2019-2020, 2022-2023 Nick Bowler dnl dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2. 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. -dnl remove pointless gnulib warning flag check -AC_DEFUN([gl_CC_GNULIB_WARNINGS]) +DX_PATCH_GNULIB AC_INIT([upkg],[0.1],[nbowler@draconx.ca]) AC_CONFIG_SRCDIR([src/libupkg.c]) -- 2.43.0 From b25e52c14bbec4edfe175f6692b88cd93e349129 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Fri, 1 Dec 2023 01:07:50 -0500 Subject: [PATCH 15/16] Manual updates. For literal strings, we need to use \- instead of just - as some troff processors turn plain "-" into "proper" unicode hyphens (as opposed to hyphen-minus), which breaks copy+paste and searching. Ensure that .Os follows .Dt in the mdoc prologue as apparently not doing this results in broken manpage headings with groff 1.23. Add missing copyright and permission notice. --- doc/man/upkg.1 | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/doc/man/upkg.1 b/doc/man/upkg.1 index f3a1009..521ab19 100644 --- a/doc/man/upkg.1 +++ b/doc/man/upkg.1 @@ -1,6 +1,6 @@ -.Dd June 17, 2010 -.Os libuobject +.Dd December 1, 2023 .Dt UPKG \&1 "UObject Reference Manual" +.Os libuobject .Sh NAME .Nm upkg .Nd manipulate UObject packages @@ -12,22 +12,22 @@ .Op Ar object ... .Sh OPTIONS .Bl -tag -width indent -.It Fl i , -info +.It Fl i , \-info Display information about a package. More information is displayed at higher verbosity levels. -.It Fl l , -list +.It Fl l , \-list List objects belonging to a package. -.It Fl x , -export +.It Fl x , \-export Export all exportable objects from a package. -.It Fl v , -verbose +.It Fl v , \-verbose Increase the amount of information printed to standard output. This option can be specified multiple times for increased effect. -.It Fl f , -file Ar package +.It Fl f , \-file Ar package Loads a specific package by filename. Currently, this is the only way to load packages. -.It Fl V , -version +.It Fl V , \-version Print a version message and exit. -.It Fl H , -help +.It Fl H , \-help Print a help message and exit. .It Ar object Specifies the object(s) upon which @@ -38,3 +38,12 @@ will use the last package specified by the .Fl f option. .El +.Sh AUTHORS +Nick Bowler +.Sh COPYRIGHT +Copyright \(co 2009\(en2011, 2023 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. -- 2.43.0 From 1bb31b311822e4263134685fa262181185ca75d9 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Fri, 1 Dec 2023 01:15:29 -0500 Subject: [PATCH 16/16] Stop using gnulib's flexmember module. The only thing we're actually using from this module is provided directly by Autoconf, via AC_C_FLEXIBLE_ARRAY_MEMBER, so we can just use that macro instead. --- configure.ac | 2 ++ m4/gnulib-cache.m4 | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index ebd7d4d..1b3a262 100644 --- a/configure.ac +++ b/configure.ac @@ -18,6 +18,8 @@ DX_AUTOMAKE_COMPAT AC_PROG_CC_C99 gl_EARLY +AC_C_FLEXIBLE_ARRAY_MEMBER + LT_CONFIG_LTDL_DIR([libltdl]) LT_INIT([dlopen]) LTDL_INIT([nonrecursive]) diff --git a/m4/gnulib-cache.m4 b/m4/gnulib-cache.m4 index 5a3ed85..5159cac 100644 --- a/m4/gnulib-cache.m4 +++ b/m4/gnulib-cache.m4 @@ -40,7 +40,6 @@ # --macro-prefix=gl \ # --no-vc-files \ # copysignf \ -# flexmember \ # getopt-gnu \ # inline \ # ldexpf \ @@ -50,7 +49,6 @@ gl_LOCAL_DIR([]) gl_MODULES([ copysignf - flexmember getopt-gnu inline ldexpf -- 2.43.0