Fix fix on fix of 1990/tbr

When I added the 'gets()' and 'exit()' macros to make the code look more
like the original I accidentally left out a space between 'gets(x)' and
'fgets(...' so that it looked like:

    #define gets(x)fgets((x),512,stdin)

which I believe is incorrect. It now looks instead like:

    #define gets(x) fgets((x),512,stdin)

The compact version that the authors provided was compile fixed quite
some time back but I never added the exit macro to match the original
more closely.

Also since the compact version was meant to be identical in function of
the entry and since that entry was changed to use fgets() (by the macro
gets()) I decided it would be better to make it use fgets() also, also
through redefining gets(). To make the line length closer in match to
the original compact version I changed the code to be two lines. This
wasn't necessary to do, as I recall, in the entry itself though it's
possible it was and I just managed to get the ASCII art the same or
almost the same.

The thanks-for-fixes.md file was updated for this change but
unfortunately I had made some changes yesterday that I forgot about
(just rewording) in another entry so that will also be in this commit.
This commit is contained in:
Cody Boone Ferguson committed 2023-10-11 03:09:57 -07:00
1 parent 4454a491ba
commit 44728e695b
4 files changed
+51 -26

No files matched your search

+11 -6
View File
@@ -23,7 +23,8 @@ make all
NOTE: globs do not work with this entry. Why?
NOTE: `exit` does not work and neither does `logout`. To exit try sending ctrl-d
or ctrl-c (or kill it from another terminal :-) ).
or ctrl-c (or kill it from another terminal :-) ). But why does it not work with
just `exit` or `logout`? Hint: see the authors' remarks.
## Try:
@@ -41,6 +42,10 @@ vi tbr.c
What happens if you try using `cd -` to return to previous directory? What about
`cd` with no args?
### TNABTAF - they're not a bug they're a feature! :-)
The authors include a section called [BUGS](#bugs) that, because they were
documented, are not considered bugs as such in the context of the contest.
## Judges' remarks:
@@ -51,7 +56,7 @@ Shell source was a major inspiration for the formation of the IOCCC back in
1984?
The author supplied us with a slightly smaller unformatted version
The authors supplied us with a slightly smaller unformatted version
of the program which we include below:
```c
@@ -67,11 +72,11 @@ r(o,0)D o)D*f):4,wait(0):(o?dup2(*f,0)D*f)D o):*i?1 D
e(x){x<0?write(2,"?\n$ "-x/4,2),x+1||(exit(1),0):5;}
```
It has the `exit()` returns void fix but not the `gets()` to `fgets()` fix
applied.
It has the `exit()` returns void fix as well as the `gets()` to `fgets()` fix
applied to it to make it functionally equivalent like the authors intended.
## Author's remarks:
## Authors' remarks:
This program is a rudimentary shell. It does I/O redirection, pipes
and cd. It flags errors on failed `chdir()`, `open()`, `creat()`,
@@ -87,7 +92,7 @@ system calls) a question mark is printed.
The error value of `chdir()` is doubled so that we don't exit from the parent
shell on a `chdir()` error (since `e()` exits on `-1` errors only). All other
system call failures exit since they are from subshells.
system call failures exit since they are from sub-shells.
Recursion is sneakily employed to avoid a second call to `fork()`,
and the line is parsed in a fairly bizarre fashion: backwards. The
+5 -3
View File
@@ -1,11 +1,13 @@
#define D ,close(
#define exit(x) exit((x)),0
#define gets(x) fgets((x),512,stdin)
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),gets(1+(c=q))||(exit(0),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]=
32]=m[*m=124[m]=9]=6;e(-8),((gets(1+(c=q)),(c+1)[strlen(c+1)-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:3)if(!m[*c]){for(*++c=0;!m[*--c];);*--u=
++c;}u-v^98?strcmp(*u,"cd")?*c?pipe(f),o=f[1]:1,(p=fork())?e(p),o?
r(o,0)D o)D*f):4,wait(0):(o?dup2(*f,0)D*f)D o):*i?1 D
0),e(open(*i,0)):5,t?dup2(t,1)D t):i[2]?9 D
1),e(creat(i[2],438)):2,e(execvp(*u,u))):e(chdir(u[1])*2):6;}
e(x){x<0?write(2,"?\n$ "-x/4,2),x+1||(exit(1),0):5;}
e(x){x<0?write(2,"?\n$ "-x/4,2),x+1||(exit(1)):5;}
+1 -1
View File
@@ -1,4 +1,4 @@
#define gets(x)fgets((x),512,stdin)
#define gets(x) fgets((x),512,stdin)
#define exit(x) exit((x)),0
#define D ,close(