Improve alt build of 1989/ovdluhe

One can now do

    make clobber P=5 alt

instead of the more awkward

    make clobber CDEFINE="-DP=5" alt

The try.alt.sh script was added and allows one to do

    P=5 ./try.alt.sh

If P is not specified it uses the default of the alt code (which checks
if it's defined first via #ifdef..#endif). Otherwise it uses the new
value. Of course if one specifies not an int or too high value (or maybe
too low - didn't try that) the program will fail. That is the fault of
the user. The author does note a reasonable range to try.
This commit is contained in:
Cody Boone Ferguson committed 2024-01-11 10:11:03 -08:00
1 parent 250d1904b5
commit b066c51da1
4 files changed
+60 -6

No files matched your search

+38
View File
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
#
# try.alt.sh - demonstrate IOCCC winner 1989/ovdluhe.alt 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
# user may also reconfigure P
if [[ -n "$P" ]]; then
make clobber CC="$CC" P="$P" alt >/dev/null || exit 1
else
make clobber CC="$CC" alt >/dev/null || exit 1
fi
# clear screen after compilation so that only the entry is shown
i=0
for ((i=0; i<4; ++i)); do
read -r -n 1 -p "Press any key to run: ./ovdluhe.alt < ovdluhe.alt.c: "
echo 1>&2
./ovdluhe.alt < ovdluhe.alt.c
echo 1>&2
read -r -n 1 -p "Press any key to run: ./ovdluhe.alt < README.md: "
echo 1>&2
./ovdluhe.alt < README.md
echo 1>&2
read -r -n 1 -p "Press any key to run: ./ovdluhe.alt < Makefile: "
echo 1>&2
./ovdluhe.alt < Makefile
echo 1>&2
done