Add 2001/coupard/try.sh

This commit is contained in:
Cody Boone Ferguson committed 2024-02-06 02:37:52 -08:00
1 parent 73df990d9f
commit c6f12a2a23
3 files changed
+46 -16

No files matched your search

+1 -12
View File
@@ -14,19 +14,8 @@ make
## Try:
If you have access to `/dev/audio` or `/dev/sound/dsp`:
```sh
./coupard > /dev/audio
./coupard > /dev/sound/dsp
```
If you do not, first install [sox](https://en.wikipedia.org/wiki/SoX). If you
use macOS you might install it from [MacPorts](https://www.macports.org) or
[Homebrew](https://brew.sh). Then you can try:
```sh
./coupard | sox -q -traw -r8000 -b8 -e unsigned-integer - -tcoreaudio
./try.sh
```
+36
View File
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
#
# try.sh - demonstrate IOCCC winner 2001/coupard
#
# 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.
[[ -z "$CC" ]] && CC="cc"
# in this case we won't fail if we can't compile the code because we can still
# run the supplementary program.
make CC="$CC" everything >/dev/null
# clear screen after compilation so that only the entry is shown
clear
# hopefully sox(1) is installed but we check for it just in case that it's not
SOX="$(type -P sox)"
AUDIO="/dev/audio"
DSP="/dev/sound/dsp"
if [[ -n "$SOX" ]]; then
echo "$ ./coupard | $SOX -q -traw -r8000 -b8 -e unsigned-integer - -tcoreaudio" 1>&2
read -r -n 1 -p "Press any key to continue: "
echo 1>&2
./coupard | "$SOX" -q -traw -r8000 -b8 -e unsigned-integer - -tcoreaudio
echo 1>&2
elif [[ -S "$AUDIO" ]]; then
./coupard > "$AUDIO"
elif [[ -S "$DSP" ]]; then
./coupard > "$DSP"
else
echo "SoX not installed. Please install it and try again." 1>&2
echo "Tip: see https://github.com/ioccc-src/temp-test-ioccc/blob/master/faq.md#sox." 1>&2
fi