From aaad5330a0e214cf274032c0d49e95c6d0bc6645 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sat, 9 Sep 2023 06:17:06 -0700 Subject: [PATCH] Improve fixes to 1990/dds Two things had to be done here to make the code look much more like the original (though it is hardly discernible at first glance). First thing was I redefined free() to be free() + the comma operator as it was a binary expression error in modern systems (this fix was provided by Yusuke Endoh). The second one was an improvement to one of my earlier several fixes and in particular the prevention of warnings that cannot be disabled at compilation/linking/runtime (the latter of which can be interspersed with the output of the program): gets() to fgets(). The way this was done is redefining gets() to use fgets(). The second and third arg are the same so it was possible to just redefine gets() to use fgets() but gets() having one arg like the original function. It should be noticed that the original code used fgets() in one case because it has to read from a different FILE * than stdin so there still is a reference to fgets() that is not part of the macros. --- 1990/dds/dds.c | 5 +++-- thanks-for-fixes.md | 13 +++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/1990/dds/dds.c b/1990/dds/dds.c index a7585e669..1b4f61147 100644 --- a/1990/dds/dds.c +++ b/1990/dds/dds.c @@ -6,13 +6,14 @@ #define X ;break;case #define _ return #define R 999 +#define gets(x) fgets((x),R,stdin) typedef char*A;int*C,E[R],L[R],M[R],P[R],l,i,j;char B[R],F[2];A m[12*R],malloc (),p,q,x,y,z,s,d;FILE *f;A Q(s,o)A s,o;{for(x=s;*x;x++){for(y=x,z=o;*z&&*y== -*z;y++)z++;if(z>o&&!*z)_ x;}_ 0;}main(){m[11*R]="E";while(puts("Ok"),fgets(B,R,stdin), +*z;y++)z++;if(z>o&&!*z)_ x;}_ 0;}main(){m[11*R]="E";while(puts("Ok"),gets(B), B[strlen(B)-1]='\0',1)switch(*B){X'R':C=E;l=1;for(i=0;i",'#');U("<=",'$');U(">=",'!');}d=B;while(*F=*s){*s=='"'&&j ++;if(j&1||!Q(" \t",F))*d++=*s;s++;}*d--=j=0;if(B[1]!='=')switch(*B){X'E':l=-1 -X'R':B[2]!='M'&&(l=*--C)X'I':B[1]=='N'?fgets(p=B,R,stdin),P[*d]=S():(*(q=Q(B,"TH"))=0,p +X'R':B[2]!='M'&&(l=*--C)X'I':B[1]=='N'?gets(p=B),P[*d]=S():(*(q=Q(B,"TH"))=0,p =B+2,S()&&(p=q+4,l=S()-1))X'P':B[5]=='"'?*d=0,puts(B+6):(p=B+5,printf("%d\n",S ()))X'G':p=B+4,B[2]=='S'&&(*C++=l,p++),l=S()-1 X'F':*(q=Q(B,"TO"))=0;p=B+5;P[i =B[3]]=S();p=q+2;M[i]=S();L[i]=l X'N':++P[*d]<=M[*d]&&(l=L[*d]);}else p=B+2,P[ diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index 4271c0080..5148ced94 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -388,14 +388,23 @@ judge and user the executioner? :-) Yusuke and Cody in conjunction fixed this for modern systems. Yusuke added the comma operator for a binary expression with `free(3)` which is -an error because `free()` returns void. +an error because `free()` returns void. Cody then made it slightly more like the +original in this way by redefining `free` to have the comma operator itself. Cody removed the erroneous prototype to `fopen()` which caused a compiler error and he also made this use `fgets()` instead of `gets()` to make it safer and to prevent an annoying and potentially alarming warning at compiling and/or linking -and/or runtime. He also changed a file to be a proper `FILE *` and fixed a typo +and/or runtime. + +Cody also changed a file to be a proper `FILE *` and fixed a typo in [LANDER.BAS](1990/dds/LANDER.BAS). +Later Cody improved the `gets()`/`fgets()` fix by redefining `gets()` to use +`fgets()`. Notice that the original entry used `fgets()` in one case as it has +to read from another file and in this place nothing was changed. + +With these improvements the entry looks much more like the original. + ## [1990/jaw](1990/jaw/jaw.c) ([README.md](1990/jaw/README.md]))