From: Nick Bowler Date: Fri, 1 Dec 2023 06:15:29 +0000 (-0500) Subject: Stop using gnulib's flexmember module. X-Git-Url: https://git.draconx.ca/gitweb/upkg.git/commitdiff_plain/HEAD?hp=db03b6ae47317f74767e4850da14a02afaa90d6b 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. --- diff --git a/.gitignore b/.gitignore index 15c133e..f017110 100644 --- a/.gitignore +++ b/.gitignore @@ -1,29 +1,38 @@ -*.o -*.lo -*.la +*.a *.gobstamp -Makefile -Makefile.in -.libs +*.la +*.lo +*.o .deps .dirstamp -/config.* -/configure +.libs +/INSTALL +/Makefile +/Makefile.in /aclocal.m4 +/atconfig +/atlocal /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 +/package.m4 /snippet -/upkg -/test-suite.log +/stamp-h1 /test-driver -/exported.sh +/test-suite.log +/testsuite +/testsuite.deps +/testsuite.dir +/testsuite.log +/upkg diff --git a/.gitmodules b/.gitmodules index 13c6889..c2e6052 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "gnulib"] path = gnulib - url = git://git.savannah.gnu.org/gnulib.git + url = https://git.savannah.gnu.org/git/gnulib.git [submodule "common"] path = common - url = git://git.draconx.ca/dxcommon.git + url = https://git.draconx.ca/dxcommon.git diff --git a/Makefile.am b/Makefile.am index e5140a4..fa034c3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,22 +1,24 @@ -# Copyright © 2009-2012, 2015, 2019-2020 Nick Bowler +# Copyright © 2009-2012, 2015, 2019-2020, 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. -AUTOMAKE_OPTIONS = parallel-tests color-tests ACLOCAL_AMFLAGS = -I m4 -I common/m4 MAINTAINERCLEANFILES = MOSTLYCLEANFILES = DISTCLEANFILES = -CLEANFILES = + +# Distribution should be buildable without working gob. +AM_DISTCHECK_CONFIGURE_FLAGS = GOB2=false EXTRA_DIST = $(MAINTAINERCLEANFILES) m4/gnulib-cache.m4 +CLEANFILES = $(EXTRA_LTLIBRARIES) $(EXTRA_LIBRARIES) AM_CPPFLAGS = -I$(top_builddir)/src -I$(top_srcdir)/src \ - -I$(top_srcdir)/$(DX_BASEDIR)/src \ - -I$(top_builddir)/lib -I$(top_srcdir)/lib \ - -DPKGLIBDIR=\"$(pkglibdir)\" -DPKGDATADIR=\"$(pkgdatadir)\" + -I$(top_builddir)/lib -I$(top_srcdir)/lib \ + -I$(DX_BASEDIR)/src -DPKGLIBDIR=\"$(pkglibdir)\" \ + -DPKGDATADIR=\"$(pkgdatadir)\" AM_CFLAGS = $(LTDLINCL) $(GLIB_CFLAGS) $(LIBMODPLUG_CFLAGS) @@ -29,16 +31,14 @@ 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 -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 +$(libupkg_la_OBJECTS): $(gnulib_headers) uobjectdir = $(includedir)/uobject uobject_HEADERS = src/uobject/uobject.h src/uobject/exportable.h \ @@ -60,6 +60,7 @@ moduleflags = -module -avoid-version -export-symbols-regex _LTX_ engine_GOBS = src/engine/palette.gob src/engine/texture.gob \ src/engine/music.gob src/engine/sound.gob src/engine/mesh.gob +EXTRA_DIST += $(engine_GOBS) MAINTAINERCLEANFILES += $(engine_GOBS:.gob=.gobstamp) \ $(engine_GOBS:.gob=.c) $(engine_GOBS:.gob=.h) @@ -71,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 @@ -82,22 +83,20 @@ 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_a_SOURCES = test/common.c test/common.h common/src/help.c +$(libtest_a_OBJECTS): $(gnulib_headers) -libtest_la_SOURCES = test/common.c test/common.h +TEST_LIBS = libtest.a libgnu.la -test_decodeindex_LDADD = libupkg.la libgnu.la libtest.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) +EXTRA_DIST += tests/data/test0.utx tests/data/hatch2x2.pcx # Supporting rules for GObject Builder GOB_V = $(GOB_V_@AM_V@) @@ -113,7 +112,8 @@ if HAVE_GOB2_DYN $(GOB_V) od='$(@D)'; case $$od in \ src/*) od=src ;; \ */src/*) od=$${od%/src/*}/src ;; \ - esac; $(GOB2) -o "$$od" --file-sep=/ --no-private-header $< + esac; $(GOB2) -o "$$od" --file-sep=/ \ + --no-private-header --no-touch-headers $< $(AM_V_at) mv -f $@.tmp $@ else if HAVE_GOB2 @@ -136,5 +136,33 @@ 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 +update-headers: unfuck-distdir + for f in $(engine_GOBS:.gob=.h); do \ + touch -c '$(distdir)'/"$$f" || exit; \ + done +.PHONY: update-headers + +# When running "make dist" in a VPATH build with a read-only srcdir, Automake +# will produce a distribution with all files read-only. Moreover, the files +# are read-only in distdir when the dist hooks are run. This hook will +# manually fix up the permissions. All dist hooks that modify files in +# distdir should list unfuck-distdir as a prerequisite. +dist-hook: unfuck-distdir +unfuck-distdir: + find '$(distdir)' -type f -exec chmod u+w {} + +.PHONY: unfuck-distdir + include $(top_srcdir)/lib/gnulib.mk include $(top_srcdir)/libltdl/ltdl.mk +include $(top_srcdir)/common/snippet/autotest.mk diff --git a/bootstrap b/bootstrap index d7e5087..2ab4a58 100755 --- a/bootstrap +++ b/bootstrap @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright © 2011-2012, 2015 Nick Bowler +# Copyright © 2011-2012, 2015, 2021-2023 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 @@ -50,4 +57,9 @@ $PERL common/scripts/fix-ltdl.pl -o libltdl/ltdl.mk -i libltdl/ltdl.mk.in \ # 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 4705ffd..262d3ea 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 4705ffd69e7b7551bab4650f9e49756667be783b +Subproject commit 262d3eaea39294df3f6172b28213e927e2f3b424 diff --git a/configure.ac b/configure.ac index 36c3ffd..1b3a262 100644 --- a/configure.ac +++ b/configure.ac @@ -1,13 +1,14 @@ -dnl Copyright © 2009-2012, 2015, 2019-2020 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. -AC_PREREQ(2.62) +DX_PATCH_GNULIB + AC_INIT([upkg],[0.1],[nbowler@draconx.ca]) AC_CONFIG_SRCDIR([src/libupkg.c]) -AC_CONFIG_HEADER([config.h]) +AC_CONFIG_HEADERS([config.h]) AC_CONFIG_MACRO_DIR([m4]) AM_INIT_AUTOMAKE([-Wall -Wno-portability foreign subdir-objects]) @@ -17,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]) @@ -28,6 +31,8 @@ AC_CACHE_SAVE m4_include([lib/gnulib.mk]) DX_LIB_GLIB2([], [gobject]) +AC_DEFINE([GLIB_DISABLE_DEPRECATION_WARNINGS], [1], + [Define to shut up glib deprecation silliness.]) AC_ARG_WITH([modlib], [AS_HELP_STRING([--with-modlib], @@ -74,5 +79,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/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. diff --git a/gnulib b/gnulib index 233419c..8a1e161 160000 --- a/gnulib +++ b/gnulib @@ -1 +1 @@ -Subproject commit 233419c39c6d13d84439b95766328a238ffb6518 +Subproject commit 8a1e1616f143ccebf13ea477a1d0a4040ce2ddc4 diff --git a/m4/.gitignore b/m4/.gitignore index d89469b..f49561a 100644 --- a/m4/.gitignore +++ b/m4/.gitignore @@ -1,19 +1,20 @@ 00gnulib.m4 +absolute-header.m4 copysignf.m4 exponentd.m4 exponentf.m4 exponentl.m4 extensions.m4 extern-inline.m4 +flexmember.m4 float_h.m4 fpieee.m4 getopt.m4 -gnulib-cache.m4~ gnulib-common.m4 gnulib-comp.m4 -gnulib-comp.m4~ gnulib-tool.m4 include_next.m4 +inline.m4 isnand.m4 isnanf.m4 isnanl.m4 @@ -30,6 +31,7 @@ math_h.m4 mathfunc.m4 nocrash.m4 off_t.m4 +pid_t.m4 signbit.m4 ssize_t.m4 stddef_h.m4 @@ -37,5 +39,7 @@ strcase.m4 strings_h.m4 sys_types_h.m4 unistd_h.m4 +vararrays.m4 warn-on-use.m4 wchar_t.m4 +zzgnulib.m4 diff --git a/m4/gnulib-cache.m4 b/m4/gnulib-cache.m4 index 39ed0f6..5159cac 100644 --- a/m4/gnulib-cache.m4 +++ b/m4/gnulib-cache.m4 @@ -1,8 +1,8 @@ -# Copyright (C) 2002-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2022 Free Software Foundation, Inc. # # This file 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 +# the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This file is distributed in the hope that it will be useful, @@ -11,7 +11,7 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with this file. If not, see . +# along with this file. If not, see . # # As a special exception to the GNU General Public License, # this file may be distributed as part of a program that @@ -27,13 +27,30 @@ # Specification in the form of a command-line invocation: -# gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=. --makefile-name=gnulib.mk.in --conditional-dependencies --libtool --macro-prefix=gl --no-vc-files copysignf getopt-gnu ldexpf strcase +# gnulib-tool --import \ +# --lib=libgnu \ +# --source-base=lib \ +# --m4-base=m4 \ +# --doc-base=doc \ +# --tests-base=tests \ +# --aux-dir=. \ +# --makefile-name=gnulib.mk.in \ +# --conditional-dependencies \ +# --libtool \ +# --macro-prefix=gl \ +# --no-vc-files \ +# copysignf \ +# getopt-gnu \ +# inline \ +# ldexpf \ +# strcase # Specification in the form of a few gnulib-tool.m4 macro invocations: gl_LOCAL_DIR([]) gl_MODULES([ copysignf getopt-gnu + inline ldexpf strcase ]) 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/engine/engine.c b/src/engine/engine.c index 652614a..093a41f 100644 --- a/src/engine/engine.c +++ b/src/engine/engine.c @@ -1,21 +1,22 @@ /* - * upkg: tool for manipulating Unreal Tournament packages. - * Copyright © 2009-2012, 2020 Nick Bowler + * upkg: tool for manipulating Unreal Tournament packages. + * Copyright © 2009-2012, 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 #include #include diff --git a/src/engine/mesh.gob b/src/engine/mesh.gob index ed633a8..8e60828 100644 --- a/src/engine/mesh.gob +++ b/src/engine/mesh.gob @@ -1,28 +1,36 @@ %alltop{ /* - * upkg: tool for manipulating Unreal Tournament packages. - * Copyright © 2020 Nick Bowler + * upkg: tool for manipulating Unreal Tournament packages. + * Copyright © 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 . */ %} +%ctop{ +#include +%} + %{ -#include +#include #include #include #include "pack.h" + +#ifndef SIZE_MAX +# define SIZE_MAX ((size_t)-1) +#endif %} %h{ diff --git a/src/engine/music-dummymod.c b/src/engine/music-dummymod.c index c9094e7..ef1cff1 100644 --- a/src/engine/music-dummymod.c +++ b/src/engine/music-dummymod.c @@ -1,21 +1,22 @@ /* - * 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 . */ +#include #include #include #include diff --git a/src/engine/music-modplug.c b/src/engine/music-modplug.c index 449a480..ecd3062 100644 --- a/src/engine/music-modplug.c +++ b/src/engine/music-modplug.c @@ -1,21 +1,22 @@ /* - * upkg: tool for manipulating Unreal Tournament packages. - * Copyright © 2009-2011, 2019 Nick Bowler + * upkg: tool for manipulating Unreal Tournament packages. + * Copyright © 2009-2011, 2019, 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 #include #include #include diff --git a/src/engine/music.gob b/src/engine/music.gob index f0bde09..e0d13b6 100644 --- a/src/engine/music.gob +++ b/src/engine/music.gob @@ -1,23 +1,27 @@ %alltop{ /* - * 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 . */ %} +%ctop{ +#include +%} + %{ #include #include diff --git a/src/engine/palette.gob b/src/engine/palette.gob index ce57459..79712a6 100644 --- a/src/engine/palette.gob +++ b/src/engine/palette.gob @@ -1,23 +1,27 @@ %alltop{ /* - * upkg: tool for manipulating Unreal Tournament packages. - * Copyright © 2011, 2020 Nick Bowler + * upkg: tool for manipulating Unreal Tournament packages. + * Copyright © 2011, 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 . */ %} +%ctop{ +#include +%} + %{ #include #include diff --git a/src/engine/sound.gob b/src/engine/sound.gob index fd0a060..71c4a39 100644 --- a/src/engine/sound.gob +++ b/src/engine/sound.gob @@ -1,23 +1,27 @@ %alltop{ /* - * upkg: tool for manipulating Unreal Tournament packages. - * Copyright © 2011 Nick Bowler + * upkg: tool for manipulating Unreal Tournament packages. + * 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 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 . */ %} +%ctop{ +#include +%} + %{ #include #include diff --git a/src/engine/texture.gob b/src/engine/texture.gob index 630013e..cc6b271 100644 --- a/src/engine/texture.gob +++ b/src/engine/texture.gob @@ -1,23 +1,27 @@ %alltop{ /* - * upkg: tool for manipulating Unreal Tournament packages. - * Copyright © 2009-2012, 2020 Nick Bowler + * upkg: tool for manipulating Unreal Tournament packages. + * Copyright © 2009-2012, 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 . */ %} +%ctop{ +#include +%} + %{ #include #include @@ -36,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/libupkg.c b/src/libupkg.c index c87f668..60dcab0 100644 --- a/src/libupkg.c +++ b/src/libupkg.c @@ -1,21 +1,22 @@ /* - * 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 #include #include #include @@ -25,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 @@ -131,28 +142,23 @@ 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; + 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; } diff --git a/src/uobject/avl.c b/src/uobject/avl.c index b9a5c43..9ded83b 100644 --- a/src/uobject/avl.c +++ b/src/uobject/avl.c @@ -20,6 +20,7 @@ 02110-1301 USA. */ +#include #include #include #include diff --git a/src/uobject/exportable.c b/src/uobject/exportable.c index 541e698..6e75f25 100644 --- a/src/uobject/exportable.c +++ b/src/uobject/exportable.c @@ -1,21 +1,22 @@ /* - * 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 . */ +#include #include #include "exportable.h" diff --git a/src/uobject/loadable.c b/src/uobject/loadable.c index 1e41c46..d0fef58 100644 --- a/src/uobject/loadable.c +++ b/src/uobject/loadable.c @@ -1,21 +1,22 @@ /* - * 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 . */ +#include #include "loadable.h" GType u_object_loadable_get_type(void) diff --git a/src/uobject/module.c b/src/uobject/module.c index 057d1d0..1d41d07 100644 --- a/src/uobject/module.c +++ b/src/uobject/module.c @@ -1,21 +1,22 @@ /* - * 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 #include #include #include @@ -79,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; diff --git a/src/uobject/package.c b/src/uobject/package.c index 3b8091b..30a42cc 100644 --- a/src/uobject/package.c +++ b/src/uobject/package.c @@ -1,21 +1,22 @@ /* - * 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 . */ +#include #include #include #include @@ -158,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 3bada24..cf07735 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 @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -36,11 +35,14 @@ #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; unsigned long size, array_idx; - bool tag_msb; + gboolean tag_msb; enum { PROPERTY_END, 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) diff --git a/src/upkg.c b/src/upkg.c index 55d13f8..db9a747 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) @@ -170,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]); 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. 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 c072a07..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) @@ -52,7 +49,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; } @@ -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); diff --git a/tests/data/hatch2x2.pcx b/tests/data/hatch2x2.pcx new file mode 100644 index 0000000..b5bead6 Binary files /dev/null and b/tests/data/hatch2x2.pcx differ diff --git a/tests/data/test0.utx b/tests/data/test0.utx new file mode 100644 index 0000000..433c56c Binary files /dev/null and b/tests/data/test0.utx differ 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/export.at b/tests/export.at new file mode 100644 index 0000000..09f1397 --- /dev/null +++ b/tests/export.at @@ -0,0 +1,26 @@ +# 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_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/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 f5c913d..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 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..fbdb0c6 --- /dev/null +++ b/testsuite.at @@ -0,0 +1,22 @@ +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]) +m4_include([tests/export.at])