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:
1 parent
ec71d8ad68
commit
53fb889475
4 files changed
+65
-19
No files matched your search
@@ -141,6 +141,8 @@ ${PROG}: ${PROG}.c ${PROG}.alt2.c
|
|||||||
alt: data ${ALT_TARGET}
|
alt: data ${ALT_TARGET}
|
||||||
@${TRUE}
|
@${TRUE}
|
||||||
|
|
||||||
|
${PROG}.alt: ${PROG}.alt.c
|
||||||
|
${CC} ${CFLAGS} -traditional-cpp $< -o $@ ${LDFLAGS}
|
||||||
|
|
||||||
# data files
|
# data files
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -4,13 +4,14 @@
|
|||||||
make all
|
make all
|
||||||
```
|
```
|
||||||
|
|
||||||
NOTE: there is an [alternate version](#alternate-code) for those who have an old
|
There is an alternate version for those with an old enough compiler or one that
|
||||||
enough compiler or have a compiler that supports the option `-traditional-cpp`.
|
accepts `-traditional-cpp`. The second alt version will be compiled in the case
|
||||||
There is also an alternate version that is meant to work in the case that your
|
that you have a compiler that does not support 1 arg only in `main()`. For
|
||||||
version of clang fails to compile it due to the wrong number of args to `main()`
|
instance clang has a number of defects and some versions say that `main()` can
|
||||||
should that ever happen (a compiler error of some versions of clang if `main()`
|
only have 0, 2 or 3 args. The versions that have this that we know about do
|
||||||
has four args is that `main()` can only have 0, 2 or 3 args but it does
|
support 1 arg but in case this is ever changed the
|
||||||
currently accept 1 arg to `main()` nonetheless).
|
[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:
|
## To use:
|
||||||
@@ -35,8 +36,8 @@ echo IOCCC | ./sicherman
|
|||||||
|
|
||||||
## Alternate code:
|
## Alternate code:
|
||||||
|
|
||||||
This alternate version, which is the original entry, requires either an old
|
The [sicherman.alt.c](sicherman.alt.c) is the original entry and requires either
|
||||||
enough compiler or a compiler that supports `-traditional-cpp`. If you have such
|
an old enough compiler or a compiler that supports `-traditional-cpp`. If you have such
|
||||||
a compiler you can try this version.
|
a compiler you can try this version.
|
||||||
|
|
||||||
|
|
||||||
@@ -44,6 +45,7 @@ a compiler you can try this version.
|
|||||||
|
|
||||||
```sh
|
```sh
|
||||||
make alt
|
make alt
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Executable
+36
@@ -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
|
||||||
+16
-10
@@ -304,18 +304,18 @@ case as `c`.
|
|||||||
|
|
||||||
- The code in `main()` is where there are significant changes, changing from:
|
- The code in `main()` is where there are significant changes, changing from:
|
||||||
|
|
||||||
```c
|
```c
|
||||||
while (read(0,&__,1) & write((_=(_=C_C_(__),C)),
|
while (read(0,&__,1) & write((_=(_=C_C_(__),C)),
|
||||||
_C_,1)) _=C-V+subr(&V);
|
_C_,1)) _=C-V+subr(&V);
|
||||||
```
|
```
|
||||||
|
|
||||||
to:
|
to:
|
||||||
|
|
||||||
```c
|
```c
|
||||||
while (read(0,&__,1) & write((_=(_=C_C_(__),
|
while (read(0,&__,1) & write((_=(_=C_C_(__),
|
||||||
V))?__:__-_+'\b'b'\b'|((_-52)%('\b'b'\b'+~
|
V))?__:__-_+'\b'b'\b'|((_-52)%('\b'b'\b'+~
|
||||||
' '&'\t'b'\n')+1),1),&_,1))_=c-v+subr(&v));
|
' '&'\t'b'\n')+1),1),&_,1))_=c-v+subr(&v));
|
||||||
```
|
```
|
||||||
|
|
||||||
Note how numerous of the macros (though two changed in case) can still be
|
Note how numerous of the macros (though two changed in case) can still be
|
||||||
used but some cannot be. Can you figure out why? Why too is it that the
|
used but some cannot be. Can you figure out why? Why too is it that the
|
||||||
@@ -324,6 +324,12 @@ case as `c`.
|
|||||||
remove it from `main()`? What happens if you remove it from `subr()` or
|
remove it from `main()`? What happens if you remove it from `subr()` or
|
||||||
don't even bother calling `subr()`?
|
don't even bother calling `subr()`?
|
||||||
|
|
||||||
|
Additional code was added in case the fix cannot be compiled by some compilers
|
||||||
|
should they object to `main()` having only one arg. This version will
|
||||||
|
automatically be compiled if the entry fails to compile for some reason.
|
||||||
|
|
||||||
|
Cody also added the [try.sh](/1985/sicherman/try.sh) script.
|
||||||
|
|
||||||
|
|
||||||
# <a name="1986"></a>1986
|
# <a name="1986"></a>1986
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user