From e60815bdb36b3a9e90631f70427703566a45a76c Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sat, 27 Jan 2024 08:55:51 -0800 Subject: [PATCH 01/19] Improve try section of 2013/endoh2 Don't cat jpeg.c as it's longer than a page. Use less(1) instead. --- 2013/endoh2/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2013/endoh2/README.md b/2013/endoh2/README.md index ff5878802..5b095666e 100644 --- a/2013/endoh2/README.md +++ b/2013/endoh2/README.md @@ -24,7 +24,7 @@ download one or both before exiting. ## Try: ```sh -cat jpeg.c +less jpeg.c ``` Next look at `jpeg.jpg` in an image viewer program. From 6f20a57493ab61cf779882a0abeb6e9520ea9208 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sat, 27 Jan 2024 10:25:15 -0800 Subject: [PATCH 02/19] Add 2013/endoh3/try.sh The script checks for SoX, padsp and otherwise ruby. It allows one to pass in args: each one is first checked to be a readable file and if it is it'll be processed as a file; otherwise it'll be processed as a string. If no arg is specified it runs the program on twinkle.abc and the strings ABC and CDEFGABc (the latter suggested by the author). If none of the three tools noted above are installed it tells the user to install one of them first. I was not able to test the padsp(1) one but the invocation matches the author's remarks. /dev/dsp seems to not be installed in modern linux systems so it would be useful to have padsp(1) if not SoX (which is preferable in general for entries that play sound). The ruby script wavify.rb provided by the author is the last resort which turns the output to a WAV file. --- 2013/endoh3/.gitignore | 1 + 2013/endoh3/Makefile | 2 +- 2013/endoh3/README.md | 27 +++++++--- 2013/endoh3/endoh3.c | 2 +- 2013/endoh3/try.sh | 116 +++++++++++++++++++++++++++++++++++++++++ thanks-for-help.md | 8 +++ 6 files changed, 146 insertions(+), 10 deletions(-) create mode 100755 2013/endoh3/try.sh diff --git a/2013/endoh3/.gitignore b/2013/endoh3/.gitignore index fbe1fd107..a86f8b31b 100644 --- a/2013/endoh3/.gitignore +++ b/2013/endoh3/.gitignore @@ -7,3 +7,4 @@ indent indent.c indent.o prog.orig +*.wav diff --git a/2013/endoh3/Makefile b/2013/endoh3/Makefile index f419e61bf..41622f97f 100644 --- a/2013/endoh3/Makefile +++ b/2013/endoh3/Makefile @@ -39,7 +39,7 @@ include ../../var.mk # Common C compiler warnings to silence # CSILENCE= -Wno-error -Wno-implicit-function-declaration -Wno-implicit-int \ - -Wno-main -Wno-deprecated-non-prototype + -Wno-main -Wno-deprecated-non-prototype -Wno-unused-parameter # Common C compiler warning flags # diff --git a/2013/endoh3/README.md b/2013/endoh3/README.md index b330ca946..ca7d055ae 100644 --- a/2013/endoh3/README.md +++ b/2013/endoh3/README.md @@ -22,21 +22,32 @@ For more detailed information see [2013 endoh3 in bugs.md](/bugs.md#2013-endoh3) ./endoh3 ``` +This program plays sound. See [FAQ 3.10 - How do I compile and use an IOCCC +winner that requires sound?](/faq.md#faq3_10) if you do not know how to set your +system up for this or if you want to verify that everything is oky. + ## Try: -Trying this out will depend on how your system can play sounds. The author's -remarks include some options for different operating systems. - -The simplest way is to create a .wav file and have your system play that. - ```sh -echo 'CDEFGABc' | ./endoh3 | ruby wavify.rb > cde.wav +./try.sh + +./try.sh ABC + +./try.sh test.abc yankee.abc + +./try.sh *.abc ``` -Observe how you will need ruby installed. +The script will check for SoX first and next `padsp` from `PulseAudio` and +finally if neither are found if you have `ruby(1)` installed it'll use the +included ruby script to convert it to a WAV file for you to play. -There are also some other musical samples, twinkle.abc and menuet.abc. +If no args are passed to the script it will play [twinkle.abc](twinkle.abc) and +the string `ABC`. Otherwise while there's a remaining arg if it's a file it will +run the program on the file. If it's not a file it'll run it as a string. + +The `*.abc` files are provided as music samples. ## Judges' remarks: diff --git a/2013/endoh3/endoh3.c b/2013/endoh3/endoh3.c index ef1a255a1..dfdd552db 100644 --- a/2013/endoh3/endoh3.c +++ b/2013/endoh3/endoh3.c @@ -1 +1 @@ -char a;float b,c;main(d){for(;d>2e3*c?c=1,scanf(" %c%f",&a,&c),d=55-a%32*9/5,b=d>9,d=d%13-a/32*12:1;a=2)++d<24?b*=89/84.:putchar(a=b*d);} \ No newline at end of file +char a;float b,c;main(d,e)char**e;{for(;d>2e3*c?c=1,scanf(" %c%f",&a,&c),d=55-a%32*9/5,b=d>9,d=d%13-a/32*12:1;a=2)++d<24?b*=89/84.:putchar(a=b*d);} diff --git a/2013/endoh3/try.sh b/2013/endoh3/try.sh new file mode 100755 index 000000000..02606cd4c --- /dev/null +++ b/2013/endoh3/try.sh @@ -0,0 +1,116 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 2013/endoh3 +# + +# make sure CC is set so that when we do make CC="$CC" it isn't empty. Doing it +# this way allows us to have the user specify a different compiler in an easy +# way. +if [[ -z "$CC" ]]; then + CC="cc" +fi + +make CC="$CC" all >/dev/null || exit 1 + +# clear screen after compilation so that only the entry is shown +clear + +# Because there are numerous ways to run this entry we check for different tools +# being installed in order to determine how to proceed. Even so /dev/dsp seems +# to be uninstalled in modern systems so we check for what the author suggested +# with that but only if the other options won't work (like SoX not installed). +# +SOX="$(type -P sox)" +PADSP="$(type -P padsp)" +RUBY="$(type -P ruby)" + +endoh3() +{ + if [[ "$#" -ne 1 ]]; then + echo "$0: endoh3() requires one arg, got: $#" 1>&2 + return + fi + if [[ -f "$1" && -r "$1" ]]; then + if [[ -n "$SOX" ]]; then + echo "$ cat $1 | ./endoh3 | $SOX -q -traw -r8000 -b8 -e unsigned-integer - -tcoreaudio" 1>&2 + read -r -n 1 -p "Press any key to continue: " + echo 1>&2 + # The author suggested the form below and it simplifies the command + # as well so we disable the supposed useless cat (there are no + # useless cats). + # + # SC2002 (style): Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. + # https://www.shellcheck.net/wiki/SC2002 + # shellcheck disable=SC2002 + cat "$1" | ./endoh3 | "$SOX" -q -traw -r8000 -b8 -e unsigned-integer - -tcoreaudio + echo 1>&2 + elif [[ -n "$PADSP" ]]; then + echo "$ cat $1 | ./endoh3 | $PADSP tee /dev/dsp > /dev/null" 1>&2 + read -r -n 1 -p "Press any key to continue: " + echo 1>&2 + # The author suggested the form below and it simplifies the command + # as well so we disable the supposed useless cat (there are no + # useless cats). + # + # SC2002 (style): Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. + # https://www.shellcheck.net/wiki/SC2002 + # shellcheck disable=SC2002 + cat "$1" | ./endoh3 | "$PADSP" tee /dev/dsp > /dev/null + echo 1>&2 + elif [[ -n "$RUBY" ]]; then + echo "$ cat $1 | ./endoh3 | $RUBY wavify.rb > $1.wav" 1>&2 + read -r -n 1 -p "Press any key to continue: " + echo 1>&2 + # The author suggested the form below and it simplifies the command + # as well so we disable the supposed useless cat (there are no + # useless cats). + # + # SC2002 (style): Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. + # https://www.shellcheck.net/wiki/SC2002 + # shellcheck disable=SC2002 + cat "$1" | ./endoh3 | "$RUBY" wavify.rb > "$1".wav + echo "Now try playing $1.wav in a program that plays WAV files." 1>&2 + echo 1>&2 + else + echo "Please install either SoX, ruby or padsp (from PulseAudio)." 1>&2 + exit 1 + fi + else # no file + if [[ -n "$SOX" ]]; then + echo "$ echo $1 | ./endoh3 | $SOX -q -traw -r8000 -b8 -e unsigned-integer - -tcoreaudio" 1>&2 + read -r -n 1 -p "Press any key to continue: " + echo 1>&2 + echo "$1" | ./endoh3 | "$SOX" -q -traw -r8000 -b8 -e unsigned-integer - -tcoreaudio + echo 1>&2 + elif [[ -n "$PADSP" ]]; then + echo "$ echo $1 | ./endoh3 | $PADSP tee /dev/dsp > /dev/null" 1>&2 + read -r -n 1 -p "Press any key to continue: " + echo 1>&2 + echo "$1" | ./endoh3 | "$PADSP" tee /dev/dsp > /dev/null + echo 1>&2 + elif [[ -n "$RUBY" ]]; then + echo "$ echo $1 | ./endoh3 | $RUBY wavify.rb > $1.wav" 1>&2 + read -r -n 1 -p "Press any key to continue: " + echo 1>&2 + echo "$1" | ./endoh3 | "$RUBY" wavify.rb > "$1".wav + echo "Now try playing $1.wav in a program that plays WAV files." 1>&2 + echo 1>&2 + else + echo "Please install either SoX, ruby or padsp (from PulseAudio)." 1>&2 + exit 1 + fi + fi +} + +if [[ "$#" -lt 1 ]]; then + # if we have no arg just run endoh3 with twinkle.abc and the string ABC. + endoh3 twinkle.abc + endoh3 ABC + endoh3 CDEFGABc +else + # otherwise while we have an arg run endoh3 on it as a file or string + while [[ "$#" -gt 0 ]]; do + endoh3 "$1" + shift 1 + done +fi diff --git a/thanks-for-help.md b/thanks-for-help.md index ba05f795d..1d2b540de 100644 --- a/thanks-for-help.md +++ b/thanks-for-help.md @@ -3977,6 +3977,14 @@ not found. The entry can still be enjoyed if you do not have these tools, however. +## [2013/endoh3](/2013/endoh3/endoh3.c) ([README.md](/2013/endoh3/README.md)) + +[Cody](#cody) added the [try.sh](/2013/endoh3/try.sh) script. + +Cody also (out of an abundance of caution for `clang(1)` which is strict with +arg type and count to `main()`) added a second (unused) arg to `main()`. + + ## [2013/endoh4](/2013/endoh4/endoh4.c) ([README.md](/2013/endoh4/README.md)) [Cody](#cody) added the [try.sh](/2013/endoh4/try.sh) script which temporarily From d8fa53cc29c8a56390443d3cc5a8092c0ec79386 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sat, 27 Jan 2024 10:52:18 -0800 Subject: [PATCH 03/19] Improvements to build and script of 2013/endoh4 The Makefile was modified in such a way that allows one to easily redefine the size (in the code the S macro). For instance: make clobber SIZE=50,50 all The try.sh was renamed to endoh4.sh as it's more of a wrapper to the program rather than things to try. Also it now lets one specify more than one file to feed to the program (in sequence). The bugs.md was updated - added INABIAF. If the file format is invalid it will very likely crash. --- 2013/endoh4/Makefile | 6 +++- 2013/endoh4/README.md | 57 ++++++++++++++++++++++++++----- 2013/endoh4/{try.sh => endoh4.sh} | 23 +++++++++---- bugs.md | 9 +++++ thanks-for-help.md | 9 +++-- 5 files changed, 86 insertions(+), 18 deletions(-) rename 2013/endoh4/{try.sh => endoh4.sh} (60%) diff --git a/2013/endoh4/Makefile b/2013/endoh4/Makefile index ded40e601..7111b5cf2 100644 --- a/2013/endoh4/Makefile +++ b/2013/endoh4/Makefile @@ -55,9 +55,13 @@ CSTD= -std=gnu11 # ARCH= +# Variable to simplify redefining size +# +SIZE= 70,23 + # Defines that are needed to compile # -CDEFINE= +CDEFINE= -DS=${SIZE} # Include files that are needed to compile # diff --git a/2013/endoh4/README.md b/2013/endoh4/README.md index a4ca3d20e..7fbe88128 100644 --- a/2013/endoh4/README.md +++ b/2013/endoh4/README.md @@ -4,23 +4,45 @@ make ``` +If you wish to change the size (see the [Author's remarks](#authors-remarks) +below) you can do so with the `SIZE` variable. For instance you can do: + + +```sh +make clobber SIZE=50,50 all +``` + +but you can also do this directly with the [endoh4.sh](endoh4.sh) script as +described below. + + +### Bugs and (Mis)features: + +The current status of this entry is: + +``` +STATUS: INABIAF - please **DO NOT** fix +``` + +For more detailed information see [2013 endoh4 in bugs.md](/bugs.md#2013-endoh4). + ## To use: ```sh ./endoh4 < file -./run.sh file +./endoh4.sh file ``` The second form is preferable as it will temporarily make the cursor invisible -as recommended by the author. If no file is specified in `run.sh` command line -it will feed to the program [endoh4.c](endoh4.c). +as recommended by the author. If no file is specified in the `./endoh4.sh` command +line it will feed to the program [endoh4.c](endoh4.c). ## Try: ```sh -./run.sh cube.txt +./endoh4.sh cube.txt ``` Hit ctrl-c to end the program. @@ -30,14 +52,31 @@ The author recommends the use of xterm. For an example, if you are a football/soccer fan, try: ```sh -./run.sh solids/archimedian-solid/a11-truncated-icosahedron.txt +./endoh4.sh solids/archimedian-solid/a11-truncated-icosahedron.txt ``` +You can provide more than one file: + +```sh +./endoh4.sh solids/archimedian-solid/a11-truncated-icosahedron.txt cube.txt +``` + +Hit ctrl-c/intr to go to the next file. + +If you wish to change the size to `50,50` without passing any arg: + + +```sh +SIZE=50,50 ./endoh4.sh +``` + +Not specifying a file feeds [endoh4.c](endoh4.c) to the program. + ## Judges' remarks: This program is formatted as the net for a tetrahedron (hint: try feeding the -program it's own source code like `./run.sh`). When it runs there is an +program it's own source code like `./endoh4.sh`). When it runs there is an animation for the computation to work out the convex hull. @@ -69,7 +108,7 @@ This simple spec involves many details. ### Portability I think it conforms with both C89 and C99. I confirmed that it worked on gcc, -clang, and tcc. It should not be warned with `-pedantic` and `-Wextra`. +clang, and tcc. It should not trigger warnings with `-pedantic` and `-Wextra`. ### Tips @@ -85,7 +124,7 @@ tput cnorm or ```sh -./run.sh cube.txt +./endoh4.sh cube.txt ``` ### Bonuses @@ -100,7 +139,7 @@ The shape of this code is the geometric net of a regular tetrahedron. So, try: ```sh -./endoh4 < endoh4.c # or ./run.sh +./endoh4 < endoh4.c # or ./endoh4.sh ``` The [solids/](solids/) directory includes various solid data: diff --git a/2013/endoh4/try.sh b/2013/endoh4/endoh4.sh similarity index 60% rename from 2013/endoh4/try.sh rename to 2013/endoh4/endoh4.sh index 82b34f2fc..486bb2e8f 100755 --- a/2013/endoh4/try.sh +++ b/2013/endoh4/endoh4.sh @@ -6,11 +6,13 @@ # make sure CC is set so that when we do make CC="$CC" it isn't empty. Doing it # this way allows us to have the user specify a different compiler in an easy # way. -if [[ -z "$CC" ]]; then - CC="cc" -fi +[[ -z "$CC" ]] && CC="cc" -make CC="$CC" all >/dev/null || exit 1 +# let user redefine size. This requires that we clobber so that they can change +# it each time. +[[ -z "$SIZE" ]] && SIZE=70,23 + +make clobber CC="$CC" SIZE="$SIZE" all >/dev/null || exit 1 # clear screen after compilation so that only the entry is shown clear @@ -23,11 +25,20 @@ trap "tput cnorm;echo" 0 1 2 3 15 tput civis # run program attempting to feed it a file, if specified -if [[ "$#" -eq 1 ]]; then - ./endoh4 < "$1" +if [[ "$#" -gt 0 ]]; then + while [[ "$#" -gt 0 ]]; do + read -r -n 1 -p "Press any key to run: ./endoh4 < $1: " + echo 1>&2 + ./endoh4 < "$1" + echo 1>&2 + shift 1 + done else # otherwise feed the source code of the program to the program + read -r -n 1 -p "Press any key to run: ./endoh4 < endoh4.c: " + echo 1>&2 ./endoh4 < endoh4.c + echo 1>&2 fi # explicitly set cursor back just in case it's not terminated through one of the diff --git a/bugs.md b/bugs.md index aa081950b..25d8d0b16 100644 --- a/bugs.md +++ b/bugs.md @@ -3114,6 +3114,15 @@ A workaround is inserting a whitespace: `C2 E2`. -- +## 2013 endoh4 + +### STATUS: INABIAF - please **DO NOT** fix +### Source code: [2013/endoh4/endoh4.c](2013/endoh4/endoh4.c) +### Information: [2013/endoh4/README.md](2013/endoh4/README.md) + +Invalid input files will very likely crash the program. + + ## 2013 hou diff --git a/thanks-for-help.md b/thanks-for-help.md index 1d2b540de..29c1f390d 100644 --- a/thanks-for-help.md +++ b/thanks-for-help.md @@ -3987,11 +3987,16 @@ arg type and count to `main()`) added a second (unused) arg to `main()`. ## [2013/endoh4](/2013/endoh4/endoh4.c) ([README.md](/2013/endoh4/README.md)) -[Cody](#cody) added the [try.sh](/2013/endoh4/try.sh) script which temporarily +[Cody](#cody) added the [endoh4.sh](/2013/endoh4/endoh4.sh) script which temporarily turns off the cursor as suggested by the author, with the addition that if no file is specified it will feed the source code [endoh4.c](/2013/endoh4/endoh4.c) to the program rather than the file specified. It does not try and detect if the -file exists or can be read as that will be handled by the shell/program. +file exists or can be read as that will be handled by the shell/program. One may +pass more than one file to the script. + +Cody also made it easier to redefine the size at compilation time (see the +author's remarks for more details on what this means). The `endoh4.sh` script +allows one to redefine it as well. ## [2013/hou](/2013/hou/hou.c) ([README.md](/2013/hou/README.md)) From b156b37ef05c73a7ee14b0b5452126b264c486b0 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sat, 27 Jan 2024 11:08:31 -0800 Subject: [PATCH 04/19] Improve 2013/misaka/try.sh --- 2013/misaka/try.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/2013/misaka/try.sh b/2013/misaka/try.sh index f65668d71..4dfc3eea6 100755 --- a/2013/misaka/try.sh +++ b/2013/misaka/try.sh @@ -26,13 +26,13 @@ echo 1>&2 echo 1>&2 rm -f long_cat.txt same_as_long_cat.txt -read -r -n 1 -p "Press any key to run: ./long_cat > long_cat.txt: " +read -r -n 1 -p "Press any key to run: ./long_cat | tee long_cat.txt: " echo 1>&2 -./long_cat > long_cat.txt +./long_cat | tee long_cat.txt echo 1>&2 -read -r -n 1 -p "Press any key to run: ./same_as_long_cat > same_as_long_cat.txt: " +read -r -n 1 -p "Press any key to run: ./same_as_long_cat | tee same_as_long_cat.txt: " echo 1>&2 -./same_as_long_cat > same_as_long_cat.txt +./same_as_long_cat | tee same_as_long_cat.txt echo 1>&2 read -r -n 1 -p "Press any key to run: diff -s long_cat.txt same_as_long_cat.txt: " @@ -65,8 +65,8 @@ echo 1>&2 ./loooooooong_cat | less -EX echo 1>&2 -echo "Press any key to run: seq -f '%.0f ' 45 | ./horizontal_cat - misaka.c" -read -r -n 1 -p "(space = next page, q = quit): " +echo "$ seq -f '%.0f ' 45 | ./horizontal_cat - misaka.c" +read -r -n 1 -p "Press any key to continue (space = next page, q = quit): " echo 1>&2 -seq -f '%.0f ' 45 | ./horizontal_cat - misaka.c | less -EX +seq -f '%.0f ' 45 | ./horizontal_cat - misaka.c | less -rEXFK echo 1>&2 From d4783f02e7d1e96b3c41afab2bf75f6e1b4d0c28 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sat, 27 Jan 2024 11:16:09 -0800 Subject: [PATCH 05/19] Add 2013/morgan1/try.sh --- 2013/morgan1/README.md | 13 +++++-------- 2013/morgan1/try.sh | 36 ++++++++++++++++++++++++++++++++++++ thanks-for-help.md | 2 ++ 3 files changed, 43 insertions(+), 8 deletions(-) create mode 100755 2013/morgan1/try.sh diff --git a/2013/morgan1/README.md b/2013/morgan1/README.md index 10c106721..1b0e00aee 100644 --- a/2013/morgan1/README.md +++ b/2013/morgan1/README.md @@ -8,20 +8,17 @@ make ## To use: ```sh -echo "2013/10/03" | ./morgan1 +echo "YYYY/MM/DD" | ./morgan1 ``` +where `YYYY` is the four digit year, `MM` is the two digit month and `DD` is two +digit day of the month. + ## Try: ```sh -echo "1985/10/28" | ./morgan1 - -echo "1996/12/31" | ./morgan1 - -echo "1986/03/31" | ./morgan1 # Comet Halley (look for 'Ha') - -echo "1997/04/01" | ./morgan1 # Comet Hale-Bopp (look for 'Hb') +./try.sh ``` Try pressing the arrow keys when your focus is in the window. diff --git a/2013/morgan1/try.sh b/2013/morgan1/try.sh new file mode 100755 index 000000000..d90c1cba5 --- /dev/null +++ b/2013/morgan1/try.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 2013/morgan1 +# + +# make sure CC is set so that when we do make CC="$CC" it isn't empty. Doing it +# this way allows us to have the user specify a different compiler in an easy +# way. +if [[ -z "$CC" ]]; then + CC="cc" +fi + +make CC="$CC" all >/dev/null || exit 1 + +# clear screen after compilation so that only the entry is shown +clear + +read -r -n 1 -p "Press any key to run: echo 1985/10/28 | ./morgan1: " +echo 1>&2 +echo "1985/10/28" | ./morgan1 +echo 1>&2 + +read -r -n 1 -p "Press any key to run: echo 1996/12/31 | ./morgan1: " +echo 1>&2 +echo "1996/12/31" | ./morgan1 +echo 1>&2 + +read -r -n 1 -p "Press any key to run: echo 1986/03/31 | ./morgan1 # Comet Halley (look for 'Ha'): " +echo 1>&2 +echo "1986/03/31" | ./morgan1 # Comet Halley (look for 'Ha') +echo 1>&2 + +read -r -n 1 -p "Press any key to run: echo 1997/04/01 | ./morgan1 # Comet Hale-Bopp (look for 'Hb'): " +echo 1>&2 +echo "1997/04/01" | ./morgan1 # Comet Hale-Bopp (look for 'Hb') +echo 1>&2 diff --git a/thanks-for-help.md b/thanks-for-help.md index 29c1f390d..4c3c86c59 100644 --- a/thanks-for-help.md +++ b/thanks-for-help.md @@ -4052,6 +4052,8 @@ Firefox both had the problem. [Cody](#cody) added explicit linking of libm (`-lm`) as not all systems do this implicitly (Linux doesn't seem to but macOS does). +Cody also added the [try.sh](/2013/morgan1/try.sh) script. + ## [2013/robison](/2013/robison/robison.c) ([README.md](/2013/robison/README.md)) From 0120eac02b2725f41e080dd78eea4f1faf819c24 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sat, 27 Jan 2024 11:35:00 -0800 Subject: [PATCH 06/19] Add 2013/hou/try.sh --- 2013/hou/README.md | 15 ++++++--------- 2013/hou/try.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++++ thanks-for-help.md | 2 ++ 3 files changed, 54 insertions(+), 9 deletions(-) create mode 100755 2013/hou/try.sh diff --git a/2013/hou/README.md b/2013/hou/README.md index cacaf70ac..4e2655cbd 100644 --- a/2013/hou/README.md +++ b/2013/hou/README.md @@ -30,17 +30,14 @@ effects should be more or less recognizable when you see 16. ## Try: ```sh -./hou BIG -./hou old_default.scene BIG -./hou otherroom.scene -./hou otherroom.scene NAIVE +./try.sh ``` -Try opening the file and then let the program run a while and every so often -reopen the file, to see how it changes. The author suggests that you leave the -program running overnight to see what happens. If however you do not have all -night :-) then the following JPEG files should show you what happens with some -of the invocations above: +Try opening the file noted by the program then let the program run a while and +every so often reopen the file, to see how it changes. The author suggests that +you leave the program running overnight to see what happens. If however you do +not have all night :-) then the following JPEG files should show you what +happens with some of the invocations above: ![./hou BIG - Luna](luna.jpg) diff --git a/2013/hou/try.sh b/2013/hou/try.sh new file mode 100755 index 000000000..d5ef47743 --- /dev/null +++ b/2013/hou/try.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 2013/hou +# + +# make sure CC is set so that when we do make CC="$CC" it isn't empty. Doing it +# this way allows us to have the user specify a different compiler in an easy +# way. +if [[ -z "$CC" ]]; then + CC="cc" +fi + +make CC="$CC" all >/dev/null || exit 1 + +# clear screen after compilation so that only the entry is shown +clear + +echo "2013/hou menu" 1>&2 +echo 1>&2 +echo "(0) BIG (luna.ppm)" 1>&2 +echo "(1) old_default.scene BIG (old_default.ppm)" 1>&2 +echo "(2) otherroom (otherroom.ppm)" 1>&2 +echo "(3) NAIVE otherroom (otherroom.ppm)" 1>&2 +echo 1>&2 +read -rp "Make your selection (0 - 3, anything else to quit): " mode + +case "$mode" in + 0) # BIG + echo "$ ./hou BIG" 1>&2 + ./hou BIG + ;; + 1) # old_default BIG + echo "$ ./hou old_default.scene BIG" 1>&2 + ./hou old_default.scene BIG + ;; + 2) # otherroom + echo "$ ./hou otherroom.scene" 1>&2 + ./hou otherroom.scene + ;; + 3) # otherroom NAIVE + echo "$ ./hou otherroom.scene NAIVE" 1>&2 + ./hou otherroom.scene NAIVE + ;; + *) exit 0 + ;; +esac diff --git a/thanks-for-help.md b/thanks-for-help.md index 4c3c86c59..68ed2718c 100644 --- a/thanks-for-help.md +++ b/thanks-for-help.md @@ -4031,6 +4031,8 @@ Further, after the file `2013/hou/doc/example.markdown` was moved to [2013/hou/doc/example.md](/2013/hou/doc/example.md) to match the rest of the repo this broke `make` which Cody also fixed. +Cody also added the [try.sh](/2013/hou/try.sh) script. + ## [2013/mills](/2013/mills/mills.c) ([README.md)[2013/mills/README.md)) From dcd12a4d083173d9ac7857d4a044995bf2f208a4 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sat, 27 Jan 2024 11:55:46 -0800 Subject: [PATCH 07/19] Typo fix in bin/all-run.sh --- bin/all-run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/all-run.sh b/bin/all-run.sh index e49ca4ef8..2bee8e0e4 100755 --- a/bin/all-run.sh +++ b/bin/all-run.sh @@ -42,7 +42,7 @@ fi shopt -s nullglob # enable expanded to nothing rather than remaining unexpanded shopt -u failglob # disable error message if no matches are found shopt -u dotglob # disable matching files starting with . -shopt -s globskipdots # enable never matching . nor .. +shopt -s globskipdots # enable never matching . or .. shopt -u nocaseglob # disable strict case matching shopt -u extglob # enable extended globbing patterns shopt -s globstar # enable ** to match all files and zero or more directories and subdirectories From 33913e5e870c71c1cde7c62db36d8917144f4513 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 28 Jan 2024 08:27:48 -0800 Subject: [PATCH 08/19] Fix make clobber in 1998/schweikh3 Needs to remove samefile.alt. Updated .gitignore too. --- 1998/schweikh3/.gitignore | 1 + 1998/schweikh3/Makefile | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/1998/schweikh3/.gitignore b/1998/schweikh3/.gitignore index 5e2e8803f..271e76fff 100644 --- a/1998/schweikh3/.gitignore +++ b/1998/schweikh3/.gitignore @@ -10,6 +10,7 @@ indent.c indent.o prog.orig samefile +samefile.alt schweikh3 schweikh3.alt schweikh3.orig diff --git a/1998/schweikh3/Makefile b/1998/schweikh3/Makefile index 8c9281799..d2b3ee245 100644 --- a/1998/schweikh3/Makefile +++ b/1998/schweikh3/Makefile @@ -211,7 +211,7 @@ clean: fi clobber: clean - ${RM} -f ${TARGET} ${ALT_TARGET} + ${RM} -f ${TARGET} ${ALT_TARGET} samefile.alt ${RM} -rf *.dSYM @-if [ -e sandwich ]; then \ ${RM} -f sandwich; \ From b7683b6f6ea4739fe044258eb4b0daee4308ffcf Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 28 Jan 2024 08:51:38 -0800 Subject: [PATCH 09/19] Fix make clobber in 2013/endoh3 Have to remove *.wav files. This is important for updating the manifest if the program was run and generated wav files (because the other tools were not found). --- 2013/endoh3/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2013/endoh3/Makefile b/2013/endoh3/Makefile index 41622f97f..31aa8d3b6 100644 --- a/2013/endoh3/Makefile +++ b/2013/endoh3/Makefile @@ -204,7 +204,7 @@ clean: clobber: clean ${RM} -f ${TARGET} ${ALT_TARGET} - ${RM} -rf *.dSYM + ${RM} -rf *.dSYM *.wav @-if [ -e sandwich ]; then \ ${RM} -f sandwich; \ echo 'ate sandwich'; \ From 6641c43fb9b2349aaa534a9087b53606242b2473 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 28 Jan 2024 08:54:25 -0800 Subject: [PATCH 10/19] Fix make clobber in 2015/yang + update .gitignore Remove output and output.c. --- 2015/yang/.gitignore | 2 ++ 2015/yang/Makefile | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/2015/yang/.gitignore b/2015/yang/.gitignore index ebe9519d9..fb50e799d 100644 --- a/2015/yang/.gitignore +++ b/2015/yang/.gitignore @@ -4,6 +4,8 @@ indent indent.c indent.o +output +output.c prog prog_c11 prog_c90 diff --git a/2015/yang/Makefile b/2015/yang/Makefile index 5cc6fa4ae..2fcb15a84 100644 --- a/2015/yang/Makefile +++ b/2015/yang/Makefile @@ -230,7 +230,7 @@ clean: fi clobber: clean - ${RM} -f ${TARGET} ${ALT_TARGET} + ${RM} -f ${TARGET} ${ALT_TARGET} output output.c ${RM} -rf *.dSYM @-if [ -e sandwich ]; then \ ${RM} -f sandwich; \ From 18b1a10d163ec458705f3e59ef3f9a436b92b3c1 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 28 Jan 2024 08:56:14 -0800 Subject: [PATCH 11/19] Fix make clobber in 2018/burton1 When scripthd was renamed to scripthd.sh the DATA field should have been updated to have scripthd.sh. Also make clobber should remove scripthd (but not scripthd.sh). Updated .gitignore. --- 2018/burton1/.gitignore | 1 + 2018/burton1/Makefile | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/2018/burton1/.gitignore b/2018/burton1/.gitignore index f830336a5..41faac2ca 100644 --- a/2018/burton1/.gitignore +++ b/2018/burton1/.gitignore @@ -7,3 +7,4 @@ indent.o prog prog.alt prog.orig +scripthd diff --git a/2018/burton1/Makefile b/2018/burton1/Makefile index 493c22607..61cb992bf 100644 --- a/2018/burton1/Makefile +++ b/2018/burton1/Makefile @@ -111,7 +111,7 @@ PROG= prog # OBJ= ${PROG}.o CSRC= ${PROG}.o -DATA= scripthd +DATA= scripthd.sh TARGET= ${PROG} # ALT_OBJ= ${PROG}.alt.o @@ -206,7 +206,7 @@ clean: fi clobber: clean - ${RM} -f ${TARGET} ${ALT_TARGET} + ${RM} -f ${TARGET} ${ALT_TARGET} scripthd ${RM} -rf *.dSYM @-if [ -e sandwich ]; then \ ${RM} -f sandwich; \ From 3cf98e2d4830cbdd8cb9062a58f1336d58b13f06 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 28 Jan 2024 09:00:07 -0800 Subject: [PATCH 12/19] Add .swp[a-z] to /.gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 16bb1d5af..e92548047 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,4 @@ .su[a-z] .*.sv[a-z] .*.sw[a-z] +.sw[a-z] From 997ac24261a25fcb0e96b425802b2cd8e94131ea Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 28 Jan 2024 09:08:05 -0800 Subject: [PATCH 13/19] Improve 2014/deak/try.sh Make less(1) options consistent with other scripts. --- 2014/deak/try.alt.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/2014/deak/try.alt.sh b/2014/deak/try.alt.sh index a7ef3e19c..b01fba5dc 100755 --- a/2014/deak/try.alt.sh +++ b/2014/deak/try.alt.sh @@ -18,32 +18,32 @@ echo 1>&2 make -B X1=2 X2=-1 Y1=-2.3 alt >/dev/null || exit read -r -n 1 -p "Press any key to continue (space = next page, q = quit): " echo 1>&2 -./prog.alt | less -EXF +./prog.alt | less -rEXFK read -r -n 1 -p "Press any key to change X1 to 3, X2 to -2 and Y1 to -3.3: " echo 1>&2 make -B X1=3 X2=-2 Y1=-3.3 alt >/dev/null || exit read -r -n 1 -p "Press any key to continue (space = next page, q = quit): " echo 1>&2 -./prog.alt | less -EXF +./prog.alt | less -rEXFK read -r -n 1 -p "Press any key to change X1 to 1, X2 to -1 and Y1 to -0.3: " echo 1>&2 make -B X1=1 X2=-1 Y1=-0.3 alt >/dev/null || exit read -r -n 1 -p "Press any key to continue (space = next page, q = quit): " echo 1>&2 -./prog.alt | less -EXF +./prog.alt | less -rEXFK read -r -n 1 -p "Press any key to change X1 to 1, X2 to -1, Y1 to -0.3 and Y2 to -1.3: " echo 1>&2 make -B X1=1 X2=-1 Y1=-0.3 Y2=-1.3 alt >/dev/null || exit read -r -n 1 -p "Press any key to continue (space = next page, q = quit): " echo 1>&2 -./prog.alt | less -EXF +./prog.alt | less -rEXFK read -r -n 1 -p "Press any key to try the original configuration: " echo 1>&2 make clobber alt >/dev/null || exit 1 read -r -n 1 -p "Press any key to continue (space = next page, q = quit): " echo 1>&2 -./prog.alt | less -EXF +./prog.alt | less -rEXFK From e9a8aa58defbf672ae5a0f1cf48119a4523797f2 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 28 Jan 2024 09:11:43 -0800 Subject: [PATCH 14/19] Improve less(1) consistency in 2014/endoh1/try.sh --- 2014/endoh1/try.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2014/endoh1/try.sh b/2014/endoh1/try.sh index a8fdc6a43..efc0b57dd 100755 --- a/2014/endoh1/try.sh +++ b/2014/endoh1/try.sh @@ -17,7 +17,7 @@ clear read -r -n 1 -p "Press any key to show prog.c (space = next page, q = quit): " echo 1>&2 -less -EXF prog.c +less -rEXFK prog.c echo 1>&2 read -r -n 1 -p "Press any key to run: ./prog: " From 9f5964ec1bd667316fd05102ea12c0bb01777a6d Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 28 Jan 2024 09:17:01 -0800 Subject: [PATCH 15/19] Fix make clobber in 2014/endoh2 Since the try script creates the files hello.c, hello, ioccc.c and ioccc the clobber rule needs to remove those files. The script now uses less(1) for longer output (it's possible there are still small enough displays where it would be useful). --- 2014/endoh2/Makefile | 2 +- 2014/endoh2/try.sh | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/2014/endoh2/Makefile b/2014/endoh2/Makefile index 4befe3606..120097ebf 100644 --- a/2014/endoh2/Makefile +++ b/2014/endoh2/Makefile @@ -201,7 +201,7 @@ clean: fi clobber: clean - ${RM} -f ${TARGET} ${ALT_TARGET} + ${RM} -f ${TARGET} ${ALT_TARGET} ioccc ioccc.c hello hello.c ${RM} -rf *.dSYM @-if [ -e sandwich ]; then \ ${RM} -f sandwich; \ diff --git a/2014/endoh2/try.sh b/2014/endoh2/try.sh index 0fbfd5a61..42a4cdf7f 100755 --- a/2014/endoh2/try.sh +++ b/2014/endoh2/try.sh @@ -15,14 +15,14 @@ make CC="$CC" all >/dev/null || exit 1 # clear screen after compilation so that only the entry is shown clear -read -r -n 1 -p "Press any key to run: echo Hello | ./prog: " +read -r -n 1 -p "Press any key to run: echo Hello | ./prog (space = next page, q = quit): " echo 1>&2 -echo Hello | ./prog +echo Hello | ./prog | less -rEXFK echo 1>&2 -read -r -n 1 -p "Press any key to run: echo IOCCC | ./prog: " +read -r -n 1 -p "Press any key to run: echo IOCCC | ./prog (space = next page, q = quit): " echo 1>&2 -echo IOCCC | ./prog +echo IOCCC | ./prog | less -rEXFK echo 1>&2 read -r -n 1 -p "Press any key to run: echo Hello | ./prog > hello.c: " @@ -30,6 +30,13 @@ echo 1>&2 echo Hello | ./prog > hello.c echo 1>&2 +# we don't use tee(1) above as it makes the message longer and it's not strictly +# necessary +read -r -n 1 -p "Press any key to show hello.c (space = next page, q = quit): " +echo 1>&2 +less -rEXFK hello.c +echo 1>&2 + read -r -n 1 -p "Press any key to compile hello.c: " echo 1>&2 make hello >/dev/null From a71766448335a19ec971a8f7cb5af2cee4cfa1f2 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 28 Jan 2024 11:55:55 -0800 Subject: [PATCH 16/19] Fix comments for shellcheck in 2014/maffiodo1 --- 2014/maffiodo1/giana.sh | 8 +++++++- 2014/maffiodo1/mario.sh | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/2014/maffiodo1/giana.sh b/2014/maffiodo1/giana.sh index 9fa2961af..2960e81ad 100755 --- a/2014/maffiodo1/giana.sh +++ b/2014/maffiodo1/giana.sh @@ -23,6 +23,12 @@ if [[ -z "$COLS" ]]; then COLS="640" fi -# ^---------^ SC2002 (style): Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. +# We disable the useless cat warning of ShellCheck because the to use +# instructions have it and for such a long command line it's easier to deal +# with. Besides that it is dubious to claim there is such a thing as useless +# cat. +# +# SC2002 (style): Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. +# https://www.shellcheck.net/wiki/SC2002 # shellcheck disable=SC2002 cat giana.level | ./prog "$COLS" "$ROWS" 1000 300 192 168 giana.rgba giana8.wav 5459393 diff --git a/2014/maffiodo1/mario.sh b/2014/maffiodo1/mario.sh index 28e462c1d..7e9cb1a72 100755 --- a/2014/maffiodo1/mario.sh +++ b/2014/maffiodo1/mario.sh @@ -23,6 +23,12 @@ if [[ -z "$COLS" ]]; then COLS="640" fi -# ^---------^ SC2002 (style): Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. +# We disable the useless cat warning of ShellCheck because the to use +# instructions have it and for such a long command line it's easier to deal +# with. Besides that it is dubious to claim there is such a thing as useless +# cat. +# +# SC2002 (style): Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. +# https://www.shellcheck.net/wiki/SC2002 # shellcheck disable=SC2002 cat mario.level | ./prog "$COLS" "$ROWS" 800 300 128 144 mario.rgba mario8.wav 10343679 && telnet telehack.com 23 From 061c86ebf89123f5ff96516ec14d3f587409b5c5 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 28 Jan 2024 12:11:34 -0800 Subject: [PATCH 17/19] Fix shellcheck for 2014/maffiodo2/try.sh --- 2014/maffiodo2/try.sh | 49 +++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/2014/maffiodo2/try.sh b/2014/maffiodo2/try.sh index bad1431ef..5685ad202 100755 --- a/2014/maffiodo2/try.sh +++ b/2014/maffiodo2/try.sh @@ -15,44 +15,33 @@ make CC="$CC" all >/dev/null || exit 1 # clear screen after compilation so that only the entry is shown clear -echo "$ cat image.rgb | ./prog ' .,:;!$#@'" 1>&2 -read -r -n 1 -p "Press any key to run command (space = next page, q = quit): " +echo "$ ./prog ' .,:;!$#@' < image.rgb" 1>&2 +read -r -n 1 -p "Press any key to continue (space = next page, q = quit): " +echo 1>&2 +./prog ' .,:;!$#@' < image.rgb | less -rEXFK echo 1>&2 -# ^-------^ SC2002 (style): Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. -# shellcheck disable=SC2002 -cat image.rgb | ./prog ' .,:;!$#@' | less -EXF -echo "$ cat image.rgb | ./prog ' .:;Y0'" 1>&2 -read -r -n 1 -p "Press any key to run command (space = next page, q = quit): " +echo "$ ./prog \" .:;Y0\" < image.rgb" 1>&2 +read -r -n 1 -p "Press any key to continue (space = next page, q = quit): " echo 1>&2 -# ^-------^ SC2002 (style): Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. -# shellcheck disable=SC2002 -cat image.rgb | ./prog " .:;Y0" | less -EXF +./prog " .:;Y0" < image.rgb | less -rEXFK -echo "$ cat image.rgb | ./prog ' :1'" 1>&2 -read -r -n 1 -p "Press any key to run command (space = next page, q = quit): " +echo "$ ./prog ' :1' < image.rgb" 1>&2 +read -r -n 1 -p "Press any key to continue (space = next page, q = quit): " echo 1>&2 -# ^-------^ SC2002 (style): Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. -# shellcheck disable=SC2002 -cat image.rgb | ./prog ' :1' | less -EXF +./prog ' :1' < image.rgb | less -rEXFK -echo "$ cat image.rgb | ./prog ' .:;Y0'" 1>&2 -read -r -n 1 -p "Press any key to run command (space = next page, q = quit): " +echo "$ ./prog ' .:;Y0' < image.rgb" 1>&2 +read -r -n 1 -p "Press any key to continue (space = next page, q = quit): " echo 1>&2 -# ^-------^ SC2002 (style): Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. -# shellcheck disable=SC2002 -cat image.rgb | ./prog ' .:;Y0' | less -EXF +./prog ' .:;Y0' < image.rgb | less -rEXFK -echo "$ cat image.rgb | ./prog ' .:-=+*#%@'" 1>&2 -read -r -n 1 -p "Press any key to run command (space = next page, q = quit): " +echo "$ ./prog ' .:-=+*#%@' < image.rgb" 1>&2 +read -r -n 1 -p "Press any key to continue (space = next page, q = quit): " echo 1>&2 -# ^-------^ SC2002 (style): Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. -# shellcheck disable=SC2002 -cat image.rgb | ./prog ' .:-=+*#%@' | less -EXF +./prog ' .:-=+*#%@' < image.rgb | less -rEXFK -echo "$ cat image.rgb | ./prog ' .,:!-iots&8%#@$'" 1>&2 -read -r -n 1 -p "Press any key to run command (space = next page, q = quit): " +echo "$ ./prog ' .,:!-iots&8%#@$' < image.rgb" 1>&2 +read -r -n 1 -p "Press any key to continue (space = next page, q = quit): " echo 1>&2 -# ^-------^ SC2002 (style): Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. -# shellcheck disable=SC2002 -cat image.rgb | ./prog ' .,:!-iots&8%#@$' | less -EXF +./prog ' .,:!-iots&8%#@$' < image.rgb | less -rEXFK From 691a901b55b556a2abe2017aae858705e4e2a2c2 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 28 Jan 2024 12:18:49 -0800 Subject: [PATCH 18/19] Improve 2014/morgan/try.sh After copying prog to morgan (which was already done) it removes prog and then uses morgan to build prog. Following this it shows that they're identical to each other. The rest of the script it uses morgan, not prog, and it's the same as before (what it runs) except that the use of 'ls' is no longer there as there is no need for it. --- 2014/morgan/try.sh | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/2014/morgan/try.sh b/2014/morgan/try.sh index a464cbb3e..9bb056dcd 100755 --- a/2014/morgan/try.sh +++ b/2014/morgan/try.sh @@ -15,31 +15,35 @@ make CC="$CC" all >/dev/null || exit 1 # clear screen after compilation so that only the entry is shown clear - -echo "$ cp -f prog morgan" 1>&2 +read -r -n 1 -p "Press any key to run: cp -f prog morgan: " +echo 1>&2 cp -f prog morgan -echo "$ ls" 1>&2 -ls +echo 1>&2 + +read -r -n 1 -p "Press any key to run: rm -vf prog: " +echo 1>&2 +rm -vf prog +echo 1>&2 +read -r -n 1 -p "Press any key to run: ./morgan prog: " +echo 1>&2 +./morgan prog +echo 1>&2 + +read -r -n 1 -p "Press any key to compare prog and morgan: " +echo 1>&2 +diff -s prog morgan +echo 1>&2 read -r -n 1 -p "Press any key to run: ./morgan all install: " echo 1>&2 ./morgan all install echo 1>&2 -echo "$ ls" 1>&2 -ls + +read -r -n 1 -p "Press any key to run: ./morgan love haste waste supernova: " +echo 1>&2 +./morgan love haste waste supernova echo 1>&2 -read -r -n 1 -p "Press any key to run: ./prog love haste waste supernova: " +read -r -n 1 -p "Press any key to run: ./morgan magic: " echo 1>&2 -./prog love haste waste supernova -echo 1>&2 -echo "$ ls" 1>&2 -ls -echo 1>&2 - -read -r -n 1 -p "Press any key to run: ./prog magic: " -echo 1>&2 -./prog magic -echo 1>&2 -echo "$ ls" 1>&2 -ls +./morgan magic From 0903d9f3b9314010f8a511ccb068465320a95415 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 28 Jan 2024 12:42:07 -0800 Subject: [PATCH 19/19] Fix and improve 2014/sinon scripts The try script now runs the demo mode if perl is installed. It also now prompts before running each script (the below noted ones) so that one can control the pace of the output a bit more. The glock.sh and hecate.sh scripts could only be run once successfully because the output of run.c overwrites it (with non code). First one has to do cp -f prog.c run.c which the scripts now do. This was not a problem in the try script because I added that step explicitly (and is now not needed or there). --- 2014/sinon/README.md | 22 ++++++++++++---------- 2014/sinon/glock.sh | 2 +- 2014/sinon/hecate.sh | 2 +- 2014/sinon/try.sh | 25 ++++++++++++++++++++++++- thanks-for-help.md | 12 +++++++++--- 5 files changed, 47 insertions(+), 16 deletions(-) diff --git a/2014/sinon/README.md b/2014/sinon/README.md index 786e5be72..60a9b21e2 100644 --- a/2014/sinon/README.md +++ b/2014/sinon/README.md @@ -8,7 +8,9 @@ make ## To use: ```sh -cp -f prog.c run.c; ./hecate.sh +./hecate.sh + +./glock.sh ``` @@ -33,7 +35,7 @@ or unspecified behavior? ### Summary -Sinon is a game of timing, the goal is to eliminate all enemies in +`Sinon` is a game of timing, the goal is to eliminate all enemies in under one minute. To start, compile and run the program. To resume, compile and run the @@ -48,7 +50,7 @@ gcc -O2 run.c -o run && ./run | tee run.c ### Details -Sinon is played by compiling and running the output repeatedly. Two +`Sinon` is played by compiling and running the output repeatedly. Two factors determine what actions are taken: + Time since last compilation. @@ -58,7 +60,7 @@ If you fire too quickly, the weapon will jam. If you fire too slowly, you will not be able to eliminate all the enemies in time. Thus the primary objective of the game is to time your compilations just right. -Sinon has two weapons that are selected based on compiler optimization +`Sinon` has two weapons that are selected based on compiler optimization level: + "gcc -O2" or "clang -O2" will fire Hecate II, a powerful rifle that @@ -80,7 +82,7 @@ compilers. ### Compatibility -Sinon has been tested and verified to work on these platforms: +`Sinon` has been tested and verified to work on these platforms: + gcc 4.4.3 on Linux. + gcc 4.4.5 on Linux. @@ -93,14 +95,14 @@ Sinon has been tested and verified to work on these platforms: + tcc 0.9.25 on JS/Linux (no optimization, so only "hard" mode is available). -Sinon is intended to be played in a 80x25 terminal. +`Sinon` is intended to be played in a 80x25 terminal. ### Miscellaneous features -Sinon might be the first game that uses compiler optimization level as +`Sinon` might be the first game that uses compiler optimization level as a primary input. -Sinon has a demo mode that plays the game automatically. Make sure +`Sinon` has a demo mode that plays the game automatically. Make sure that there are no files named "run" and "run.c" in current directory (they will be overwritten) and run: @@ -110,9 +112,9 @@ perl prog.c | bash File size and CRC32 of [prog.c](prog.c) are embedded in line 7. -Process for making Sinon is included in [spoiler.html](spoiler.html). +Process for making `Sinon` is included in [spoiler.html](spoiler.html). -Layout of this code is based on Asada Shino, also known as "Sinon", +Layout of this code is based on Asada Shino, also known as "`Sinon`", from Sword Art Online. diff --git a/2014/sinon/glock.sh b/2014/sinon/glock.sh index 4e32ed664..ae96f52e6 100755 --- a/2014/sinon/glock.sh +++ b/2014/sinon/glock.sh @@ -1,2 +1,2 @@ #!/usr/bin/env bash -cc -O0 run.c -o run > /dev/null && ./run | tee run.c +cp -f prog.c run.c && cc -O0 run.c -o run > /dev/null && ./run | tee run.c diff --git a/2014/sinon/hecate.sh b/2014/sinon/hecate.sh index 3f1ff87db..f9e1ab390 100755 --- a/2014/sinon/hecate.sh +++ b/2014/sinon/hecate.sh @@ -1,2 +1,2 @@ #!/usr/bin/env bash -cc -O2 run.c -o run > /dev/null && ./run | tee run.c +cp -f prog.c run.c && cc -O2 run.c -o run > /dev/null && ./run | tee run.c diff --git a/2014/sinon/try.sh b/2014/sinon/try.sh index a29de9df2..0a63aa266 100755 --- a/2014/sinon/try.sh +++ b/2014/sinon/try.sh @@ -15,9 +15,32 @@ make CC="$CC" all >/dev/null || exit 1 # clear screen after compilation so that only the entry is shown clear +# find out if perl is installed +PERL="$(type -P perl)" +if [[ -n "$PERL" ]]; then + read -r -n 1 -p "Press any key to play the game automatically ($PERL prog.c | bash): " + echo 1>&2 + "$PERL" prog.c | bash + echo 1>&2 +fi + while :; do - cp -f prog.c run.c; ./hecate.sh; ./glock.sh; sleep 3; ./glock.sh; sleep 1; ./hecate.sh + read -r -n 1 -p "Press any key to run: ./hecate.sh: " + echo 1>&2 + ./hecate.sh + + read -r -n 1 -p "Press any key to run: ./glock.sh: " + echo 1>&2 + ./glock.sh + + read -r -n 1 -p "Press any key to run: ./glock.sh: " + echo 1>&2 + ./glock.sh + + read -r -n 1 -p "Press any key to run: ./hecate.sh: " + echo 1>&2 + ./hecate.sh read -r -p "Do you want to try again (Y/N)? " if [[ "$REPLY" != "y" && "$REPLY" != "Y" ]]; then diff --git a/thanks-for-help.md b/thanks-for-help.md index 68ed2718c..3ee1fb2fe 100644 --- a/thanks-for-help.md +++ b/thanks-for-help.md @@ -4151,9 +4151,15 @@ provided by the author. once did. The problem is that it expects a certain file name which was `sinon.c`. The code now refers to `prog.c`. -Cody also added the [try.sh](/2014/sinon/try.sh) script which is an improvement -over what was once suggested in that when it's over it will ask you if you wish -to try again, say because of a jam (see the README.md file for details). +Cody also fixed the scripts [glock.sh](/2014/sinon/glock.sh) and +[hecate.sh](/2014/sinon/hecate.sh) which did not work after running either once +as they compile `run.c` and then do `./run | tee run.c` which overwrites it with +output that is not code. + +Cody also added the [try.sh](/2014/sinon/try.sh) script that will first (if perl +is installed) run the demo mode and then after that it will run the above noted +scripts in a loop until the user says they do not want to try again (or they +kill it). This is done this way in case it jams (see README.md for details). ## [2014/skeggs](/2014/skeggs/prog.c) ([README.md](/2014/skeggs/README.md))