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
/
MBUG
/
MBUG086.ARC
/
START2.LBR
/
PARAMSTR.IZ
/
PARAMSTR.I
Wrap
Text File
|
1979-12-31
|
2KB
|
64 lines
FUNCTION _paramstr (N:INTEGER) : STRING127;
{Function to emulate the paramstr function of TURBO v3.
Returns the Nth parameter in the commandline,
returns a null string if less than N parameters on line.
routine checks each character and decides if it is inside a word
or not, incrementing the count on the transition from not inside
to inside. When the Nth parameter is found, it starts copying characters
to a temporary string until not inside a parameter or the end of the
commandline is reached.
Space & tab characters are the separators.
NOTE type STRING127 needs to be defined in the calling program
ie TYPE
STRING127 = STRING[127]
R.J. Foord ph052 513131 AH
Mar '88
MBUG member 1044
}
CONST
tab = ^I;
VAR
inside : BOOLEAN; {true if inside a word}
found : BOOLEAN; {true after Nth parameter found}
i,L, count : INTEGER;
ch : CHAR;
parameterN : STRING127;
{ cmdline : STRING127 ABSOLUTE CSEG:$80; (*MSDOS*)}
cmdline : STRING127 ABSOLUTE $80; (*CP/M *)
BEGIN
parameterN[0] := ^@; {blank string}
inside := FALSE;
found := FALSE;
count := 0;
L := LENGTH(cmdline);
i := 1;
IF L > 0 THEN {if anything on commandline}
WHILE (i <= L) AND (NOT found) DO
BEGIN
ch := cmdline[i]; {get next char from command line}
IF inside <> NOT (ch IN [' ',tab]) THEN {space & tab are separators }
BEGIN {gone from not inside a word to}
inside := NOT inside; {inside a word or vice versa }
IF inside THEN count := SUCC(count);
END;
IF (inside AND (count = N)) THEN {if the Nth parameter}
parameterN := parameterN + ch; {build up the copy}
IF count > N THEN found := TRUE;
i := i+1;
END;
_paramstr := parameterN
END; {_paramstr}