Change how 1985/sicherman alt code is managed
Removed the original sicherman.alt.c (which was the original code that requires -traditional-cpp or an older compiler) and make sicherman.alt2.c it instead which is a slight modification of sicherman.c: it has two args to main() in case some compilers (like clang) eventually object to having one arg (like it does for 4 args and claims it does for 1 even though it does not). Since the sicherman.alt.c is built automatically if compilation fails in the sicherman rule it will compile to sicherman. However if it is built manually like 'make alt' then it's built as sicherman.alt. This makes it easier to use but also allows one to build the alt version should they wish and not have it overwrite sicherman. The try.alt.sh script was added in the case of manual compilation of sicherman.alt.c.
This commit is contained in:
1 parent
5292717f04
commit
8ad90e157e
6 files changed
+77
-61
No files matched your search
@@ -132,18 +132,15 @@ all: data ${TARGET}
|
||||
clean clobber install love haste waste maker easter_egg \
|
||||
sandwich supernova deep_magic magic charon pluto
|
||||
|
||||
${PROG}: ${PROG}.c ${PROG}.alt2.c
|
||||
${PROG}: ${PROG}.c ${PROG}.alt.c
|
||||
${CC} ${CFLAGS} $< -o $@ ${LDFLAGS} || \
|
||||
${CC} ${CFLAGS} ${PROG}.alt2.c -o $@ ${LDFLAGS}
|
||||
${CC} ${CFLAGS} ${PROG}.alt.c -o $@ ${LDFLAGS}
|
||||
|
||||
# alternative executable
|
||||
#
|
||||
alt: data ${ALT_TARGET}
|
||||
@${TRUE}
|
||||
|
||||
${PROG}.alt: ${PROG}.alt.c
|
||||
${CC} ${CFLAGS} -traditional-cpp $< -o $@ ${LDFLAGS}
|
||||
|
||||
# data files
|
||||
#
|
||||
data: ${DATA}
|
||||
|
||||
+19
-18
@@ -4,14 +4,9 @@
|
||||
make all
|
||||
```
|
||||
|
||||
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.
|
||||
There is another version that will be compiled in case the first fails. This
|
||||
should happen automatically. See [Alternate code](#alternate-code) below for
|
||||
more details on it.
|
||||
|
||||
|
||||
## To use:
|
||||
@@ -20,34 +15,40 @@ code](#alternate-code) below for details on the alt code, the original entry.
|
||||
./sicherman < file
|
||||
|
||||
echo foo | ./sicherman
|
||||
|
||||
./sicherman
|
||||
# type or paste some text, making sure to hit enter after each line typed
|
||||
```
|
||||
|
||||
|
||||
### Try:
|
||||
|
||||
```sh
|
||||
./sicherman < sicherman.c
|
||||
|
||||
echo IOCCC | ./sicherman
|
||||
|
||||
./sicherman < sicherman.c | ./sicherman
|
||||
./try.sh
|
||||
```
|
||||
|
||||
|
||||
## Alternate code:
|
||||
|
||||
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.
|
||||
The [sicherman.alt.c](sicherman.alt.c) is a slight change in the fixed version
|
||||
(fixed so it does not require `-traditional-cpp`) in that it has two args to
|
||||
`main()` as some compilers object to certain number of args in `main()`. This
|
||||
will be built in the case of the [sicherman.c](sicherman.c) failing to compile.
|
||||
In this case it'll be compiled to `sicherman` to simplify it for the larger
|
||||
audience.
|
||||
|
||||
|
||||
### Alternate build:
|
||||
|
||||
Although this will be built if the original fails to compile you can do it
|
||||
manually like:
|
||||
|
||||
```sh
|
||||
make alt
|
||||
|
||||
```
|
||||
|
||||
In this case it will be built as `sicherman.alt`.
|
||||
|
||||
|
||||
### Alternate use:
|
||||
|
||||
@@ -59,7 +60,7 @@ make alt
|
||||
### Alternate try:
|
||||
|
||||
```sh
|
||||
./sicherman.alt < README.md | ./sicherman.alt
|
||||
./try.alt.sh
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -2,22 +2,25 @@
|
||||
#define _C_C(_)('\b'b'\b'>=C_C>'\t'b'\n')
|
||||
#define C_C _|_
|
||||
#define b *
|
||||
#define C /b/
|
||||
#define V _C_C(
|
||||
main(C,V)
|
||||
char **V;
|
||||
#define c /**/
|
||||
#define v _C_C(
|
||||
char _,__;
|
||||
main(
|
||||
/* C program. (If you don't
|
||||
* understand it look it
|
||||
*/ up.) (In the C Manual)
|
||||
* up.) (In the */C, Manual)
|
||||
char **Manual;
|
||||
{
|
||||
char _,__;
|
||||
while (read(0,&__,1) & write((_=(_=C_C_(__),C)),
|
||||
_C_,1)) _=C-V+subr(&V);
|
||||
char _,__;
|
||||
while (read(0,&__,1) & write((_=(_=C_C_(__),
|
||||
v))?__:__-_+'\b'b'\b'|((_-52)%('\b'b'\b'+~
|
||||
' '&'\t'b'\n')+1),1),&_,1))_=c-v+subr(&v));
|
||||
}
|
||||
|
||||
subr(C)
|
||||
char *C;
|
||||
{
|
||||
C="Lint says "argument Manual isn't used." What's that
|
||||
mean?"; while (write((read(C_C('"'-'/*"'/*"*/))?__:__-_+
|
||||
C="Lint says \"argument Manual isn't used.\" What's that\
|
||||
mean?"; while (write((read(('"'-'/*"'))?__:__-_+
|
||||
'\b'b'\b'|((_-52)%('\b'b'\b'+C_C_('\t'b'\n'))+1),1),&_,1));
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
#define C_C_(_)~' '&_
|
||||
#define _C_C(_)('\b'b'\b'>=C_C>'\t'b'\n')
|
||||
#define C_C _|_
|
||||
#define b *
|
||||
#define c /**/
|
||||
#define v _C_C(
|
||||
char _,__;
|
||||
main(
|
||||
/* C program. (If you don't
|
||||
* understand it look it
|
||||
* up.) (In the */C, Manual)
|
||||
char **Manual;
|
||||
{
|
||||
char _,__;
|
||||
while (read(0,&__,1) & write((_=(_=C_C_(__),
|
||||
v))?__:__-_+'\b'b'\b'|((_-52)%('\b'b'\b'+~
|
||||
' '&'\t'b'\n')+1),1),&_,1))_=c-v+subr(&v));
|
||||
}
|
||||
|
||||
subr(C)
|
||||
char *C;
|
||||
{
|
||||
C="Lint says \"argument Manual isn't used.\" What's that\
|
||||
mean?"; while (write((read(('"'-'/*"'))?__:__-_+
|
||||
'\b'b'\b'|((_-52)%('\b'b'\b'+C_C_('\t'b'\n'))+1),1),&_,1));
|
||||
}
|
||||
Executable
+36
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# try.alt.sh - demonstrate IOCCC winner 1985/sicherman.alt alt code
|
||||
#
|
||||
|
||||
# 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.alt < sicherman.alt.c: "
|
||||
echo 1>&2
|
||||
./sicherman.alt < sicherman.alt.c
|
||||
echo 1>&2
|
||||
|
||||
read -r -n 1 -p "Press any key to run: echo IOCCC | ./sicherman.alt: "
|
||||
echo 1>&2
|
||||
echo IOCCC | ./sicherman.alt
|
||||
echo 1>&2
|
||||
|
||||
read -r -n 1 -p "Press any key to run: ./sicherman.alt < sicherman.alt.c | ./sicherman.alt: "
|
||||
echo 1>&2
|
||||
./sicherman.alt < sicherman.alt.c | ./sicherman.alt
|
||||
echo 1>&2
|
||||
|
||||
read -r -n 1 -p "Press any key to run: ./sicherman.alt < sicherman.alt.c | ./sicherman.alt | diff -s - sicherman.alt.c: "
|
||||
echo 1>&2
|
||||
./sicherman.alt < sicherman.alt.c | ./sicherman.alt | diff -s - sicherman.alt.c
|
||||
+7
-2
@@ -326,9 +326,14 @@ case as `c`.
|
||||
|
||||
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.
|
||||
automatically be compiled if the entry fails to compile for some reason but one
|
||||
can compile it manually as `make alt` in which case it'll be compiled as
|
||||
`sicherman.alt` (if it's done because [sicherman.c](/1985/sicherman/sicherman.c)
|
||||
fails to compile it will be built as `sicherman` as part of the `sicherman`
|
||||
rule).
|
||||
|
||||
Cody also added the [try.sh](/1985/sicherman/try.sh) script.
|
||||
Cody also added the [try.sh](/1985/sicherman/try.sh) and
|
||||
[try.alt.sh](/1985/sicherman/try.alt.sh) scripts.
|
||||
|
||||
|
||||
# <a name="1986"></a>1986
|
||||
|
||||
Reference in new issue
Block a user