Merge pull request #104 from xexyl/1990-tbr-fgets
Make 1990/tbr alt version that uses fgets not gets
This commit is contained in:
5 files changed
+51
-8
No files matched your search
@@ -1 +1,2 @@
|
||||
tbr
|
||||
tbr.alt
|
||||
+3
-3
@@ -98,7 +98,7 @@ CDEFINE=
|
||||
|
||||
# Include files that are needed to compile
|
||||
#
|
||||
CINCLUDE=
|
||||
CINCLUDE= -include stdio.h
|
||||
#CINCLUDE= -include stdlib.h
|
||||
#CINCLUDE= -include stdio.h
|
||||
#CINCLUDE= -include stdlib.h -include stdio.h
|
||||
@@ -168,8 +168,8 @@ OBJ= ${PROG}.o
|
||||
DATA=
|
||||
TARGET= ${PROG}
|
||||
#
|
||||
ALT_OBJ=
|
||||
ALT_TARGET=
|
||||
ALT_OBJ= ${PROG}.alt.o
|
||||
ALT_TARGET= ${PROG}.alt
|
||||
|
||||
|
||||
#################
|
||||
|
||||
+23
-3
@@ -18,8 +18,24 @@
|
||||
make all
|
||||
|
||||
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed this to work with
|
||||
modern computers; `exit(3)` returns void but the function was used in a binary
|
||||
expression so this would not even compile. Thank you Cody for your assistance!
|
||||
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 execution which was interspersed with the output. Thank you Cody for
|
||||
your assistance!
|
||||
|
||||
For the original version with `gets()` see the alternative code section below.
|
||||
|
||||
## Alternative code:
|
||||
|
||||
If you wish to see the original source (fixed so it can compile) that uses
|
||||
`gets()` instead of `fgets()` you can look at [tbr.alt.c](tbr.alt.c). To compile
|
||||
it:
|
||||
|
||||
make alt
|
||||
|
||||
Use `./tbr.alt` instead of `./tbr` for this version. You'll likely get a warning
|
||||
about the usage of `gets()`.
|
||||
|
||||
|
||||
## To run:
|
||||
@@ -27,6 +43,8 @@ expression so this would not even compile. Thank you Cody for your assistance!
|
||||
./tbr
|
||||
# enter some shell commands
|
||||
|
||||
NOTE: globs do not work with this entry. Why?
|
||||
|
||||
## Try:
|
||||
|
||||
./tbr
|
||||
@@ -37,6 +55,8 @@ expression so this would not even compile. Thank you Cody for your assistance!
|
||||
vi tbr.c
|
||||
# then figure out how to exit vi :-)
|
||||
|
||||
What happens if you try using `cd -` to return to previous directory? What about
|
||||
`cd` with no args?
|
||||
|
||||
## Judges' comments:
|
||||
|
||||
@@ -64,7 +84,7 @@ of the program which we include below:
|
||||
|
||||
|
||||
|
||||
## Author's comments
|
||||
## Author's comments:
|
||||
|
||||
Rot13:
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
|
||||
#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) ,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]= *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 ]:
|
||||
4 ,(p=fork())?e(p),o?r(o,0)D o)D*f):
|
||||
1 ,wait(0):(o?dup2(*f,0)D*f)D o):*i?
|
||||
5 D 0),e(open(*i,0)):
|
||||
9 ,t?dup2(t,1)D t):i[
|
||||
2 ]?
|
||||
6 D 1),e(creat(i[2],438)):
|
||||
5 ,e(execvp(*u,u))):e(chdir(u[1])*2):
|
||||
3 ;}e(x){x<0?write(2,"?\n$ "-x/4,2),x+1||(exit(1),0):
|
||||
5 ;}
|
||||
+1
-2
@@ -1,10 +1,9 @@
|
||||
|
||||
#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) ,gets (1+( c=q) )|| (exit (0),0); r(0,0)
|
||||
e(-8) ,(c=fgets(q,512,stdin),(c==NULL &&(exit(0),1))||(c[strlen(c)-1]='\0'),1)||(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]= *u,u- v^98 &&++u:
|
||||
|
||||
Reference in new issue
Block a user