mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-14 13:09:22 +02:00
+ implemented envcount, envstr and getenv for i8086-msdos
git-svn-id: trunk@24587 -
This commit is contained in:
parent
3aeea835f9
commit
0f7673105b
@ -74,6 +74,11 @@ implementation
|
|||||||
uses
|
uses
|
||||||
strings;
|
strings;
|
||||||
|
|
||||||
|
type
|
||||||
|
PFarByte = ^Byte;far;
|
||||||
|
PFarChar = ^Char;far;
|
||||||
|
PFarWord = ^Word;far;
|
||||||
|
|
||||||
{$DEFINE HAS_GETMSCOUNT}
|
{$DEFINE HAS_GETMSCOUNT}
|
||||||
{$DEFINE HAS_INTR}
|
{$DEFINE HAS_INTR}
|
||||||
{$DEFINE HAS_SETCBREAK}
|
{$DEFINE HAS_SETCBREAK}
|
||||||
@ -571,48 +576,66 @@ end;
|
|||||||
--- Environment ---
|
--- Environment ---
|
||||||
******************************************************************************}
|
******************************************************************************}
|
||||||
|
|
||||||
|
function GetEnvStr(EnvNo: Integer; var OutEnvStr: string): integer;
|
||||||
|
var
|
||||||
|
dos_env_seg: Word;
|
||||||
|
ofs: Word;
|
||||||
|
Ch, Ch2: Char;
|
||||||
|
begin
|
||||||
|
dos_env_seg := PFarWord(Ptr(dos_psp, $2C))^;
|
||||||
|
GetEnvStr := 1;
|
||||||
|
OutEnvStr := '';
|
||||||
|
ofs := 0;
|
||||||
|
repeat
|
||||||
|
Ch := PFarChar(Ptr(dos_env_seg,ofs))^;
|
||||||
|
Ch2 := PFarChar(Ptr(dos_env_seg,ofs + 1))^;
|
||||||
|
if (Ch = #0) and (Ch2 = #0) then
|
||||||
|
exit;
|
||||||
|
|
||||||
|
if Ch = #0 then
|
||||||
|
Inc(GetEnvStr);
|
||||||
|
|
||||||
|
if (Ch <> #0) and (GetEnvStr = EnvNo) then
|
||||||
|
OutEnvStr := OutEnvStr + Ch;
|
||||||
|
|
||||||
|
Inc(ofs);
|
||||||
|
if ofs = 0 then
|
||||||
|
exit;
|
||||||
|
until false;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
function envcount : longint;
|
function envcount : longint;
|
||||||
var
|
var
|
||||||
hp : ppchar;
|
tmpstr: string;
|
||||||
begin
|
begin
|
||||||
hp:=envp;
|
envcount := GetEnvStr(-1, tmpstr);
|
||||||
envcount:=0;
|
|
||||||
while assigned(hp^) do
|
|
||||||
begin
|
|
||||||
inc(envcount);
|
|
||||||
inc(hp);
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function envstr (Index: longint): string;
|
function envstr (Index: longint): string;
|
||||||
begin
|
begin
|
||||||
if (index<=0) or (index>envcount) then
|
GetEnvStr(Index, envstr);
|
||||||
envstr:=''
|
|
||||||
else
|
|
||||||
envstr:=strpas(ppchar(pointer(envp)+SizeOf(PChar)*(index-1))^);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
Function GetEnv(envvar: string): string;
|
Function GetEnv(envvar: string): string;
|
||||||
var
|
var
|
||||||
hp : ppchar;
|
|
||||||
hs : string;
|
hs : string;
|
||||||
eqpos : longint;
|
eqpos : longint;
|
||||||
|
I : integer;
|
||||||
begin
|
begin
|
||||||
envvar:=upcase(envvar);
|
envvar:=upcase(envvar);
|
||||||
hp:=envp;
|
|
||||||
getenv:='';
|
getenv:='';
|
||||||
while assigned(hp^) do
|
for I := 1 to envcount do
|
||||||
begin
|
begin
|
||||||
hs:=strpas(hp^);
|
hs:=envstr(I);
|
||||||
eqpos:=pos('=',hs);
|
eqpos:=pos('=',hs);
|
||||||
if upcase(copy(hs,1,eqpos-1))=envvar then
|
if upcase(copy(hs,1,eqpos-1))=envvar then
|
||||||
begin
|
begin
|
||||||
getenv:=copy(hs,eqpos+1,length(hs)-eqpos);
|
getenv:=copy(hs,eqpos+1,length(hs)-eqpos);
|
||||||
break;
|
break;
|
||||||
end;
|
end;
|
||||||
inc(hp);
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user