diff --git a/.gitignore b/.gitignore index c7172ea..02f577c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,19 @@ orig *.IMG real-ld -objcopy -objdump *.o *.sw? coffsyrup 123 -ld binutils-* +as +objcopy +objdump +ld +gzip-* +gzip +gunzip +zcat drawtest *.a keymap/keymap diff --git a/Makefile b/Makefile index 04643d4..b0ca94a 100644 --- a/Makefile +++ b/Makefile @@ -1,26 +1,26 @@ +platform != uname -s +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 +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 = -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 -LDFLAGS = $(CFLAGS) -lc -B. -Wl,-b,$(BFD_OUT_TARGET) -no-pie -LDLIBS = -lncurses -ltinfo -lm -PATH := .:$(PATH) -prefix = /usr/local - +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 filename.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 -KEYMAPS := $(KEYMAPS) $(patsubst %,%-256color,$(KEYMAPS)) -KEYMAPS += screen.xterm-256color vt100 vt320 $(TERM) - -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 +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 @@ -28,19 +28,25 @@ 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) $< $@ - coffsyrup $@ $(@:.o=.tmp.o) $$(cat undefine.lst) +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)) 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 $@ + +forceplt.o: forceplt.s + $(AS) $(ASFLAGS) -o $@ forceplt.s ttydraw/ttydraw.a: $(MAKE) -C ttydraw @@ -48,27 +54,26 @@ 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 filename.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. -$(sort $(KEYMAPS)): keymap/keymap - mkdir -p share/lotus/keymaps/$(shell printf "%c" $@) - keymap/keymap $@ > share/lotus/keymaps/$(shell printf "%c" $@)/$@ +$(KEYMAPS): keymap/keymap + ./install-keymap.sh $@ 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 @@ -79,21 +84,34 @@ 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)/{}" \; - 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/pbd" -type f -exec install -Dm 644 {} "$(prefix)/{}" \; - find "share/lotus/123.v10/ri" -type f -exec install -Dm 644 {} "$(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) "$(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/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/atfuncs/date.c b/atfuncs/date.c index 50a2aa3..d209590 100644 --- a/atfuncs/date.c +++ b/atfuncs/date.c @@ -1,9 +1,9 @@ #include #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/binutils.sh b/binutils.sh index d6b642d..6b1171f 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 +# Make sure we have GNU make +. "$ORIGIN_DIR/detect-gnu-make.sh" # 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 -f "$ORIGIN_DIR/objcopy" "$ORIGIN_DIR/objdump" "$ORIGIN_DIR/ld" "$ORIGIN_DIR/as" + rm -rf "$BINUTILS_DIR" + rm -f "$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-libctf \ + --disable-plugins \ + --disable-gprof \ + --enable-compressed-debug-sections=none && \ + "$gnu_make" all-ld all-gas MAKEINFO=true + cd "$ORIGIN_DIR" fi # Copy compiled binaries to working directory. copy() { - test ! -x "$2" && cp -v "$1" "$2" + test ! -x "$2" && cp "$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" +copy "$BINUTILS_DIR/gas/as-new" "$ORIGIN_DIR/as" 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) diff --git a/coffsyrup.c b/coffsyrup.c index 34f25c4..63aa2e7 100644 --- a/coffsyrup.c +++ b/coffsyrup.c @@ -145,7 +145,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."); @@ -171,9 +172,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++) { @@ -202,6 +206,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. @@ -258,7 +265,8 @@ int main(int argc, char **argv) relocs[i] = calloc(scn[i].s_nreloc + nmkrelocs, 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) { @@ -282,9 +290,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++) { @@ -313,6 +324,9 @@ int main(int argc, char **argv) } } } + + // free symname if it was duplicated on heap + if (symnamedup) free(symname); } for (int mkr = 0; mkr < nmkrelocs; mkr++) { 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/detect-os-symbol-list-file.sh b/detect-os-symbol-list-file.sh new file mode 100755 index 0000000..37e9427 --- /dev/null +++ b/detect-os-symbol-list-file.sh @@ -0,0 +1,38 @@ +#!/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 +fi + +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 + 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 diff --git a/draw.c b/draw.c index 32d2bc6..3c855d9 100644 --- a/draw.c +++ b/draw.c @@ -1,8 +1,8 @@ #include -#include "lottypes.h" #include "lotdefs.h" -#include "ttydraw.h" +#include "lottypes.h" +#include "ttydraw/ttydraw.h" // The canvas used for drawing ascii-art graphics. extern caca_canvas_t *cv; diff --git a/extract.sh b/extract.sh index 0a419bd..08ee3d9 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 @@ -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,12 @@ 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 -m 0644 "${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 -m 0755 -d "${ETC}" +install -m 0644 "l123set.cf" "${ETC}/l123set.cf" echo '==> Copying man page' -install -vDm644 "${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" 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/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 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 cb273f8..7f098b9 100644 --- a/graphics.c +++ b/graphics.c @@ -7,7 +7,7 @@ #include "lottypes.h" #include "lotdefs.h" #include "lotfuncs.h" -#include "ttydraw.h" +#include "ttydraw/ttydraw.h" #include "graphics.h" #include "draw.h" diff --git a/gzip.sh b/gzip.sh index d066fe9..5ca7cac 100755 --- a/gzip.sh +++ b/gzip.sh @@ -6,49 +6,48 @@ 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 +# Make sure we have GNU make +. "$ORIGIN_DIR/detect-gnu-make.sh" # 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 -f "$ORIGIN_DIR/gzip" "$ORIGIN_DIR/gunzip" "$ORIGIN_DIR/zcat" + rm -rf "$GZIP_DIR" + rm -f "$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 && "$gnu_make" + cd "$ORIGIN_DIR" fi # Copy compiled binaries to working directory. copy() { - test ! -x "$2" && cp -v "$1" "$2" + test ! -x "$2" && cp "$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" diff --git a/install-keymap.sh b/install-keymap.sh new file mode 100755 index 0000000..38c741d --- /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 -m 755 -d "$KEYMAPS_DIR/$c" +keymap/keymap "$1" > "$KEYMAPS_DIR/$c/$1" diff --git a/keymap/Makefile b/keymap/Makefile index 3120704..220776a 100644 --- a/keymap/Makefile +++ b/keymap/Makefile @@ -1,4 +1,4 @@ -LDLIBS = -lncurses -ltinfo +LDLIBS != ../ncurses-config.sh CFLAGS = -ggdb3 -O0 CPPFLAGS = -W -Wall -Wno-missing-field-initializers -Wno-sign-compare -Wno-unused-parameter .PHONY: clean @@ -6,4 +6,4 @@ CPPFLAGS = -W -Wall -Wno-missing-field-initializers -Wno-sign-compare -Wno-unuse all: keymap clean: - $(RM) *.o keymap + rm -f *.o keymap diff --git a/localize.lst b/localize.lst index 3820ade..1e6cff3 100644 --- a/localize.lst +++ b/localize.lst @@ -21,6 +21,7 @@ pclose fdopen fprintf fscanf +fwrite freopen fwrite sys_errlist diff --git a/main.c b/main.c index fba31d1..d623f15 100644 --- a/main.c +++ b/main.c @@ -6,7 +6,6 @@ #include #include #include -#include #include #include "lottypes.h" diff --git a/ncurses-config.sh b/ncurses-config.sh new file mode 100755 index 0000000..899fdd5 --- /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)" +elif command -v pkg-config > /dev/null; then + pkgcfglibs="$(pkg-config --libs ncurses 2>/dev/null)" + if [ "$?" -eq 0 -a -n "$pkgcfglibs" ]; then + nclibs="$pkgcfglibs" + fi +fi +echo "$nclibs" diff --git a/patch.c b/patch.c index 3d6cfbb..e797b89 100644 --- a/patch.c +++ b/patch.c @@ -1,6 +1,6 @@ +#include #include #include -#include #include #include "lottypes.h" 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 diff --git a/undefine.freebsd b/undefine.freebsd new file mode 100644 index 0000000..9926833 --- /dev/null +++ b/undefine.freebsd @@ -0,0 +1,260 @@ +_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 +init_showme 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/undefine.openbsd b/undefine.openbsd new file mode 100644 index 0000000..77e6b54 --- /dev/null +++ b/undefine.openbsd @@ -0,0 +1,232 @@ +_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 +creat +ctermid +ctime +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 +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 +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 +ttyslot +twalk +tzname +tzset +umask +uname +ungetc +unlink +utime +vfprintf +vprintf +vsprintf +wait +write +close +tgetent +tgetstr +tgetflag +tgetnum +tgoto +tputs +tmpfile +chown +msgctl +semctl +shmctl +fstat64 +stat64 +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 +fabs +kbd_term +set_raw_mode +ustat +init_showme +setup_screen_mem diff --git a/wrappers.c b/wrappers.c index ca2e3e1..d796283 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,8 +409,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_reclen = lent->d_reclen; uent.d_type = lent->d_type; strncpy(uent.d_name, lent->d_name, sizeof uent.d_name); return &uent; @@ -417,7 +419,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 @@ -426,10 +428,10 @@ sighandler_t __unix_signal(int signum, sighandler_t handler) [16] = SIGUSR1, [17] = SIGUSR2, [18] = SIGCHLD, - [19] = SIGPWR, + [19] = SIGCONT, [20] = SIGWINCH, [21] = SIGURG, - [22] = SIGPOLL, + [22] = SIGTTOU, [23] = SIGSTOP, [24] = SIGTSTP, [25] = SIGCONT,