* works also under go32v2

This commit is contained in:
peter 2000-01-10 23:46:19 +00:00
parent dc4b6d1710
commit 7861b48108
2 changed files with 67 additions and 40 deletions

View File

@ -1,9 +1,9 @@
@echo off @echo off
echo Setting environment variables: echo Setting environment variables:
set REQUEST_METHOD=GET set REQUEST_METHOD=GET
set "QUERY_STRING=name=michael&address=home&city=heaven" set QUERY_STRING=name=michael&address=home&city=heaven
set "HTTP_USER_AGENT=Shell script" set HTTP_USER_AGENT=Shell script
set "HTTP_REFERER=The shell prompt" set HTTP_REFERER=The shell prompt
echo Running program echo Running program
testcgi testcgi.exe

View File

@ -98,6 +98,37 @@ Var EnvP : PChar;
function GetEnvironmentStrings : pchar; external 'kernel32' name 'GetEnvironmentStringsA'; function GetEnvironmentStrings : pchar; external 'kernel32' name 'GetEnvironmentStringsA';
function FreeEnvironmentStrings(p : pchar) : longbool; external 'kernel32' name 'FreeEnvironmentStringsA'; function FreeEnvironmentStrings(p : pchar) : longbool; external 'kernel32' name 'FreeEnvironmentStringsA';
Procedure FInitWin32CGI;
begin
{ Free memory }
FreeMem (EnvP,EnvLen);
ExitProc:=OldExitProc;
end;
Procedure InitWin32CGI;
var s : String;
i,len : longint;
hp,p : pchar;
begin
{ Make a local copy of environment}
p:=GetEnvironmentStrings;
hp:=p;
envp:=Nil;
envlen:=0;
while hp[0]<>#0 do
begin
len:=strlen(hp);
hp:=hp+len+1;
EnvLen:=Envlen+len+1;
end;
GetMem(EnvP,Envlen);
Move(P^,EnvP^,EnvLen);
FreeEnvironmentStrings(p);
OldExitProc:=ExitProc;
ExitProc:=@FinitWin32CGI;
end;
Function GetEnv(envvar: string): pchar; Function GetEnv(envvar: string): pchar;
{ Getenv that can return environment vars of length>255 } { Getenv that can return environment vars of length>255 }
var s : String; var s : String;
@ -123,41 +154,34 @@ begin
hp:=hp+len+1; hp:=hp+len+1;
end; end;
end; end;
{$endif}
Procedure FInitWin32CGI; {$ifdef GO32V2}
Function GetEnv(envvar: string): pchar;
var
hp : ppchar;
p : pchar;
hs : string;
eqpos : longint;
begin begin
{ Free memory } envvar:=upcase(envvar);
FreeMem (EnvP,EnvLen); hp:=envp;
ExitProc:=OldExitProc; getenv:=nil;
end; while assigned(hp^) do
begin
Procedure InitWin32CGI; hs:=strpas(hp^);
eqpos:=pos('=',hs);
var s : String; if copy(hs,1,eqpos-1)=envvar then
i,len : longint; begin
hp,p : pchar; getenv:=hp^+eqpos;
exit;
begin end;
{ Make a local copy of environment} inc(hp);
p:=GetEnvironmentStrings; end;
hp:=p;
envp:=Nil;
envlen:=0;
while hp[0]<>#0 do
begin
len:=strlen(hp);
hp:=hp+len+1;
EnvLen:=Envlen+len+1;
end;
GetMem(EnvP,Envlen);
Move(P^,EnvP^,EnvLen);
FreeEnvironmentStrings(p);
OldExitProc:=ExitProc;
ExitProc:=@FinitWin32CGI;
end; end;
{$endif} {$endif}
var var
done_init : boolean; done_init : boolean;
@ -389,7 +413,10 @@ end.
{ {
HISTORY HISTORY
$Log$ $Log$
Revision 1.5 1999-11-14 15:59:06 peter Revision 1.6 2000-01-10 23:46:19 peter
* works also under go32v2
Revision 1.5 1999/11/14 15:59:06 peter
* fpcmake'd * fpcmake'd
Revision 1.4 1999/07/26 20:07:44 michael Revision 1.4 1999/07/26 20:07:44 michael