Improve 2012/endoh1 alt code, add try.alt.sh
The alt code now has an option to use alarm(3) so that one need not hit ctrl-c/intr for each run (default 10 seconds, can be disabled or changed at compilation just like the other macros). This is used in try.alt.sh which shows the program (colour version) on the source code and then the text files provided by the author. The script does two 'versions' for each file: one with setting gravity factor to I (see author's remarks) and one without that. These changes make a nice demonstration of the entry. This commit also fixed a problem that the previous commit caused to do with the alt targets in the Makefile. This should complete the review of 2012/endoh1, leaving two more to go for 2012.
This commit is contained in:
1 parent
af3b4f5166
commit
c9503446e4
7 files changed
+106
-23
No files matched your search
Executable
+47
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# try.alt.sh - demonstrate IOCCC winner 2012/endoh1 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
|
||||
|
||||
|
||||
# unlike other try.sh/try.alt.sh scripts this one has two compiled binaries: one
|
||||
# which sets the gravity factor to I and the other that does not.
|
||||
make clobber CC="$CC" CDEFINE="-DA=10 -DG=I -DS=39000" alt >/dev/null || exit 1
|
||||
# we have to move the endoh1_color.alt to endoh1_color.alt3, not alt2, because
|
||||
# we have to use make clobber which would wipe out endoh1_color.alt2.
|
||||
mv endoh1_color.alt endoh1_color.alt3
|
||||
make clobber CC="$CC" CDEFINE="-DA=10 -DS=39000" alt >/dev/null || exit 1
|
||||
read -r -n 1 -p "Press any key run run slower fluid on endoh1_color.alt.c: "
|
||||
mv endoh1_color.alt3 endoh1_color.alt2
|
||||
# clear screen before continuing
|
||||
clear
|
||||
|
||||
|
||||
# now that we have both binaries we can run each one on the data files, first
|
||||
# the source file.
|
||||
./endoh1_color.alt < endoh1_color.alt.c 2>/dev/null
|
||||
./endoh1_color.alt2 < endoh1_color.alt.c 2>/dev/null
|
||||
clear
|
||||
|
||||
# for each of the supplied text files we will run both 'versions' on them, in
|
||||
# succession, prompting the user for each text file so they know the name.
|
||||
for i in clock.txt column.txt column2.txt column3.txt corners.txt \
|
||||
dripping-pan.txt evaporation.txt flat.txt fountain.txt funnel.txt \
|
||||
funnel2.txt funnel3.txt glass-half-empty.txt leidenfrost.txt logo.txt \
|
||||
pour-out.txt tanada.txt; do
|
||||
|
||||
# to make it more 'fluid' :-) we only prompt once per file even though the
|
||||
# second command is a different file in that the gravity factor is set to I.
|
||||
read -r -n 1 -p "Press any key to run: ./endoh1_color.alt < $i: "
|
||||
./endoh1_color.alt < "$i" 2>/dev/null
|
||||
clear
|
||||
./endoh1_color.alt2 < "$i" 2>/dev/null
|
||||
clear
|
||||
done
|
||||
Reference in new issue
Block a user