home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / znode3 / uploads / mouse-ps.lbr / PARAMSTR.IZC / PARAMSTR.INC
Encoding:
Text File  |  1993-02-23  |  1.8 KB  |  54 lines

  1.  
  2. Function ParamStr(i:integer):str80;
  3.  
  4. {
  5.  
  6. Returns ith string of command. If i=0, returns command itself. If i=1, 
  7. returns the first command tail parameter, etc. This uses the multiple 
  8. command line, *not* the tbuff (hex 80 to hex ff.) Turbo Pascal itself uses 
  9. tbuff+32 to tbuff+79 for its own purposes! Needed to write this function 
  10. because it is *not* in the standard lib of Turbo Pascal Version 2.
  11.  
  12. Updated on 1/19/91 - Now using message buffer's "error address" which under 
  13. z33+ holds address of current command.
  14.  
  15. Updated on 2/23/93 - Removed an extraneous semicolon. Remember, syntax 
  16. is:
  17.  
  18. if condition then
  19.  st1
  20. else
  21.  st2; 
  22.  
  23. }
  24.  
  25. Var
  26.   j,p,ea    : Integer;
  27.   current   : str80;
  28.   msg       : msgptr; { from nz-tool.box }
  29.   byt       : Byte;
  30.  
  31. Begin
  32.   msg := Ptr(getmsg);  {get message buffer, using nz-tool.box}
  33.   ea := msg^.eradr;    {get address of current command}
  34.   byt := Mem[ea]; j := 0; {load first byte of current command and init. j}
  35.   While (byt <> ord(';')) And (byt <> 0) Do Begin {find end of command}
  36.     current[j+1] := Chr(byt); {and load work string}
  37.     j := j+1;
  38.     byt := Mem[ea+j]; End;
  39.   current[0] := Chr(j);  {fill in command length}
  40.   p := Pos(' ',current); {locate first space}
  41.   If (i > 0) And (p = 0) Then current := '';
  42.   While (i <> 0) And (p <> 0) Do Begin  {grab the ith parm}
  43.     i := i-1; {decrement parm counter}
  44.     Delete(current,1,p);   {lop off the leading parm}
  45.     p := Pos(' ',current); {locate next space}
  46.   End;
  47.   If p=0 Then {if at end, use what's left}
  48.     ParamStr := current
  49.   Else
  50.     ParamStr := Copy(current,1,p-1);
  51.            {else, what's at the beginning}
  52. End;   {of what's left}
  53.  
  54.