diff --git a/1994/schnitzi/.gitignore b/1994/schnitzi/.gitignore index f8f3ac60e..07752b42f 100644 --- a/1994/schnitzi/.gitignore +++ b/1994/schnitzi/.gitignore @@ -8,6 +8,11 @@ prog.orig schnitzi schnitzi2 schnitzi2.c +schnitzi3 +schnitzi3.c schnitzi.alt schnitzi.alt2 schnitzi.orig +try1.txt +try2.txt +try3.txt diff --git a/1994/schnitzi/Makefile b/1994/schnitzi/Makefile index b19f80c7f..89928da1b 100644 --- a/1994/schnitzi/Makefile +++ b/1994/schnitzi/Makefile @@ -39,7 +39,7 @@ include ../../var.mk # Common C compiler warnings to silence # CSILENCE= -Wno-deprecated-declarations -Wno-error -Wno-implicit-function-declaration \ - -Wno-strict-prototypes + -Wno-strict-prototypes -Wno-implicit-int # Common C compiler warning flags # diff --git a/1994/schnitzi/README.md b/1994/schnitzi/README.md index 33f4adfbc..ca8fd4440 100644 --- a/1994/schnitzi/README.md +++ b/1994/schnitzi/README.md @@ -31,12 +31,7 @@ For more detailed information see [1994 schnitzi in bugs.md](/bugs.md#1994-schni ## Try: ```sh -./schnitzi < /etc/motd 2>/dev/null -./schnitzi < /etc/passwd 2>/dev/null - -./schnitzi < schnitzi.c > schnitzi2.c 2>/dev/null -make schnitzi2 -./schnitzi2 < README.md +./try.sh ``` @@ -65,6 +60,13 @@ Use `schnitzi.alt` and `schnitzi.alt2` as you would `schnitzi` above except that feeding the source code to it will not work right. +### Alternate try: + +```sh +./try.alt.sh +``` + + ## Judges' remarks: Try: @@ -77,6 +79,9 @@ Compare the output of the program with its source. Sure the output is different, but there is more than meets the `diff`'s eye. Can you find out why? +You might also wish to redirect the output to another file, +compile it and compare how it works to the original code. + ## Author's remarks: @@ -92,14 +97,14 @@ line; for instance, for the file 'info', the program would be run as follows: ```sh -schnitzi < info +./schnitzi < info ``` The program generates interesting results when its source file is used as input: ```sh -schnitzi < schnitzi.c +./schnitzi < schnitzi.c ``` The result of this command is a program which does the exact same diff --git a/1994/schnitzi/try.alt.sh b/1994/schnitzi/try.alt.sh new file mode 100755 index 000000000..2e61c3d39 --- /dev/null +++ b/1994/schnitzi/try.alt.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# +# try.alt.sh - demonstrate IOCCC winner 1994/schnitzi 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 + + +read -r -n 1 -p "Press any key to run: ./schnitzi.alt < README.md (space = next page, q = quit): " +echo 1>&2 +./schnitzi.alt < README.md | less -rEXF +echo 1>&2 + +echo "$ ./schnitzi.alt2 < schnitzi.alt2.c | diff - schnitzi.c" 1>&2 +read -r -n 1 -p "Press any key to continue (space = next page, q = quit): " +echo 1>&2 +./schnitzi.alt2 < schnitzi.alt2.c | diff - schnitzi.c +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./schnitzi.alt2 < README.md (space = next page, q = quit): " +echo 1>&2 +./schnitzi.alt2 < README.md +echo 1>&2 diff --git a/1994/schnitzi/try.sh b/1994/schnitzi/try.sh new file mode 100755 index 000000000..1da6af393 --- /dev/null +++ b/1994/schnitzi/try.sh @@ -0,0 +1,66 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 1994/schnitzi +# + +# 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 + + +read -r -n 1 -p "Press any key to run: ./schnitzi < schnitzi.c > schnitzi2.c: " +echo 1>&2 +./schnitzi < schnitzi.c > schnitzi2.c 2>/dev/null +echo 1>&2 + +read -r -n 1 -p "Press any key to run: make schnitzi2: " +echo 1>&2 +make schnitzi2 +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./schnitzi2 < schnitzi2.c > schnitzi3.c: " +echo 1>&2 +./schnitzi2 < schnitzi2.c > schnitzi3.c 2>/dev/null +echo 1>&2 + +read -r -n 1 -p "Press any key to run: make schnitzi3: " +echo 1>&2 +make schnitzi3 +echo 1>&2 + + +read -r -n 1 -p "Press any key to run: diff3 schnitzi.c schnitzi2.c schnitzi3.c (space = next page, q = quit): " +echo 1>&2 +diff3 schnitzi.c schnitzi2.c schnitzi3.c | less -rEXF +echo 1>&2 + +read -r -n 1 -p "Press any key to show try.txt: " +echo 1>&2 +cat try.txt +echo 1>&2 + +rm -f try1.txt try2.txt try3.txt +read -r -n 1 -p "Press any key to run: ./schnitzi < try.txt | tee try1.txt (space = next page, q = quit): " +echo 1>&2 +./schnitzi < try.txt 2>/dev/null | tee try1.txt +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./schnitzi2 < try.txt | tee try2.txt (space = next page, q = quit): " +echo 1>&2 +./schnitzi2 < try.txt 2>/dev/null | tee try2.txt +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./schnitzi3 < try.txt | tee try3.txt (space = next page, q = quit): " +echo 1>&2 +./schnitzi3 < try.txt 2>/dev/null | tee try3.txt +echo 1>&2 + +read -r -n 1 -p "Press any key to run: diff3 try1.txt try2.txt try3.txt: " +echo 1>&2 +diff3 try1.txt try2.txt try3.txt && echo "All three files are the same!" +echo 1>&2 diff --git a/1994/schnitzi/try.txt b/1994/schnitzi/try.txt new file mode 100644 index 000000000..f175fa345 --- /dev/null +++ b/1994/schnitzi/try.txt @@ -0,0 +1 @@ +1994/schnitzi IOCCC winner test file. diff --git a/thanks-for-help.md b/thanks-for-help.md index 8889a8e75..282c8d7a0 100644 --- a/thanks-for-help.md +++ b/thanks-for-help.md @@ -1935,11 +1935,15 @@ bugs.md](/bugs.md#1994-schnitzi). The purpose for these versions it both demonstrate how the magic works behind it and to help others, should they wish, get the code to work with `fgets(3)`, with -or without an increase in buffer size. See [1994/schnitzi in +or without an increase in buffer size. Note that without this feeding longer +files, say the README.md file, will crash the program. See [1994/schnitzi in bugs.md](/bugs.md#1994-schnitzi) where Cody also explains the magic for more details. Later on, if nobody takes up the task, Cody might resume it, but for now there is more important work to do so that the next contest can run. +Cody also added the [try.sh](/1994/schnitzi/try.sh) and +[try.alt.sh](/1994/schnitzi/try.alt.sh) scripts. + ## [1994/shapiro](/1994/shapiro/shapiro.c) ([README.md](/1994/shapiro/README.md]))