Category : Utilities for DOS and Windows Machines
Archive   : PCPATH.ZIP
Filename : HOMEPATH.PAS
(*----------------------------------------------------------------------*)
(* Function: HomePath *)
(* *)
(* Argument : if true, prune .COM filename from return string *)
(* (leaving only dev:\dir\dir\ .. \dir\ *)
(* Returns : Value of path where program lives, ending with '\' *)
(* (+ name of executable file unless DiscardCommand) *)
(* Requires string type def AnyStr = string[255]) *)
(* *)
(* C Goodrich *)
(* PussyCat Systems *)
(* Mar '87 *)
(* Remarks: *)
(* *)
(* The string is set into the tail of the DOS environment area *)
(* by the DOS loader, preceded by a parameter count. *)
(* *)
(* This routine works with DOS 3.x only, and does not check *)
(* the version! Adding a version check is left, as *)
(* they say, as an excercise for the reader . . *)
(* *)
(* (c) 1987 PussyCat Systems, box 266, Washington Grove MD 20880 *)
(* all rights reserved *)
(* Released to the DOS user community for non-commercial use only. *)
(* *)
(*----------------------------------------------------------------------*)
const
Null : char = #0; { MicroSoft does love C-type ASCIIZ strings! }
DirSeparator = '\'; { directory separator for pruning routine }
type
DosEnv = array[0..MaxInt] of char;
var
EnvPtr: ^DosEnv;
sp : ^AnyStr; { store this string in the heap to save data space }
Done : boolean;
i : integer;
begin (* HomePath *)
(* Get address of DOS environment area *)
EnvPtr := ptr( MemW[ CSeg:$002C ] , 0 );
Done := false;
HomePath:= '';
i := 0;
repeat
if EnvPtr^[i] = Null then
(* Environment area ends with two *)
(* successive 0 bytes. *)
if ( EnvPtr^[succ(i)] = Null ) then
Done := true;
(* Not Null + Null --- keep looking *)
i := succ(i);
until ((Done) or (i = sizeof(AnyStr)));
i := succ(succ(succ(i))); { skip 2 byte parameter count . . }
new(sp); { get space for our big string }
sp^ := '';
while EnvPtr^[i] <> Null do { build fully-expanded invocation string }
begin
sp^ := sp^ + EnvPtr^[i];
i := succ(i);
end;
if DiscardCommand then
begin
i := length(sp^);
while sp^[i] <> DirSeparator do i := pred(i);
sp^[0] := char(i);
end;
HomePath := sp^;
dispose(sp); { and get rid of our temp string }
end { HomePath };
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/