Add 1996/gandalf/try.sh and format README.md

The script is rather elaborate in that it runs the programs in the
different ways the judges previously suggested as well as some
additional runs and shows the difference (or if no difference says they
are identical) of the different commands, using temporary files that are
deleted if the script is sent (some) signals, the script is quit (when
prompted to press a key pressing 'q' will quit the script) or if the
script runs to completion.

The README.md file was format/typo checked.

BTW: it is absolutely perilous to try the patience of Gandalf
(https://www.glyphweb.com/arda/g/gandalf.html). Go ahead, try it! :-)

The Makefile has had -Wno-implicit-int added to CSILENCE.
This commit is contained in:
Cody Boone Ferguson committed 2023-11-11 04:20:00 -08:00
1 parent 64154fcc25
commit aee071cdf8
4 files changed
+118 -14

No files matched your search

+1 -1
View File
@@ -39,7 +39,7 @@ include ../../var.mk
# Common C compiler warnings to silence
#
CSILENCE= -Wno-error -Wno-implicit-function-declaration -Wno-keyword-macro \
-Wno-shift-op-parentheses -Wno-unused-parameter \
-Wno-shift-op-parentheses -Wno-unused-parameter -Wno-implicit-int \
-Wno-deprecated-non-prototype -Wno-strict-prototypes -Wno-unsequenced
# Common C compiler warning flags
+7 -13
View File
@@ -26,21 +26,12 @@ For more detailed information see [1996 gandalf in bugs.md](/bugs.md#1996-gandal
### Try:
```sh
PATH=.:$PATH
./hatcat
./cathat
./try.sh
```
And next try:
```sh
./cathat
`pwd`/cathat
```
Care to guess why these execute differently? Only the
compiler knows ... ok maybe other things like the author,
the judges and maybe you too?
As the script asks, care to guess why these execute differently? Only the
compiler knows ... ok maybe other things like the author, the judges and perhaps
you too?
## Judges' remarks:
@@ -51,6 +42,9 @@ For misleading C pre-processor output, try:
cc -E gandalf.c
```
BTW: it is perilous to try the patience of
[Gandalf](https://www.glyphweb.com/arda/g/gandalf.html). Go ahead, try it! :-)
## Author's remarks:
+104
View File
@@ -0,0 +1,104 @@
#!/usr/bin/env bash
make all 1>/dev/null || exit 1
# remove temporary files to show later
rm -f hatcat.txt cathat.txt hatcat2.txt cathat2.txt hatcat3.txt cathat3.txt
trap 'rm -f hatcat.txt cathat.txt hatcat2.txt cathat2.txt hatcat3.txt cathat3.txt; exit' 0 1 2 3 15
delete_tmp_files()
{
rm -f hatcat.txt cathat.txt hatcat2.txt cathat2.txt hatcat3.txt cathat3.txt
return 0
}
press_any_key()
{
echo 1>&2
read -r -n 1 -p "Press any key to continue (q = quit): " 1>&2
test "$REPLY" = "q" && delete_tmp_files && echo 1>&2 && exit
}
show_diff()
{
if [[ "$#" -ne 2 ]]; then
echo "$0: show_diff expects two args, got: $#" 1>&2
exit 1
fi
echo "$ diff $1 $2" 1>&2
diff "$1" "$2" && echo "$1 and $2 are identical"
}
echo "Notice how the programs are the same:" 1>&2
diff -s hatcat cathat
press_any_key
echo "Now notice how running both cathat and hatcat in different ways" 1>&2
echo "shows different output." 1>&2
press_any_key
echo "Running hatcat without a path:" 1>&2
echo "$ PATH=.:\$PATH" 1>&2
PATH=.:$PATH
echo "$ hatcat | tee hatcat.txt" 1>&2
hatcat | tee hatcat.txt
press_any_key
echo "Running cathat without a path:" 1>&2
echo "$ cathat | tee cathat.txt" 1>&2
cathat | tee cathat.txt
press_any_key
echo "Showing diff between the above two commands, 'hatcat' and './cathat':" 1>&2
show_diff hatcat.txt cathat.txt
press_any_key
echo "Now watch ./hatcat:" 1>&2
./hatcat | tee hatcat2.txt
press_any_key
echo "Now watch ./cathat:" 1>&2
./cathat | tee cathat2.txt
press_any_key
echo "Showing diff between running 'hatcat' and './hatcat':" 1>&2
show_diff hatcat.txt hatcat2.txt
press_any_key
echo "Now watch \$(pwd)/cathat" 1>&2
"$(pwd)"/cathat | tee cathat3.txt
press_any_key
echo "Finally, watch \$(pwd)/hatcat" 1>&2
"$(pwd)"/hatcat | tee hatcat3.txt
press_any_key
echo "Showing diff between running './hatcat' and './cathat':" 1>&2
show_diff hatcat2.txt cathat2.txt
press_any_key
echo "Showing diff between running '\$(pwd)/hatcat' and '\$(pwd)/cathat':" 1>&2
show_diff hatcat3.txt cathat3.txt
press_any_key
echo "Showing diff between running '\$(pwd)/hatcat' and 'hatcat':" 1>&2
show_diff hatcat3.txt hatcat.txt
press_any_key
echo "Showing diff between running '\$(pwd)/hatcat' and './hatcat':" 1>&2
show_diff hatcat3.txt hatcat2.txt
press_any_key
echo "Showing diff between running '\$(pwd)/cathat' and 'cathat':" 1>&2
show_diff cathat3.txt cathat.txt
press_any_key
echo "Showing diff between running '\$(pwd)/cathat' and './cathat':" 1>&2
show_diff cathat3.txt cathat2.txt
press_any_key
# remove temporary files
rm -f hatcat.txt cathat.txt hatcat2.txt cathat2.txt hatcat3.txt cathat3.txt
echo 1>&2
echo "Now answer: why did some of the same programs execute differently?" 1>&2
+6
View File
@@ -1951,6 +1951,12 @@ Cody fixed this to compile and work with modern systems. As he loved the
references in the code that could not compile he just commented out as little as
possible to get this to compile.
Cody also added the rather useful [try.sh](1996/gandalf/try.sh) script to
really demonstrate the different ways of running the program ends up showing
either different output or the same output that we briefly pointed out.
BTW: it is perilous to try the patience of
[Gandalf](https://www.glyphweb.com/arda/g/gandalf.html). Go ahead, try it! :-)
## [1996/jonth](1996/jonth/jonth.c) ([README.md](1996/jonth/README.md]))