home *** CD-ROM | disk | FTP | other *** search
-
- {initcmd.pas}
-
- {
- copyright (c) 1981
- by: bell telephone laboratories, inc. and
- whitesmith's ltd.,
-
- this software is derived from the book
- "software tools in pascal", by
- brian w. kernighan and p. j. plauger
- addison-wesley, 1981
- isbn 0-201-10342-7
-
- right is hereby granted to freely distribute or duplicate this
- software, providing distribution or duplication is not for profit
- or other commercial gain and that this copyright notice remains
- intact.
- }
-
- procedure initcmd;
- var
- fd:filedesc;
- fname:xstring;
- ft:filtyp;
- idx:1..maxstr;
- i,jskip:integer;
- junk:boolean;
-
-
- begin
- cmdfil[stdin]:=stdio;
- cmdfil[stdout]:=stdio;
- cmdfil[stderr]:=stdio;
- for fd:=succ(stderr) to maxopen do
- cmdfil[fd]:=closed;
- writeln;
- write('$ ');
- for ft:= fil1 to fil4 do
- cmdopen[ft]:=false;
- kbdn:=0;
- if (not getline(cmdlin,stdin,maxstr)) then error('no cmdline');
- cmdargs:=0;
- jskip:=0;
- idx:=1;
- while ((cmdlin[idx]<>endstr)
- and(cmdlin[idx]<>newline)) do begin
- while((cmdlin[idx]=blank)and(jskip mod 2 <>1))do
- idx:=idx+1;
- if(cmdlin[idx]<>newline) then begin
- cmdargs:=cmdargs+1;
- cmdidx[cmdargs]:=idx-jskip;
- while((cmdlin[idx]<>newline)and
- ((cmdlin[idx]<>blank)or(jskip mod 2 <>0)))do begin
- if (cmdlin[idx]=dquote)then begin
- jskip:=jskip+1;
- idx:=idx+1
- end
- else begin
- cmdlin[idx-jskip]:=cmdlin[idx];
- idx:=idx+1
- end
-
- end;
- cmdlin[idx-jskip]:=endstr;
- idx:=idx+1;
- if (cmdlin[cmdidx[cmdargs]]=less) then begin
- xclose(stdin);
- cmdidx[cmdargs]:=cmdidx[cmdargs]+1;
- junk:=getarg(cmdargs,fname,maxstr);
- fd:=mustopen(fname,ioread);
- cmdargs:=cmdargs-1;
- end
- else if (cmdlin[cmdidx[cmdargs]]=greater) then begin
- xclose(stdout);
- cmdidx[cmdargs]:=cmdidx[cmdargs]+1;
- junk:=getarg(cmdargs,fname,maxstr);
- fd:=mustcreate(fname,iowrite);
- cmdargs:=cmdargs-1;
- end
- end
- end;
- end;