home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / ENTERPRS / CPM / UTILS / S / TURBTOOL.ARC / INITCMD.PAS < prev    next >
Pascal/Delphi Source File  |  1989-09-27  |  2KB  |  84 lines

  1.  
  2. {initcmd.pas}
  3.  
  4. {
  5.         copyright (c) 1981
  6.         by:     bell telephone laboratories, inc. and
  7.                 whitesmith's ltd.,
  8.  
  9.         this software is derived from the book
  10.                 "software tools in pascal", by
  11.                 brian w. kernighan and p. j. plauger
  12.                 addison-wesley, 1981
  13.                 isbn 0-201-10342-7
  14.  
  15.         right is hereby granted to freely distribute or duplicate this
  16.         software, providing distribution or duplication is not for profit
  17.         or other commercial gain and that this copyright notice remains
  18.         intact.
  19. }
  20.  
  21. procedure initcmd;
  22. var
  23.   fd:filedesc;
  24.   fname:xstring;
  25.   ft:filtyp;
  26.   idx:1..maxstr;
  27.   i,jskip:integer;
  28.   junk:boolean;
  29.  
  30.  
  31. begin
  32.   cmdfil[stdin]:=stdio;
  33.   cmdfil[stdout]:=stdio;
  34.   cmdfil[stderr]:=stdio;
  35.   for fd:=succ(stderr) to maxopen do
  36.     cmdfil[fd]:=closed;
  37.   writeln;
  38.   write('$ ');
  39.   for ft:= fil1 to fil4 do
  40.     cmdopen[ft]:=false;
  41.   kbdn:=0;
  42.   if (not getline(cmdlin,stdin,maxstr)) then error('no cmdline');
  43. cmdargs:=0;
  44.   jskip:=0;
  45.   idx:=1;
  46.   while ((cmdlin[idx]<>endstr)
  47.     and(cmdlin[idx]<>newline)) do begin
  48.       while((cmdlin[idx]=blank)and(jskip mod 2 <>1))do
  49.         idx:=idx+1;
  50.       if(cmdlin[idx]<>newline) then begin
  51.         cmdargs:=cmdargs+1;
  52.         cmdidx[cmdargs]:=idx-jskip;
  53.         while((cmdlin[idx]<>newline)and
  54.           ((cmdlin[idx]<>blank)or(jskip mod 2 <>0)))do begin
  55.               if (cmdlin[idx]=dquote)then begin
  56.                 jskip:=jskip+1;
  57.                 idx:=idx+1
  58.               end
  59.               else begin
  60.                 cmdlin[idx-jskip]:=cmdlin[idx];
  61.                 idx:=idx+1
  62.               end
  63.  
  64.             end;
  65.         cmdlin[idx-jskip]:=endstr;
  66.         idx:=idx+1;
  67.         if (cmdlin[cmdidx[cmdargs]]=less) then begin
  68.           xclose(stdin);
  69.           cmdidx[cmdargs]:=cmdidx[cmdargs]+1;
  70.           junk:=getarg(cmdargs,fname,maxstr);
  71.           fd:=mustopen(fname,ioread);
  72.           cmdargs:=cmdargs-1;
  73.         end
  74.         else if (cmdlin[cmdidx[cmdargs]]=greater) then begin
  75.           xclose(stdout);
  76.           cmdidx[cmdargs]:=cmdidx[cmdargs]+1;
  77.           junk:=getarg(cmdargs,fname,maxstr);
  78.           fd:=mustcreate(fname,iowrite);
  79.           cmdargs:=cmdargs-1;
  80.         end
  81.       end
  82.     end;
  83. end;
  84.