pilgrimk@lafcol.UUCP (Kenwyn A. Pilgrim) (05/16/89)
Some time ago in the dark ages I posted a request for a solution
to setting the prompt in DOS. I've come up with something but
I'm not sure whether it's foolproof, but it has worked in every
instance I've used it so far.
Basically what I did was modify the environment which the CALLING
program inherited from DOS (in this case, the prompt string.)
Then, when a child process is called, it would then inherit the
modified environment of the calling program.
Thought I'd share this with you all:
---------------------- CUT HERE -------------------------------
{$M 8092,0,0}
uses Dos;
var
EnvAddr: word;
i : byte;
Ch : char;
function GetStr(i: byte): string;
{I think this function is available in TP50. }
{It's used here only to be nice, i.e. reset the prompt to }
{its original value. I'm not even sure that this is necessary}
var
EnvAddr: word;
NumMark: byte;
Index : integer;
S: string;
begin
Move(Ptr(PrefixSeg,$2C)^,EnvAddr,SizeOf(word));
Index := 0; NumMark := 0;
repeat
Move(Ptr(EnvAddr,Index)^,Ch,1);
Inc(Index);
if Ch=#0 then Inc(NumMark)
until NumMark=i;
S := '';
if i=0 then Dec(Index);
repeat
Move(Ptr(EnvAddr,Index)^,Ch,1);
S := S+Ch;
Inc(Index);
until Ch=#0;
GetStr := S
end;
procedure ModifyPrompt(S: String);
var NumMark: byte;
EnvAddr: word; Index: integer;
begin
S := S + #0; {zero-byte terminates string}
Move(Ptr(PrefixSeg,$2C)^,EnvAddr,SizeOf(word));
{$2C is the offset at which the environment address is found}
NumMark := 0; Index := 0;
repeat
Move(Ptr(EnvAddr,Index)^,Ch,1);
Inc(Index);
if Ch=#0 then Inc(NumMark)
until NumMark=2;
{I assume that the prompt string is the 3rd string.}
Move(S[1],Ptr(EnvAddr,Index)^,Length(S))
{S[0] contains length and should not be included}
end;
var
OrigPrompt: string;
begin
OrigPrompt := GetStr(2);
ModifyPrompt('PROMPT=type Exit to return to MENU $_'+Copy(OrigPrompt,8,Length(OrigPrompt)));
Exec('c:\command.com','');
ModifyPrompt(OrigPrompt);
end.
{------------------------ cut here too ----------------}
Possible problems:
If the prompt string isn't the last string in the environment and
it's length is increased, other important info may be destroyed.
Also if (as I assumed) the prompt is not the third string in the
environment, this will not work. If anyone has another solution,
please post, since I am in need of a truly-known bug free
ModifyPrompt procedure (mine relies on too many assumptions).
(Is any of this code necessary or is it already part of TP50?)
Thanks
-Kenwyn