Fixes in 1989/westley

Try and improve the note during compilation that some versions will not
work with some compilers.

Make the other versions alt code. Running make alt will stop on the
first error but I made it alt targets so that make clobber will remove
the compiled files. In order to make it actual targets the Makefile
would have to do more to generate the files and this might or might not
be better.

Format fixes and a typo fix in README.md.
This commit is contained in:
Cody Boone Ferguson committed 2023-07-01 08:23:13 -07:00
1 parent 2d2970dc2b
commit a7f9a722fc
2 files changed
+42 -22

No files matched your search

+20 -3
View File
@@ -113,8 +113,8 @@ OBJ= ${PROG}.o
DATA= DATA=
TARGET= ${PROG} TARGET= ${PROG}
# #
ALT_OBJ= ALT_OBJ= ver0.o ver1.o ver2.o ver3.o
ALT_TARGET= ALT_TARGET= ver0 ver1 ver2 ver3
################# #################
@@ -129,7 +129,6 @@ all: data ${TARGET}
supernova deep_magic magic charon pluto supernova deep_magic magic charon pluto
${PROG}: ${PROG}.c ${PROG}: ${PROG}.c
@echo "NOTE: This entry uses non-standard args to main() that do not work with some modern compilers."
${CC} ${CFLAGS} $< -o $@ ${LIBS} ${CC} ${CFLAGS} $< -o $@ ${LIBS}
# alternative executable # alternative executable
@@ -137,6 +136,24 @@ ${PROG}: ${PROG}.c
alt: data ${ALT_TARGET} alt: data ${ALT_TARGET}
@${TRUE} @${TRUE}
ver0: ver0.c
${CC} ${CFLAGS} $< -o $@ ${LIBS}
ver1: ver1.c
@echo "** NOTE: this version will not compile with clang **"
${CC} ${CFLAGS} $< -o $@ ${LIBS}
@echo "** NOTE: this version will not compile with clang **"
ver2: ver2.c
@echo "** NOTE: this version will not compile with clang **"
${CC} ${CFLAGS} $< -o $@ ${LIBS}
@echo "** NOTE: this version will not compile with clang **"
ver3: ver3.c
@echo "** NOTE: this version will not compile with clang **"
${CC} ${CFLAGS} $< -o $@ ${LIBS}
@echo "** NOTE: this version will not compile with clang **"
# data files # data files
# #
data: ${DATA} data: ${DATA}
+22 -19
View File
@@ -1,10 +1,6 @@
# Most algorithms in one program # Most algorithms in one program
Merlyn LeRoy (Brian Westley) Merlyn LeRoy (Brian Westley)
Starfire Consulting
1026 Blair Ave.
St. Paul, MN
55104
US US
<http://www.westley.org> <http://www.westley.org>
@@ -15,16 +11,14 @@ make all
``` ```
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) was able to get NOTE: this entry only partly works with clang; clang requires that the second, third and
this to partially work with clang; clang requires that the second, third and fourth args to `main()` be `char **`. Only `westley.c` and `ver0.c` (see below) will
fourth args to main() be `char **`. Only `westley.c` and `ver0.c` (see below) will
compile with clang. It's possible to get `ver1.c` to compile too but this causes compile with clang. It's possible to get `ver1.c` to compile too but this causes
problems with generating the output of the remaining files so we have opted, at problems with generating the output of the remaining files so we have opted, at
least for now, to not do that, as it does not have to output just source code. least for now, to not do that, as it does not have to output just source code.
He notes that the original source code sometimes segfaults with `ver2` which The original source code sometimes segfaults with `ver2` which also happens with
also happens with the fix but it'll only compile with a compiler that the fix but it'll only compile with a compiler that does not require the second,
does not require the second, third and fourth args of main() to be a `char **`. third and fourth args of `main()` to be a `char **`.
Thank you Cody for your help!
## Try: ## Try:
@@ -46,12 +40,22 @@ make ver2
make ver3 make ver3
``` ```
Then run:
```sh
./westley
# input some lines of text, sending EOF (usually ctrl-d) to end
echo IOCCC | ./ver0
echo Version 1 | ./ver1
echo Version 2 | ./ver2
echo Version 3 | ./ver3
```
## Judges' remarks: ## Judges' remarks:
There is a secret way to get ONE of the versions to print out There is a secret way to get ONE of the versions to print out
"Hello, world!\n". Can you find how to do it? "`Hello, world!\n`". Can you find how to do it?
## Author's remarks: ## Author's remarks:
@@ -91,7 +95,7 @@ check for ROT13 version] is all it complains about).
`ver0` and `ver1` use a range check and a calculation to do ROT13, `ver0` and `ver1` use a range check and a calculation to do ROT13,
while `ver2` and `ver3` use table lookup. All versions contain while `ver2` and `ver3` use table lookup. All versions contain
`main()` and it's ROT13 fn, `znva()`. `ver0`/`ver1` [`ver2`/`ver3`] are `main()` and its ROT13 function, `znva()`. `ver0`/`ver1` [`ver2`/`ver3`] are
(of course) syntactically identical, since the syntax is in the (of course) syntactically identical, since the syntax is in the
non-alphabetic characters. However, since one program starts non-alphabetic characters. However, since one program starts
at `main()` while it's ROT13 counterpart starts at `znva()`, `znva()` at `main()` while it's ROT13 counterpart starts at `znva()`, `znva()`
@@ -132,17 +136,16 @@ expr1 && (expr2,expr3);
`expr2` was OFTEN evaluated even if `expr1` was false. I removed `expr2` was OFTEN evaluated even if `expr1` was false. I removed
such statements to make it more portable. such statements to make it more portable.
The variable names are worth noting: ### Variable names worth noting
--
'irk' and 'vex' are ROT13 pairs and are synonyms. `irk` and `vex` are ROT13 pairs and are synonyms.
'Near' and 'Arne' are ROT13 pairs and are anagrams. `Near` and `Arne` are ROT13 pairs and are anagrams.
'NOON' and 'ABBA' are ROT13 pairs and are palindromes. `NOON` and `ABBA` are ROT13 pairs and are palindromes.
'tang' and 'gnat' are both ROT13 and palindrome pairs! `tang` and `gnat` are both ROT13 and palindrome pairs!
-- --