home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / window / miscutil / enved2 / $enved.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1987-07-15  |  2.4 KB  |  91 lines

  1. (*
  2.     Convert (possibly editted) output of DOS "SET" command to
  3.     a .BAT file which will make that the current environment.
  4.  
  5.     Each line is of the form: var=string
  6.  
  7.     Case of var does not matter. Case of string will be preserved, and
  8.     may make a difference for some things (like PROMPT) and not others.
  9.  
  10.     Each line except for PROMPT= and PATH= in input is automatically
  11.     prefixed with "SET ". ("SET" is not needed in those cases, and
  12.     sometimes "SET PROMPT=..." is a syntax error. I have no idea why.)
  13.  
  14.     Any variables which exist at time of conversion but which are not in
  15.     the input file are cleared, except for PATH and COMSPEC. Therefore
  16.     when editting the file to be used as input you can drop a variable
  17.     by deleting its line.
  18.  
  19.     Input is standard input (keyboard) and output is standard output
  20.     (video screen). Keyboard input is terminated by a null line.
  21.     Use redirection for disk files.
  22.  
  23.     Written by:
  24.         Bill Mayne
  25.         9707 Lawndale Dr.
  26.         Silver Spring, MD  20901
  27. *)
  28.  
  29. {$G256}
  30. {$P256}
  31. {$V-}
  32. type
  33.   str255=string[255];
  34.   byte_array=array[1..1] of byte;
  35.   char_array=array[1..1] of char;
  36.   char_array_ptr=^char_array;
  37.  
  38. function envstr(start_ptr:char_array_ptr):str255;
  39. var
  40.   i:integer;
  41.   result:str255;
  42. begin
  43.   i:=1;
  44.   while (start_ptr^[i]>chr(0))
  45.     begin
  46.       result[i]:=start_ptr^[i];
  47.       i:=i+1;
  48.     end;
  49.    result[0]:=chr(i);
  50.    envstr:=result;
  51. end;
  52.  
  53. function UpStr(instr:str255):str255;
  54.   var result:str255;
  55.       i:integer;
  56. begin
  57.   result[0]:=instr[0];
  58.   for i:=1 to ord(instr[0]) do
  59.     result[i]:=UpCase(instr[i]);
  60.   UpStr:=result;
  61. end;
  62.  
  63. var
  64.   EnvSeg:integer absolute CSeg:$2C;
  65.   Estr:char_array_ptr;
  66.   i:integer;
  67.   hold_str:str255;
  68. begin
  69.   i:=0;
  70.   Estr:=Ptr(EnvSeg,0);
  71.   repeat
  72.     hold_str:=envstr(Estr);
  73.     if ((UpStr((copy(hold_str,1,5)))<>'PATH=') and
  74.         (UpStr((copy(hold_str,1,8)))<>'COMSPEC=')) then
  75.       begin
  76.         if (UpStr(copy(hold_str,1,7))<>'PROMPT=') then write('SET ');
  77.         writeln(copy(hold_str,1,pos('=',hold_str)));
  78.       end;
  79.     i:=i+ord(hold_str[0]);
  80.     Estr:=Ptr(EnvSeg,i)
  81.   until (Estr^[1]=chr(0));
  82.   readln(hold_str);
  83.   while (hold_str<>'')
  84.     begin
  85.       if ((UpStr((copy(hold_str,1,5)))<>'PATH=') and
  86.           (UpStr(copy(hold_str,1,7))<>'PROMPT=')) then write('SET ');
  87.       writeln(hold_str);
  88.       readln(hold_str);
  89.     end;
  90. end.
  91.