From d91bced2b8dc83e5aecc37b2b2a4f45c07221966 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 14 Jan 2024 05:28:07 -0800 Subject: [PATCH 01/10] Fix funny problem in 1989/fubar In some cases if one were to modify the C code (possibly the same with the script) in certain ways the program would fail to work even after changing the code back. Trying to figure out what to put in bugs.md and on a hunch, changing the fubar.sh script (in particular the ex(1) part) remedies the problem (or so it seems from the various tests I have performed including some that caused a problem). In particular: --- i/1989/fubar/fubar.sh +++ w/1989/fubar/fubar.sh @@ -7,13 +7,12 @@ if [[ $# -ne 1 ]]; then exit 1 fi # run/compile it rm -f ouroboros.c x1 x -ex - < x1 +cat ouroboros.c | ./x $1 > x1 if [[ $? -ne 0 ]]; then exit fi -mv x1 ./ouroboros.c -chmod +x ./ouroboros.c +mv x1 ouroboros.c +chmod +x ouroboros.c exec ./ouroboros.c $1 exit */ diff --git a/1989/fubar/fubar.sh b/1989/fubar/fubar.sh index 816a1147d..74929c5ea 100755 --- a/1989/fubar/fubar.sh +++ b/1989/fubar/fubar.sh @@ -9,8 +9,7 @@ fi # run/compile it rm -f ouroboros.c x1 x -ex - < Date: Sun, 14 Jan 2024 07:28:59 -0800 Subject: [PATCH 02/10] Fix 1992/buzzard.2 alt code, add try scripts The bug fix is simply so it can compile. It assumed exit(3) returned a value, not void. The fixes noted in the remarks (though I did not see them at a quick glance) of the author are not in the alt version (that's the purpose of it). The try.sh and try.alt.sh scripts correspond to the entry and the alt code. Updated .gitignore. Added 'first.alt' to Makefile for the try.alt.sh script. --- 1992/buzzard.2/.gitignore | 2 ++ 1992/buzzard.2/Makefile | 6 +++++- 1992/buzzard.2/README.md | 32 ++++++++++++++++++++++---------- 1992/buzzard.2/buzzard.2.alt.c | 2 +- 1992/buzzard.2/help.th | 2 +- 1992/buzzard.2/try.alt.sh | 34 ++++++++++++++++++++++++++++++++++ 1992/buzzard.2/try.sh | 34 ++++++++++++++++++++++++++++++++++ thanks-for-help.md | 10 ++++++++++ 8 files changed, 109 insertions(+), 13 deletions(-) create mode 100755 1992/buzzard.2/try.alt.sh create mode 100755 1992/buzzard.2/try.sh diff --git a/1992/buzzard.2/.gitignore b/1992/buzzard.2/.gitignore index 8ae53d7e6..023828d87 100644 --- a/1992/buzzard.2/.gitignore +++ b/1992/buzzard.2/.gitignore @@ -1,9 +1,11 @@ # # sort with: sort -d -u buzzard.2 +buzzard.2.alt buzzard.2.orig *.dSYM first +first.alt indent indent.c indent.o diff --git a/1992/buzzard.2/Makefile b/1992/buzzard.2/Makefile index 3074e911d..9fccec062 100644 --- a/1992/buzzard.2/Makefile +++ b/1992/buzzard.2/Makefile @@ -114,7 +114,7 @@ DATA= TARGET= ${PROG} first # ALT_OBJ= ${PROG}.alt.o -ALT_TARGET= ${PROG}.alt +ALT_TARGET= ${PROG}.alt first.alt ################# @@ -144,6 +144,10 @@ alt: data ${ALT_TARGET} ${PROG}.alt: ${PROG}.alt.c ${CC} ${CFLAGS} $< -o $@ ${LDFLAGS} +first.alt: ${PROG}.alt + ${RM} -f $@ + ${LN} $< $@ + # data files # data: ${DATA} diff --git a/1992/buzzard.2/README.md b/1992/buzzard.2/README.md index abb57e09d..5985703b4 100644 --- a/1992/buzzard.2/README.md +++ b/1992/buzzard.2/README.md @@ -10,8 +10,8 @@ code](#alternate-code) below for details. ## To use: -First, you must make sure that first is made first (even though `make all` -should do it :-) ): +First, you must make sure that `first` is made first (even though `make all` +should make first first :-) ): ```sh make first @@ -48,6 +48,13 @@ Sorry, this is third! ``` +## Try: + +```sh +./try.sh +``` + + ## Alternate code: This alternate version, [buzzard.2.alt.c](buzzard.2.alt.c), does not contain a @@ -66,6 +73,12 @@ make alt Use `buzzard.2.alt` as you would `buzzard.2` above. +### Alternate try: + +```sh +./try.alt.sh +``` + ## Judges' remarks: Have fun! @@ -99,8 +112,8 @@ further down. `first` expects you to first enter the names of the 13 primitives, separated by whitespace--it doesn't care what you name them, but if all the names aren't unique, you won't be able to use some of -them. After this you may type any sequence of valid first input. -Valid first input is defined as any sequence of whitespace-delimited +them. After this you may type any sequence of valid `first` input. +Valid `first` input is defined as any sequence of whitespace-delimited tokens which consist of primitives, new words you've defined, and integers (as parsed by `"%d"`). Invalid input behaves unpredictably, but gives no warning messages. A sample program, `demo1.1st`, is @@ -108,7 +121,7 @@ included, but it only works on ASCII systems. Do not expect to be able to do anything interesting with `first`. -To do something interesting, you need to feed first the file +To do something interesting, you need to feed `first` the file [third](third) first. In unix, you can do ```sh @@ -159,7 +172,7 @@ Other related obfuscations are still present. The top of the stack is cached in a variable, which increases performance massively if the compiler can figure out to keep it in a register; it also obfuscates the code. (Unfortunately, the top of stack is a global variable and neither gcc nor most bundled compilers seem to -register allocate it.) +`register` allocate it.) More significant are the design obfuscations. `m[0]` is the "dictionary pointer", used when compiling words, and `m[1]` is the return stack index. Both @@ -205,15 +218,14 @@ are primitives in [FORTH](https://en.wikipedia.org/wiki/Forth_(programming_language)) (like swap) take a significant amount of time in THIRD. -When you get the `Ok.` message from third, try out some sample -[FORTH](https://en.wikipedia.org/wiki/Forth_(programming_language)) code (first -has no way of knowing if keyboard input is waiting, so it can't actually prompt +When you get the `Ok.` message from `third`, try out some sample +[FORTH](https://en.wikipedia.org/wiki/Forth_(programming_language)) code +(`first` has no way of knowing if keyboard input is waiting, so it can't actually prompt you in a normal way. It only prints `'Ok.'` after you define a word). ```sh 2 3 + . cr - ``` (which adds 2 and 3, and print the result and a newline.) diff --git a/1992/buzzard.2/buzzard.2.alt.c b/1992/buzzard.2/buzzard.2.alt.c index 7f77ab117..6b11b6ad3 100644 --- a/1992/buzzard.2/buzzard.2.alt.c +++ b/1992/buzzard.2/buzzard.2.alt.c @@ -17,7 +17,7 @@ a(x) r(x) { switch(x++[m]){ - z 5: for(w=scanf("%s",s)<1?exit(0):L;strcmp(s,&w[&m[1]][s]);w=m[w]); + z 5: for(w=scanf("%s",s)<1?exit(0),0:L;strcmp(s,&w[&m[1]][s]);w=m[w]); w-1 ? r(w+2) : (c 2,c atoi(s)) z 12: I=1[m]--[m] z 15: f=S[-f] diff --git a/1992/buzzard.2/help.th b/1992/buzzard.2/help.th index 7afab271a..025d9ca1c 100644 --- a/1992/buzzard.2/help.th +++ b/1992/buzzard.2/help.th @@ -1,7 +1,7 @@ : help key ( flush the carriage return form the input buffer ) " The following are the standard known words; words marked with (*) are -immediate words, which cannot be used from command mode, but only in +immediate words, which cannot be used in command mode, but only in word definitions. Words marked by (**) declare new words, so are always followed by the new word. diff --git a/1992/buzzard.2/try.alt.sh b/1992/buzzard.2/try.alt.sh new file mode 100755 index 000000000..9f6159c2b --- /dev/null +++ b/1992/buzzard.2/try.alt.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# +# try.alt.sh - demonstrate IOCCC winner 1992/buzzard.2 alt code +# + +# 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" alt >/dev/null || exit 1 + +# clear screen after compilation so that only the entry is shown +clear + +echo "$ echo help | cat third help.th - | ./first.alt" 1>&2 +read -r -n 1 -p "Press any key to read help (space = next page, q = quit): " +echo 1>&2 +echo help | cat third help.th - | ./first.alt | less -rEXF + +for i in demo[1-6].th; do + # try out each demo + # + read -r -n 1 -p "Press any key to show $i (space = next page, q = quit): " + echo 1>&2 + less -rEXF "$i" + echo 1>&2 + read -r -n 1 -p "Press any key to run cat third $i | ./first.alt (demo $i): " + echo 1>&2 + cat third "$i" | ./first.alt + echo 1>&2 +done diff --git a/1992/buzzard.2/try.sh b/1992/buzzard.2/try.sh new file mode 100755 index 000000000..64482e8a5 --- /dev/null +++ b/1992/buzzard.2/try.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 1992/buzzard.2 +# + +# 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 "$ echo help | cat third help.th - | ./first" 1>&2 +read -r -n 1 -p "Press any key to read help (space = next page, q = quit): " +echo 1>&2 +echo help | cat third help.th - | ./first | less -rEXF + +for i in demo[1-6].th; do + # try out each demo + # + read -r -n 1 -p "Press any key to show $i (space = next page, q = quit): " + echo 1>&2 + less -rEXF "$i" + echo 1>&2 + read -r -n 1 -p "Press any key to run cat third $i | ./first (demo $i): " + echo 1>&2 + cat third "$i" | ./first + echo 1>&2 +done diff --git a/thanks-for-help.md b/thanks-for-help.md index 106076839..d1e9e4209 100644 --- a/thanks-for-help.md +++ b/thanks-for-help.md @@ -1530,6 +1530,16 @@ He also added the [try.sh](/1991/buzzard.1/try.sh) script to try out some commands that we suggested and some additional ones that provide for some fun. +## [1992/buzzard.2](/1992/buzzard.2/buzzard.2.c) ([README.md](/1992/buzzard.2/README.md)) + +[Cody](#cody) fixed the alt code to compile. The problem was it assumed that +`exit(3)` returns a value, not `void`. This was fixed with a `,0`. + +Cody also added the [try.sh](/1992/buzzard.2/try.sh) and +[try.alt.sh](/1992/buzzard.2/try.alt.sh) scripts that correspond to the entry +and its alt code. + + ## [1992/gson](/1992/gson/gson.c) ([README.md](/1992/gson/README.md])) [Cody](#cody) fixed a crash that prevented this entry from working in some cases in some From 903ef5472a510fabe1a587d9e63402a7b3b052df Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 14 Jan 2024 08:49:09 -0800 Subject: [PATCH 03/10] Typo (link) fix in thanks for 1992/buzzard.1 --- thanks-for-help.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/thanks-for-help.md b/thanks-for-help.md index d1e9e4209..4f3d96b4b 100644 --- a/thanks-for-help.md +++ b/thanks-for-help.md @@ -1526,8 +1526,8 @@ used. This was not originally done but at a time it was changed to be considered a bug so it was fixed at that point as it only took a few seconds and had to be verified that it was consistent with the [bugs.md](/bugs.md) file. -He also added the [try.sh](/1991/buzzard.1/try.sh) script to try out some -commands that we suggested and some additional ones that provide for some fun. +He also added the [try.sh](/1992/buzzard.1/try.sh) script to try out some +commands that we suggested and some additional ones that he provide for some fun. ## [1992/buzzard.2](/1992/buzzard.2/buzzard.2.c) ([README.md](/1992/buzzard.2/README.md)) From b0918543df7d6d309abc0e333bfc42ec1718d4f5 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 14 Jan 2024 09:01:01 -0800 Subject: [PATCH 04/10] Add 1992/ant/try.sh If you like ants there are now 1992 of them here to try out (whatever that means :-) ). Some typos in the test Makefile were also fixed (just those that I saw as the command was scrolling by - I didn't look at the whole file). --- 1992/ant/README.md | 14 ++++---------- 1992/ant/ant.test.mk | 4 ++-- 1992/ant/try.sh | 33 +++++++++++++++++++++++++++++++++ thanks-for-help.md | 7 +++++-- 4 files changed, 44 insertions(+), 14 deletions(-) create mode 100755 1992/ant/try.sh diff --git a/1992/ant/README.md b/1992/ant/README.md index ade2667ad..e89334ba4 100644 --- a/1992/ant/README.md +++ b/1992/ant/README.md @@ -9,24 +9,18 @@ make all ```sh ./ant Makefile + +./ant Makefile rule ``` -where `Makefile` is a Makefile to use. +where `Makefile` is a Makefile to use and `rule` is an optional rule to use. ### Try: -First build the tool itself with our Makefile: ```sh -./ant Makefile am -``` - -Now use `am` to do some things: - -```sh -./am Makefile am_clobber # clobber everything except am -./am ant.test.mk # run the test Makefile with am +./try.sh ``` diff --git a/1992/ant/ant.test.mk b/1992/ant/ant.test.mk index 6004c4fae..987b232ac 100644 --- a/1992/ant/ant.test.mk +++ b/1992/ant/ant.test.mk @@ -57,7 +57,7 @@ TEXT_2 = test macro split \ three lines TEXT_3 = test dollar macro '$$' TEXT_4 = test dollar again "$$(TEXT_1)" -TEXT_5 = imbeded macro '$(TEXT_1)' +TEXT_5 = embedded macro '$(TEXT_1)' redefine : r1 r2 r3 r4 r5 @@ -161,7 +161,7 @@ leaf.5 : # Command lines split across lines. split.cmd: - echo Try spliting command \ + echo Try splitting command \ lines across more \ than one line. diff --git a/1992/ant/try.sh b/1992/ant/try.sh new file mode 100755 index 000000000..465a0cb2b --- /dev/null +++ b/1992/ant/try.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 1992/ant +# + +# 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 "$ ./ant Makefile am # build the tool itself" 1>&2 +read -r -n 1 -p "Press any key to run: ./ant Makefile am: " +echo 1>&2 +./ant Makefile am +echo 1>&2 + +echo "$ ./am Makefile am_clobber # clobber everything except am" 1>&2 +read -r -n 1 -p "Press any key to continue: " +echo 1>&2 +./am Makefile am_clobber # clobber everything except am +echo 1>&2 + +echo "$ ./am ant.test.mk # run the test Makefile with am" 1>&2 +read -r -n 1 -p "Press any key to continue: " +echo 1>&2 +./am ant.test.mk # run the test Makefile with am diff --git a/thanks-for-help.md b/thanks-for-help.md index 4f3d96b4b..0d044e9b2 100644 --- a/thanks-for-help.md +++ b/thanks-for-help.md @@ -1505,7 +1505,7 @@ return void. [Cody](#cody) fixed the Makefile so that the program will actually work with it (or at least the rule to clobber files and link `am` to `ant`). The issue was that the variables in the Makefile could not be evaluated in the same way as it's not as -feature-rich as other implementations of `make`. Thus the use of `${RM}` and +feature-rich as other implementations of `make(1)`. Thus the use of `${RM}` and `${CP}` were in the respective rules changed to `rm` and `cp`, for two examples. A new rule had to be added as well. The variable situation might be because they are obtained from the root variable Makefile `var.mk` via `include` which the @@ -1516,7 +1516,10 @@ Cody also fixed another problem, unrelated, in the Makefile with the `.PHONY` rule where a line was not ended with a `\` but should have been. The author stated that in some systems like DOS with Turbo C, it might be -necessary to include `time.h` so Cody did this as well. +necessary to include `time.h` so Cody did this as well as this exists in other +systems too. + +Cody also added the [try.sh](/1992/ant/try.sh) script. ## [1992/buzzard.1](/1992/buzzard.1/buzzard.1.c) ([README.md](/1992/buzzard.1/README.md)) From 85a9066b0207ff1431fb83a266411bf155002745 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 14 Jan 2024 09:13:46 -0800 Subject: [PATCH 05/10] Add try scripts to 1992/albert --- 1992/albert/README.md | 8 +++++++- 1992/albert/try.alt.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 1992/albert/try.sh | 37 +++++++++++++++++++++++++++++++++++++ thanks-for-help.md | 8 ++++++-- 4 files changed, 92 insertions(+), 3 deletions(-) create mode 100755 1992/albert/try.alt.sh create mode 100755 1992/albert/try.sh diff --git a/1992/albert/README.md b/1992/albert/README.md index 2fcd9d9b3..ce571df55 100644 --- a/1992/albert/README.md +++ b/1992/albert/README.md @@ -29,7 +29,7 @@ For more detailed information see [1992 albert in bugs.md](/bugs.md#1992-albert) ### Try: ```sh -./albert 1234567890123456789 +./try.sh ``` @@ -74,6 +74,12 @@ make alt Use `albert.alt` as you would `albert` above. +### Alternate try: + +```sh +./try.alt.sh +``` + ## Judges' remarks: We were impressed with the speed at which it was able to factor diff --git a/1992/albert/try.alt.sh b/1992/albert/try.alt.sh new file mode 100755 index 000000000..e4ec13e02 --- /dev/null +++ b/1992/albert/try.alt.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +# +# try.alt.sh - demonstrate IOCCC winner 1992/albert alt code +# + +# 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" alt >/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: ./albert.alt 1234567890123456789: " +echo 1>&2 +./albert.alt 1234567890123456789 +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./albert.alt 12345678987654321: " +echo 1>&2 +./albert.alt 12345678987654321 +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./albert.alt 42: " +echo 1>&2 +./albert.alt 42 +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./albert.alt 4242424242: " +echo 1>&2 +./albert.alt 4242424242 +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./albert.alt 10000000001: " +echo 1>&2 +./albert.alt 10000000001 +echo 1>&2 diff --git a/1992/albert/try.sh b/1992/albert/try.sh new file mode 100755 index 000000000..ec9439684 --- /dev/null +++ b/1992/albert/try.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 1992/albert +# + +# 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: ./albert 1234567890123456789: " +echo 1>&2 +./albert 1234567890123456789 +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./albert 12345678987654321: " +echo 1>&2 +./albert 12345678987654321 +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./albert 42: " +echo 1>&2 +./albert 42 +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./albert 4242424242: " +echo 1>&2 +./albert 4242424242 +echo 1>&2 diff --git a/thanks-for-help.md b/thanks-for-help.md index 0d044e9b2..fc0e91b99 100644 --- a/thanks-for-help.md +++ b/thanks-for-help.md @@ -1496,8 +1496,12 @@ the additional tools. applied to the code, provided as the alt code as that version is not obfuscated. Thus Cody's fix applies to the original entry. The problems were that `malloc.h` is not the correct header file now (at least in some systems?) and a non-void -(implicit int) function returning without a value. That function was changed to -return void. +(implicit `int`) function returning without a value. That function was changed to +return `void`. + +Cody also added the [try.sh](/1992/albert/try.sh) and +[try.alt.sh](/1992/albert/try.alt.sh) scripts that correspond to the entry and +the alt code. ## [1992/ant](/1992/ant/ant.c) ([README.md](/1992/ant/README.md])) From 094a4da91ab051ad7bc379a2807b50179683106d Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 14 Jan 2024 09:46:54 -0800 Subject: [PATCH 06/10] Add 1992/adrian/try.sh This script shows the entry itself as well as some of the other tools that the entry generates. The adwc / wc one uses a pipeline to show the output (with leading spaces and filename removed along with squeezing spaces) and also writes each to a text file to use diff on, to show how they have the same output. Not all the tools are in the script. The adbasename might have a bug (in any case it doesn't appear to function exactly like basename(1) in that it requires two args, not one) so it is not used and adgrep is not used either. For the latter one the author's remarks might provide some clues as to why I did not include it. --- 1992/adrian/.gitignore | 2 ++ 1992/adrian/README.md | 17 +++++------- 1992/adrian/try.sh | 61 ++++++++++++++++++++++++++++++++++++++++++ thanks-for-help.md | 7 ++++- 4 files changed, 76 insertions(+), 11 deletions(-) create mode 100755 1992/adrian/try.sh diff --git a/1992/adrian/.gitignore b/1992/adrian/.gitignore index d62e915cf..b4e2580d6 100644 --- a/1992/adrian/.gitignore +++ b/1992/adrian/.gitignore @@ -13,8 +13,10 @@ adsleep adsleep.c adwc adwc.c +adwc.adwc.txt *.dSYM indent indent.c indent.o prog.orig +wc.adwc.txt diff --git a/1992/adrian/README.md b/1992/adrian/README.md index ff12916b2..338ba8a1d 100644 --- a/1992/adrian/README.md +++ b/1992/adrian/README.md @@ -20,7 +20,7 @@ For more detailed information see [1992 adrian in bugs.md](/bugs.md#1992-adrian) ### Try: ```sh -./adrian adrian.grep.try < README.md +./try.sh ``` For the slow minded, try: @@ -29,9 +29,6 @@ For the slow minded, try: ./adsleep 32767 ``` -NOTE: if you do not specify an arg some of the programs such as `adsleep` it -will very likely segfault do something funny. This is supposed to happen. - ## Judges' remarks: @@ -160,11 +157,11 @@ Running: will perform a function similar to that of the unix `from` command. -If no filename is specified on the command line, then `__FILE__` is used -as the specification for the automaton. (Originally `"adgrep.c"` the file was renamed -to `adrian.c` by the judges but for more portability the arg was changed to -`__FILE__`.) In this case, the program will search for -matches to the regular expression: +If no filename is specified on the command line, then `__FILE__` is used as the +specification for the automaton. (Originally this was `"adgrep.c"` but the file +was renamed to `adrian.c` by the judges and for more portability the arg was +changed to `__FILE__`.) In this case, the program will search for matches to +the regular expression: ``` ^.[^|C][^w[Q]*(Q|[w[]c).*|^.[C|]$ @@ -219,7 +216,7 @@ you can search for matches to By some freak happenstance, lines of `adrian.c` which match this regular expression form a unix `head(1)` command. It prints the first ten lines of -the file specified on the command line or adrian.c if no file is +the file specified on the command line or `adrian.c` if no file is specified (again this was changed to `__FILE__`). By setting the first line to diff --git a/1992/adrian/try.sh b/1992/adrian/try.sh new file mode 100755 index 000000000..59b715692 --- /dev/null +++ b/1992/adrian/try.sh @@ -0,0 +1,61 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 1992/adrian +# + +# 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 + +# don't redirect output to /dev/null so that they can see how it's done, +# assuming it's not already built +make CC="$CC" everything || exit 1 +# DON'T clear the screen so they can see how the files are generated! + +echo 1>&2 +read -r -n 1 -p "Press any key to show: adrian.grep.try: " +echo 1>&2 +cat adrian.grep.try +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./adrian adrian.grep.try < README.md: " +echo 1>&2 +./adrian adrian.grep.try < README.md +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./adhead try.sh: " +echo 1>&2 +./adhead try.sh +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./adecho 1992 IOCCC adrian: " +echo 1>&2 +./adecho 1992 IOCCC adrian +echo 1>&2 + +rm -f wc.adwc.txt adwc.adwc.txt +echo "$ wc adwc.c | sed -e 's/^[[:space:]]//g' | tr -s '[:space:]' | cut -d' ' -f1-3 | tee wc.adwc.txt" 1>&2 +read -r -n 1 -p "Press any key to continue: " +echo 1>&2 +wc adwc.c | sed -e 's/^[[:space:]]//g' | tr -s '[:space:]' | cut -d' ' -f1-3 | tee wc.adwc.txt +echo 1>&2 + +echo "$ ./adwc adwc.c|tr -s ' '|sed -e 's/^[[:space:]]//g' | tee adwc.adwc.txt" 1>&2 +read -r -n 1 -p "Press any key to continue: " +echo 1>&2 +./adwc adwc.c|tr -s ' '|sed -e 's/^[[:space:]]//g' | tee adwc.adwc.txt +echo 1>&2 + +read -r -n 1 -p "Press any key to show diff between wc.adwc.txt and adwc.adwc.txt: " +echo 1>&2 +diff -s wc.adwc.txt adwc.adwc.txt +echo 1>&2 +rm -f wc.adwc.txt adwc.adwc.txt + +echo "$ ./adsleep 10" 1>&2 +read -r -n 1 -p "Press any key to take a 10 second nap: " +echo 1>&2 +./adsleep 10 diff --git a/thanks-for-help.md b/thanks-for-help.md index fc0e91b99..96abb5d9f 100644 --- a/thanks-for-help.md +++ b/thanks-for-help.md @@ -1427,7 +1427,7 @@ from (`__FILE__`), not `adgrep.c`, as the latter does not exist: `adgrep` is simply a link to `adrian` as `adgrep` is what the program was submitted as but the winner is `adrian.c`. -Not fixing the above problem would have also cause the program to crash if no +Not fixing the above problem would have also caused the program to crash if no arg was specified as the file doesn't exist. In making the above fix, at first the change to check for a `NULL` file was added. Then it was noticed that the problem is that `adgrep.c` was an incorrect reference that never existed and it @@ -1489,6 +1489,11 @@ one must keep the `Y[strlen(Y)-1]='\0';` part and keep it there. These fixes are complex changes due to the way the program and Makefile generate the additional tools. +Cody finally added the [try.sh](/1992/adrian/try.sh) script that shows the entry +and some of the tools this entry generates. Unlike other scripts, it does not +clear the screen after compilation so that one can see how the other files are +generated. + ## [1992/albert](/1992/albert/albert.c) ([README.md](/1992/albert/README.md])) From 5609ceaf59c517a6ec5e5cc7facc2637e5692a46 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 14 Jan 2024 10:15:40 -0800 Subject: [PATCH 07/10] Add 1993/vanb/try.sh --- 1993/vanb/README.md | 6 ++--- 1993/vanb/try.sh | 57 +++++++++++++++++++++++++++++++++++++++++++++ thanks-for-help.md | 2 ++ 3 files changed, 62 insertions(+), 3 deletions(-) create mode 100755 1993/vanb/try.sh diff --git a/1993/vanb/README.md b/1993/vanb/README.md index 0ecea9fdf..35020f285 100644 --- a/1993/vanb/README.md +++ b/1993/vanb/README.md @@ -29,9 +29,7 @@ hexadecimal and decimal numbers. ### Try: ```sh -./vanb '1+1' - -./vanb '4+4' +./try.sh ``` What happens if you use something other than valid digits? @@ -63,6 +61,7 @@ The program does no error checking - erroneous expressions will produce spurious results. Note that unary `-` is an operator. Thus, decimal `-46` would be entered as `-d46` and not `d-46`. + ### What Makes This Program Special: 0. Of course, the fact that the program takes input and produces output in @@ -86,6 +85,7 @@ format a program which has no explicit control structures (other than `?:`s). 6. Many simple tasks are done many times. I tried to do these differently each time, to make the program harder to understand. + ### How It Works: It's a recursive descent parser, calling `main()` diff --git a/1993/vanb/try.sh b/1993/vanb/try.sh new file mode 100755 index 000000000..febf723f9 --- /dev/null +++ b/1993/vanb/try.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 1993/vanb +# + +# 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: ./vanb '1+1': " +echo 1>&2 +./vanb '1+1' +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./vanb '4+4': " +echo 1>&2 +./vanb '4+4' +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./vanb '+(1777-x11)*d2': " +echo 1>&2 +./vanb '+(1777-x11)*d2' +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./vanb '-(1777-x11)*d2': " +echo 1>&2 +./vanb '-(1777-x11)*d2' +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./vanb '(1777-xfeed*xdead-xd00d+xf00d)*d2': " +echo 1>&2 +./vanb '(1777-xfeed*xdead-xd00d+xf00d)*d2' +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./vanb '777+777-111*111/123%155': " +echo 1>&2 +./vanb '777+777-111*111/123%155' +echo 1>&2 + +read -r -n 1 -p "Press any key: ./vanb '777-8': " +echo 1>&2 +./vanb '777-8' +echo "... what happened?" 1>&2 + +read -r -n 1 -p "Press any key to run: ./vanb '777*8': " +echo 1>&2 +./vanb '777*8' +echo "... what happened?" 1>&2 +exit 0 diff --git a/thanks-for-help.md b/thanks-for-help.md index 96abb5d9f..4d7047f1c 100644 --- a/thanks-for-help.md +++ b/thanks-for-help.md @@ -1809,6 +1809,8 @@ but fixed to work with clang as well. NOTE: the `N1` and `N2` are provided as notes in the README.md file describing this code. Other code is also described there. +Cody also added the [try.sh](/1993/vanb/try.sh) script. + # 1994 From d347b24626b1ee4c4ab741d72dc5338015e91918 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 14 Jan 2024 10:23:37 -0800 Subject: [PATCH 08/10] Add 1993/ejb/try.sh --- 1993/ejb/README.md | 8 ++++++++ 1993/ejb/try.sh | 31 +++++++++++++++++++++++++++++++ thanks-for-help.md | 5 +++++ 3 files changed, 44 insertions(+) create mode 100755 1993/ejb/try.sh diff --git a/1993/ejb/README.md b/1993/ejb/README.md index 51cc9d0e4..57208d11e 100644 --- a/1993/ejb/README.md +++ b/1993/ejb/README.md @@ -18,6 +18,14 @@ level a value from -128 to 127 ``` +## Try: + + +```sh +./try.sh +``` + + ## Judges' remarks: A negative argument plays the patience puzzle. An argument diff --git a/1993/ejb/try.sh b/1993/ejb/try.sh new file mode 100755 index 000000000..cca8f30b4 --- /dev/null +++ b/1993/ejb/try.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 1993/ejb +# + +# 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 play the patience puzzle: ./ejb -3: " +echo 1>&2 +./ejb -3 +echo 1>&2 + +read -r -n 1 -p "Press any key to play the Tower of Hanoi puzzle: ./ejb 3: " +echo 1>&2 +./ejb 3 +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./ejb 0: " +echo 1>&2 +./ejb 0 +exit 0 diff --git a/thanks-for-help.md b/thanks-for-help.md index 4d7047f1c..a84ffa18a 100644 --- a/thanks-for-help.md +++ b/thanks-for-help.md @@ -1716,6 +1716,11 @@ first. [Cody](#cody) fixed the script to work which assumed that `.` is in the path. +## [1993/ejb](/1993/ejb/ejb.c) ([README.md](/1993/ejb/README.md])) + +[Cody](#cody) added the [try.sh](/1993/ejb/try.sh) script. + + ## [1993/jonth](/1993/jonth/jonth.c) ([README.md](/1993/jonth/README.md])) Both [Cody](#cody) and [Yusuke](#yusuke) fixed this so that it will work with modern systems. Yusuke From 58195f6192db4cc8e1be1e8a2b2fb4cb38303f34 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 14 Jan 2024 10:34:44 -0800 Subject: [PATCH 09/10] Add 1993/dgibson/try.sh --- 1993/dgibson/README.md | 5 +++-- 1993/dgibson/dgibson.sh | 12 ++++++++++-- 1993/dgibson/try.sh | 17 +++++++++++++++++ thanks-for-help.md | 6 +++++- 4 files changed, 35 insertions(+), 5 deletions(-) create mode 100755 1993/dgibson/try.sh diff --git a/1993/dgibson/README.md b/1993/dgibson/README.md index 9c265098d..046b90d25 100644 --- a/1993/dgibson/README.md +++ b/1993/dgibson/README.md @@ -19,7 +19,7 @@ where: ### Try: ```sh -./dgibson.sh dgibson.data3 +./try.sh ``` @@ -38,7 +38,8 @@ There are a number of data files available: - [dgibson.data5](dgibson.data5) For [dgibson.data5](dgibson.data5) you will need a large screen, lots of virtual -memory and lots of time! +memory and lots of time! The [try.sh](try.sh) script will run +[dgibson.sh](dgibson.sh) on all the data files. Good luck trying to use a debugger on this entry! Life is not always pretty. diff --git a/1993/dgibson/dgibson.sh b/1993/dgibson/dgibson.sh index 35bb9d8f0..c3482fce9 100755 --- a/1993/dgibson/dgibson.sh +++ b/1993/dgibson/dgibson.sh @@ -1,6 +1,6 @@ #!/bin/sh # -# dgibson.sh - run the dgibson entry +# dgibson.sh - run the IOCCC winner 1993/dgibson # # usage: # dgibson.sh [data_file] @@ -45,7 +45,15 @@ fi # build a new copy of the program # rm -f dgibson -make dgibson +# 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 + # form the next generation # diff --git a/1993/dgibson/try.sh b/1993/dgibson/try.sh new file mode 100755 index 000000000..c5ffa0550 --- /dev/null +++ b/1993/dgibson/try.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 1993/dgibson +# + +# we make use of the script dgibson.sh so we don't need to compile it. In any +# event that script rebuilds the program. +if [[ -z "$CC" ]]; then + CC="cc" +fi + +for f in dgibson.data[1-5]; do + read -r -n 1 -p "Press any key to run: CC=$CC ./dgibson.sh $f: " + echo 1>&2 + CC="$CC" ./dgibson.sh "$f" + echo 1>&2 +done diff --git a/thanks-for-help.md b/thanks-for-help.md index a84ffa18a..2c710308f 100644 --- a/thanks-for-help.md +++ b/thanks-for-help.md @@ -1713,7 +1713,11 @@ first. ## [1993/dgibson](/1993/dgibson/dgibson.c) ([README.md](/1993/dgibson/README.md])) -[Cody](#cody) fixed the script to work which assumed that `.` is in the path. +[Cody](#cody) fixed the [dgibson.sh](/1993/dgibson/dgibson.sh) script to work +which assumed that `.` is in the path. + +Cody also added the [try.sh](/1993/dgibson/try.sh) script which runs the above +mentioned script on all the data files. ## [1993/ejb](/1993/ejb/ejb.c) ([README.md](/1993/ejb/README.md])) From 9a283ae744d5a08ed0ea2f6eebb47b66e190f519 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 14 Jan 2024 10:50:02 -0800 Subject: [PATCH 10/10] Add 1993/ant/try.txt and ants.txt The ants.txt file is something that kids throughout the English speaking world are tortured with, some having been forced to repeat it many, many, many, too many times, but which fits well here: a grep program called 'ant' should find lots of ants :-) (and it is a fun use .. or maybe I just wish to subject others to the torture I was subjected to decades ago? :-) ) --- 1993/ant/README.md | 4 +--- 1993/ant/ants.txt | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 1993/ant/try.sh | 41 +++++++++++++++++++++++++++++++ thanks-for-help.md | 6 +++++ 4 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 1993/ant/ants.txt create mode 100755 1993/ant/try.sh diff --git a/1993/ant/README.md b/1993/ant/README.md index d8e45d594..e509d18b0 100644 --- a/1993/ant/README.md +++ b/1993/ant/README.md @@ -25,10 +25,8 @@ For more detailed information see [1993 ant in bugs.md](/bugs.md#1993-ant). ### Try: -You may also want to try the author's test suite: - ```sh -make -f ant.test.mk +./try.sh ``` diff --git a/1993/ant/ants.txt b/1993/ant/ants.txt new file mode 100644 index 000000000..50037e126 --- /dev/null +++ b/1993/ant/ants.txt @@ -0,0 +1,60 @@ +The ants go marching one by one, hurrah, hurrah +The ants go marching one by one, hurrah, hurrah +The ants go marching one by one, +The little one stops to suck his thumb +And they all go marching down to the ground +To get out of the rain, BOOM! BOOM! BOOM! +The ants go marching two by two, hurrah, hurrah +The ants go marching two by two, hurrah, hurrah +The ants go marching two by two, +The little one stops to tie his shoe +And they all go marching down to the ground +To get out of the rain, BOOM! BOOM! BOOM! +The ants go marching three by three, hurrah, hurrah +The ants go marching three by three, hurrah, hurrah +The ants go marching three by three, +The little one stops to climb a tree +And they all go marching down to the ground +To get out of the rain, BOOM! BOOM! BOOM! +The ants go marching four by four, hurrah, hurrah +The ants go marching four by four, hurrah, hurrah +The ants go marching four by four, +The little one stops to shut the door +And they all go marching down to the ground +To get out of the rain, BOOM! BOOM! BOOM! +The ants go marching five by five, hurrah, hurrah +The ants go marching five by five, hurrah, hurrah +The ants go marching five by five, +The little one stops to take a dive +And they all go marching down to the ground +To get out of the rain, BOOM! BOOM! BOOM! +The ants go marching six by six, hurrah, hurrah +The ants go marching six by six, hurrah, hurrah +The ants go marching six by six, +The little one stops to pick up sticks +And they all go marching down to the ground +To get out of the rain, BOOM! BOOM! BOOM! +The ants go marching seven by seven, hurrah, hurrah +The ants go marching seven by seven, hurrah, hurrah +The ants go marching seven by seven, +The little one stops to pray to heaven +And they all go marching down to the ground +To get out of the rain, BOOM! BOOM! BOOM! +The ants go marching eight by eight, hurrah, hurrah +The ants go marching eight by eight, hurrah, hurrah +The ants go marching eight by eight, +The little one stops to roller skate +And they all go marching down to the ground +To get out of the rain, BOOM! BOOM! BOOM! +The ants go marching nine by nine, hurrah, hurrah +The ants go marching nine by nine, hurrah, hurrah +The ants go marching nine by nine, +The little one stops to check the time +And they all go marching down to the ground +To get out of the rain, BOOM! BOOM! BOOM! +The ants go marching ten by ten, hurrah, hurrah +The ants go marching ten by ten, hurrah, hurrah +The ants go marching ten by ten, +The little one stops to shout "The End", +And they all go marching down to the ground +To get out of the rain. diff --git a/1993/ant/try.sh b/1993/ant/try.sh new file mode 100755 index 000000000..331d88553 --- /dev/null +++ b/1993/ant/try.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 1993/ant +# + +# 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: ./ant ant README.md: " +echo 1>&2 +./ant ant README.md +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./ant '\[' ant.txt: " +echo 1>&2 +./ant '\[' ant.txt +echo 1>&2 + +echo "Note: the next one should show: ag: Pattern too long." 1>&2 +read -r -n 1 -p "Press any key to run: ./ant '[' ant.txt: " +echo 1>&2 +./ant '[' ant.txt +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./ant ant ants.txt | cut -d: -f2 (space = next page, q = quit): " +echo 1>&2 +./ant ant ants.txt | cut -d: -f2 | less -rEXF +echo 1>&2 + +read -r -n 1 -p "Press any key to run the test suite (make -f ant.test.mk) (space = next page, q = quit): " +echo 1>&2 +make -f ant.test.mk | less -rEXF diff --git a/thanks-for-help.md b/thanks-for-help.md index 2c710308f..3c805708d 100644 --- a/thanks-for-help.md +++ b/thanks-for-help.md @@ -1703,6 +1703,12 @@ encourage you to try the original without two args :-) # 1993 +## [1993/ant](/1993/ant/ant.c) ([README.md](/1993/ant/README.md])) + +[Cody](#cody) added the [try.sh](/1993/ant/try.sh) script and a data file, +[ants.txt](/1993/ant/ants.txt), full of ants for the script. + + ## [1993/cmills](/1993/cmills/cmills.c) ([README.md](/1993/cmills/README.md])) [Yusuke](#yusuke) suggested that with modern systems this goes too fast so he added a call