home *** CD-ROM | disk | FTP | other *** search
- (*
- Convert (possibly editted) output of DOS "SET" command to
- a .BAT file which will make that the current environment.
-
- Each line is of the form: var=string
-
- Case of var does not matter. Case of string will be preserved, and
- may make a difference for some things (like PROMPT) and not others.
-
- Each line except for PROMPT= and PATH= in input is automatically
- prefixed with "SET ". ("SET" is not needed in those cases, and
- sometimes "SET PROMPT=..." is a syntax error. I have no idea why.)
-
- Any variables which exist at time of conversion but which are not in
- the input file are cleared, except for PATH and COMSPEC. Therefore
- when editting the file to be used as input you can drop a variable
- by deleting its line.
-
- Input is standard input (keyboard) and output is standard output
- (video screen). Keyboard input is terminated by a null line.
- Use redirection for disk files.
-
- Written by:
- Bill Mayne
- 9707 Lawndale Dr.
- Silver Spring, MD 20901
- *)
-
- {$G256}
- {$P256}
- {$V-}
- type
- str255=string[255];
- byte_array=array[1..1] of byte;
- char_array=array[1..1] of char;
- char_array_ptr=^char_array;
-
- function envstr(start_ptr:char_array_ptr):str255;
- var
- i:integer;
- result:str255;
- begin
- i:=1;
- while (start_ptr^[i]>chr(0))
- begin
- result[i]:=start_ptr^[i];
- i:=i+1;
- end;
- result[0]:=chr(i);
- envstr:=result;
- end;
-
- function UpStr(instr:str255):str255;
- var result:str255;
- i:integer;
- begin
- result[0]:=instr[0];
- for i:=1 to ord(instr[0]) do
- result[i]:=UpCase(instr[i]);
- UpStr:=result;
- end;
-
- var
- EnvSeg:integer absolute CSeg:$2C;
- Estr:char_array_ptr;
- i:integer;
- hold_str:str255;
- begin
- i:=0;
- Estr:=Ptr(EnvSeg,0);
- repeat
- hold_str:=envstr(Estr);
- if ((UpStr((copy(hold_str,1,5)))<>'PATH=') and
- (UpStr((copy(hold_str,1,8)))<>'COMSPEC=')) then
- begin
- if (UpStr(copy(hold_str,1,7))<>'PROMPT=') then write('SET ');
- writeln(copy(hold_str,1,pos('=',hold_str)));
- end;
- i:=i+ord(hold_str[0]);
- Estr:=Ptr(EnvSeg,i)
- until (Estr^[1]=chr(0));
- readln(hold_str);
- while (hold_str<>'')
- begin
- if ((UpStr((copy(hold_str,1,5)))<>'PATH=') and
- (UpStr(copy(hold_str,1,7))<>'PROMPT=')) then write('SET ');
- writeln(hold_str);
- readln(hold_str);
- end;
- end.