home *** CD-ROM | disk | FTP | other *** search
- Program DemoEnv;
-
- { * This program demonstrates all of the procedures and functions in the
- { * Turbo Pascal Unit ENV.PAS.
- { *
- { * All lines of code in this demonstration program that reference the
- { * ENV.PAS unit are remarked with a leading exclamation point.
- { *
- { * Dave Bennett
- { *
- }
-
- Uses Dos, Crt, Env; { ! Env.Pas is compiled into a .TPU }
-
- Var
- EnvBuf : EnvRecord; { ! Record type defined in ENV.PAS }
- EnvAry : EnvArray; { ! " " " " " }
- I : Integer; { Used in displaying PATH directories }
- Fil : Text; { Used in the EnvAssign Demo }
- St : String[80]; { " " " " " }
-
- Begin
-
- { List the entire environment area to the screen }
-
- ClrScr;
- FirstEnv(EnvBuf); { ! Find the 1st environment str }
- While Not(EndEnv) Do Begin { ! Check for end of environment }
- WriteLn('Var # ',EnvBuf.Pos:2,': ', { ! Write the environment string }
- EnvBuf.Name,'=',EnvBuf.Data); { data to the screen }
- NextEnv(EnvBuf); { ! Find the next environment str }
- End;
- WriteLn;
-
- { Show user the COMSPEC }
-
- EnvBuf.Name := 'COMSPEC'; { ! Set the var name to find }
- GetEnvStr(EnvBuf); { ! Find the COMSPEC }
- WriteLn('Your COMSPEC is ',EnvBuf.Data); { ! Display the COMSPEC }
-
- { Break the PATH out into it's seperate directories }
-
- WriteLn;
- EnvBuf.Name := 'PATH'; { ! Set search var to PATH }
- GetEnvStr(EnvBuf); { ! Get path string }
- EnvParse(EnvBuf.Data, EnvAry); { ! Parse the PATH string }
- For I := 1 to 20 Do
- If EnvAry[I] > #00 Then { ! Empty parsed paths equal #00 }
- WriteLn('PATH #',I,' = ',EnvAry[I]); { ! Display a parsed path }
-
- { Use EnvAssign to assign a file var to a CONFIG.SYS in the path directories }
-
- WriteLn;
- Write('The file CONFIG.SYS ');
- EnvAssign(Fil,'PATH','CONFIG.SYS'); { ! EnvAssign using the PATH var }
- {$I-} Reset(Fil); {$I+}
- If (IOResult = 0) Then Begin
- WriteLn('wast found in the current or a PATH directory, It reads:');
- While Not(Eof(Fil)) Do Begin
- ReadLn(Fil,St);
- WriteLn(' ',St);
- End;
- Close(Fil);
- End Else
- WriteLn('not found in current or path directories.');
-
- End {DEMOENV.PAS}.