{->>>>SearchEnvironment<<<<------------------------------------} { } { Filename: SRCHENV.SRC -- Last modified 10/20/85 } { } { This routine searches the DOS environment for a parameter, } { and if it finds the parameter, returns the value of that } { parameter as read from the environment. The function return } { value is set to True if the parameter is found. The value } { of the found parameter is placed in Value. If the parameter } { is not found, Value will be set to the null string. ('') } { The requested parameter is forced to upper-case before the } { search is begun, since COMMAND.COM capslocks the parameter } { when it is entered via the SET DOS command. } {--------------------------------------------------------------} FUNCTION SearchEnvironment(Parm : String80; VAR Value : String80) : Boolean; TYPE String255 = String[255]; VAR I,J,K : Integer; EnvSegment : Integer; EnvOffset : Integer; TempString : String255; BEGIN SearchEnvironment := False; { Defaults to "not found" } Value := ''; { Set Value to null string } FOR I := 1 TO Length(Parm) DO { Caps lock the parm } Parm[I] := UpCase(Parm[I]); EnvSegment := MEMW[CSEG:$2C]; { Locate the DOS environment } EnvOffset := 0; J := 0; { Until we run out of environment, search: } WHILE MEM[EnvSegment : EnvOffset] <> 0 DO BEGIN TempString := ''; I := 1; { Here we copy an environment string into TempString: } REPEAT TempString[I] := CHR(MEM[EnvSegment : EnvOffset]); I := SUCC(I); EnvOffset := SUCC(EnvOffset) UNTIL MEM[EnvSegment : EnvOffset]=0; TempString[0] := CHR(EnvOffset-J); { Set length of TempString } K := Pos('=',TempString); { Locate "=" in TempString } IF K > 0 THEN { If there is an "=" in this string... } IF Copy(TempString,1,K-1) = Parm THEN { If Parm is found } BEGIN SearchEnvironment := True; { We found it! } { Copy procedure's value into Value... } Value := Copy(TempString,K+1,Length(TempString)-K); Exit { ...and duck out of proc } END; J := EnvOffset+1; EnvOffset := SUCC(EnvOffset) END END;