Browse Source

* works also under go32v2

peter 25 years ago
parent
commit
7861b48108
2 changed files with 65 additions and 38 deletions
  1. 9 9
      packages/uncgi/testcgi.bat
  2. 56 29
      packages/uncgi/uncgi.pp

+ 9 - 9
packages/uncgi/testcgi.bat

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

+ 56 - 29
packages/uncgi/uncgi.pp

@@ -98,34 +98,7 @@ Var EnvP : PChar;
 function GetEnvironmentStrings : pchar; external 'kernel32' name 'GetEnvironmentStringsA';
 function FreeEnvironmentStrings(p : pchar) : longbool; external 'kernel32' name 'FreeEnvironmentStringsA';
 
-Function GetEnv(envvar: string): pchar;
-{ Getenv that can return environment vars of length>255 }
-var s : String;
-    i,len : longint;
-    hp : pchar;
-
-begin
-  s:=Envvar+#0;
-  getenv:=Nil;
-  hp:=envp;
-  while hp[0]<>#0 do
-    begin
-    len:=strlen(hp);
-    i:=Longint(strscan(hp,'='))-longint(hp);
-    if StrLIComp(@s[1],HP,i-1)=0 then
-       begin
-       Len:=Len-i;
-       getmem (getenv,len);
-       Move(HP[I+1],getenv^,len+1);
-       break;
-       end;
-    { next string entry}
-    hp:=hp+len+1;
-    end;
-end;
-
 Procedure FInitWin32CGI;
-
 begin
   { Free memory }
   FreeMem (EnvP,EnvLen);
@@ -133,7 +106,6 @@ begin
 end;
 
 Procedure InitWin32CGI;
-
 var s : String;
     i,len : longint;
     hp,p : pchar;
@@ -156,8 +128,60 @@ begin
   OldExitProc:=ExitProc;
   ExitProc:=@FinitWin32CGI;
 end;
+
+Function GetEnv(envvar: string): pchar;
+{ Getenv that can return environment vars of length>255 }
+var s : String;
+    i,len : longint;
+    hp : pchar;
+
+begin
+  s:=Envvar+#0;
+  getenv:=Nil;
+  hp:=envp;
+  while hp[0]<>#0 do
+    begin
+    len:=strlen(hp);
+    i:=Longint(strscan(hp,'='))-longint(hp);
+    if StrLIComp(@s[1],HP,i-1)=0 then
+       begin
+       Len:=Len-i;
+       getmem (getenv,len);
+       Move(HP[I+1],getenv^,len+1);
+       break;
+       end;
+    { next string entry}
+    hp:=hp+len+1;
+    end;
+end;
+{$endif}
+
+{$ifdef GO32V2}
+Function  GetEnv(envvar: string): pchar;
+var
+  hp    : ppchar;
+  p     : pchar;
+  hs    : string;
+  eqpos : longint;
+begin
+  envvar:=upcase(envvar);
+  hp:=envp;
+  getenv:=nil;
+  while assigned(hp^) do
+   begin
+     hs:=strpas(hp^);
+     eqpos:=pos('=',hs);
+     if copy(hs,1,eqpos-1)=envvar then
+      begin
+        getenv:=hp^+eqpos;
+        exit;
+      end;
+     inc(hp);
+   end;
+end;
 {$endif}
 
+
 var
   done_init     : boolean;
 
@@ -389,7 +413,10 @@ end.
 {
   HISTORY
   $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
 
   Revision 1.4  1999/07/26 20:07:44  michael