home *** CD-ROM | disk | FTP | other *** search
- { Copyright (C) 1984 D.M. Fritz-Rohner }
-
- procedure ArgInit ( var narg : integer; var argv : argvec ) ;
- { }
- { Name: ArgInit - ARGument vector INITialization. }
- { }
- { Version: 1.0/TURBO (tm) Date: 1984 May 16 }
- { }
- { Purpose: Parse reduced command tail just enough to }
- { extract argument strings. Note that argument }
- { counting conforms to Pascal's one origin indexing }
- { so that argument indices run from 1 to narg. }
- { }
- { Notice that command tail length is limited because }
- { TURBO writes a jump vector over the command buffer }
- { beginning at offset 20H. Therefore, only 31 bytes }
- { of the command tail are available in default line }
- { buffer. See ALTCMD.PAS if the entire command line }
- { must be parsed. }
- { }
- { Author: D.M. Fritz-Rohner }
- { Post Office Box 9080 }
- { Akron, Ohio 44305 }
- { }
-
- const MAXLINE = 31 ;
-
- type xstrptr = ^xstr ;
- xstr = record
- len : char ;
- tail : array[1..MAXLINE] of char ;
- end ;
-
- var arg : argstr ; { intermediate variable }
- cptr : xstrptr ; { command tail pointer }
- icl : integer ; { command tail index }
- ncl : integer ; { number command chars }
-
- begin
-
- cptr := ptr(128) ; { command line tail }
- ncl := ord(cptr^.len) ;
- if (ncl > MAXLINE) then
- ncl := MAXLINE ;
-
- narg := 0 ;
- icl := 1 ;
- while ((icl <= ncl) and (narg < MAXARG)) do begin
- arg := '' ;
-
- { gobble leading blanks }
-
- while ((icl <= ncl) and (cptr^.tail[icl] = BLANK)) do
- icl := icl + 1 ;
-
- { extract argument }
-
- while ((icl <= ncl) and (cptr^.tail[icl] <> BLANK)
- and (length(arg) < MAXSTR)) do begin
- arg := concat(arg,cptr^.tail[icl]) ;
- icl := icl + 1
- end ;
-
- { skip argument tail if truncated }
-
- while ((icl <= ncl) and (cptr^.tail[icl] <> BLANK)) do
- icl := icl + 1 ;
-
- { update argument vector }
-
- if (length(arg) > 0) then begin
- narg := narg + 1 ;
- argv[narg] := arg
- end
- end
- end ;
-
- {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
-
- function GetArg (n : integer; var s : argstr; maxstr : integer) : boolean ;
- { }
- { Name: GetArg - GET and copy command line ARGument. }
- { }
- { Version: 1.0/Turbo (tm) Date: 1984 May 16 }
- { }
- { Purpose: Copy n-th argument from command line argu- }
- { ment vector to string s. Note that maxstr is dummy. }
- { }
- { Author: D.M. Fritz-Rohner }
- { Post Office Box 9080 }
- { Akron, Ohio 44305 }
- { }
- { Reference: 'Software Tools in Pascal' }
- { Brian W. Kernighan and P. J. Plauger }
- { Addison-Wesley Publishing Company, 1981 }
- { pp. 350 }
- { }
- begin
- if (n > 0) and (n <= Narg) then begin
- s := Argv[n] ;
- GetArg := true
- end
- else
- GetArg := false
- end ;