home *** CD-ROM | disk | FTP | other *** search
- { File: GETENV2.INC }
- {
- ** The following function will look for an environment variable
- ** and return it's definition if found. If the variable is not
- ** found, then the returned definition variable will be empty.
- ** Compiled and run with Turbo Pascal v2.0 on an IBM PC/XT running
- ** PC-DOS v2.1.
- **
- ** This code is entered into the Public Domain for free use by all.
- ** George B. Smith, March 15, 1985. }
-
- type Env_String = string[80];
-
- procedure GetEnvParam(name: Env_String; { environment variable to search for }
- var param: Env_String { returned definition }
- );
-
- var
- envseg: integer; { segment address of environment from PSP }
- ei: integer; { index into environment }
- envname: Env_String; { current environment string name }
- ch: char; { current character from environment }
- found: boolean; { if true then environment name was found }
-
- begin
- envseg := MemW[CSeg:$2C]; { get address of environment from PSP }
- found := FALSE;
- ch := chr(Mem[envseg:ei]); { get first char from environment }
- while (ch <> chr(0)) and (not found) do begin
- envname := '';
- while (ch <> '=') AND (Length(EnvName) < 255)
- do begin { get environment string name }
- envname := envname + ch;
- ei := ei + 1;
- ch := chr(Mem[envseg:ei])
- end;
- ei := ei + 1; { skip over the EQUALS }
- param := '';
- ch := chr(Mem[envseg:ei]);
- while ch <> chr(0) do begin { get environment string parameter }
- param := param + ch;
- ei := ei + 1;
- ch := chr(Mem[envseg:ei])
- end;
- if name = envname then { check for a match }
- found := TRUE;
- ei := ei + 1;
- ch := chr(Mem[envseg:ei])
- end;
- if not found then
- param := ''
- end; { Procedure GetEnvParam }
-