Get 1989/westley to compile with clang

Some important notes here should be made. First of all with clang the
recommended commands in the README.md (which was also formatted and typo
fixed) will seemingly generate the correct files but still only
westley.c and ver0.c will compile with clang. With gcc they do compile
and seem to work as expected.

However I found a bug in the original code too where ver2 will sometimes
segfault. This also goes for the fix (again when compiled with gcc).

I did get ver[123].c to also compile but this seemed to cause invalid
output in some of the commands. That being said it might (though I don't
think so at this time) have been not knowing exactly what should be
displayed. Maybe I will look at it in the future but at least it now
works with clang even if not all of the generated files will compile
that way. Still macOS users can now take a look at the different output
of the program which seems good to me (it does not even have to be
source code that is output).

These things have been noted in the README.md as well.
This commit is contained in:
Cody Boone Ferguson committed 2023-03-17 06:55:06 -07:00
1 parent 45fd90259b
commit 892b94c5a6
4 files changed
+56 -18

No files matched your search

+8
View File
@@ -1 +1,9 @@
ver0
ver0.c
ver1
ver1.c
ver2
ver2.c
ver3
ver3.c
westley westley
+1 -1
View File
@@ -94,7 +94,7 @@ ARCH=
# Defines that are needed to compile # Defines that are needed to compile
# #
#CDEFINE= #CDEFINE=
CDEFINE= -Dtrgpune=putchar CDEFINE= -Dtrgpune=putchar -Dpune=char -Dvag=int
# Include files that are needed to compile # Include files that are needed to compile
# #
+44 -15
View File
@@ -1,4 +1,4 @@
Most algorithms in one program: # Most algorithms in one program:
Merlyn LeRoy (Brian Westley) Merlyn LeRoy (Brian Westley)
Starfire Consulting Starfire Consulting
@@ -7,21 +7,50 @@ Most algorithms in one program:
55104 55104
USA USA
Judges notes: ## To build:
make all
NOTE: [Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) was able to get
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
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
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
also happens with the fix but it'll only compile with a compiler that
does not require the second, third and fourth args of main() to be a `char **`.
Thank you Cody for your help!
## Try:
./westley < westley.c > ver0.c
./westley 1 < westley.c > ver1.c
./westley 1 2 < westley.c > ver2.c
./westley 1 2 3 < westley.c > ver3.c
Try compiling and running the 4 resulting programs. To compile try:
make ver0
make ver1
make ver2
make ver3
## Judges notes:
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?
Try the following commands:
westley < westley.c > ver0.c ## Selected notes from the author:
westley 1 < westley.c > ver1.c
westley 1 2 < westley.c > ver2.c
westley 1 2 3 < westley.c > ver3.c
Try compiling and running the 4 resulting programs.
Selected notes from the author:
This is a filter. If it is run with no arguments, it copies This is a filter. If it is run with no arguments, it copies
stdin to stdout. With one argument, it ROT13's stdin to stdin to stdout. With one argument, it ROT13's stdin to
@@ -36,17 +65,17 @@ Selected notes from the author:
(ROT13 and reversed)). (ROT13 and reversed)).
When compiling these versions, one needs to define 'trgpune' When compiling these versions, one needs to define 'trgpune'
in the compile line. Example: in the compile line (which the Makefile now has). Example:
cc -Dtrgpune=putchar ver3.c -o ver3 cc -Dtrgpune=putchar ver3.c -o ver3
"trgpune" is the ROT13 of getchar(), so getchar() and putchar() "trgpune" is the ROT13 of getchar(), so getchar() and putchar()
are exchanged in the ROT13 counterpart. It is easy to see that are exchanged in the ROT13 counterpart. It is easy to see that
this is unavoidable. I must have a #define for a library this is unavoidable. I must have a #define for a library
function; otherwise I would have an unidentifed extern for the function; otherwise I would have an unidentified extern for the
ROT13 version. If I then define this function, it won't link ROT13 version. If I then define this function, it won't link
in the library version for the ORIGINAL code, since my in the library version for the ORIGINAL code, since my
definition will supercede the library function. Hence, the definition will supersede the library function. Hence, the
compiler option gives me putchar(), and allows me to use compiler option gives me putchar(), and allows me to use
getchar(). I pass a dummy argument to getchar() to eliminate getchar(). I pass a dummy argument to getchar() to eliminate
"variable number of args" from lint (unless it checks against "variable number of args" from lint (unless it checks against
@@ -110,7 +139,7 @@ Selected notes from the author:
The code can therefore be interlaced. There are eight The code can therefore be interlaced. There are eight
such palindromic bits. You can find them within the such palindromic bits. You can find them within the
/*//**/ /**//*/ pairs. `/*//**/ /**//*/` pairs.
The body of the code of ver0 and ver1 is a large lumpy 'K' (for The body of the code of ver0 and ver1 is a large lumpy 'K' (for
Kernighan); the code of ver2 and ver3 is a flat-topped and Kernighan); the code of ver2 and ver3 is a flat-topped and
+3 -2
View File
@@ -1,7 +1,8 @@
/**//*/};)/**/main(/*//**/tang ,gnat/**//*/,ABBA~,0-0(avnz;)0-0,tang,raeN /**//*/};)/**/main(/*//**/tang ,gnat/**//*/,ABBA~,0-0(avnz;)0-0,tang,raeN
,ABBA(niam&&)))2-]--tang-[kri - =raeN(&&0<)/*clerk*/,noon,raeN){(!tang&& ,ABBA(niam&&)))2-]--tang-[kri - =raeN(&&0<)/*clerk*/,noon,raeN)char
noon!=-1&&(gnat&2)&&((raeN&&( getchar(noon+0)))||(1-raeN&&(trgpune(noon **gnat, **noon, **raeN;{int gn = gnat, ra = raeN, no = noon; (!tang&&
no!=-1&&(gn&2)&&((raeN&&( getchar(no+0)))||(1-ra&&(trgpune(no
)))))||tang&&znva(/*//**/tang ,tang,tang/**|**//*/((||)))0(enupgrt=raeN )))))||tang&&znva(/*//**/tang ,tang,tang/**|**//*/((||)))0(enupgrt=raeN
(&&tang!(||)))0(rahcteg=raeN( &&1==tang((&&1-^)gnat=raeN(;;;)tang,gnat (&&tang!(||)))0(rahcteg=raeN( &&1==tang((&&1-^)gnat=raeN(;;;)tang,gnat
,ABBA,0(avnz;)gnat:46+]552&)191+gnat([kri?0>]652%)191+gnat([kri=gnat ,ABBA,0(avnz;)gnat:46+]552&)191+gnat([kri?0>]652%)191+gnat([kri=gnat