Merge pull request #944 from xexyl/1990-tbr-surgery

This commit is contained in:
Landon Curt Noll authored and GitHub committed 2023-09-09 08:25:29 -07:00
commit 6f3c21b8ea
2 files changed
+17 -4

No files matched your search

+4 -1
View File
@@ -1,9 +1,12 @@
int e(int x),r(int t,int o);
#define gets(x)fgets((x),512,stdin)
#define exit(x) exit((x)),0
#define D ,close(
char *c,q [512 ],m[ 256
],*v[ 99], **u, *i[3];int f[2],p;main (){for
(m[m [60]= m[62 ]=32 ]=m[* m=124 [m]= 9]=6;
e(-8) ,(c=fgets(q,512,stdin),(c==NULL &&(exit(0),1))||(c[strlen(c)-1]='\0'),1)||(exit(0),0);r(0,0)
e(-8) ,(c=gets(q), (c[strlen(c)-1] ='\0'),1)||(exit(0));r(0,0)
)for( ;*++ c;); }r(t, o){ *i=i [2]= 0;for
(u=v +98 ;m[*--c] ^9;m [*c] &32 ?i[*c
&2]= *u,u- v^98 &&++u:
+13 -3
View File
@@ -413,9 +413,19 @@ Endoh](/winners.html#Yusuke_Endoh).
Cody fixed this to work with modern compilers; `exit(3)` returns void but the
function was used in a binary expression so this wouldn't even compile. Cody
also changed the code to use `fgets()` instead of `gets()` so one would not get
a warning about the use of `gets()` at linking time or execution, the latter
case causing confusing output due to the warning being interspersed with the
program's (which is interactive) output.
a warning about the use of `gets()` at linking time or execution, the latter of
which was causing confusing output due to the warning being interspersed with
the program's interactive output.
Cody later improved the fix improved so that it looks more like the original. A
problem that usually occurs with `gets()` to `fgets()` is for 'backwards
compatibility' (so the man page once said) `fgets()` retains the newline and
`gets()` does not. In this program if one does not remove the newline it breaks
the program. This usually requires that one check that `fgets()` does not return
NULL but with some experimenting this proved to seem to not be a problem here so
by adding a couple macros that redefine `exit()` and `gets()` a whole binary
expression could be removed (thus removing an extra `exit()` call) and it now
almost looks like the same as the original.
## [1990/theorem](1990/theorem/theorem.c) ([README.md](1990/theorem/README.md]))