From 09a6d8154184f89008dfc775368df6262a20db19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Sat, 4 Jun 2022 08:38:57 +0200 Subject: [PATCH 01/41] Ignore local gzip build --- .gitignore | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index c7172ea..e416a7d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,18 @@ orig *.IMG real-ld -objcopy -objdump *.o *.sw? coffsyrup 123 -ld binutils-* +objcopy +objdump +ld +gzip-* +gzip +gunzip +zcat drawtest *.a keymap/keymap From 65683f9a01f506b513cc72c425026508cc16d88f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Sat, 4 Jun 2022 08:39:13 +0200 Subject: [PATCH 02/41] Shell script portability improvements - support BSD tar(1) - support BSD install(1) - remove dependency on working directory from binutils and gzip build scripts - explicit dependency on GNU make (gmake(1)) --- binutils.sh | 48 ++++++++++++++++++++++++------------------------ extract.sh | 7 +++---- gzip.sh | 33 ++++++++++++++++----------------- 3 files changed, 43 insertions(+), 45 deletions(-) diff --git a/binutils.sh b/binutils.sh index d6b642d..4b35bd0 100755 --- a/binutils.sh +++ b/binutils.sh @@ -4,55 +4,55 @@ BINUTILS_DL="https://ftp.gnu.org/gnu/binutils" BINUTILS_XZ="binutils-2.38.tar.xz" BINUTILS_DIR="$(basename $BINUTILS_XZ .tar.xz)" BINUTILS_URL="$BINUTILS_DL/$BINUTILS_XZ" -ORIG_DIR="$(pwd)" +ORIGIN_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)" # Dont continue on error. set -e # Help text. if [ "$1" = '-h' ]; then - echo >&2 "Usage: $0 [clean]" - echo >&2 - echo >&2 'Specify "clean" to remove binutils, otherwise it will be downloaded and built.' - exit 1 + echo >&2 "Usage: $0 [clean]" + echo >&2 + echo >&2 'Specify "clean" to remove binutils, otherwise it will be downloaded and built.' + exit 1 fi # Optional cleanup if requested. if [ "$1" = 'clean' ]; then - rm -fv objcopy objdump ld "$BINUTILS_XZ" - rm -rfv "$BINUTILS_DIR" - exit + rm -fv "$ORIGIN_DIR/objcopy" "$ORIGIN_DIR/objdump" "$ORIGIN_DIR/ld" + rm -rfv "$BINUTILS_DIR" + rm -fv "$ORIGIN_DIR/$BINUTILS_XZ" + exit fi # Download binutils. if [ ! -f "$BINUTILS_XZ" ]; then - wget "$BINUTILS_URL" + wget "$BINUTILS_URL" fi # Extract binutils. if [ ! -d "$BINUTILS_DIR" ]; then - tar xf "$BINUTILS_XZ" + xzcat "$BINUTILS_XZ" | tar xf - fi # Compile binutils. if [ ! -x "$BINUTILS_DIR/binutils/objcopy" ]; then - cd "$BINUTILS_DIR" - ./configure --enable-targets=i386-pc-elf32 \ - --disable-gas \ - --disable-libctf \ - --disable-plugins \ - --disable-gprof \ - --enable-compressed-debug-sections=none - - make all-ld -j$(nproc) MAKEINFO=true + cd "$BINUTILS_DIR" && \ + ./configure --enable-targets=i386-pc-elf32 \ + --disable-gas \ + --disable-libctf \ + --disable-plugins \ + --disable-gprof \ + --enable-compressed-debug-sections=none && \ + gmake all-ld -j$(nproc) MAKEINFO=true + cd "$ORIGIN_DIR" fi # Copy compiled binaries to working directory. copy() { - test ! -x "$2" && cp -v "$1" "$2" + test ! -x "$2" && cp -v "$1" "$2" } -cd "$ORIG_DIR" -copy "$BINUTILS_DIR/binutils/objcopy" objcopy -copy "$BINUTILS_DIR/binutils/objdump" objdump -copy "$BINUTILS_DIR/ld/ld-new" ld +copy "$BINUTILS_DIR/binutils/objcopy" "$ORIGIN_DIR/objcopy" +copy "$BINUTILS_DIR/binutils/objdump" "$ORIGIN_DIR/objdump" +copy "$BINUTILS_DIR/ld/ld-new" "$ORIGIN_DIR/ld" diff --git a/extract.sh b/extract.sh index 0a419bd..4313f1d 100755 --- a/extract.sh +++ b/extract.sh @@ -50,7 +50,6 @@ echo '==> Reconstructing object file' if ! cat "${LOTUS}"/sysV386/lib/123.o.z_1 "${LOTUS}"/sysV386/lib/123.o.z_2 | zcat > "${ORIG}/123.o"; then echo >&2 'Failed to decompress object files.' - echo >&2 'If you see the message "code out of range", gzip is too old.' echo >&2 'You can try running ./gzip.sh to build a recent gzip that is known to work.' exit 1 @@ -63,10 +62,10 @@ echo '==> Uncompressing and copying remaining object files' cp "${LOTUS}"/sysV386/lib/*.o "${ORIG}/" echo '==> Copying the banner template over' -install -vDm644 "${ROOT}/usr/tmp/lotus_install/123/banner" "${LOTUS}/ri/USA-English/123ban.ri" +install -Dm 644 "${ROOT}/usr/tmp/lotus_install/123/banner" "${LOTUS}/ri/USA-English/123ban.ri" echo '==> Copying default config file' -install -vDm644 l123set.cf "${ETC}/l123set.cf" +install -Dm 644 "l123set.cf" "${ETC}/l123set.cf" echo '==> Copying man page' -install -vDm644 "${ROOT}/lotus/man/man1/123.1" "${ROOT}/man/man1/123.1" +install -Dm 644 "${ROOT}/lotus/man/man1/123.1" "${ROOT}/man/man1/123.1" diff --git a/gzip.sh b/gzip.sh index d066fe9..171b575 100755 --- a/gzip.sh +++ b/gzip.sh @@ -6,41 +6,41 @@ GZIP_DL="https://ftp.gnu.org/gnu/gzip" GZIP_XZ="gzip-1.12.tar.xz" GZIP_DIR="$(basename $GZIP_XZ .tar.xz)" GZIP_URL="$GZIP_DL/$GZIP_XZ" -ORIG_DIR="$(pwd)" +ORIGIN_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)" # Dont continue on error. set -e # Help text. if [ "$1" = '-h' ]; then - echo >&2 "Usage: $0 [clean]" - echo >&2 - echo >&2 'Specify "clean" to remove gzip, otherwise it will be downloaded and built.' - exit 1 + echo >&2 "Usage: $0 [clean]" + echo >&2 + echo >&2 'Specify "clean" to remove gzip, otherwise it will be downloaded and built.' + exit 1 fi # Optional cleanup if requested. if [ "$1" = 'clean' ]; then - rm -fv gzip gunzip zcat "$GZIP_XZ" - rm -rfv "$GZIP_DIR" - exit + rm -fv "$ORIGIN_DIR/gzip" "$ORIGIN_DIR/gunzip" "$ORIGIN_DIR/zcat" + rm -rfv "$GZIP_DIR" + rm -fv "$ORIGIN_DIR/$GZIP_XZ" + exit fi # Download gzip. if [ ! -f "$GZIP_XZ" ]; then - wget "$GZIP_URL" + wget "$GZIP_URL" fi # Extract gzip. if [ ! -d "$GZIP_DIR" ]; then - tar xf "$GZIP_XZ" + xzcat "$GZIP_XZ" | tar xf - fi # Compile gzip. if [ ! -x "$GZIP_DIR/gzip" ]; then - cd "$GZIP_DIR" - ./configure - make -j$(nproc) + cd "$GZIP_DIR" && ./configure && gmake -j$(nproc) + cd "$ORIGIN_DIR" fi # Copy compiled binaries to working directory. @@ -48,7 +48,6 @@ copy() { test ! -x "$2" && cp -v "$1" "$2" } -cd "$ORIG_DIR" -copy "$GZIP_DIR/gzip" gzip -copy "$GZIP_DIR/gunzip" gunzip -copy "$GZIP_DIR/zcat" zcat +copy "$GZIP_DIR/gzip" "$ORIGIN_DIR/gzip" +copy "$GZIP_DIR/gunzip" "$ORIGIN_DIR/gunzip" +copy "$GZIP_DIR/zcat" "$ORIGIN_DIR/zcat" From 731619f6a8f7b4b0a855a19fb97baa63e75d1369 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Sat, 4 Jun 2022 11:04:13 +0200 Subject: [PATCH 03/41] Portable detection of ncurses linker lib flags --- ncurses-config.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100755 ncurses-config.sh diff --git a/ncurses-config.sh b/ncurses-config.sh new file mode 100755 index 0000000..6780c11 --- /dev/null +++ b/ncurses-config.sh @@ -0,0 +1,11 @@ +#!/bin/sh +nclibs="-lncurses" +if command -v ncurses6-config > /dev/null; then + nclibs="$(ncurses6-config --libs-only-l)" +elif command -v pkg-config > /dev/null; then + pkgcfglibs="$(pkg-config --libs ncurses)" + if [ -n "$pkgcfglibs" ]; then + nclibs="$pkgcfglibs" + fi +fi +echo "$nclibs" From 8892e2ad62f57382931518d9c5a57be23e895109 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Sat, 4 Jun 2022 11:04:40 +0200 Subject: [PATCH 04/41] More portable Makefile --- Makefile | 22 +++++++++------------- check-binutils-coff.sh | 9 +++++++++ 2 files changed, 18 insertions(+), 13 deletions(-) create mode 100755 check-binutils-coff.sh diff --git a/Makefile b/Makefile index 7607198..7ebe842 100644 --- a/Makefile +++ b/Makefile @@ -6,37 +6,33 @@ CFLAGS = -m32 -ggdb3 -O0 -fno-stack-protector CPPFLAGS = -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64 -D_GNU_SOURCE -I ttydraw ASFLAGS = --32 LDFLAGS = $(CFLAGS) -lc -B. -Wl,-b,$(BFD_OUT_TARGET) -no-pie -LDLIBS = -lncurses -ltinfo -lm -PATH := .:$(PATH) +LDLIBS = $(shell ./ncurses-config.sh) -lm +PATH := $(shell pwd):$(PATH) KEYMAPS = xterm rxvt-unicode-256color xterm-256color $(TERM) prefix = /usr/local -define BFD_TARGET_ERROR -Your version of binutils was compiled without coff-i386 target support. -You can try running ./binutils.sh to build a version that does support it. -endef - -export BFD_TARGET_ERROR - .PHONY: clean check distclean install uninstall all: check 123 keymaps @size 123 check: - @objdump --info | egrep -q '^coff-i386$$' || (echo "$$BFD_TARGET_ERROR"; false) + ./check-binutils-coff.sh + +coffsyrup: + $(CC) -o $@ coffsyrup.c orig/123.o: @echo You need to run the extract.sh script to get the 1-2-3 files. @false -123.o: orig/123.o $(OBJCOPY_FILES) | coffsyrup - objcopy -I $(BFD_INP_TARGET) -O $(BFD_OUT_TARGET) $(OBJCOPY_FLAGS) $< $@ +123.o: coffsyrup orig/123.o $(OBJCOPY_FILES) + objcopy -I $(BFD_INP_TARGET) -O $(BFD_OUT_TARGET) $(OBJCOPY_FLAGS) orig/123.o $@ coffsyrup $@ $(@:.o=.tmp.o) $$(cat undefine.lst) mv $(@:.o=.tmp.o) $@ dl_init.o: orig/dl_init.o - objcopy -I $(BFD_INP_TARGET) -O $(BFD_OUT_TARGET) $(OBJCOPY_FLAGS) $< $@ + objcopy -I $(BFD_INP_TARGET) -O $(BFD_OUT_TARGET) $(OBJCOPY_FLAGS) orig/dl_init.o $@ ttydraw/ttydraw.a: $(MAKE) -C ttydraw diff --git a/check-binutils-coff.sh b/check-binutils-coff.sh new file mode 100755 index 0000000..7bd6bed --- /dev/null +++ b/check-binutils-coff.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +BASE="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)" +PATH="${BASE}:$PATH" + +BFD_TARGET_ERROR="Your version of binutils was compiled without coff-i386 target support. +You can try running ./binutils.sh to build a version that does support it." + +objdump --info | grep -q '^coff-i386$' || (echo "$BFD_TARGET_ERROR"; false) From dbd71a80c4d461d5f302a22386b684e9682b68a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Sat, 4 Jun 2022 11:07:30 +0200 Subject: [PATCH 05/41] $(RM) might not be set --- Makefile | 12 ++++++------ keymap/Makefile | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 7ebe842..7854a3c 100644 --- a/Makefile +++ b/Makefile @@ -58,9 +58,9 @@ $(sort $(KEYMAPS)): keymap/keymap keymaps: $(KEYMAPS) clean: - $(RM) *.o coffsyrup 123 - $(RM) vgcore.* core.* core - $(RM) -r bin share/lotus/keymaps + rm -f *.o coffsyrup 123 + rm -f vgcore.* core.* core + rm -rf bin share/lotus/keymaps $(MAKE) -C ttydraw clean $(MAKE) -C atfuncs clean $(MAKE) -C keymap clean @@ -86,6 +86,6 @@ install: all find "share/lotus/123.v10/smpfiles" -type f -exec install -Dm 644 {} "$(prefix)/{}" \; uninstall: - $(RM) "$(prefix)/bin/123" - $(RM) "$(prefix)/share/man/man1/123.1" - $(RM) -r "$(prefix)/share/lotus" + rm -f "$(prefix)/bin/123" + rm -f "$(prefix)/share/man/man1/123.1" + rm -rf "$(prefix)/share/lotus" diff --git a/keymap/Makefile b/keymap/Makefile index 737d14a..abc07be 100644 --- a/keymap/Makefile +++ b/keymap/Makefile @@ -5,4 +5,4 @@ CFLAGS = -ggdb3 -O0 all: keymap clean: - $(RM) *.o keymap + rm -f *.o keymap From dc940210e93040f9e8ea9cf6619d9619297ffb94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Sat, 4 Jun 2022 11:15:13 +0200 Subject: [PATCH 06/41] Remove GNU-specific $(sort) and | --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 7854a3c..6f3a4df 100644 --- a/Makefile +++ b/Makefile @@ -40,7 +40,7 @@ ttydraw/ttydraw.a: atfuncs/atfuncs.a: $(MAKE) -C atfuncs -bin/123: 123.o dl_init.o main.o wrappers.o patch.o filemap.o graphics.o draw.o | ttydraw/ttydraw.a atfuncs/atfuncs.a forceplt.o +bin/123: 123.o dl_init.o main.o wrappers.o patch.o filemap.o graphics.o draw.o ttydraw/ttydraw.a atfuncs/atfuncs.a forceplt.o @mkdir -p $(@D) $(CC) forceplt.o $(CFLAGS) $(LDFLAGS) $^ -Wl,--whole-archive,ttydraw/ttydraw.a,atfuncs/atfuncs.a,--no-whole-archive -o $@ $(LDLIBS) @@ -51,7 +51,7 @@ keymap/keymap: $(MAKE) -C keymap # This generates the keymaps in a seperate directory based on the first letter. -$(sort $(KEYMAPS)): keymap/keymap +$(KEYMAPS): keymap/keymap mkdir -p share/lotus/keymaps/$(shell printf "%c" $@) keymap/keymap $@ > share/lotus/keymaps/$(shell printf "%c" $@)/$@ From 0db1e6f6f1ce6188d257e1c62c6075cff72fddf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Sat, 4 Jun 2022 12:12:55 +0200 Subject: [PATCH 07/41] Helper shell script to install keymaps --- install-keymap.sh | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100755 install-keymap.sh diff --git a/install-keymap.sh b/install-keymap.sh new file mode 100755 index 0000000..4624a9c --- /dev/null +++ b/install-keymap.sh @@ -0,0 +1,9 @@ +#!/bin/sh +if [ "$#" -ne 1 ]; then + echo >&2 "Usage: $0 keymap" + exit 1 +fi +KEYMAPS_DIR="share/lotus/keymaps" +c="$(echo "$1" | cut -c1)" +install -dm 755 "$KEYMAPS_DIR/$c" +keymap/keymap "$1" > "$KEYMAPS_DIR/$c/$1" From 98e7eac1713038deb5cf20a47bbe27a5a2d1d358 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Sat, 4 Jun 2022 12:13:41 +0200 Subject: [PATCH 08/41] More Makefile compatibility --- Makefile | 23 ++++++++++++++--------- atfuncs/Makefile | 2 +- keymap/Makefile | 2 +- ttydraw/Makefile | 15 ++++++++------- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index 6f3a4df..66a2cac 100644 --- a/Makefile +++ b/Makefile @@ -6,9 +6,12 @@ CFLAGS = -m32 -ggdb3 -O0 -fno-stack-protector CPPFLAGS = -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64 -D_GNU_SOURCE -I ttydraw ASFLAGS = --32 LDFLAGS = $(CFLAGS) -lc -B. -Wl,-b,$(BFD_OUT_TARGET) -no-pie -LDLIBS = $(shell ./ncurses-config.sh) -lm -PATH := $(shell pwd):$(PATH) -KEYMAPS = xterm rxvt-unicode-256color xterm-256color $(TERM) +NCURSES_LIBS != ./ncurses-config.sh +LDLIBS = $(NCURSES_LIBS) -lm +OBJECT_FILES = 123.o dl_init.o main.o wrappers.o patch.o filemap.o graphics.o draw.o ttydraw/ttydraw.a atfuncs/atfuncs.a forceplt.o +workdir != pwd +PATH := $(workdir):$(PATH) +KEYMAPS != echo xterm rxvt-unicode-256color xterm-256color $(TERM) | tr ' ' '\n' | sort -u prefix = /usr/local .PHONY: clean check distclean install uninstall @@ -28,32 +31,34 @@ orig/123.o: 123.o: coffsyrup orig/123.o $(OBJCOPY_FILES) objcopy -I $(BFD_INP_TARGET) -O $(BFD_OUT_TARGET) $(OBJCOPY_FLAGS) orig/123.o $@ - coffsyrup $@ $(@:.o=.tmp.o) $$(cat undefine.lst) + ./coffsyrup $@ $(@:.o=.tmp.o) $$(cat undefine.lst) mv $(@:.o=.tmp.o) $@ dl_init.o: orig/dl_init.o objcopy -I $(BFD_INP_TARGET) -O $(BFD_OUT_TARGET) $(OBJCOPY_FLAGS) orig/dl_init.o $@ +forceplt.o: forceplt.s + as --32 -o $@ forceplt.s + ttydraw/ttydraw.a: $(MAKE) -C ttydraw atfuncs/atfuncs.a: $(MAKE) -C atfuncs -bin/123: 123.o dl_init.o main.o wrappers.o patch.o filemap.o graphics.o draw.o ttydraw/ttydraw.a atfuncs/atfuncs.a forceplt.o +bin/123: $(OBJECT_FILES) @mkdir -p $(@D) - $(CC) forceplt.o $(CFLAGS) $(LDFLAGS) $^ -Wl,--whole-archive,ttydraw/ttydraw.a,atfuncs/atfuncs.a,--no-whole-archive -o $@ $(LDLIBS) + $(CC) forceplt.o $(CFLAGS) $(LDFLAGS) $(OBJECT_FILES) -Wl,--whole-archive,ttydraw/ttydraw.a,atfuncs/atfuncs.a,--no-whole-archive -o $@ $(LDLIBS) 123: bin/123 - @ln -fs $^ $@ + @ln -fs bin/123 $@ keymap/keymap: $(MAKE) -C keymap # This generates the keymaps in a seperate directory based on the first letter. $(KEYMAPS): keymap/keymap - mkdir -p share/lotus/keymaps/$(shell printf "%c" $@) - keymap/keymap $@ > share/lotus/keymaps/$(shell printf "%c" $@)/$@ + ./install-keymap.sh $@ keymaps: $(KEYMAPS) diff --git a/atfuncs/Makefile b/atfuncs/Makefile index 3d7560c..1d6b60c 100644 --- a/atfuncs/Makefile +++ b/atfuncs/Makefile @@ -8,7 +8,7 @@ LDLIBS= all: atfuncs.a atfuncs.a: date.o - $(AR) r $@ $^ + $(AR) r $@ date.o clean: rm -f *.a *.o diff --git a/keymap/Makefile b/keymap/Makefile index abc07be..e7c8e42 100644 --- a/keymap/Makefile +++ b/keymap/Makefile @@ -1,4 +1,4 @@ -LDLIBS = -lncurses -ltinfo +LDLIBS != ../ncurses-config.sh CFLAGS = -ggdb3 -O0 .PHONY: clean diff --git a/ttydraw/Makefile b/ttydraw/Makefile index 9a7d2cd..6de6d4e 100644 --- a/ttydraw/Makefile +++ b/ttydraw/Makefile @@ -1,17 +1,18 @@ -CPPFLAGS=-I. -CFLAGS=-m32 -ggdb3 -O0 -fno-stack-protector -fvisibility=hidden -LDFLAGS=$(CFLAGS) -LDLIBS=-lncurses -ltinfo +CPPFLAGS = -I. +CFLAGS = -m32 -ggdb3 -O0 -fno-stack-protector -fvisibility=hidden +LDFLAGS = $(CFLAGS) +LDLIBS != ../ncurses-config.sh +OBJECT_FILES = attr.o box.o canvas.o charset.o conic.o frame.o line.o string.o transfrm.o triangle.o .PHONY: clean all: ttydraw.a drawtest -ttydraw.a: attr.o box.o canvas.o charset.o conic.o frame.o line.o string.o transfrm.o triangle.o - $(AR) r $@ $^ +ttydraw.a: $(OBJECT_FILES) + $(AR) r $@ $(OBJECT_FILES) drawtest: drawtest.o ttydraw.a - + $(CC) $(CFLAGS) $(LDLIBS) -o $@ drawtest.o ttydraw.a clean: rm -f *.a *.o drawtest From d85e3980aedf65cbe3487f8af38815db4cec269e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Sat, 4 Jun 2022 12:15:43 +0200 Subject: [PATCH 09/41] Use more portable strndup instad of strndupa --- coffsyrup.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/coffsyrup.c b/coffsyrup.c index 0bf5be3..aaff915 100644 --- a/coffsyrup.c +++ b/coffsyrup.c @@ -124,7 +124,8 @@ int main(int argc, char **argv) // Read in each symbol. for (int i = 0; i < hdr.f_nsyms; i++) { - const char *symname; + char *symname; + int symnamedup = 0; if (fread(&symtab[i], sizeof *symtab, 1, infile) != 1) { err(EXIT_FAILURE, "Failed to read in a symbol."); @@ -150,9 +151,12 @@ int main(int argc, char **argv) } // Figure out the symbol name. - symname = symtab[i].e.e.e_zeroes - ? strndupa(symtab[i].e.e_name, sizeof symtab[i].e.e_name) - : (strtab + symtab[i].e.e.e_offset); + if (symtab[i].e.e.e_zeroes) { + symname = strndup(symtab[i].e.e_name, sizeof symtab[i].e.e_name); + symnamedup = 1; + } else { + symname = strtab + symtab[i].e.e.e_offset; + } // See if we are supposed to be adjusting this symbol. for (int check = 3; check < argc; check++) { @@ -164,6 +168,9 @@ int main(int argc, char **argv) } } + // free symname if it was duplicated on heap + if (symnamedup) free(symname); + // XXX: Note the ++i, this must be last in the loop!!! if (symtab[i].e_numaux) { // Read in any auxiliary entry. @@ -219,7 +226,8 @@ int main(int argc, char **argv) relocs[i] = calloc(scn[i].s_nreloc, sizeof(RELOC)); for (int r = 0; r < scn[i].s_nreloc; r++) { - const char *symname; + char *symname; + int symnamedup = 0; RELOC *rel = &relocs[i][r]; if (fread(rel, sizeof *rel, 1, infile) != 1) { @@ -243,9 +251,12 @@ int main(int argc, char **argv) } // Figure out the symbol name. - symname = symtab[rel->r_symndx].e.e.e_zeroes - ? strndupa(symtab[rel->r_symndx].e.e_name, sizeof symtab[rel->r_symndx].e.e_name) - : (strtab + symtab[rel->r_symndx].e.e.e_offset); + if (symtab[rel->r_symndx].e.e.e_zeroes) { + symname = strndup(symtab[rel->r_symndx].e.e_name, sizeof symtab[rel->r_symndx].e.e_name); + symnamedup = 1; + } else { + symname = (strtab + symtab[rel->r_symndx].e.e.e_offset); + } // See if we are supposed to be adjusting this symbol. for (int check = 3; check < argc; check++) { @@ -274,6 +285,9 @@ int main(int argc, char **argv) } } } + + // free symname if it was duplicated on heap + if (symnamedup) free(symname); } // Seek to the line numbers From 91a047f48ba24e353d92eee97ad33de788788424 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Sat, 4 Jun 2022 12:16:06 +0200 Subject: [PATCH 10/41] Use malloc instead of GNU-specific alloca --- main.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index eca3a68..c1486af 100644 --- a/main.c +++ b/main.c @@ -5,7 +5,6 @@ #include #include #include -#include #include #include "lotdefs.h" @@ -100,7 +99,7 @@ int main(int argc, char **argv, char **envp) lotargc += 2; // Allocate the argument vector we're going to pass through to lotus. - lotargv = alloca(lotargc * sizeof(*argv)); + lotargv = malloc(lotargc * sizeof(*argv)); // Now reset and copy the options over. lotargc = 0; @@ -128,7 +127,7 @@ int main(int argc, char **argv, char **envp) // If we reach here, we want to pass this option through to // Lotus verbatim. - lotargv[lotargc] = alloca(3); + lotargv[lotargc] = malloc(3); lotargv[lotargc][0] = '-'; lotargv[lotargc][1] = opt; lotargv[lotargc][2] = 0; From 3ce58b826419456dc8fc69018e43274d95b76a44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Sun, 5 Jun 2022 09:09:43 +0200 Subject: [PATCH 11/41] Remove non-portable sighandler_t --- wrappers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wrappers.c b/wrappers.c index 2c54688..3015b9b 100644 --- a/wrappers.c +++ b/wrappers.c @@ -416,7 +416,7 @@ struct unixdirent * __unix_readdir(DIR *dirp) return NULL; } -sighandler_t __unix_signal(int signum, sighandler_t handler) +void (* __unix_signal(int signum, void (*handler)))(int) { static int unix_sig_table[] = { [7] = -1, // SIGEMT From 8a040b3d276487f02d6537cec4e9d4d96cbdb349 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Sun, 5 Jun 2022 09:14:11 +0200 Subject: [PATCH 12/41] Better ncurses linker flags detection --- ncurses-config.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ncurses-config.sh b/ncurses-config.sh index 6780c11..899fdd5 100755 --- a/ncurses-config.sh +++ b/ncurses-config.sh @@ -1,10 +1,10 @@ #!/bin/sh nclibs="-lncurses" if command -v ncurses6-config > /dev/null; then - nclibs="$(ncurses6-config --libs-only-l)" + nclibs="$(ncurses6-config --libs)" elif command -v pkg-config > /dev/null; then - pkgcfglibs="$(pkg-config --libs ncurses)" - if [ -n "$pkgcfglibs" ]; then + pkgcfglibs="$(pkg-config --libs ncurses 2>/dev/null)" + if [ "$?" -eq 0 -a -n "$pkgcfglibs" ]; then nclibs="$pkgcfglibs" fi fi From 296be705f8d57d9d2a71e50b5a886bb0439474fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Sun, 5 Jun 2022 09:15:30 +0200 Subject: [PATCH 13/41] Use malloc instead of alloca --- patch.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/patch.c b/patch.c index 4462611..eb6a2d2 100644 --- a/patch.c +++ b/patch.c @@ -1,6 +1,5 @@ #include #include -#include #include #include "lotdefs.h" @@ -39,7 +38,7 @@ int display_column_labels() uint8_t *buf; // Is this right? - buf = alloca(COLS); + buf = malloc(COLS); // I have no idea what this structure is. if (dspinfo[11]) { From be48ef6a2198e9308469a31f89698c56d62e0082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Sun, 5 Jun 2022 10:03:32 +0200 Subject: [PATCH 14/41] More portable install(1) invocation --- extract.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/extract.sh b/extract.sh index 4313f1d..003041c 100755 --- a/extract.sh +++ b/extract.sh @@ -13,7 +13,7 @@ CPIO="$(command -v cpio)" TAR="$(command -v tar)" if [ "$1" = 'clean' ]; then - rm -rfv "${ROOT}" "${ORIG}" "${ETC}" + rm -rf "${ROOT}" "${ORIG}" "${ETC}" exit fi @@ -62,10 +62,12 @@ echo '==> Uncompressing and copying remaining object files' cp "${LOTUS}"/sysV386/lib/*.o "${ORIG}/" echo '==> Copying the banner template over' -install -Dm 644 "${ROOT}/usr/tmp/lotus_install/123/banner" "${LOTUS}/ri/USA-English/123ban.ri" +install -m 644 "${ROOT}/usr/tmp/lotus_install/123/banner" "${LOTUS}/ri/USA-English/123ban.ri" echo '==> Copying default config file' -install -Dm 644 "l123set.cf" "${ETC}/l123set.cf" +install -m 755 -d "${ETC}" +install -m 644 "l123set.cf" "${ETC}/l123set.cf" echo '==> Copying man page' -install -Dm 644 "${ROOT}/lotus/man/man1/123.1" "${ROOT}/man/man1/123.1" +install -m 755 -d "${ROOT}/man/man1" +install -m 644 "${ROOT}/lotus/man/man1/123.1" "${ROOT}/man/man1/123.1" From f5e373d0454704d1e76713aaee878da3960d6f53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Sun, 5 Jun 2022 10:10:36 +0200 Subject: [PATCH 15/41] More portable install(1) invocation --- Makefile | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 66a2cac..efe139f 100644 --- a/Makefile +++ b/Makefile @@ -76,18 +76,31 @@ distclean: clean ./extract.sh clean install: all - install -Dm 755 "bin/123" "$(prefix)/bin/123" - install -Dm 644 "share/man/man1/123.1" "$(prefix)/share/man/man1/123.1" - install -Dm 644 "share/lotus/etc/l123set.cf" "$(prefix)/share/lotus/etc/l123set.cf" - find "share/lotus/keymaps" -type f -exec install -Dm 644 {} "$(prefix)/{}" \; - install -Dm 644 "share/lotus/123.v10/sysV386/lotus.bcf" "$(prefix)/share/lotus/123.v10/sysV386/lotus.bcf" - install -Dm 644 "share/lotus/123.v10/sysV386/lib/wyse50-lts123" "$(prefix)/share/lotus/123.v10/sysV386/lib/wyse50-lts123" - find "share/lotus/123.v10/cbd" -type f -exec install -Dm 644 {} "$(prefix)/{}" \; - find "share/lotus/123.v10/fonts" -type f -exec install -Dm 644 {} "$(prefix)/{}" \; + install -m 755 -d "$(prefix)/bin" + install -m 755 "bin/123" "$(prefix)/bin/123" + install -m 755 -d "$(prefix)/share/man/man1" + install -m 644 "share/man/man1/123.1" "$(prefix)/share/man/man1/123.1" + install -m 755 -d "$(prefix)/share/lotus/etc" + install -m 644 "share/lotus/etc/l123set.cf" "$(prefix)/share/lotus/etc/l123set.cf" + find "share/lotus/keymaps" -type d -exec install -m 755 -d "$(prefix)/{}" \; + find "share/lotus/keymaps" -type f -exec install -m 644 {} "$(prefix)/{}" \; + install -m 755 -d "$(prefix)/share/lotus/123.v10/sysV386" + install -m 644 "share/lotus/123.v10/sysV386/lotus.bcf" "$(prefix)/share/lotus/123.v10/sysV386/lotus.bcf" + install -m 755 -d "$(prefix)/share/lotus/123.v10/sysV386/lib" + install -m 644 "share/lotus/123.v10/sysV386/lib/wyse50-lts123" "$(prefix)/share/lotus/123.v10/sysV386/lib/wyse50-lts123" + find "share/lotus/123.v10/cbd" -type d -exec install -m 755 -d "$(prefix)/{}" \; + find "share/lotus/123.v10/cbd" -type f -exec install -m 644 {} "$(prefix)/{}" \; + find "share/lotus/123.v10/fonts" -type d -exec install -m 755 -d "$(prefix)/{}" \; + find "share/lotus/123.v10/fonts" -type f -exec install -m 644 {} "$(prefix)/{}" \; + find "share/lotus/123.v10/hlp" -type d -exec install -m 755 -d "$(prefix)/{}" \; find "share/lotus/123.v10/hlp" -type f -exec install -Dm 644 {} "$(prefix)/{}" \; - find "share/lotus/123.v10/keymaps" -type f -exec install -Dm 644 {} "$(prefix)/{}" \; + find "share/lotus/123.v10/keymaps" -type d -exec install -m 755 -d "$(prefix)/{}" \; + find "share/lotus/123.v10/keymaps" -type f -exec install -m 644 {} "$(prefix)/{}" \; + find "share/lotus/123.v10/pbd" -type d -exec install -m 755 -d "$(prefix)/{}" \; find "share/lotus/123.v10/pbd" -type f -exec install -Dm 644 {} "$(prefix)/{}" \; + find "share/lotus/123.v10/ri" -type d -exec install -m 755 -d "$(prefix)/{}" \; find "share/lotus/123.v10/ri" -type f -exec install -Dm 644 {} "$(prefix)/{}" \; + find "share/lotus/123.v10/smpfiles" -type d -exec install -m 755 -d "$(prefix)/{}" \; find "share/lotus/123.v10/smpfiles" -type f -exec install -Dm 644 {} "$(prefix)/{}" \; uninstall: From a075613bf686766685a729b3c421c81da02f77ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Sun, 5 Jun 2022 10:10:52 +0200 Subject: [PATCH 16/41] Fix missing include --- patch.c | 1 + 1 file changed, 1 insertion(+) diff --git a/patch.c b/patch.c index eb6a2d2..49a6a52 100644 --- a/patch.c +++ b/patch.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "lotdefs.h" #include "lottypes.h" From d8914be6df1d50d67ab42586ae4cdf63ade8496a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Sun, 5 Jun 2022 10:19:22 +0200 Subject: [PATCH 17/41] Consistent install invocation --- install-keymap.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install-keymap.sh b/install-keymap.sh index 4624a9c..38c741d 100755 --- a/install-keymap.sh +++ b/install-keymap.sh @@ -5,5 +5,5 @@ if [ "$#" -ne 1 ]; then fi KEYMAPS_DIR="share/lotus/keymaps" c="$(echo "$1" | cut -c1)" -install -dm 755 "$KEYMAPS_DIR/$c" +install -m 755 -d "$KEYMAPS_DIR/$c" keymap/keymap "$1" > "$KEYMAPS_DIR/$c/$1" From 8683a846f27006c3f60c1ad93e9dba6e1b576a55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Tue, 7 Jun 2022 11:22:00 +0200 Subject: [PATCH 18/41] Include malloc through stdlib.h --- patch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patch.c b/patch.c index 49a6a52..fdbd8aa 100644 --- a/patch.c +++ b/patch.c @@ -1,7 +1,7 @@ +#include #include #include #include -#include #include "lotdefs.h" #include "lottypes.h" From 2ade82f94fab0019ce45410ca0f62fcbf195ea5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Wed, 8 Jun 2022 12:08:16 +0200 Subject: [PATCH 19/41] Build GNU as with binutils --- binutils.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/binutils.sh b/binutils.sh index 4b35bd0..c1ea037 100755 --- a/binutils.sh +++ b/binutils.sh @@ -19,7 +19,7 @@ fi # Optional cleanup if requested. if [ "$1" = 'clean' ]; then - rm -fv "$ORIGIN_DIR/objcopy" "$ORIGIN_DIR/objdump" "$ORIGIN_DIR/ld" + rm -fv "$ORIGIN_DIR/objcopy" "$ORIGIN_DIR/objdump" "$ORIGIN_DIR/ld" "$ORIGIN_DIR/as" rm -rfv "$BINUTILS_DIR" rm -fv "$ORIGIN_DIR/$BINUTILS_XZ" exit @@ -39,12 +39,11 @@ fi if [ ! -x "$BINUTILS_DIR/binutils/objcopy" ]; then cd "$BINUTILS_DIR" && \ ./configure --enable-targets=i386-pc-elf32 \ - --disable-gas \ --disable-libctf \ --disable-plugins \ --disable-gprof \ --enable-compressed-debug-sections=none && \ - gmake all-ld -j$(nproc) MAKEINFO=true + gmake all-ld all-gas MAKEINFO=true cd "$ORIGIN_DIR" fi @@ -56,3 +55,4 @@ copy() { copy "$BINUTILS_DIR/binutils/objcopy" "$ORIGIN_DIR/objcopy" copy "$BINUTILS_DIR/binutils/objdump" "$ORIGIN_DIR/objdump" copy "$BINUTILS_DIR/ld/ld-new" "$ORIGIN_DIR/ld" +copy "$BINUTILS_DIR/gas/as-new" "$ORIGIN_DIR/as" From da75ccedac8523beef6519eb3a5c4498fb1470b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Wed, 8 Jun 2022 12:08:35 +0200 Subject: [PATCH 20/41] Drop non-portable nproc --- gzip.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gzip.sh b/gzip.sh index 171b575..a68e4ed 100755 --- a/gzip.sh +++ b/gzip.sh @@ -39,7 +39,7 @@ fi # Compile gzip. if [ ! -x "$GZIP_DIR/gzip" ]; then - cd "$GZIP_DIR" && ./configure && gmake -j$(nproc) + cd "$GZIP_DIR" && ./configure && gmake cd "$ORIGIN_DIR" fi From e62f1427d7b8aa258c76ebb025d090105cfddcbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Wed, 8 Jun 2022 12:09:50 +0200 Subject: [PATCH 21/41] Add locally built as to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e416a7d..02f577c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ real-ld coffsyrup 123 binutils-* +as objcopy objdump ld From 5d88b628429b59a8435ee92299d7160ffeaa2aa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Wed, 8 Jun 2022 12:12:06 +0200 Subject: [PATCH 22/41] Port to FreeBSD --- Makefile | 25 +++-- atfuncs/date.c | 6 +- draw.c | 2 +- filemap.c | 10 +- forceplt.s | 2 - graphics.c | 2 +- localize.freebsd | 66 ++++++++++++ undefine.freebsd | 259 +++++++++++++++++++++++++++++++++++++++++++++++ wrappers.c | 9 +- 9 files changed, 360 insertions(+), 21 deletions(-) create mode 100644 localize.freebsd create mode 100644 undefine.freebsd diff --git a/Makefile b/Makefile index efe139f..bc95d70 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,23 @@ +platform != uname -s +undefine != if [ "$(platform)" = "FreeBSD" ]; then echo undefine.freebsd; else echo undefine.lst; fi +redefine = redefine.lst +localize != if [ "$(platform)" = "FreeBSD" ]; then echo localize.freebsd; else echo localize.lst; fi +globalize = globalize.lst +OBJCOPY_FLAGS = --wildcard --localize-symbols=$(localize) --globalize-symbols=$(globalize) --redefine-syms=$(redefine) +OBJCOPY_FILES = $(localize) $(globalize) $(redefine) $(undefine) +OBJCOPY != if [ -x ./objcopy ]; then echo ./objcopy; else echo objcopy; fi +AS != if [ -x ./as ]; then echo ./as; else echo as; fi BFD_INP_TARGET = coff-i386 BFD_OUT_TARGET = coff-i386 -OBJCOPY_FLAGS = --wildcard --localize-symbols=localize.lst --globalize-symbols=globalize.lst --redefine-syms=redefine.lst -OBJCOPY_FILES = localize.lst globalize.lst redefine.lst undefine.lst CFLAGS = -m32 -ggdb3 -O0 -fno-stack-protector CPPFLAGS = -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64 -D_GNU_SOURCE -I ttydraw ASFLAGS = --32 -LDFLAGS = $(CFLAGS) -lc -B. -Wl,-b,$(BFD_OUT_TARGET) -no-pie +LINUX_LDFLAGS = -lc +GENERIC_LDFLAGS = $(CFLAGS) -B. -Wl,-b,$(BFD_OUT_TARGET) -no-pie +LDFLAGS != if [ "$(platform)" = "Linux" ]; then echo $(LINUX_LDFLAGS) $(GENERIC_LDFLAGS); else echo $(GENERIC_LDFLAGS); fi NCURSES_LIBS != ./ncurses-config.sh LDLIBS = $(NCURSES_LIBS) -lm OBJECT_FILES = 123.o dl_init.o main.o wrappers.o patch.o filemap.o graphics.o draw.o ttydraw/ttydraw.a atfuncs/atfuncs.a forceplt.o -workdir != pwd -PATH := $(workdir):$(PATH) KEYMAPS != echo xterm rxvt-unicode-256color xterm-256color $(TERM) | tr ' ' '\n' | sort -u prefix = /usr/local @@ -30,15 +37,15 @@ orig/123.o: @false 123.o: coffsyrup orig/123.o $(OBJCOPY_FILES) - objcopy -I $(BFD_INP_TARGET) -O $(BFD_OUT_TARGET) $(OBJCOPY_FLAGS) orig/123.o $@ - ./coffsyrup $@ $(@:.o=.tmp.o) $$(cat undefine.lst) + $(OBJCOPY) -I $(BFD_INP_TARGET) -O $(BFD_OUT_TARGET) $(OBJCOPY_FLAGS) orig/123.o $@ + ./coffsyrup $@ $(@:.o=.tmp.o) $$(cat $(undefine)) mv $(@:.o=.tmp.o) $@ dl_init.o: orig/dl_init.o - objcopy -I $(BFD_INP_TARGET) -O $(BFD_OUT_TARGET) $(OBJCOPY_FLAGS) orig/dl_init.o $@ + $(OBJCOPY) -I $(BFD_INP_TARGET) -O $(BFD_OUT_TARGET) $(OBJCOPY_FLAGS) orig/dl_init.o $@ forceplt.o: forceplt.s - as --32 -o $@ forceplt.s + $(AS) $(ASFLAGS) -o $@ forceplt.s ttydraw/ttydraw.a: $(MAKE) -C ttydraw diff --git a/atfuncs/date.c b/atfuncs/date.c index 676b23d..a741a7f 100644 --- a/atfuncs/date.c +++ b/atfuncs/date.c @@ -1,8 +1,8 @@ #include -#include "lottypes.h" -#include "lotfuncs.h" -#include "lotdefs.h" +#include "../lottypes.h" +#include "../lotfuncs.h" +#include "../lotdefs.h" int16_t at_date() { diff --git a/draw.c b/draw.c index c729fdc..d8e5bdd 100644 --- a/draw.c +++ b/draw.c @@ -2,7 +2,7 @@ #include "lotdefs.h" #include "lottypes.h" -#include "ttydraw.h" +#include "ttydraw/ttydraw.h" // The canvas used for drawing ascii-art graphics. extern caca_canvas_t *cv; diff --git a/filemap.c b/filemap.c index e86c6ef..3ace0e7 100644 --- a/filemap.c +++ b/filemap.c @@ -14,11 +14,17 @@ static const char *get_lotus_runtimefile(const char *file) static char *exedir; static char filepath[PATH_MAX]; static char localpath[PATH_MAX]; + static char procexefile[PATH_MAX]; + pid_t pid; // Cache this path so it only has to be looked up once. if (lotusdir == NULL) { - if (readlink("/proc/self/exe", exepath, PATH_MAX) == -1) { - err(EXIT_FAILURE, "Failed to determine the lotus root directory"); + if (readlink("/proc/self/exe", exepath, PATH_MAX) == -1) { // Linux + pid = getpid(); + snprintf(procexefile, PATH_MAX, "/proc/%d/file", pid); + if (readlink(procexefile, exepath, PATH_MAX) == -1) { // BSD + err(EXIT_FAILURE, "Failed to determine the lotus root directory"); + } } // Figure out the containing directory from the exe path. exedir = dirname(exepath); diff --git a/forceplt.s b/forceplt.s index 1873366..89857ac 100644 --- a/forceplt.s +++ b/forceplt.s @@ -225,8 +225,6 @@ __require_ref: call msgctl@plt call semctl@plt call shmctl@plt - call fstat64@plt - call stat64@plt call atexit@plt call sin@plt call cos@plt diff --git a/graphics.c b/graphics.c index c2dfeba..478f6a5 100644 --- a/graphics.c +++ b/graphics.c @@ -6,7 +6,7 @@ #include "lotdefs.h" #include "lottypes.h" #include "lotfuncs.h" -#include "ttydraw.h" +#include "ttydraw/ttydraw.h" #include "draw.h" extern struct LOTUSFUNCS *core_funcs; diff --git a/localize.freebsd b/localize.freebsd new file mode 100644 index 0000000..7e729b4 --- /dev/null +++ b/localize.freebsd @@ -0,0 +1,66 @@ +# vim: set ft=conf: +# +# Note: blank lines are not permitted. +# +# These are symbols that 123.o exports that should not be visible to other +# code, such as statically linked libc functions. +# +fopen +fread +fflush +fgets +fclose +fseek +fgetc +close_range +fputc +fgetgrent +fgetpwent +popen +pclose +fdopen +fprintf +fscanf +fwrite +freopen +sys_errlist +sys_nerr +gtty +stty +initscr +refresh +getch +endwin +wmove +waddch +wclear +wrefresh +LINES +COLS +getmsg +putmsg +stime +opterr +optind +optopt +optarg +getopt +tmpnam +tempnam +move +clrtoeol +clrtobot +clear +addstr +addnstr +beep +reset_shell_mode +addch +reset_prog_mode +def_shell_mode +tparm +setupterm +ttytype +cur_term +longjmp +setjmp diff --git a/undefine.freebsd b/undefine.freebsd new file mode 100644 index 0000000..65883c6 --- /dev/null +++ b/undefine.freebsd @@ -0,0 +1,259 @@ +_start +__unix_ioctl +__unix_fcntl +__unix_stat +__unix_fstat +__unix_open +__unix_uname +__unix_times +__unix_read +__unix_sysi86 +__unix_access +__unix_readdir +__unix_signal +a64l +abort +abs +access +acct +alarm +asctime +atof +atoi +atol +bsearch +calloc +chdir +chmod +chroot +clearerr +clock +closedir +copysign +creat +ctermid +ctime +drand48 +dup2 +dup +eaccess +endgrent +endpwent +environ +erand48 +execle +execl +execlp +execve +execv +execvp +_exit +exit +free +frexp +fstatfs +fstat +ftok +ftw +getchar +getcwd +getegid +getenv +geteuid +getgid +getgrent +getgrgid +getgrnam +getlogin +getopt +getpass +getpgrp +getpid +getppid +getpwent +getpwnam +getpwuid +getuid +getw +gmtime +hcreate +hdestroy +hsearch +isatty +jrand48 +kill +l64a +labs +lcong48 +ldexp +lfind +link +localtime +lockf +lrand48 +lsearch +lseek +malloc +memccpy +memchr +memcmp +memcpy +memmove +memset +mkdir +mknod +mlock +modf +mount +mrand48 +msgget +msgrcv +msgsnd +nice +nrand48 +opendir +open +optarg +opterr +optind +optopt +pause +perror +poll +printf +profil +ptrace +putchar +putenv +puts +putw +qsort +rand +readdir +read +realloc +rename +rewind +rmdir +sbrk +scanf +seed48 +seekdir +semget +semop +setbuf +setgid +setgrent +setpgrp +setpwent +setuid +setvbuf +shmat +shmdt +shmget +sighold +sigignore +signal +sigpause +sigrelse +sigset +sleep +sprintf +srand48 +srand +sscanf +statfs +stat +strcat +strchr +strcmp +strcpy +strcspn +strdup +strlen +strncat +strncmp +strncpy +strpbrk +strrchr +strspn +strtod +strtok +strtol +swab +sync +syscall +system +tdelete +telldir +tfind +time +times +timezone +tolower +toupper +tsearch +ttyname +twalk +tzname +tzset +ulimit +umask +uname +ungetc +unlink +utime +vfprintf +vprintf +vsprintf +wait +write +close +tgetent +tgetstr +tgetflag +tgetnum +tgoto +tputs +tempnam +tmpfile +tmpnam +chown +msgctl +semctl +shmctl +lic_init +open_printer_drivers +load_printer_drivers +close_printer_drivers +read_print_config_dir +display_column_labels +init_unix_display_code +at_date +sin +cos +tan +tan2 +asin +acos +remainder +sqrt +log +log10 +floor +ceil +fmod +fabs +kbd_term +set_raw_mode +unset_raw_mode +ustat +ftell +fputs +nlist +mktemp +write +isnumber +exect +getdents +brk diff --git a/wrappers.c b/wrappers.c index 3015b9b..092d8d5 100644 --- a/wrappers.c +++ b/wrappers.c @@ -23,6 +23,10 @@ extern int __unix_errno; #define SI86FPHW 40 #define FP_387 3 +#define TCGETS 0x5401 +#define TCSETS 0x5402 +#define TCSETSW 0x5403 + static struct termios original; void __attribute__((constructor)) init_terminal_settings() @@ -405,7 +409,6 @@ struct unixdirent * __unix_readdir(DIR *dirp) if ((lent = readdir(dirp))) { uent.d_ino = lent->d_ino; uent.d_off = lent->d_off; - uent.d_reclen = lent->d_reclen; uent.d_type = lent->d_type; strncpy(uent.d_name, lent->d_name, sizeof uent.d_name); return &uent; @@ -425,10 +428,10 @@ void (* __unix_signal(int signum, void (*handler)))(int) [16] = SIGUSR1, [17] = SIGUSR2, [18] = SIGCHLD, - [19] = SIGPWR, + [19] = SIGCONT, [20] = SIGWINCH, [21] = SIGURG, - [22] = SIGPOLL, + [22] = SIGTTOU, [23] = SIGSTOP, [24] = SIGTSTP, [25] = SIGCONT, From 98c3acef14ade6e85b39354484f9489f4efb792d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Wed, 8 Jun 2022 12:50:57 +0200 Subject: [PATCH 23/41] Find GNU make in PATH --- binutils.sh | 16 ++++++++++++---- detect_gnu_make.sh | 9 +++++++++ gzip.sh | 8 ++++---- 3 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 detect_gnu_make.sh diff --git a/binutils.sh b/binutils.sh index c1ea037..98c709d 100755 --- a/binutils.sh +++ b/binutils.sh @@ -6,8 +6,16 @@ BINUTILS_DIR="$(basename $BINUTILS_XZ .tar.xz)" BINUTILS_URL="$BINUTILS_DL/$BINUTILS_XZ" ORIGIN_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)" -# Dont continue on error. -set -e +# Make sure we have GNU make +. "$ORIGIN_DIR/detect_gnu_make.sh" +#gnu_make="$(command -v make 2>/dev/null)" +#if command -v gmake >/dev/null 2>&1; then +# gnu_make="$(command -v gmake)" +#fi +#if [ -z "$gnu_make" -o "$("$gnu_make" --version 2>/dev/null | head -n 1 | cut -c-3)" != "GNU" ]; then +# echo >&2 "Could not find GNU make in PATH" +# exit 1 +#fi # Help text. if [ "$1" = '-h' ]; then @@ -20,7 +28,7 @@ fi # Optional cleanup if requested. if [ "$1" = 'clean' ]; then rm -fv "$ORIGIN_DIR/objcopy" "$ORIGIN_DIR/objdump" "$ORIGIN_DIR/ld" "$ORIGIN_DIR/as" - rm -rfv "$BINUTILS_DIR" + rm -rf "$BINUTILS_DIR" rm -fv "$ORIGIN_DIR/$BINUTILS_XZ" exit fi @@ -43,7 +51,7 @@ if [ ! -x "$BINUTILS_DIR/binutils/objcopy" ]; then --disable-plugins \ --disable-gprof \ --enable-compressed-debug-sections=none && \ - gmake all-ld all-gas MAKEINFO=true + "$gnu_make" all-ld all-gas MAKEINFO=true cd "$ORIGIN_DIR" fi diff --git a/detect_gnu_make.sh b/detect_gnu_make.sh new file mode 100644 index 0000000..fdff300 --- /dev/null +++ b/detect_gnu_make.sh @@ -0,0 +1,9 @@ +#!/bin/sh +gnu_make="$(command -v make 2>/dev/null)" +if command -v gmake >/dev/null 2>&1; then + gnu_make="$(command -v gmake)" +fi +if [ -z "$gnu_make" -o "$("$gnu_make" --version 2>/dev/null | head -n 1 | cut -c-3)" != "GNU" ]; then + echo >&2 "Could not find GNU make in PATH" + exit 1 +fi diff --git a/gzip.sh b/gzip.sh index a68e4ed..714f606 100755 --- a/gzip.sh +++ b/gzip.sh @@ -8,8 +8,8 @@ GZIP_DIR="$(basename $GZIP_XZ .tar.xz)" GZIP_URL="$GZIP_DL/$GZIP_XZ" ORIGIN_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)" -# Dont continue on error. -set -e +# Make sure we have GNU make +. "$ORIGIN_DIR/detect_gnu_make.sh" # Help text. if [ "$1" = '-h' ]; then @@ -22,7 +22,7 @@ fi # Optional cleanup if requested. if [ "$1" = 'clean' ]; then rm -fv "$ORIGIN_DIR/gzip" "$ORIGIN_DIR/gunzip" "$ORIGIN_DIR/zcat" - rm -rfv "$GZIP_DIR" + rm -rf "$GZIP_DIR" rm -fv "$ORIGIN_DIR/$GZIP_XZ" exit fi @@ -39,7 +39,7 @@ fi # Compile gzip. if [ ! -x "$GZIP_DIR/gzip" ]; then - cd "$GZIP_DIR" && ./configure && gmake + cd "$GZIP_DIR" && ./configure && "$gnu_make" cd "$ORIGIN_DIR" fi From 0777099d8b3df6b1694dd3876274144669973068 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Wed, 8 Jun 2022 12:53:49 +0200 Subject: [PATCH 24/41] Remove commented out code --- binutils.sh | 8 -------- 1 file changed, 8 deletions(-) diff --git a/binutils.sh b/binutils.sh index 98c709d..92d98a4 100755 --- a/binutils.sh +++ b/binutils.sh @@ -8,14 +8,6 @@ ORIGIN_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)" # Make sure we have GNU make . "$ORIGIN_DIR/detect_gnu_make.sh" -#gnu_make="$(command -v make 2>/dev/null)" -#if command -v gmake >/dev/null 2>&1; then -# gnu_make="$(command -v gmake)" -#fi -#if [ -z "$gnu_make" -o "$("$gnu_make" --version 2>/dev/null | head -n 1 | cut -c-3)" != "GNU" ]; then -# echo >&2 "Could not find GNU make in PATH" -# exit 1 -#fi # Help text. if [ "$1" = '-h' ]; then From 14042559e6d7d262380df55e5e1f94da78d11180 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Wed, 8 Jun 2022 13:03:54 +0200 Subject: [PATCH 25/41] Fix install(1) invocation --- Makefile | 52 ++++++++++++++++++++++++++-------------------------- extract.sh | 10 +++++----- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/Makefile b/Makefile index bc95d70..f802de7 100644 --- a/Makefile +++ b/Makefile @@ -83,32 +83,32 @@ distclean: clean ./extract.sh clean install: all - install -m 755 -d "$(prefix)/bin" - install -m 755 "bin/123" "$(prefix)/bin/123" - install -m 755 -d "$(prefix)/share/man/man1" - install -m 644 "share/man/man1/123.1" "$(prefix)/share/man/man1/123.1" - install -m 755 -d "$(prefix)/share/lotus/etc" - install -m 644 "share/lotus/etc/l123set.cf" "$(prefix)/share/lotus/etc/l123set.cf" - find "share/lotus/keymaps" -type d -exec install -m 755 -d "$(prefix)/{}" \; - find "share/lotus/keymaps" -type f -exec install -m 644 {} "$(prefix)/{}" \; - install -m 755 -d "$(prefix)/share/lotus/123.v10/sysV386" - install -m 644 "share/lotus/123.v10/sysV386/lotus.bcf" "$(prefix)/share/lotus/123.v10/sysV386/lotus.bcf" - install -m 755 -d "$(prefix)/share/lotus/123.v10/sysV386/lib" - install -m 644 "share/lotus/123.v10/sysV386/lib/wyse50-lts123" "$(prefix)/share/lotus/123.v10/sysV386/lib/wyse50-lts123" - find "share/lotus/123.v10/cbd" -type d -exec install -m 755 -d "$(prefix)/{}" \; - find "share/lotus/123.v10/cbd" -type f -exec install -m 644 {} "$(prefix)/{}" \; - find "share/lotus/123.v10/fonts" -type d -exec install -m 755 -d "$(prefix)/{}" \; - find "share/lotus/123.v10/fonts" -type f -exec install -m 644 {} "$(prefix)/{}" \; - find "share/lotus/123.v10/hlp" -type d -exec install -m 755 -d "$(prefix)/{}" \; - find "share/lotus/123.v10/hlp" -type f -exec install -Dm 644 {} "$(prefix)/{}" \; - find "share/lotus/123.v10/keymaps" -type d -exec install -m 755 -d "$(prefix)/{}" \; - find "share/lotus/123.v10/keymaps" -type f -exec install -m 644 {} "$(prefix)/{}" \; - find "share/lotus/123.v10/pbd" -type d -exec install -m 755 -d "$(prefix)/{}" \; - find "share/lotus/123.v10/pbd" -type f -exec install -Dm 644 {} "$(prefix)/{}" \; - find "share/lotus/123.v10/ri" -type d -exec install -m 755 -d "$(prefix)/{}" \; - find "share/lotus/123.v10/ri" -type f -exec install -Dm 644 {} "$(prefix)/{}" \; - find "share/lotus/123.v10/smpfiles" -type d -exec install -m 755 -d "$(prefix)/{}" \; - find "share/lotus/123.v10/smpfiles" -type f -exec install -Dm 644 {} "$(prefix)/{}" \; + install -m 0755 -d "$(prefix)/bin" + install -m 0755 "bin/123" "$(prefix)/bin/123" + install -m 0755 -d "$(prefix)/share/man/man1" + install -m 0644 "share/man/man1/123.1" "$(prefix)/share/man/man1/123.1" + install -m 0755 -d "$(prefix)/share/lotus/etc" + install -m 0644 "share/lotus/etc/l123set.cf" "$(prefix)/share/lotus/etc/l123set.cf" + find "share/lotus/keymaps" -type d -exec install -m 0755 -d "$(prefix)/{}" \; + find "share/lotus/keymaps" -type f -exec install -m 0644 {} "$(prefix)/{}" \; + install -m 0755 -d "$(prefix)/share/lotus/123.v10/sysV386" + install -m 0644 "share/lotus/123.v10/sysV386/lotus.bcf" "$(prefix)/share/lotus/123.v10/sysV386/lotus.bcf" + install -m 0755 -d "$(prefix)/share/lotus/123.v10/sysV386/lib" + install -m 0644 "share/lotus/123.v10/sysV386/lib/wyse50-lts123" "$(prefix)/share/lotus/123.v10/sysV386/lib/wyse50-lts123" + find "share/lotus/123.v10/cbd" -type d -exec install -m 0755 -d "$(prefix)/{}" \; + find "share/lotus/123.v10/cbd" -type f -exec install -m 0644 {} "$(prefix)/{}" \; + find "share/lotus/123.v10/fonts" -type d -exec install -m 0755 -d "$(prefix)/{}" \; + find "share/lotus/123.v10/fonts" -type f -exec install -m 0644 {} "$(prefix)/{}" \; + find "share/lotus/123.v10/hlp" -type d -exec install -m 0755 -d "$(prefix)/{}" \; + find "share/lotus/123.v10/hlp" -type f -exec install -m 0644 {} "$(prefix)/{}" \; + find "share/lotus/123.v10/keymaps" -type d -exec install -m 0755 -d "$(prefix)/{}" \; + find "share/lotus/123.v10/keymaps" -type f -exec install -m 0644 {} "$(prefix)/{}" \; + find "share/lotus/123.v10/pbd" -type d -exec install -m 0755 -d "$(prefix)/{}" \; + find "share/lotus/123.v10/pbd" -type f -exec install -m 0644 {} "$(prefix)/{}" \; + find "share/lotus/123.v10/ri" -type d -exec install -m 0755 -d "$(prefix)/{}" \; + find "share/lotus/123.v10/ri" -type f -exec install -m 0644 {} "$(prefix)/{}" \; + find "share/lotus/123.v10/smpfiles" -type d -exec install -m 0755 -d "$(prefix)/{}" \; + find "share/lotus/123.v10/smpfiles" -type f -exec install -m 0644 {} "$(prefix)/{}" \; uninstall: rm -f "$(prefix)/bin/123" diff --git a/extract.sh b/extract.sh index 003041c..08ee3d9 100755 --- a/extract.sh +++ b/extract.sh @@ -62,12 +62,12 @@ echo '==> Uncompressing and copying remaining object files' cp "${LOTUS}"/sysV386/lib/*.o "${ORIG}/" echo '==> Copying the banner template over' -install -m 644 "${ROOT}/usr/tmp/lotus_install/123/banner" "${LOTUS}/ri/USA-English/123ban.ri" +install -m 0644 "${ROOT}/usr/tmp/lotus_install/123/banner" "${LOTUS}/ri/USA-English/123ban.ri" echo '==> Copying default config file' -install -m 755 -d "${ETC}" -install -m 644 "l123set.cf" "${ETC}/l123set.cf" +install -m 0755 -d "${ETC}" +install -m 0644 "l123set.cf" "${ETC}/l123set.cf" echo '==> Copying man page' -install -m 755 -d "${ROOT}/man/man1" -install -m 644 "${ROOT}/lotus/man/man1/123.1" "${ROOT}/man/man1/123.1" +install -m 0755 -d "${ROOT}/man/man1" +install -m 0644 "${ROOT}/lotus/man/man1/123.1" "${ROOT}/man/man1/123.1" From 1faceb1edb13f679ad571c97209a6553b36f7b48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Wed, 8 Jun 2022 13:21:09 +0200 Subject: [PATCH 26/41] Fix typo --- Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 15b5432..9551f1e 100755 --- a/Makefile +++ b/Makefile @@ -18,9 +18,8 @@ LDFLAGS != if [ "$(platform)" = "Linux" ]; then echo $(LINUX_LDFLAGS) $(GENERIC_ NCURSES_LIBS != ./ncurses-config.sh LDLIBS = $(NCURSES_LIBS) -lm OBJECT_FILES = 123.o dl_init.o main.o wrappers.o patch.o filemap.o graphics.o draw.o ttydraw/ttydraw.a atfuncs/atfuncs.a forceplt.o -# # The list of terminals we generate keymaps for by default. -KEYMAPS = xterm rxvt-unicode xterm-256color rxvt-unicode-256color screen.xterm-256color $(TERM) +KEYMAPS = xterm rxvt-unicode xterm-256color rxvt-unicode-256color screen $(TERM) prefix = /usr/local .PHONY: clean check distclean install uninstall From 3fcb192679626f4a1e3dc0f3ad22a680e03be143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Wed, 8 Jun 2022 13:21:21 +0200 Subject: [PATCH 27/41] Undefine init_showme on FreeBSD --- undefine.freebsd | 1 + 1 file changed, 1 insertion(+) diff --git a/undefine.freebsd b/undefine.freebsd index 65883c6..9926833 100644 --- a/undefine.freebsd +++ b/undefine.freebsd @@ -257,3 +257,4 @@ isnumber exect getdents brk +init_showme From 2116cb3f2600e384d221a99d2c45a6351a0214d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Wed, 8 Jun 2022 13:58:27 +0200 Subject: [PATCH 28/41] Shell script to detect OS-specific symbol list file --- Makefile | 8 ++++---- detect-os-symbol-list-file.sh | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) create mode 100755 detect-os-symbol-list-file.sh diff --git a/Makefile b/Makefile index 9551f1e..7374985 100755 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ platform != uname -s -undefine != if [ "$(platform)" = "FreeBSD" ]; then echo undefine.freebsd; else echo undefine.lst; fi -redefine = redefine.lst -localize != if [ "$(platform)" = "FreeBSD" ]; then echo localize.freebsd; else echo localize.lst; fi -globalize = globalize.lst +undefine != ./detect-os-symbol-list-file.sh undefine +redefine != ./detect-os-symbol-list-file.sh redefine +localize != ./detect-os-symbol-list-file.sh localize +globalize != ./detect-os-symbol-list-file.sh globalize OBJCOPY_FLAGS = --wildcard --localize-symbols=$(localize) --globalize-symbols=$(globalize) --redefine-syms=$(redefine) OBJCOPY_FILES = $(localize) $(globalize) $(redefine) $(undefine) OBJCOPY != if [ -x ./objcopy ]; then echo ./objcopy; else echo objcopy; fi diff --git a/detect-os-symbol-list-file.sh b/detect-os-symbol-list-file.sh new file mode 100755 index 0000000..e646200 --- /dev/null +++ b/detect-os-symbol-list-file.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +file_undefine=undefine.lst +file_redefine=redefine.lst +file_localize=localize.lst +file_globalize=globalize.lst + +if [ "$#" -lt 1 ]; then + echo >&2 "Usage: $0 " + exit 1 +fi + +platform=`(uname -s)` + +if [ "$platform" = "FreeBSD" ]; then + file_undefine=undefine.freebsd + file_localize=localize.freebsd +fi + +if [ "$platform" = "NetBSD" ]; then + file_undefine=undefine.netbsd +fi + +if [ "$1" = "undefine" ]; then + echo "$file_undefine" + elif [ "$1" = "redefine" ]; then + echo "$file_redefine" + elif [ "$1" = "localize" ]; then + echo "$file_localize" + elif [ "$1" = "globalize" ]; then + echo "$file_globalize" + else + echo >&2 "Usage: $0 " + exit 1 +fi From 76e18724122d4ca37bcb7bc32309b251b46661fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Wed, 8 Jun 2022 13:59:42 +0200 Subject: [PATCH 29/41] Use kebab case for script name --- binutils.sh | 2 +- detect_gnu_make.sh => detect-gnu-make.sh | 0 gzip.sh | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename detect_gnu_make.sh => detect-gnu-make.sh (100%) diff --git a/binutils.sh b/binutils.sh index 92d98a4..6f0cc47 100755 --- a/binutils.sh +++ b/binutils.sh @@ -7,7 +7,7 @@ BINUTILS_URL="$BINUTILS_DL/$BINUTILS_XZ" ORIGIN_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)" # Make sure we have GNU make -. "$ORIGIN_DIR/detect_gnu_make.sh" +. "$ORIGIN_DIR/detect-gnu-make.sh" # Help text. if [ "$1" = '-h' ]; then diff --git a/detect_gnu_make.sh b/detect-gnu-make.sh similarity index 100% rename from detect_gnu_make.sh rename to detect-gnu-make.sh diff --git a/gzip.sh b/gzip.sh index 714f606..548747c 100755 --- a/gzip.sh +++ b/gzip.sh @@ -9,7 +9,7 @@ GZIP_URL="$GZIP_DL/$GZIP_XZ" ORIGIN_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)" # Make sure we have GNU make -. "$ORIGIN_DIR/detect_gnu_make.sh" +. "$ORIGIN_DIR/detect-gnu-make.sh" # Help text. if [ "$1" = '-h' ]; then From 2c8f2d4964d07d2dd84adf7d0be9614711bb152c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Wed, 8 Jun 2022 15:30:35 +0200 Subject: [PATCH 30/41] Fix build on NetBSD --- undefine.netbsd | 258 ++++++++++++++++++++++++++++++++++++++++++++++++ wrappers.c | 1 - 2 files changed, 258 insertions(+), 1 deletion(-) create mode 100644 undefine.netbsd diff --git a/undefine.netbsd b/undefine.netbsd new file mode 100644 index 0000000..dd84e80 --- /dev/null +++ b/undefine.netbsd @@ -0,0 +1,258 @@ +_start +__unix_ioctl +__unix_fcntl +__unix_stat +__unix_fstat +__unix_open +__unix_uname +__unix_times +__unix_read +__unix_sysi86 +__unix_access +__unix_readdir +__unix_signal +a64l +abort +abs +access +acct +alarm +asctime +atof +atoi +atol +bsearch +calloc +chdir +chmod +chroot +clearerr +clock +closedir +copysign +creat +ctermid +ctime +drand48 +dup2 +dup +endgrent +endpwent +environ +erand48 +execle +execl +execlp +execve +execv +execvp +_exit +exit +free +frexp +fstatfs +fstat +ftok +ftw +getchar +getcwd +getegid +getenv +geteuid +getgid +getgrent +getgrgid +getgrnam +getlogin +getopt +getpass +getpgrp +getpid +getppid +getpwent +getpwnam +getpwuid +getuid +getw +gmtime +hcreate +hdestroy +hsearch +isatty +jrand48 +kill +l64a +labs +lcong48 +ldexp +lfind +link +localtime +lockf +lrand48 +lsearch +lseek +malloc +memccpy +memchr +memcmp +memcpy +memmove +memset +mkdir +mknod +mlock +modf +mount +mrand48 +msgget +msgrcv +msgsnd +nice +nrand48 +opendir +open +optarg +opterr +optind +optopt +pause +perror +poll +printf +profil +ptrace +putchar +putenv +puts +putw +qsort +rand +readdir +read +realloc +rename +rewind +rmdir +sbrk +scanf +seed48 +seekdir +semget +semop +setbuf +setgid +setgrent +setpgrp +setpwent +setuid +setvbuf +shmat +shmdt +shmget +sighold +sigignore +signal +sigpause +sigrelse +sigset +sleep +sprintf +srand48 +srand +sscanf +statfs +stat +strcat +strchr +strcmp +strcpy +strcspn +strdup +strlen +strncat +strncmp +strncpy +strpbrk +strrchr +strspn +strtod +strtok +strtol +swab +sync +syscall +system +tdelete +telldir +tfind +time +times +timezone +tolower +toupper +tsearch +ttyname +twalk +tzname +tzset +ulimit +umask +uname +ungetc +unlink +utime +vfprintf +vprintf +vsprintf +wait +write +close +tgetent +tgetstr +tgetflag +tgetnum +tgoto +tputs +tempnam +tmpfile +tmpnam +chown +msgctl +semctl +shmctl +lic_init +open_printer_drivers +load_printer_drivers +close_printer_drivers +read_print_config_dir +display_column_labels +init_unix_display_code +at_date +sin +cos +tan +tan2 +asin +acos +remainder +sqrt +log +log10 +floor +ceil +fmod +fabs +kbd_term +set_raw_mode +unset_raw_mode +ustat +ftell +fputs +nlist +mktemp +write +exect +getdents +brk +init_showme diff --git a/wrappers.c b/wrappers.c index 092d8d5..e5db71d 100644 --- a/wrappers.c +++ b/wrappers.c @@ -408,7 +408,6 @@ struct unixdirent * __unix_readdir(DIR *dirp) // Fetch the real entry, and translate it to the UNIX format. if ((lent = readdir(dirp))) { uent.d_ino = lent->d_ino; - uent.d_off = lent->d_off; uent.d_type = lent->d_type; strncpy(uent.d_name, lent->d_name, sizeof uent.d_name); return &uent; From aac37642190d252de1bfa59eb48ed4c88b18cf76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Wed, 8 Jun 2022 15:43:54 +0200 Subject: [PATCH 31/41] Localize fwrite on Linux --- detect-os-symbol-list-file.sh | 1 - localize.freebsd | 66 ----------------------------------- localize.lst | 1 + 3 files changed, 1 insertion(+), 67 deletions(-) delete mode 100644 localize.freebsd diff --git a/detect-os-symbol-list-file.sh b/detect-os-symbol-list-file.sh index e646200..096cd5e 100755 --- a/detect-os-symbol-list-file.sh +++ b/detect-os-symbol-list-file.sh @@ -14,7 +14,6 @@ platform=`(uname -s)` if [ "$platform" = "FreeBSD" ]; then file_undefine=undefine.freebsd - file_localize=localize.freebsd fi if [ "$platform" = "NetBSD" ]; then diff --git a/localize.freebsd b/localize.freebsd deleted file mode 100644 index 7e729b4..0000000 --- a/localize.freebsd +++ /dev/null @@ -1,66 +0,0 @@ -# vim: set ft=conf: -# -# Note: blank lines are not permitted. -# -# These are symbols that 123.o exports that should not be visible to other -# code, such as statically linked libc functions. -# -fopen -fread -fflush -fgets -fclose -fseek -fgetc -close_range -fputc -fgetgrent -fgetpwent -popen -pclose -fdopen -fprintf -fscanf -fwrite -freopen -sys_errlist -sys_nerr -gtty -stty -initscr -refresh -getch -endwin -wmove -waddch -wclear -wrefresh -LINES -COLS -getmsg -putmsg -stime -opterr -optind -optopt -optarg -getopt -tmpnam -tempnam -move -clrtoeol -clrtobot -clear -addstr -addnstr -beep -reset_shell_mode -addch -reset_prog_mode -def_shell_mode -tparm -setupterm -ttytype -cur_term -longjmp -setjmp diff --git a/localize.lst b/localize.lst index 6e96623..7e729b4 100644 --- a/localize.lst +++ b/localize.lst @@ -21,6 +21,7 @@ pclose fdopen fprintf fscanf +fwrite freopen sys_errlist sys_nerr From 8c8a21e953e5c8b7cdce6c248bc22c4df29bf4ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Thu, 9 Jun 2022 11:59:18 +0200 Subject: [PATCH 32/41] Symbol undefine list for OpenBSD --- detect-os-symbol-list-file.sh | 4 ++ undefine.openbsd | 132 ++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 undefine.openbsd diff --git a/detect-os-symbol-list-file.sh b/detect-os-symbol-list-file.sh index 096cd5e..623e788 100755 --- a/detect-os-symbol-list-file.sh +++ b/detect-os-symbol-list-file.sh @@ -20,6 +20,10 @@ if [ "$platform" = "NetBSD" ]; then file_undefine=undefine.netbsd fi +if [ "$platform" = "OpenBSD" ]; then + file_undefine=undefine.openbsd +fi + if [ "$1" = "undefine" ]; then echo "$file_undefine" elif [ "$1" = "redefine" ]; then diff --git a/undefine.openbsd b/undefine.openbsd new file mode 100644 index 0000000..82ddf48 --- /dev/null +++ b/undefine.openbsd @@ -0,0 +1,132 @@ +_start +__unix_ioctl +__unix_fcntl +__unix_stat +__unix_fstat +__unix_open +__unix_uname +__unix_times +__unix_read +__unix_sysi86 +__unix_access +__unix_readdir +__unix_signal +abort +access +atol +bsearch +bssearch +clock +clearerr +ctime +asctime +ftok +lockf +modf +perror +printf +putchar +puts +qsort +rand +rewind +scanf +sscanf +atof +setbuf +setvbuf +sleep +sprintf +strcspn +strtod +ldexp +strtok +strpbrk +strspn +strtol +system +localtime +tmpfile +tolower +toupper +ungetc +vfprintf +vprintf +vsprintf +frexp +getenv +exit +labs +abs +memcmp +pause +strchr +strcmp +stncpy +strncpy +strncat +time +strncmp +strrchr +strcat +memchr +memmove +memset +strcpy +strlen +memmove +tzname +timezone +daylight +getchar +atoi +calloc +endgrent +endpwent +fabs +free +fstat +getopt +malloc +memcpy +open +optarg +opterr +optopt +realloc +read +readdir +signal +stat +times +uname +lic_init +open_printer_drivers +load_printer_drivers +close_printer_drivers +read_print_config_dir +display_column_labels +init_unix_display_code +at_date +tan2 +kbd_term +set_raw_mode +unset_raw_mode +ustat +nlist +mktemp +exect +getdents +brk +init_showme +__udivsi3 +__divsi3 +__fixdfsi +fpgetmask +fpgetround +fpgetsticky +fpsetround +fpsetsticky +fpsetmask +ftell +fputs From 067bea0b28b1c716f7b3c742612ce76700d5ddf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Thu, 9 Jun 2022 12:30:28 +0200 Subject: [PATCH 33/41] Add environ to OpenBSD undefine list --- undefine.openbsd | 1 + 1 file changed, 1 insertion(+) diff --git a/undefine.openbsd b/undefine.openbsd index 82ddf48..7de26be 100644 --- a/undefine.openbsd +++ b/undefine.openbsd @@ -130,3 +130,4 @@ fpsetsticky fpsetmask ftell fputs +environ From 522c49091610a75e0a860b45010961fc2d27bab0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Fri, 10 Jun 2022 12:25:29 +0200 Subject: [PATCH 34/41] Workaround for OpenBSD OpenBSD doesn't seem to allow ioctl(2) to write directly to the data segment in constructor code. Passing a heap pointer instead. --- wrappers.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/wrappers.c b/wrappers.c index e5db71d..1a266c9 100644 --- a/wrappers.c +++ b/wrappers.c @@ -32,8 +32,20 @@ static struct termios original; void __attribute__((constructor)) init_terminal_settings() { // Make a backup of the terminal state to restore to later. - if (isatty(STDIN_FILENO) && tcgetattr(STDIN_FILENO, &original) != 0) { - err(EXIT_FAILURE, "Failed to query terminal attributes."); + // Pass a heap pointer t to tcgetattr, + // then copy result to data segment, + // as a workaround for OpenBSD not allowing + // ioctl(2) to write to the data segment at this point. + int attr; + struct termios *t; + if (isatty(STDIN_FILENO)) { + t = malloc(sizeof(struct termios)); + attr = tcgetattr(STDIN_FILENO, t); + memmove(&original, t, sizeof(struct termios)); + free(t); + if (attr != 0) { + err(EXIT_FAILURE, "Failed to query terminal attributes."); + } } } From a44ff9c4593ce66f4e383d40dee4fb21a4a4697e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Fri, 10 Jun 2022 19:04:14 +0200 Subject: [PATCH 35/41] Revert some malloc changes --- main.c | 4 ++-- patch.c | 2 +- wrappers.c | 16 ++-------------- 3 files changed, 5 insertions(+), 17 deletions(-) diff --git a/main.c b/main.c index c1486af..0fe8485 100644 --- a/main.c +++ b/main.c @@ -99,7 +99,7 @@ int main(int argc, char **argv, char **envp) lotargc += 2; // Allocate the argument vector we're going to pass through to lotus. - lotargv = malloc(lotargc * sizeof(*argv)); + lotargv = alloca(lotargc * sizeof(*argv)); // Now reset and copy the options over. lotargc = 0; @@ -127,7 +127,7 @@ int main(int argc, char **argv, char **envp) // If we reach here, we want to pass this option through to // Lotus verbatim. - lotargv[lotargc] = malloc(3); + lotargv[lotargc] = alloca(3); lotargv[lotargc][0] = '-'; lotargv[lotargc][1] = opt; lotargv[lotargc][2] = 0; diff --git a/patch.c b/patch.c index de905ec..0cf835a 100644 --- a/patch.c +++ b/patch.c @@ -39,7 +39,7 @@ int display_column_labels() uint8_t *buf; // Is this right? - buf = malloc(COLS); + buf = alloca(COLS); // I have no idea what this structure is. if (dspinfo[11]) { diff --git a/wrappers.c b/wrappers.c index 1a266c9..e5db71d 100644 --- a/wrappers.c +++ b/wrappers.c @@ -32,20 +32,8 @@ static struct termios original; void __attribute__((constructor)) init_terminal_settings() { // Make a backup of the terminal state to restore to later. - // Pass a heap pointer t to tcgetattr, - // then copy result to data segment, - // as a workaround for OpenBSD not allowing - // ioctl(2) to write to the data segment at this point. - int attr; - struct termios *t; - if (isatty(STDIN_FILENO)) { - t = malloc(sizeof(struct termios)); - attr = tcgetattr(STDIN_FILENO, t); - memmove(&original, t, sizeof(struct termios)); - free(t); - if (attr != 0) { - err(EXIT_FAILURE, "Failed to query terminal attributes."); - } + if (isatty(STDIN_FILENO) && tcgetattr(STDIN_FILENO, &original) != 0) { + err(EXIT_FAILURE, "Failed to query terminal attributes."); } } From 6b9e561911d75d80ca201e1e7053e5a83ca76598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Fri, 10 Jun 2022 19:20:59 +0200 Subject: [PATCH 36/41] Rebuild list undefine.openbsd --- undefine.openbsd | 249 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 174 insertions(+), 75 deletions(-) diff --git a/undefine.openbsd b/undefine.openbsd index 7de26be..77e6b54 100644 --- a/undefine.openbsd +++ b/undefine.openbsd @@ -11,95 +11,210 @@ __unix_sysi86 __unix_access __unix_readdir __unix_signal +a64l abort +abs access +acct +alarm +asctime +atof +atoi atol bsearch -bssearch -clock +calloc +chdir +chmod +chroot clearerr +clock +closedir +creat +ctermid ctime -asctime +daylight +drand48 +dup2 +dup +ecvt +endgrent +endpwent +environ +erand48 +execle +execl +execlp +execve +execv +execvp +_exit +exit +fcvt +free +frexp +fstatfs +fstat ftok +ftw +gcvt +getchar +getcwd +getegid +getenv +geteuid +getgid +getgrent +getgrgid +getgrnam +getlogin +getpass +getpgrp +getpid +getppid +getpwent +getpwnam +getpwuid +getuid +getw +gmtime +hcreate +hdestroy +hsearch +isatty +jrand48 +kill +l64a +labs +lcong48 +ldexp +lfind +link +localtime lockf +lrand48 +lsearch +lseek +malloc +memccpy +memchr +memcmp +memcpy +memmove +memset +mkdir +mknod +mlock modf +mount +mrand48 +msgget +msgrcv +msgsnd +nice +nrand48 +opendir +open +pause perror +poll printf +profil +ptrace putchar +putenv puts +putw qsort rand +readdir +read +realloc +rename rewind +rmdir +sbrk scanf -sscanf -atof +seed48 +seekdir +semget +semop setbuf +setgid +setgrent +setpgrp +setpwent +setuid setvbuf +shmat +shmdt +shmget +signal +sigpause sleep sprintf +srand48 +srand +sscanf +statfs +stat +strcat +strchr +strcmp +strcpy strcspn -strtod -ldexp -strtok +strdup +strlen +strncat +strncmp +strncpy strpbrk +strrchr strspn +strtod +strtok strtol +swab +sync +syscall system -localtime -tmpfile +tdelete +telldir +tfind +time +times +timezone tolower toupper +tsearch +ttyname +ttyslot +twalk +tzname +tzset +umask +uname ungetc +unlink +utime vfprintf vprintf vsprintf -frexp -getenv -exit -labs -abs -memcmp -pause -strchr -strcmp -stncpy -strncpy -strncat -time -strncmp -strrchr -strcat -memchr -memmove -memset -strcpy -strlen -memmove -tzname -timezone -daylight -getchar -atoi -calloc -endgrent -endpwent -fabs -free -fstat -getopt -malloc -memcpy -open -optarg -opterr -optopt -realloc -read -readdir -signal -stat -times -uname +wait +write +close +tgetent +tgetstr +tgetflag +tgetnum +tgoto +tputs +tmpfile +chown +msgctl +semctl +shmctl +fstat64 +stat64 lic_init open_printer_drivers load_printer_drivers @@ -109,25 +224,9 @@ display_column_labels init_unix_display_code at_date tan2 +fabs kbd_term set_raw_mode -unset_raw_mode ustat -nlist -mktemp -exect -getdents -brk init_showme -__udivsi3 -__divsi3 -__fixdfsi -fpgetmask -fpgetround -fpgetsticky -fpsetround -fpsetsticky -fpsetmask -ftell -fputs -environ +setup_screen_mem From 546186d3d1d401aa45e8a9109b81f2ead09e2a5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Sun, 12 Jun 2022 09:53:10 +0200 Subject: [PATCH 37/41] Quote command substitution --- detect-os-symbol-list-file.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/detect-os-symbol-list-file.sh b/detect-os-symbol-list-file.sh index 623e788..37e9427 100755 --- a/detect-os-symbol-list-file.sh +++ b/detect-os-symbol-list-file.sh @@ -10,7 +10,7 @@ if [ "$#" -lt 1 ]; then exit 1 fi -platform=`(uname -s)` +platform="$(uname -s)" if [ "$platform" = "FreeBSD" ]; then file_undefine=undefine.freebsd From 587d6bd6a90b43a8cd35946a46ced99efee3a2c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Mon, 13 Jun 2022 01:51:23 +0200 Subject: [PATCH 38/41] Merge updates from main --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 7374985..c0701cc 100755 --- a/Makefile +++ b/Makefile @@ -9,8 +9,8 @@ OBJCOPY != if [ -x ./objcopy ]; then echo ./objcopy; else echo objcopy; fi AS != if [ -x ./as ]; then echo ./as; else echo as; fi BFD_INP_TARGET = coff-i386 BFD_OUT_TARGET = coff-i386 -CFLAGS = -m32 -ggdb3 -O0 -fno-stack-protector -CPPFLAGS = -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64 -D_GNU_SOURCE -I ttydraw +CFLAGS = -W -Wall -m32 -ggdb3 -O0 -fno-stack-protector +CPPFLAGS = -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64 -D_GNU_SOURCE -I ttydraw -Wno-unused-parameter ASFLAGS = --32 LINUX_LDFLAGS = -lc GENERIC_LDFLAGS = $(CFLAGS) -B. -Wl,-b,$(BFD_OUT_TARGET) -no-pie @@ -19,7 +19,7 @@ NCURSES_LIBS != ./ncurses-config.sh LDLIBS = $(NCURSES_LIBS) -lm OBJECT_FILES = 123.o dl_init.o main.o wrappers.o patch.o filemap.o graphics.o draw.o ttydraw/ttydraw.a atfuncs/atfuncs.a forceplt.o # The list of terminals we generate keymaps for by default. -KEYMAPS = xterm rxvt-unicode xterm-256color rxvt-unicode-256color screen $(TERM) +KEYMAPS = xterm rxvt-unicode xterm-256color rxvt-unicode-256color screen screen.xterm-256color vt100 vt320 $(TERM) prefix = /usr/local .PHONY: clean check distclean install uninstall From 5a0db70bb0e2bb0a1f195f496416426f1bf2cfa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Mon, 13 Jun 2022 02:05:09 +0200 Subject: [PATCH 39/41] Include alloca from stdlib.h for portability --- filename.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/filename.c b/filename.c index 8db83ed..ca27364 100644 --- a/filename.c +++ b/filename.c @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include From e644cf5a2dc3f92d6459afa47c38a22b13686630 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Fri, 17 Jun 2022 14:16:08 +0200 Subject: [PATCH 40/41] Don't use non-portable -v --- binutils.sh | 6 +++--- gzip.sh | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/binutils.sh b/binutils.sh index 6f0cc47..6b1171f 100755 --- a/binutils.sh +++ b/binutils.sh @@ -19,9 +19,9 @@ fi # Optional cleanup if requested. if [ "$1" = 'clean' ]; then - rm -fv "$ORIGIN_DIR/objcopy" "$ORIGIN_DIR/objdump" "$ORIGIN_DIR/ld" "$ORIGIN_DIR/as" + rm -f "$ORIGIN_DIR/objcopy" "$ORIGIN_DIR/objdump" "$ORIGIN_DIR/ld" "$ORIGIN_DIR/as" rm -rf "$BINUTILS_DIR" - rm -fv "$ORIGIN_DIR/$BINUTILS_XZ" + rm -f "$ORIGIN_DIR/$BINUTILS_XZ" exit fi @@ -49,7 +49,7 @@ fi # Copy compiled binaries to working directory. copy() { - test ! -x "$2" && cp -v "$1" "$2" + test ! -x "$2" && cp "$1" "$2" } copy "$BINUTILS_DIR/binutils/objcopy" "$ORIGIN_DIR/objcopy" diff --git a/gzip.sh b/gzip.sh index 548747c..774f42e 100755 --- a/gzip.sh +++ b/gzip.sh @@ -45,7 +45,7 @@ fi # Copy compiled binaries to working directory. copy() { - test ! -x "$2" && cp -v "$1" "$2" + test ! -x "$2" && cp "$1" "$2" } copy "$GZIP_DIR/gzip" "$ORIGIN_DIR/gzip" From 9d413c85f7ff78007053faa799da01a78e2f1216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Fri, 17 Jun 2022 14:18:05 +0200 Subject: [PATCH 41/41] Don't use non-portable -v --- gzip.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gzip.sh b/gzip.sh index 774f42e..5ca7cac 100755 --- a/gzip.sh +++ b/gzip.sh @@ -21,9 +21,9 @@ fi # Optional cleanup if requested. if [ "$1" = 'clean' ]; then - rm -fv "$ORIGIN_DIR/gzip" "$ORIGIN_DIR/gunzip" "$ORIGIN_DIR/zcat" + rm -f "$ORIGIN_DIR/gzip" "$ORIGIN_DIR/gunzip" "$ORIGIN_DIR/zcat" rm -rf "$GZIP_DIR" - rm -fv "$ORIGIN_DIR/$GZIP_XZ" + rm -f "$ORIGIN_DIR/$GZIP_XZ" exit fi