Add alt code to 2012/omoikane + try + formatting

There are two alt versions which should be useful for (respectively)
those who do not have /dev/urandom and those who use Windows. Both of
these versions read from argv[0] instead of /dev/urandom but the second
one sets binary mode on stdin and stdout. This is to be consistent with
the fact that other entries also have this as an alt version.

The try.sh and try.alt.sh scripts work on the entry and the first
version of the alt code, the one that is not Windows specific. The
scripts consist of commands from both the to use section of the
README.md (which is still there) and the try section (which now refers
to try.sh).

Format/typo checks in README.md file.
This commit is contained in:
Cody Boone Ferguson committed 2023-12-01 09:23:43 -08:00
1 parent 06b816e353
commit 00e336df7a
8 files changed
+379 -22

No files matched your search

+89
View File
@@ -0,0 +1,89 @@
#!/usr/bin/env bash
#
# try.sh - demonstrate IOCCC winner 2012/omoikane
#
# 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
# remove temporary files before writing to them
rm -f output output.2 output.c data data.c key.c
# we need to find out if perl is installed
PERL="$(type -P perl)"
echo "$ echo \"A quick brown fox jumps over the lazy dog\" | ./nyaruko > output.c" 1>&2
echo "A quick brown fox jumps over the lazy dog" | ./nyaruko > output.c
read -r -n 1 -p "Press any key to run: less -EX output.c (space = next page, q = quit): "
echo 1>&2
less -EX output.c
# perl specific stuff
if [[ -n "$PERL" ]]; then
read -r -n 1 -p "Press any key to run: ${PERL} output.c > data.c: " 1>&2
echo 1>&2
"${PERL}" output.c > data.c
read -r -n 1 -p "Press any key to run: less -EX data.c (space = next page, q = quit): "
echo 1>&2
less -EX data.c
echo "$ cc -o data data.c" 1>&2
cc -o data data.c
read -r -n 1 -p "Press any key to run: ./data: "
echo "$ ./data" 1>&2
echo 1>&2
./data
fi
echo "$ cc -o output output.c" 1>&2
cc -o output output.c
read -r -n 1 -p "Press any key to run: ./output: "
echo 1>&2
echo "$ ./output" 1>&2
./output
read -r -n 1 -p "Press any key to run: ./nyaruko < output > output.c: "
echo 1>&2
./nyaruko < output > output.c
read -r -n 1 -p "Press any key to run: less -EX output.c (space = next page, q = quit): "
echo 1>&2
less -EX output.c
read -r -n 1 -p "Press any key to run: bash output.c > key.c: "
bash output.c > key.c
echo 1>&2
read -r -n 1 -p "Press any key to run: less -EX key.c (space = next page, q = quit): "
less -EX key.c
# more perl stuff
if [[ -n "${PERL}" ]]; then
read -r -n 1 -p "Press any key to run: ${PERL} output.c > data.c: "
echo 1>&2
"${PERL}" output.c > data.c
read -r -n 1 -p "Press any key to run: less -EX data.c (space = next page, q = quit): "
echo 1>&2
less -EX data.c
read -r -n 1 -p "Press any key to run: cat key.c data.c > output.c: "
echo 1>&2
cat key.c data.c > output.c
read -r -n 1 -p "Press any key to run: less -EX output.c (space = next page, q = quit): "
echo 1>&2
less -EX output.c
echo "$ cc output.c -o output" 1>&2
cc output.c -o output
read -r -n 1 -p "Press any key to run: ./output > output.2: "
echo 1>&2
./output > output.2
echo "$ chmod +x output.2" 1>&2
chmod +x output.2
read -r -n 1 -p "Press any key to run: ./output.2: "
./output.2
fi