Make 1992/adrian use fgets() not gets()

There was only one call to gets() and one call to fgets(). gets() reads
from stdin so the fgets() call has to as well. But why was it using
gets() and not fgets()? My guess is because fgets() stores the final
newline which means that the output had extra lines. The entry was
relying on this string NOT having a newline printed after the line
matched! Having a newline in turn broke the generation of some output
like that of adhead.c. Thus if fgets() != NULL we trim off the trailing
newline first. This allows the entry and all generated code to compile
successfully (adhead.c ended up having a multi-line macro messed up
because of an empty line after the \ at the end of the line). Since
gets() does not store the final newline and since we trim that off the
code is functionally equivalent but now safer.
This commit is contained in:
Cody Boone Ferguson committed 2023-03-28 04:17:43 -07:00
1 parent 4594e02036
commit 59c95a86d5
2 files changed
+150 -123

No files matched your search

+1 -2
View File
@@ -7,7 +7,6 @@
#define v(jr) jr
int W ,head;
#define S(W,b,f) strncpy(W,b,f),W[f]=0\
char *wcs=" \t\n";
struct{ char X[z+1];
@@ -105,7 +104,7 @@ while( s = strtok(0,wcs)) {
< 10 && printf((W,Y)); }
if(j+28) { {
; } printf("%7u%7u%7u\n", wcl , wcw , wcc); }
while( gets(Y) ) if(A(Y)) puts(Y);
while( fgets(Y,998,stdin) ){ Y[strlen(Y)-1]='\0'; if(A(Y)) puts(Y); }
W, jr; }
O(int wc,char**V) {