home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBOPAS / ENV12.ZIP / DEMOENV.PAS next >
Encoding:
Pascal/Delphi Source File  |  1988-01-19  |  2.5 KB  |  68 lines

  1. Program DemoEnv;
  2.  
  3. { * This program demonstrates all of the procedures and functions in the
  4. { * Turbo Pascal Unit ENV.PAS.
  5. { *
  6. { * All lines of code in this demonstration program that reference the
  7. { * ENV.PAS unit are remarked with a leading exclamation point.
  8. { *
  9. { * Dave Bennett
  10. { *
  11. }
  12.  
  13. Uses Dos, Crt, Env;                { ! Env.Pas is compiled into a .TPU   }
  14.  
  15. Var
  16.   EnvBuf : EnvRecord;              { ! Record type defined in ENV.PAS    }
  17.   EnvAry : EnvArray;               { !  "     "     "     "     "        }
  18.   I      : Integer;                { Used in displaying PATH directories }
  19.   Fil    : Text;                   { Used in the EnvAssign Demo          }
  20.   St     : String[80];             {  "   "   "     "       "            }
  21.  
  22. Begin
  23.  
  24. { List the entire environment area to the screen }
  25.  
  26.   ClrScr;
  27.   FirstEnv(EnvBuf);                         { ! Find the 1st environment str  }
  28.   While Not(EndEnv) Do Begin                { ! Check for end of environment  }
  29.     WriteLn('Var # ',EnvBuf.Pos:2,': ',     { ! Write the environment string  }
  30.              EnvBuf.Name,'=',EnvBuf.Data);  {             data to the screen  }
  31.     NextEnv(EnvBuf);                        { ! Find the next environment str }
  32.   End;
  33.   WriteLn;
  34.  
  35. { Show user the COMSPEC }
  36.  
  37.   EnvBuf.Name := 'COMSPEC';                 { ! Set the var name to find      }
  38.   GetEnvStr(EnvBuf);                        { ! Find the COMSPEC              }
  39.   WriteLn('Your COMSPEC is ',EnvBuf.Data);  { ! Display the COMSPEC           }
  40.  
  41. { Break the PATH out into it's seperate directories }
  42.  
  43.   WriteLn;
  44.   EnvBuf.Name := 'PATH';                    { ! Set search var to PATH }
  45.   GetEnvStr(EnvBuf);                        { ! Get path string        }
  46.   EnvParse(EnvBuf.Data, EnvAry);            { ! Parse the PATH string  }
  47.   For I := 1 to 20 Do
  48.     If EnvAry[I] > #00 Then                 { ! Empty parsed paths equal #00 }
  49.       WriteLn('PATH #',I,' = ',EnvAry[I]);  { ! Display a parsed path        }
  50.  
  51. { Use EnvAssign to assign a file var to a CONFIG.SYS in the path directories }
  52.  
  53.   WriteLn;
  54.   Write('The file CONFIG.SYS ');
  55.   EnvAssign(Fil,'PATH','CONFIG.SYS');       { ! EnvAssign using the PATH var }
  56.   {$I-} Reset(Fil); {$I+}
  57.   If (IOResult = 0) Then Begin
  58.     WriteLn('wast found in the current or a PATH directory, It reads:');
  59.     While Not(Eof(Fil)) Do Begin
  60.       ReadLn(Fil,St);
  61.       WriteLn('  ',St);
  62.     End;
  63.     Close(Fil);
  64.   End Else
  65.     WriteLn('not found in current or path directories.');
  66.  
  67. End {DEMOENV.PAS}.
  68.