From e6c61b562b2342395694e26f6977cc7d48ab325b Mon Sep 17 00:00:00 2001 From: svdijk Date: Mon, 11 Aug 2014 19:59:52 +0000 Subject: [PATCH] Add a Bourne Shell PAK file writer (remove qpakman dependency). git-svn-id: svn+ssh://svn.code.sf.net/p/quakespasm/code/trunk@964 af15c1b1-3010-417e-b628-4374ebc0bcbd --- quakespasm/Misc/qs_pak/Makefile | 11 +++ quakespasm/Misc/qs_pak/mkpak.sh | 136 +++++++++++++++++++++++++++++++- quakespasm/Quake/quakespasm.pak | Bin 329876 -> 329875 bytes 3 files changed, 143 insertions(+), 4 deletions(-) create mode 100644 quakespasm/Misc/qs_pak/Makefile diff --git a/quakespasm/Misc/qs_pak/Makefile b/quakespasm/Misc/qs_pak/Makefile new file mode 100644 index 00000000..8ce1dbf6 --- /dev/null +++ b/quakespasm/Misc/qs_pak/Makefile @@ -0,0 +1,11 @@ +INPUT := gfx/conback.lmp \ + default.cfg + +OUTPUT := quakespasm.pak + +$(OUTPUT): $(INPUT) + ./mkpak.sh $(INPUT) > $(OUTPUT) + +.PHONY: clean +clean: + rm -f $(OUTPUT) diff --git a/quakespasm/Misc/qs_pak/mkpak.sh b/quakespasm/Misc/qs_pak/mkpak.sh index 07b42f6a..57cd6593 100644 --- a/quakespasm/Misc/qs_pak/mkpak.sh +++ b/quakespasm/Misc/qs_pak/mkpak.sh @@ -1,7 +1,135 @@ #!/bin/sh +# +# Copyright (c) 2014, Sander van Dijk +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -input_files="gfx/conback.lmp default.cfg" -output_pak="quakespasm.pak" +error() { + echo "$(basename "$0"): $*" >&2 + exit 1 +} -#can use qpakman to generate -qpakman $input_files -o $output_pak +assert_valid_stdout() { + if test -t 1 + then + error "Usage: $(basename "$0") [file ...] > output.pak" + fi +} + +assert_valid_file() { + if test ! -e "$1" + then + error "$1: No such file" + fi + if test ! -f "$1" + then + error "$f: Not a regular file" + fi + if test ! -r "$1" + then + error "$1: Permission denied" + fi + if test $(echo -n "$1" | wc -c) -gt 55 + then + error "$1: Name too long" + fi +} + +assert_valid_int32() { + if test $1 -lt -2147483648 -o $1 -gt 2147483647 + then + error "Too much data" + fi +} + +octal() { + if test $1 -gt 7 + then + octal $(expr $1 / 8) + fi + echo -n $(expr $1 % 8) +} + +byte() { + echo -en \\0$(octal $1) +} + +little_endian_uint32() { + byte $(expr $1 % 256) + byte $(expr $1 / 256 % 256) + byte $(expr $1 / 65536 % 256) + byte $(expr $1 / 16777216 % 256) +} + +little_endian_int32() { + if test $1 -lt 0 + then + little_endian_uint32 $(expr $1 + 4294967296) + else + little_endian_uint32 $1 + fi +} + +zero_padding() { + if test $1 -lt 1 + then + return + fi + byte 0 + zero_padding $(expr $1 - 1) +} + +header() { + echo -n PACK + little_endian_int32 $1 + little_endian_int32 $2 +} + +directory_entry() { + echo -n "$1" + zero_padding $(expr 56 - $(echo -n "$1" | wc -c)) + little_endian_int32 $2 + little_endian_int32 $3 +} + +assert_valid_stdout + +directory_offset=12 +directory_size=0 +for file in "$@" +do + assert_valid_file "$file" + file_offset=$directory_offset + assert_valid_int32 $file_offset + file_size=$(wc -c < "$file") + assert_valid_int32 $file_size + directory_offset=$(expr $directory_offset + $file_size) + assert_valid_int32 $directory_offset + directory_size=$(expr $directory_size + 64) + assert_valid_int32 $directory_size +done + +header $directory_offset $directory_size + +for file in "$@" +do + cat "$file" +done + +file_offset=12 +for file in "$@" +do + file_size=$(wc -c < "$file") + directory_entry "$file" $file_offset $file_size + file_offset=$(expr $file_offset + $file_size) +done diff --git a/quakespasm/Quake/quakespasm.pak b/quakespasm/Quake/quakespasm.pak index 7e9478b121d07b2e7cf122923e5288aa2920d6a4..118b308986aa005ddb85e8c0ea38b5ae6519734e 100644 GIT binary patch delta 36 rcmbO-QDpK&5!L`lXK&#~)>c-=R#v7~R_0b#maVL;d>qq7I9MA1veyW1 delta 38 tcmbO{QDn+Q5!L`lXK#^4)>c-=R#v7~R_0b#maVL;d>o7n(}g)$8vwyx2yXxY