Add try.sh to 1985/sicherman

The Makefile was also modified to have a sicherman.alt rule as it
requires -traditional-cpp. There is an argument that this should be
removed and instead the alt2 version (which is compiled if a compiler
fails to compile sicherman.c because of the 'wrong' number of args to
main() - one arg) would become the alt version because if someone wants
to try the original code they can look at sicherman.orig.c. This can be
done another time if it's worth doing (which I think it might be).
This commit is contained in:
Cody Boone Ferguson committed 2023-12-23 09:07:49 -08:00
1 parent ec71d8ad68
commit 53fb889475
4 files changed
+65 -19

No files matched your search

+2
View File
@@ -141,6 +141,8 @@ ${PROG}: ${PROG}.c ${PROG}.alt2.c
alt: data ${ALT_TARGET}
@${TRUE}
${PROG}.alt: ${PROG}.alt.c
${CC} ${CFLAGS} -traditional-cpp $< -o $@ ${LDFLAGS}
# data files
#
+11 -9
View File
@@ -4,13 +4,14 @@
make all
```
NOTE: there is an [alternate version](#alternate-code) for those who have an old
enough compiler or have a compiler that supports the option `-traditional-cpp`.
There is also an alternate version that is meant to work in the case that your
version of clang fails to compile it due to the wrong number of args to `main()`
should that ever happen (a compiler error of some versions of clang if `main()`
has four args is that `main()` can only have 0, 2 or 3 args but it does
currently accept 1 arg to `main()` nonetheless).
There is an alternate version for those with an old enough compiler or one that
accepts `-traditional-cpp`. The second alt version will be compiled in the case
that you have a compiler that does not support 1 arg only in `main()`. For
instance clang has a number of defects and some versions say that `main()` can
only have 0, 2 or 3 args. The versions that have this that we know about do
support 1 arg but in case this is ever changed the
[sicherman.alt2.c](sicherman.alt2.c) is provided. See [Alternate
code](#alternate-code) below for details on the alt code, the original entry.
## To use:
@@ -35,8 +36,8 @@ echo IOCCC | ./sicherman
## Alternate code:
This alternate version, which is the original entry, requires either an old
enough compiler or a compiler that supports `-traditional-cpp`. If you have such
The [sicherman.alt.c](sicherman.alt.c) is the original entry and requires either
an old enough compiler or a compiler that supports `-traditional-cpp`. If you have such
a compiler you can try this version.
@@ -44,6 +45,7 @@ a compiler you can try this version.
```sh
make alt
```
+36
View File
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
#
# try.sh - demonstrate IOCCC winner 1985/sicherman
#
# 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
read -r -n 1 -p "Press any key to run: ./sicherman < sicherman.c: "
echo 1>&2
./sicherman < sicherman.c
echo 1>&2
read -r -n 1 -p "Press any key to run: echo IOCCC | ./sicherman: "
echo 1>&2
echo IOCCC | ./sicherman
echo 1>&2
read -r -n 1 -p "Press any key to run: ./sicherman < sicherman.c | ./sicherman: "
echo 1>&2
./sicherman < sicherman.c | ./sicherman
echo 1>&2
read -r -n 1 -p "Press any key to run: ./sicherman < sicherman.c | ./sicherman | diff -s - sicherman.c: "
echo 1>&2
./sicherman < sicherman.c | ./sicherman | diff -s - sicherman.c