home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBOPAS / TURBO.ZIP / GETARG.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1985-09-16  |  1.1 KB  |  44 lines

  1. {$V-}
  2. procedure get_arg(Narg : Integer; var arg : MaxString);
  3. var
  4.    cml : MaxString absolute Cseg:$80;
  5.    CmdLine : MaxString;
  6.    pos, last, len, i, j : Integer;
  7.    NotFound : Boolean;
  8. const
  9.    White : set of char = [' ', ^I, ','];
  10. begin
  11.    CmdLine := cml + ' ';
  12.    len := Length(CmdLine);
  13.    last := 1;
  14.    NotFound := false;
  15.    pos := 1;
  16.    While (not (CmdLine[last] in  White)) and (last < len)
  17.       do last := last+1;
  18.    if Narg = 0 then begin
  19.       if last = 1 then NotFound := true;
  20.    end
  21.    else begin
  22.       for i := 1 to Narg do begin
  23.          pos := last;
  24.          While (CmdLine[pos] in White) and (pos < len)
  25.             do pos := pos + 1;
  26.          if pos = len then NotFound := true
  27.          else begin
  28.             last := pos;
  29.             While (not (CmdLine[last] in White)) and (last < len)
  30.                do last := last +1;
  31.          end;
  32.       end;
  33.    end;
  34.    if NotFound then arg := ''
  35.    else begin
  36.       j := 0;
  37.       for i:= pos to last -1 do begin
  38.          j := j +1;
  39.          arg[j] := CmdLine[i];
  40.       end;
  41.       arg[0] := char(last - pos);
  42.    end;
  43. end;
  44. {$V+}