From e0d4b986558c3cf3e25e509e65f2902efce5ef56 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Thu, 6 Jul 2023 05:48:47 -0700 Subject: [PATCH] Fixes to 2001/herrmann1 The script herrmann1.sh invoked the program itself which is not needed and would in fact invoke it during compilation as the script is what compiles the program. The program is to be invoked via the script itself but the script also compiles the program as well. Fixed the script for shellcheck. Note that there still is a problem in that with older gcc versions it's supposed to animate on compilation but this no longer works. See the bugs.md for details. --- 2001/herrmann1/herrmann1.sh | 22 ++++++++---------- thanks-for-fixes.md | 46 ++++++++++++++++++++++++------------- 2 files changed, 40 insertions(+), 28 deletions(-) diff --git a/2001/herrmann1/herrmann1.sh b/2001/herrmann1/herrmann1.sh index 8af2b39c6..891311154 100755 --- a/2001/herrmann1/herrmann1.sh +++ b/2001/herrmann1/herrmann1.sh @@ -3,27 +3,25 @@ name=herrmann1 # Make sure things are clean to start with... -rm -f ${name} ${name}-1.c ${name}-2.c ${name}-3.c +rm -f "${name}" "${name}-1.c" "${name}-2.c" "${name}-3.c" defs="" for p in ${1+"$@"}; do defs="$defs \"-D$p\"" done -cp ${name}.c ${name}-1.c -touch ${name}-3.c +cp "${name}.c" "${name}-1.c" +touch "${name}-3.c" -until cmp -s ${name}-1.c ${name}-3.c > /dev/null; do - eval ${CC:-cc} -E ${name}-1.c -o ${name}-2.c -P $defs 2> error || exit - mv -f ${name}-1.c ${name}-3.c +until cmp -s "${name}-1.c" "${name}-3.c" > /dev/null; do + eval "${CC:-cc}" -E "${name}-1.c" -o "${name}-2.c" -P "$defs" 2> error || exit + mv -f "${name}-1.c" "${name}-3.c" sed -e 's/ */ /g' -e 's/^ //' -e '/^$/ d' -e 's:^/ \*:/*:' \ - < ${name}-2.c > ${name}-1.c - head ${name}-1.c + < "${name}-2.c" > "${name}-1.c" + head "${name}-1.c" done -eval ${CC:-cc} ${name}-1.c -o ${name} 2> error && rm error - -eval ./${name} +eval "${CC:-cc}" "${name}-1.c" -o "${name}" 2> error && rm error # Clean up intermediates... -rm -f ${name}-1.c ${name}-2.c ${name}-3.c +rm -f "${name}-1.c" "${name}-2.c" "${name}-3.c" diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index 26b18dfe9..17410c4b3 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -910,17 +910,33 @@ He also points out that there is a way to get the computer to automatically lose very quickly and he also points out that there is a flaw in the alternate version that the author did not note. Do you know what these are? +## [2001/herrmann1](2001/herrmann1/herrmann1.c) ([README.md](2001/herrmann1/README.md])) + +Cody fixed this so that the when compiling the code the program is not executed +itself by itself which just showed the usage string and exited. The [script +herrmann1.sh](2001/herrmann1/herrmann1.sh) is used to compile the program but +it's also how you invoke the program. + +He also fixed the [script herrmann1.sh](2001/herrmann1/herrmann1.sh) for +shellcheck. In particular there were quite a few: + + +``` +SC2086 (info): Double quote to prevent globbing and word splitting. +SC2248 (style): Prefer double quoting even when variables don't contain special characters. +``` + +errors/warnings. ## [2001/herrmann2](2001/herrmann2/herrmann2.c) ([README.md](2001/herrmann2/README.md])) -Cody fixed this to work with -both 64-bit and 32-bit compiles by changing most of the `int`s (all but that in -`main`) to `long`s. He also fixed it to compile with clang by changing the args -of main to be `int` and `char **` respectively and changing specific references -to the `argv` arg, casting to `long` (was `int` but the 64-bit fix requires -`long`) which was its old type. The original file, used for demonstration -purposes, as well as if you want to see if your system works with the original -code, is the alternate version. See the README.md for details. +Cody fixed this to work with both 64-bit and 32-bit compiles by changing most of +the `int`s (all but that in `main`) to `long`s. He also fixed it to compile with +clang by changing the args of main to be `int` and `char **` respectively and +changing specific references to the `argv` arg, casting to `long` (was `int` but +the 64-bit fix requires `long`) which was its old type. The original file, used +for demonstration purposes, as well as if you want to see if your system works +with the original code, is the alternate version. See the README.md for details. ## [2001/kev](2001/kev/kev.c) ([README.md](2001/kev/README.md])) @@ -958,14 +974,12 @@ int and the rest must be a `char **`. ## [2004/gavin](2004/gavin/gavin.c) ([README.md](2004/gavin/README.md])) -Yusuke provided the `kernel` and `fs.tar` -files which can be used if you cannot normally use this entry. Instead of -generating the files just use the files provided, found under the -[img/](2004/gavin/img/) -directory. Note that the `img/fs.tar` extracts into `fs/` so you will have to -fix the tarball; this is done this way to prevent extraction from the entry -directory overwriting the files and causing `make clobber` to wipe some of them -out. +Yusuke provided the `kernel` and `fs.tar` files which can be used if you cannot +normally use this entry. Instead of generating the files just use the files +provided, found under the [img/](2004/gavin/img/) directory. Note that the +`img/fs.tar` extracts into `fs/` so you will have to fix the tarball; this is +done this way to prevent extraction from the entry directory overwriting the +files and causing `make clobber` to wipe some of them out. ## [2004/kopczynski](2004/kopczynski/kopczynski.c) ([README.md](2004/kopczynski/README.md]))