Add 2014/vik/try.sh, update bugs.md, fix clobber

The bugs.md has more details on the bug I discovered when working on
2020/ferguson2. Even the usage in the try section (now in try.sh)
resulted in files that cannot be translated to English right.

The make clobber rule now removes *.raw instead of specific raw files.
This is important for clean up prior to updating the manifest.

Updated .gitignore.
This commit is contained in:
Cody Boone Ferguson committed 2024-01-29 08:17:01 -08:00
1 parent 5cbf43230c
commit 4210888212
6 files changed
+121 -14

No files matched your search

+1 -1
View File
@@ -8,4 +8,4 @@ indent.o
prog
prog.alt
prog.orig
prog.raw
*.raw
+1 -1
View File
@@ -203,7 +203,7 @@ clean:
clobber: clean
${RM} -f ${TARGET} ${ALT_TARGET}
${RM} -rf *.dSYM
${RM} -f audio_file.raw prog.raw
${RM} -f *.raw
@-if [ -e sandwich ]; then \
${RM} -f sandwich; \
echo 'ate sandwich'; \
+4 -4
View File
@@ -23,16 +23,16 @@ For more detailed information see [2014 vik in bugs.md](/bugs.md#2014-vik).
## To use:
```sh
./prog > foo.c
echo foo | ./prog > audio_file.raw
echo foo | ./prog | mplayer -demuxer rawaudio -
```
## Try:
```sh
echo 'Want to hear me beep?' | ./prog > audio_file.raw
echo 'No. I want chocolate!' | ./prog | mplayer -demuxer rawaudio -
./try.sh
```
+70
View File
@@ -0,0 +1,70 @@
#!/usr/bin/env bash
#
# try.sh - demonstrate IOCCC winner 2014/vik
#
# 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 target files for saving them
rm -f beep.raw chocolate.raw
write_to_raw()
{
if [[ "$#" -ne 2 ]]; then
echo "$0: usage: write_to_raw file arg" 1>&2
return
fi
read -r -n 1 -p "Press any key to run: echo $2 | ./prog > $1.raw: "
echo "$2" | ./prog > "$1".raw
}
# now determine if we have mplayer(1)
MPLAYER="$(type -P mplayer)"
if [[ -n "$MPLAYER" ]]; then
read -r -n 1 -p "Press any key to play: 'Want to hear me beep?': "
echo 1>&2
echo "$ echo 'Want to hear me beep?' | ./prog | mplayer -demuxer rawaudio -" 1>&2
echo 'Want to hear me beep?' | ./prog | mplayer -demuxer rawaudio -
echo 1>&2
read -r -n 1 -p "Press any key to run: ./prog e < beep.raw: "
echo 1>&2
./prog e < beep.raw
echo 1>&2
read -r -n 1 -p "Press any key to play: 'No. I want chocolate!': "
echo 1>&2
echo "$ echo 'No. I want chocolate!' | ./prog | mplayer -demuxer rawaudio - | tee chocolate.raw" 1>&2
echo 'No. I want chocolate!' | ./prog | mplayer -demuxer rawaudio - | tee chocolate.raw
read -r -n 1 -p "Press any key to run: ./prog e < chocolate.raw: "
echo 1>&2
fi
read -r -n 1 -p "Press any key to run: echo 'Want to hear me beep?' | ./prog > beep.raw: "
echo 1>&2
echo 'Want to hear me beep?' | ./prog > beep.raw
echo 1>&2
read -r -n 1 -p "Press any key to run: ./prog e < beep.raw: "
echo 1>&2
./prog e < beep.raw
echo 1>&2
read -r -n 1 -p "Press any key to run: echo 'No. I want chocolate!' | ./prog > chocolate.raw: "
echo 1>&2
echo 'No. I want chocolate!' | ./prog > chocolate.raw
echo 1>&2
read -r -n 1 -p "Press any key to run: ./prog e < chocolate.raw: "
echo 1>&2
./prog e < chocolate.raw