home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 2
/
ctrom_ii_b.zip
/
ctrom_ii_b
/
PROGRAM
/
PASCAL
/
TCSEL002
/
PROMPT.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1992-10-16
|
3KB
|
108 lines
{$A+,B-,F-,L-,N-,O-,R-,S-,V-}
unit prompt;
{
Author: Trevor J Carlsen
PO Box 568
Port Hedland
Western Australia 6721
61-[0]-91-73-2026 (voice)
61-[0]-91-73-2930 (data )
Released into the public domain.
This unit will automatically create a predefined prompt when shelling to DOS.
If you wish to create your own custom prompt, all that is required is to give
the variable NewPrompt another value and call the procedure ChangeShellPrompt.
}
interface
uses dos;
var
NewPrompt : string;
procedure ChangeShellPrompt(Nprompt: string);
implementation
type
EnvArray = array[0..32767] of byte;
EnvPtr = ^EnvArray;
var
EnvSize, EnvLen, EnvPos: word;
NewEnv, OldEnv : EnvPtr;
TempStr : string;
x : word;
procedure ChangeShellPrompt(Nprompt: string);
function MainEnvSize: word;
var
x : word;
found : boolean;
begin
found := false; x := 0;
repeat
if (OldEnv^[x] = 0) and (OldEnv^[x+1] = 0) then
found := true
else
inc(x);
until found;
MainEnvSize := x - 1;
end; { MainEnvSize}
procedure AddEnvStr(var s; var offset: word; len: word);
var st : EnvArray absolute s;
begin
move(st[1],NewEnv^[offset],len);
inc(offset,len+1);
end;
begin
OldEnv := ptr(MemW[PrefixSeg:$2C],0);
{ this gets the actual starting segment of the current program's env }
EnvSize := MemW[seg(OldEnv^)-1:3] shl 4;
{ Find the size of the current environment }
if MaxAvail < (EnvSize+256) then begin
writeln('Insufficient memory');
halt;
end;
GetMem(NewEnv, EnvSize + $100);
if ofs(NewEnv^) <> 0 then begin
inc(longint(NewEnv),$10000 + ($10000 * (longint(NewEnv) div 16)));
longint(NewEnv) := longint(NewEnv) and $ffff0000;
end;
FillChar(NewEnv^,EnvSize + $100,0);
{ Allocate heap memory for the new environment adding enough to allow }
{ alignment to a paragraph boundary or a longer prompt than the default }
{ and initialise to nuls }
EnvPos := 0;
AddEnvStr(Nprompt,EnvPos,length(Nprompt));
for x := 1 to EnvCount do begin
TempStr := EnvStr(x);
if TempStr <> GetEnv('PROMPT') then
AddEnvStr(TempStr,EnvPos,length(TempStr));
end; { for }
inc(EnvPos);
{ Transfer old env strings except the prompt to new environment }
if lo(DosVersion) > 2 then
AddEnvStr(OldEnv^[MainEnvSize + 2],EnvPos,EnvSize-(MainEnvSize + 2));
{ Add the rest of the environment }
MemW[PrefixSeg:$2C] := seg(NewEnv^);
{ let the program know where the new environment is }
end; { ChangeShellPrompt }
end. { prompt }