From c2b720f8746fc36ae221387a05a5b72b996cca50 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sat, 11 Nov 2023 04:44:45 -0800 Subject: [PATCH] Add try.sh and try.alt.sh to 1996/westley These scripts simplify running the three other scripts (that the author provided, renamed to have the extension '.sh') to show the three styles of clocks with both the fixed (for modern systems) version and the original version (the alt code). The README.md file has been format and typo checked. This should complete 1996/westley. --- 1996/westley/Makefile | 5 +-- 1996/westley/README.md | 57 ++++++++++++++---------------- 1996/westley/{clock1 => clock1.sh} | 0 1996/westley/{clock2 => clock2.sh} | 0 1996/westley/{clock3 => clock3.sh} | 0 1996/westley/try.alt.sh | 14 ++++++++ 1996/westley/try.sh | 14 ++++++++ thanks-for-fixes.md | 7 ++++ 8 files changed, 65 insertions(+), 32 deletions(-) rename 1996/westley/{clock1 => clock1.sh} (100%) rename 1996/westley/{clock2 => clock2.sh} (100%) rename 1996/westley/{clock3 => clock3.sh} (100%) create mode 100755 1996/westley/try.alt.sh create mode 100755 1996/westley/try.sh diff --git a/1996/westley/Makefile b/1996/westley/Makefile index 66153ed4e..2e228c899 100644 --- a/1996/westley/Makefile +++ b/1996/westley/Makefile @@ -39,7 +39,8 @@ include ../../var.mk # Common C compiler warnings to silence # CSILENCE= -Wno-char-subscripts -Wno-error -Wno-implicit-function-declaration \ - -Wno-int-to-pointer-cast -Wno-empty-body -Wno-deprecated-non-prototype + -Wno-int-to-pointer-cast -Wno-empty-body -Wno-deprecated-non-prototype\ + -Wno-implicit-int # Common C compiler warning flags # @@ -109,7 +110,7 @@ ENTRY= westley PROG= ${ENTRY} # OBJ= ${PROG}.o -DATA= clock1 clock2 clock3 +DATA= clock1.sh clock2.sh clock3.sh TARGET= ${PROG} # ALT_OBJ= westley.alt.o diff --git a/1996/westley/README.md b/1996/westley/README.md index 32243c253..14af157f2 100644 --- a/1996/westley/README.md +++ b/1996/westley/README.md @@ -4,51 +4,46 @@ make all ``` +There is another version which is the original entry. See [alternate +version](#alternate-code) for details as to how to use and why it was made the +alt version. + ## To use: ```sh -sh ./clock1 +./clock1.sh +./clock2.sh +./clock3.sh ``` -NOTE: the original version had a display problem in modern systems which -somewhat affected the usability of the program. See the Alternate code section -for details on the original version. - ### Try: ```sh -sh ./clock2 -``` - - -And for a good time, try: - -```sh -sh ./clock3 +./try.sh ``` ## Alternate code: -An alternate version of this entry, [westley.alt.c](westley.alt.c), is provided. -This version is the original code and does not contain the above mentioned -fixes. +The original version had a display problem in modern systems which somewhat +affected the usability of the program. This alternate code, the original, is +provided, to show the differences. + +### Alternate build: -To compile this alternate version: ```sh make alt ``` -To use it with the scripts try: + +### Alternate try: ```sh -WESTLEY=./westley.alt ./clock1 -WESTLEY=./westley.alt ./clock2 -WESTLEY=./westley.alt ./clock3 +./try.alt.sh ``` @@ -66,7 +61,8 @@ This 1-line program allows various analog ASCII clocks to print out the time; the ASCII clock is built from the command line arguments, so many different types of clocks can be generated. Three different scripts are supplied to print out a grandfather clock, a mantle clock that runs backwards, and a linear-style -clock. (they are `clock1`, `clock2`, and `clock3`) +clock. (they are [clock1.sh](clock1.sh), [clock2.sh](clock2.sh), and +[clock3.sh](clock3.sh)) The program makes the following (possibly non-portable) assumptions: @@ -74,8 +70,8 @@ The program makes the following (possibly non-portable) assumptions: 2. `argv[0]` can be written to as if it were a `long *`. -3. The first three elements of the struct * returned by localtime() are seconds, -minutes, hours, and all are ints. +3. The first three elements of the `struct *` returned by `localtime(3)` are +seconds, minutes, hours, and all are `int`s. 4. My sample scripts assume ASCII, though this is not inherent in the code, just my sample scripts. @@ -83,6 +79,7 @@ my sample scripts. These assumptions are pretty reasonable. 2) can be eliminated but makes the code larger. + The code is simple; the arguments passed are: ```sh @@ -94,14 +91,14 @@ values, looks up the offsets in `minute_map` and `hour_map` and writes the `hand_symbol` for each into the `clock_image` string. This string is then printed. -The for() loop starts by calling `time()` with `argv[0]`, so -the time value (a long) is written into the program name. -The for() control value is `argc`, which starts at `5`, but -the `/=2` statement is executed before the test, so the for() +The `for()` loop starts by calling `time()` with `argv[0]`, so +the time value (a `long`) is written into the program name. +The `for()` control value is `argc`, which starts at `5`, but +the `/=2` statement is executed before the test, so the `for()` loop is executed twice, with `h=2`, then `h=1` (for hour & minute). -The statement of the for() loop takes the hour or minute -field of the struct returned by `localtime()` by casting it +The statement of the `for()` loop takes the hour or minute +field of the struct returned by `localtime(3)` by casting it to an `int *` and dereferencing element `[h]`. It is slightly smaller to use the trick `h[(int*)localtime(*m)]` instead of `((int*)localtime(*m))[h]`. diff --git a/1996/westley/clock1 b/1996/westley/clock1.sh similarity index 100% rename from 1996/westley/clock1 rename to 1996/westley/clock1.sh diff --git a/1996/westley/clock2 b/1996/westley/clock2.sh similarity index 100% rename from 1996/westley/clock2 rename to 1996/westley/clock2.sh diff --git a/1996/westley/clock3 b/1996/westley/clock3.sh similarity index 100% rename from 1996/westley/clock3 rename to 1996/westley/clock3.sh diff --git a/1996/westley/try.alt.sh b/1996/westley/try.alt.sh new file mode 100755 index 000000000..0adf8e87c --- /dev/null +++ b/1996/westley/try.alt.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +make everything 1>/dev/null || exit 1 + +echo "Showing alt grandfather clock:" 1>&2 +WESTLEY=./westley.alt ./clock1.sh +read -r -n 1 -p "Press any key to continue: " 1>&2 + +echo "Showing alt mantle clock that runs backwards:" 1>&2 +WESTLEY=./westley.alt ./clock2.sh +read -r -n 1 -p "Press any key to continue: " 1>&2 + +echo "Showing alt linear style clock:" 1>&2 +WESTLEY=./westley.alt ./clock3.sh diff --git a/1996/westley/try.sh b/1996/westley/try.sh new file mode 100755 index 000000000..8dea325ff --- /dev/null +++ b/1996/westley/try.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +make everything 1>/dev/null || exit 1 + +echo "Showing grandfather clock:" 1>&2 +WESTLEY=./westley ./clock1.sh +read -r -n 1 -p "Press any key to continue: " 1>&2 + +echo "Showing mantle clock that runs backwards:" 1>&2 +WESTLEY=./westley ./clock2.sh +read -r -n 1 -p "Press any key to continue: " 1>&2 + +echo "Showing linear style clock:" 1>&2 +WESTLEY=./westley ./clock3.sh diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index fe9604438..2741dfe03 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -1980,6 +1980,13 @@ Note that you should check the [westley.alt.c](1996/westley/westley.alt.c) file when reading the author's comments. To see how to use the original, see the README.md file. +Cody also added the two scripts, [try.sh](1996/westley/try.sh) and +[try.alt.sh](1996/westley/try.alt.sh) to show automate showing the different +clocks, both with the fixed version and the original (alt) version. + +Also, to fix any potential problem with displaying in GitHub the scripts +provided by the author, Cody added '.sh'. + ## [1998/chaos](1998/chaos/chaos.c) ([README.md](1998/chaos/README.md]))