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 / JSAGE / ZSUS / PROGPACK / NZ-TOOL4.LBR / PARAMSTR.PZS / PARAMSTR.PAS
Pascal/Delphi Source File  |  2000-06-30  |  2KB  |  35 lines

  1. Function ParamStr(i:integer):str80;
  2. {
  3. Returns ith string of command. If i=0, returns command itself. If i=1 you 
  4. get the first command tail parameter, etc. This uses the multiple command 
  5. line, *not* the tbuff (hex 80 to hex ff.) Turbo Pascal itself uses tbuff+32 
  6. to tbuff+79 for its own purposes! Needed to write this function because it 
  7. is *not* in the standard lib of Turbo Pascal Version 2.
  8. }
  9. Var
  10.   j,j1,lcmd,lc,p      : Integer;
  11.   whatsleft           : str80;
  12.   cl                  : mclptr;  { from nz-tool.box }
  13. Begin
  14.   cl := Ptr(getmcl);  { point to multiple command line, using nz-tool.box }
  15.   { determine end of command and its offset in multiple command line } 
  16.   lc := cl^.nxtchr - 1; j := lc - Ord(cl) - 3; lcmd := 0;
  17.   While (cl^.mcl[j]<>';') And (j<>0) Do Begin { back up to start of command }
  18.     j := j - 1; lcmd := lcmd + 1; End;
  19.   { load work string with it }
  20.   For j1 := j + 1 To j + 1 + lcmd - 1 Do
  21.     whatsleft[j1 - (j + 1) + 1] := cl^.mcl[j1];
  22.   whatsleft[0] := Chr(lcmd);
  23.   p := Pos(' ',whatsleft);                 { locate first space }
  24.   If (i>0) And (p=0) Then whatsleft := '';
  25.   While (i<>0) And (p<>0) Do Begin         { grab the ith parm  }
  26.     i := i - 1;  { decrement parm counter }
  27.     Delete(whatsleft,1,p);   { lop off the leading parm }
  28.     p := Pos(' ',whatsleft); { locate next space        }
  29.   End;
  30.   If p=0 Then                              { if at end, use what's left }
  31.     ParamStr := whatsleft
  32.   Else
  33.     ParamStr := Copy(whatsleft,1,p - 1);  { else, what's at the beginning }
  34. End;                      { of what's left }
  35.