From a42d0671b17a68b19c347a17dfd4a8069e854885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Fri, 3 Jun 2022 18:44:58 +0200 Subject: [PATCH 1/2] New unified directory structure This is to simplify supporting both developer/portable installation and system-wide installation with default config --- Makefile | 17 +++++++------ README.md | 6 ++--- extract | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ extract.sh | 37 ---------------------------- filemap.c | 14 +++++++---- l123set.cf | 2 +- 6 files changed, 94 insertions(+), 54 deletions(-) create mode 100755 extract delete mode 100755 extract.sh diff --git a/Makefile b/Makefile index 3c7fca3..261cd8b 100644 --- a/Makefile +++ b/Makefile @@ -19,9 +19,9 @@ export BFD_TARGET_ERROR .PHONY: clean check -all: check 123 keymaps - @file 123 - @size 123 +all: check bin/123 keymaps + @file bin/123 + @size bin/123 check: @objdump --info | egrep -q '^coff-i386$$' || (echo "$$BFD_TARGET_ERROR"; exit 1) @@ -45,7 +45,8 @@ ttydraw/ttydraw.a: atfuncs/atfuncs.a: $(MAKE) -C atfuncs -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) keymap/keymap: @@ -53,15 +54,15 @@ keymap/keymap: # This generates the keymaps in a seperate directory based on the first letter. $(sort $(KEYMAPS)): keymap/keymap - mkdir -p keymaps/$(shell printf "%c" $@) - keymap/keymap $@ > keymaps/$(shell printf "%c" $@)/$@ + mkdir -p share/lotus/keymaps/$(shell printf "%c" $@) + keymap/keymap $@ > share/lotus/keymaps/$(shell printf "%c" $@)/$@ keymaps: $(KEYMAPS) clean: - $(RM) *.o 123 coffsyrup + $(RM) *.o bin/123 coffsyrup $(RM) vgcore.* core.* core - $(RM) -r keymaps + $(RM) -r share/lotus/keymaps $(MAKE) -C ttydraw clean $(MAKE) -C atfuncs clean $(MAKE) -C keymap clean diff --git a/README.md b/README.md index a4ed8ab..19bb4d5 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Run the included `binutils.sh` to download and compile a version of binutils kno Secondly, you need a copy of Lotus 1-2-3 for UNIX, you can download it [here](https://archive.org/details/123-unix). Just place the raw disk images in -the build directory and run `extract.sh`. +the build directory and run `extract`. Finally, just run `make`. @@ -58,13 +58,13 @@ The Makefile should automatically use the new binaries, and continue to build. ## Running -Just run `./123`. +Just run `bin/123`. ### Getting Started There is a quick start guide in the wiki [here](https://github.com/taviso/123elf/wiki/Getting-Started), and the full manual can be seen here [here](https://archive.org/details/lotus-1-2-3-release-3.1-reference/Lotus%201-2-3%20Release%203.1%20-%20Tutorial). -There is a man page in `./root/lotus/man/man1/123.1` that describes the command line options. +There is a man page in `share/man/man1/123.1` that describes the command line options. Lotus 1-2-3 has context sensitive online help, you can press F1 at most times to see some hints. diff --git a/extract b/extract new file mode 100755 index 0000000..2ae2a30 --- /dev/null +++ b/extract @@ -0,0 +1,72 @@ +#!/bin/sh +# +# Extract the necessary files from Lotus 1-2-3 UNIX +# +BASE="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)" +IMG="${BASE}" +ROOT="${BASE}/share" +ORIG="${BASE}/orig" +ETC="${BASE}/etc" +LOTUS="${ROOT}/lotus/123.v10" + +CPIO="$(command -v cpio)" +TAR="$(command -v tar)" + +if [ "$1" = 'clean' ]; then + rm -rfv "${ROOT}" "${ORIG}" "${ETC}" + exit +fi + +# Use any tools placed in this directory first. +export PATH="${BASE}:$PATH" + +if ! test -f "${IMG}/123UNIX1.IMG" \ + -a -f "${IMG}/123UNIX2.IMG" \ + -a -f "${IMG}/123UNIX3.IMG" \ + -a -f "${IMG}/123UNIX4.IMG" \ + -a -f "${IMG}/123UNIX5.IMG"; then + echo >&2 'You need to download the original 1-2-3 UNIX IMG files.' + echo >&2 'They are available here: https://archive.org/download/123-unix' + exit 1 +fi + +mkdir "${ROOT}" +mkdir "${ORIG}" +mkdir "${ETC}" + +cd "${ROOT}" +echo '==> Extracting 123UNIX1.IMG tar archive' +"${TAR}" xvf "${IMG}/123UNIX1.IMG" +echo '==> Extracting 123UNIX2.IMG cpio archive' +"${CPIO}" -idv < "${IMG}/123UNIX2.IMG" +echo '==> Extracting 123UNIX3.IMG cpio archive' +"${CPIO}" -idv < "${IMG}/123UNIX3.IMG" +echo '==> Seeking into 123UNIX4.IMG to extract cpio archive' +dd if="${IMG}/123UNIX4.IMG" skip=1 bs=550536 | "${CPIO}" -idv +echo '==> Extracting 123UNIX5.IMG cpio archive' +"${CPIO}" -idv < "${IMG}/123UNIX5.IMG" +cd - > /dev/null + +echo '==> Uncompressing .z files' +find "${ROOT}" -iname '*.z' -exec gunzip --force {} \; + +echo '==> Uncompressing and copying object files' +cat "${LOTUS}"/sysV386/lib/123.o.z_1 "${LOTUS}"/sysV386/lib/123.o.z_2 | zcat > "${ORIG}/123.o" +cp "${LOTUS}"/sysV386/lib/*.o "${ORIG}/" + +echo '==> Installing better keymaps' +for t in xterm xterm-256color; do + cp -v "${BASE}/xterm" "${LOTUS}/keymaps/$(echo "${t}" | cut -c1)/${t}" +done +if [ ! -f "${LOTUS}/keymaps/$(echo "${TERM}" | cut -c1)/${TERM}" ]; then + cp -v "${BASE}/xterm" "${LOTUS}/keymaps/$(echo "${TERM}" | cut -c1)/${TERM}" +fi + +echo '==> Copying the banner template over' +install -vDm644 "${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" + +echo '==> Copying man page' +install -vDm644 "${ROOT}/lotus/man/man1/123.1" "${ROOT}/man/man1/123.1" diff --git a/extract.sh b/extract.sh deleted file mode 100755 index e40e41a..0000000 --- a/extract.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash -# -# Extract the necessary files from Lotus 1-2-3 UNIX -# - -LOTUS=root/lotus/123.v10 - -# Use any tools placed in this directory first. -export PATH=.:$PATH - -if ! test -f 123UNIX1.IMG \ - -a -f 123UNIX2.IMG \ - -a -f 123UNIX3.IMG \ - -a -f 123UNIX4.IMG \ - -a -f 123UNIX5.IMG; then - printf "You need to download the original 1-2-3 UNIX IMG files.\n" 1>&2 - printf "They are available here: https://archive.org/download/123-unix\n" 1>&2 - exit 1 -fi - -mkdir root -mkdir orig - -tar -C root -xf 123UNIX1.IMG - -for i in 123UNIX{2..5}.IMG; do - cpio -D root -id < ${i} -done - -find root -iname '*.z' -exec gunzip {} --force \; - -cat ${LOTUS}/sysV386/lib/123.o.z_? | gzip -d > orig/123.o - -cp ${LOTUS}/sysV386/lib/*.o orig/ - -# Copy the banner template over -cp root/usr/tmp/lotus_install/123/banner ${LOTUS}/ri/USA-English/123ban.ri diff --git a/filemap.c b/filemap.c index 83efefb..a04b367 100644 --- a/filemap.c +++ b/filemap.c @@ -9,17 +9,21 @@ // Figure out where our runtime files are located. static const char *get_lotus_runtimefile(const char *file) { - static char procpath[PATH_MAX]; - static char filepath[PATH_MAX]; static char *lotusdir; + static char exepath[PATH_MAX]; + static char *exedir; + static char filepath[PATH_MAX]; + static char localpath[PATH_MAX]; // Cache this path so it only has to be looked up once. if (lotusdir == NULL) { - if (readlink("/proc/self/exe", procpath, PATH_MAX) == -1) { + if (readlink("/proc/self/exe", exepath, PATH_MAX) == -1) { err(EXIT_FAILURE, "Failed to determine the lotus root directory"); } // Figure out the containing directory from the exe path. - lotusdir = dirname(procpath); + exedir = dirname(exepath); + snprintf(localpath, PATH_MAX, "%s/%s", exedir, "../share/lotus"); + lotusdir = localpath; } // Append the requested filename, obviously this is not reentrant, but 123 @@ -50,7 +54,7 @@ const char * map_unix_pathname(const char *unixpath) // we can map it to the default configuration file instead, which // is the directory where 123 is located. if (access(unixpath, F_OK) != 0) { - return get_lotus_runtimefile("l123set.cf"); + return get_lotus_runtimefile("../../etc/l123set.cf"); } } diff --git a/l123set.cf b/l123set.cf index 69b3b92..1cda7ef 100644 --- a/l123set.cf +++ b/l123set.cf @@ -1,5 +1,5 @@ 1001 Lotus 1-2-3 Version "10" -1002 Base Directory "/{LOTUSROOT}/root/lotus" +1002 Base Directory "/{LOTUSROOT}" 1003 Printer Interface "lpr -o dest={dest} {file}" 1004 Graphics Driver "dumb" "ega egas25cc.vbd" 1007 Help Language "USA English" "USA-English" From ea6d103546408f94fa6cb22412e7a87c832c0717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20Vrzi=C4=87?= Date: Fri, 3 Jun 2022 19:01:05 +0200 Subject: [PATCH 2/2] Default config in ${PREFIX}/share/lotus/etc/l123set.cf --- extract | 3 +-- filemap.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/extract b/extract index 2ae2a30..5e5aaab 100755 --- a/extract +++ b/extract @@ -6,7 +6,7 @@ BASE="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)" IMG="${BASE}" ROOT="${BASE}/share" ORIG="${BASE}/orig" -ETC="${BASE}/etc" +ETC="${ROOT}/lotus/etc" LOTUS="${ROOT}/lotus/123.v10" CPIO="$(command -v cpio)" @@ -32,7 +32,6 @@ fi mkdir "${ROOT}" mkdir "${ORIG}" -mkdir "${ETC}" cd "${ROOT}" echo '==> Extracting 123UNIX1.IMG tar archive' diff --git a/filemap.c b/filemap.c index a04b367..e86c6ef 100644 --- a/filemap.c +++ b/filemap.c @@ -54,7 +54,7 @@ const char * map_unix_pathname(const char *unixpath) // we can map it to the default configuration file instead, which // is the directory where 123 is located. if (access(unixpath, F_OK) != 0) { - return get_lotus_runtimefile("../../etc/l123set.cf"); + return get_lotus_runtimefile("etc/l123set.cf"); } }