
program PATHFIX {PATH-FIX.PAS} ;

{ PATH-FIX #, where #=0..9, alters the ENVIRONMENT of the #'th level parent
  of PATH-FIX ; it changes EVERY occurrence of œ to the first character of
  PATH-FIX's COMSPEC environment variable.  The intended use is of PATH-FIX 1
  in AUTOEXEC.BAT, to change the drive letters dummied by œ in the PATH owned
  by the parent COMMAND.COM to the letter of the COMMAND.COM drive ; with
  moveable media, this will set the correct drive letter for COMMAND.COM and
  presumably for many other directories which are wanted on the PATH.  COMSPEC
  needs to be the default boot one and can be reset later if COMMAND.COM is not
  in the boot root :
  ú   SET BD=œ
  ú   SET PATH=œ\DOS; ... ;œ\UTYS
  ú   PATH-FIX 1
  ú   SET COMSPEC=%BD%:\DOS\COMMAND.COM
  ú   SET BD=
  DOS 4.0+ would not need to get the letter from COMSPEC; Int21 Fn33 AL=5 DL.
  See MS-DOS Bible 2nd Ed p.410 for full commented version of envsize.pas ;
  3rd Ed pp.229, 232, 235 apply ; DOS 3.0 or higher assumed. }

uses Dos ;

(*** function GetPSPseg : word { I missed PrefixSeg ! in TP System Unit }
  { DOS 3,4: INT21h Fn 62h returns PSPseg in BX ; DOS 2: use Undoc Fn 51h } ;
var DosReg : registers ;
begin DosReg.AX := $6200 ; MsDos(DosReg) ; GetPSPseg := DosReg.BX end ; ***)

function GetEnvAddr(PSPsg : word) : word { PSP word 2Ch is Seg of Env } ;
begin GetEnvAddr := MemW[PSPsg:$002C] end ;

function GetParentAddr(PSPsg : word) : word { PSP word 16h is Seg of Parent } ;
begin GetParentAddr := MemW[PSPsg:$0016] end ;

procedure FixPath(EnvSegment : word ; NewChar : char) ;
var Count : word ; FZ, SZ : boolean ; EnvCharPtr : ^char ;
begin Count := 0 ; FZ := false ; SZ := false ;
  repeat
    EnvCharPtr := Ptr(EnvSegment, Count) ;
    if EnvCharPtr^='œ' then EnvCharPtr^ := NewChar ;
    (** Write(EnvCharPtr^) ; **)
    if EnvCharPtr^<>#0 then FZ := false
      else if FZ then SZ := true else FZ := true ;
    Inc(Count) until SZ ;
  (** Writeln ; **) end {FixPath} ;

var S : string ; C : char ; X, Y : byte ; PSPseg : word ;

BEGIN ;
S := ParamStr(1) ; if S='' then X := 0 else X := Ord(S[1]) - Ord('0') ;
S := GetEnv('COMSPEC') ; C := UpCase(S[1]) ;
Writeln('   PATH-FIX.PAS ', X,'; COMSPEC = ', S, ' => NewPathDrive = ', C) ;

PSPseg := PrefixSeg ;
for Y := 1 to X do PSPseg := GetParentAddr(PSPseg) ;
FixPath(GetEnvAddr(PSPseg), C) ;
END.

Note : this was written for Dos3.3.
Consider also
  INT 2eH: Perform DOS Command  
    This undocumented service executes a DOS command as if it had been typed
    at the DOS prompt.
