From dc348718053a46c30477c1aa06ec67bee621c6ab Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Thu, 2 Nov 2023 04:49:42 -0700 Subject: [PATCH] Add alt versions to 1994/schnitzi The first version uses fgets(3). This version will compile (note that it does not compile right away: one has to make other adjustments; it is not a matter of just changing the code to use fgets()!) but when fed its own source code it will not generate code that can be compiled let alone use fgets(3). The second version, schnitzi.alt2.c, has an increased buffer size but it will not generate code with the same buffer size; rather the size will be the original. I explain this in detail (did this quite some time back) in the bugs.md file. I noticed today that the author gives quite some details too which will be something I can look at later on. Right now it's more important to get the website in order so that the next contest can run! I will only look at this later on or else at a time where I am unable to do the more important work but am able to do this (though I don't know about that happening it is still something that theoretically could happen). The alt code already existed but it was changed to the second version as the goal is to get it to use fgets(3) regardless of the buffer size. Note that the other functionality of both alt versions is not affected. More updates to bugs.md for this and the thanks file has had the entry added to it (which should have been done earlier on but was neglected due to the way it came about, the alt code). --- 1994/schnitzi/.gitignore | 3 ++ 1994/schnitzi/Makefile | 14 ++++++++- 1994/schnitzi/README.md | 42 +++++++++++++++++++------- 1994/schnitzi/schnitzi.alt.c | 8 ++--- 1994/schnitzi/schnitzi.alt2.c | 52 ++++++++++++++++++++++++++++++++ bugs.md | 57 +++++++++++++++++++++++++++++------ thanks-for-fixes.md | 18 +++++++++++ 7 files changed, 169 insertions(+), 25 deletions(-) create mode 100644 1994/schnitzi/schnitzi.alt2.c diff --git a/1994/schnitzi/.gitignore b/1994/schnitzi/.gitignore index 3c5531585..5c68dfa9a 100644 --- a/1994/schnitzi/.gitignore +++ b/1994/schnitzi/.gitignore @@ -1,4 +1,7 @@ schnitzi +schnitzi2 +schnitzi2.c schnitzi.alt +schnitzi.alt2 schnitzi.orig prog.orig diff --git a/1994/schnitzi/Makefile b/1994/schnitzi/Makefile index c9c846c89..b03fb958b 100644 --- a/1994/schnitzi/Makefile +++ b/1994/schnitzi/Makefile @@ -130,7 +130,9 @@ all: data ${TARGET} sandwich supernova deep_magic magic charon pluto ${PROG}: ${PROG}.c - @echo "NOTE: the buffer size of this entry is very small at 100." + ${CC} ${CFLAGS} $< -o $@ ${LDFLAGS} + +${PROG}2: ${PROG}2.c ${CC} ${CFLAGS} $< -o $@ ${LDFLAGS} # alternative executable @@ -138,6 +140,16 @@ ${PROG}: ${PROG}.c alt: data ${ALT_TARGET} @${TRUE} +${PROG}.alt: ${PROG}.alt.c + @echo "NOTE: this version has fgets() but will not generate code that can be compiled." + @echo "Other functionality is not affected." + ${CC} ${CFLAGS} $< -o $@ ${LDFLAGS} + +${PROG}.alt2: ${PROG}.alt2.c + @echo "NOTE: this version has an increased buffer size and will generate code that can" + @echo "compile but the buffer size is not increased. Other functionality is unaffected." + ${CC} ${CFLAGS} $< -o $@ ${LDFLAGS} + # data files # data: ${DATA} diff --git a/1994/schnitzi/README.md b/1994/schnitzi/README.md index 69d4cfec6..893aca139 100644 --- a/1994/schnitzi/README.md +++ b/1994/schnitzi/README.md @@ -1,9 +1,6 @@ # Best Layout Mark Schnitzius\ -ISX Corporation\ -1165 Northchase Pkwy, Suite 120\ -Marietta, GA 30067\ US\ @@ -14,6 +11,11 @@ US\ make all ``` +There are two alternate versions, one that has an increased buffer size and one +that uses `fgets()`; neither are completely functional. +See below section bugs and (mis)features for details and the [alternate +code](#alternate-code) section for how to use. + ### Bugs and (Mis)features @@ -36,20 +38,37 @@ For more detailed information see [1994 schnitzi in bugs.md](/bugs.md#1994-schni ## Try: ```sh -./schnitzi < /etc/motd -./schnitzi < /etc/passwd +./schnitzi < /etc/motd 2>/dev/null +./schnitzi < /etc/passwd 2>/dev/null + +./schnitzi < schnitzi.c > schnitzi2.c 2>/dev/null +make schnitzi2 +./schnitzi2 < README.md ``` ## Alternate code: -To build the alternative code try: +The first version, `schnitzi.alt.c`, uses `fgets(3)` but when fed its own code +it will generate code that still uses `gets(3)`. What's more is it will not +compile. Other functionality works fine. + +The second version, `schnitzi.alt2.c`, has an increased buffer size but when fed +its own source code it will generate code that can compile but with the original +buffer size. This is due to a comment which is explained in more detail in +[1994/schnitzi in bugs.md](/bugs.md#1994-schnitzi). + + +### Alternate build: ```sh make alt ``` -Use `schnitzi.alt` as you would `schnitzi`. +### Alternate use: + +Use `schnitzi.alt` and `schnitzi.alt2` as you would `schnitzi` above except that +feeding the source code to it will not work right. ## Judges' remarks: @@ -66,6 +85,7 @@ find out why? ## Author's remarks: + ### SPOILER: This is a program which takes any text file as input and 'flips' @@ -83,7 +103,7 @@ schnitzi < info The program generates interesting results when its source file is used as input: -\ + ```sh schnitzi < schnitzi.c ``` @@ -94,11 +114,11 @@ version of itself work identically (you'll need to redirect the output of the above command into a separate file and compile it). You might notice some differences in the flipped version, though. First off, a secret message becomes visible that was not visible -in the original program. Also, much of the code shows up in\ +in the original program. Also, much of the code shows up in different places in the flipped program than it appeared in the -first program. My first version of this program was perfectly\ +first program. My first version of this program was perfectly symmetrical along the diagonal, but later found out there were -interesting ways to break the symmetry. The best way to see this\ +interesting ways to break the symmetry. The best way to see this is to load both the original and flipped versions of the program into an editor and switch back and forth between them rapidly. diff --git a/1994/schnitzi/schnitzi.alt.c b/1994/schnitzi/schnitzi.alt.c index a28d79ee9..2b1440fd5 100644 --- a/1994/schnitzi/schnitzi.alt.c +++ b/1994/schnitzi/schnitzi.alt.c @@ -20,12 +20,12 @@ h mh111 de{l) +di (+'( d+% c n+ */ n = 0 ; main ( ) { char v [ - 10000 ] , s; - int t[100 ] , - u[100 ] ; u + 1000 ] , s; + int t[100 ] , + u[100 ] ; u [ 0 ]=ftell(stdin ) ; - while(gets (v ) ) + while(fgets(v,100,stdin )&&((v[strlen(v)-1]='\0',1)) ) {t [ r ]= strlen ( v);y= diff --git a/1994/schnitzi/schnitzi.alt2.c b/1994/schnitzi/schnitzi.alt2.c new file mode 100644 index 000000000..a28d79ee9 --- /dev/null +++ b/1994/schnitzi/schnitzi.alt2.c @@ -0,0 +1,52 @@ +#include +int r=0,x,y=0, /* +nt / +c +lx /\ / \ /|\ /|\ +u, \/ \\/ \-/ \ / +dn ] +e= ||| /|\ /\ /\ = p p + 0 \/ \ / ||| \/ f f f r r +<, tw t s s i i +sy || /|\ /\ i eh e e c n n +t= /- \ / ||| n li l e a t t +d0 ||| t ll l {< k n f f +i, || /|\ /|\ (e s ( fr ( f ( ( +o _ ||\ \ / \-/ tu s( t usw o; i s ( " " +. || - / c [[ tg rv [th rx=f t " % \ +h mh111 de{l) +di (+'( d+% c n+ +> aa000 itte; > +il x+ n inc " "+ + / ir000[ns[nytyrrne<=)'y ? t [ + r ] : y; + u[++r ] = + ftell(stdin ) ; } + while ( n + < y ) + {for(x=0 ; x +