aUCBLogo Demos and Tests / cgitest3


#!D:/Users/AndreasM/aucblogo/aucblogo_client.exe
setCaseIgnored false

to cgitest3
   
output runSecure security_connect [cgi3proc]
end

to cgi3proc
   
local [out err result]
   
catch "error
   
[
      
out=(Word [Content-typeText/html; charset=iso-8859-1

<HTML>])
      
changeDir [D:/Users/AndreasM/aucblogo]
      
result=cgi3
            
[D:/Apache2.2/htdocs/]
            
&out
      
closeall
      
if result=="reset [reset]
      
(GC true)
   
]
   
err=error
   
if not emptyP err
   
[   out=(Word out first butFirst err 
         
"\ in\  first bF bF err
         
"( first bF bF bF bF err ")</br>)
   
]
   
output out
end

to cgi3 dname &out
   
local [err errout 
      
request_method query_string content_length 
      
query_length maxArgs argCount name value 
      
start_name start_value end_value end_name 
      
namename i gr
      
%run %animate %stop %reset %commands %FrameNr FrameNr]
      
   
request_method=getEnv "REQUEST_METHOD
   
query_string  =getEnv "QUERY_STRING
   
content_length=getEnv "CONTENT_LENGTH

;request_method="GET
;query_string  ="heading=10&time=1234
;content_length=getenv "CONTENT_LENGTH
;print query_string


   
if (empty? request_methodor2 empty? query_string
   
[   goTo "nix
   
]

   
query_length=0
   
if request_method==[output []]

   
if request_method=="GET or2 request_method=="POST
   
[   if query_string==[output []]
      
ifElse content_length=="
      
[   query_length=count query_string
      
][   query_length=Int content_length
      
]
   
]
;   if request_method=="POST
;   [   if content_length==0 [output []]
;      query_length=Int content_length
;      setReader "stdin
;      query_string=readRawLine
;      setReader []
;   ]
   
maxArgs=10
   
name=Array maxArgs
   
value=Array maxArgs
   
for [maxArgs 1]
   
[   name.i=[]
      
value.i=[]
   
]
   
end_value=0
   
argCount=1
   
while [end_value query_length]
   
[   start_name=end_value+1
      
end_name=start_name
      
while [end_name<query_length and2 query_string.end_name !="=]
      
[   end_name=end_name+1
      
]
      
name.argCount=Items start_name end_name-query_string
      
name.argCount=decode_string name.argCount

      
start_value=end_name+1
      
end_value=start_value
      
while [end_value<query_length]
      
[   if query_string.end_value =="& [break]
         
if query_string.end_value =="+  
         
[   query_string.end_value="\ 
         
]
         
end_value=end_value+1
      
]
      
ifElse end_value<=query_length
      
[   value.argCount=Items start_value end_value query_string
         
value.argCount=decode_string value.argCount
      
][   value.argCount="
      
]

      
argCount=argCount+1
   
]
   
argCount=argCount-1
   
   
if argCount 0
   
[   for [argCount 1]
      
[   if not empty? name.i
         
[   namename=Word "% name.i
            
make namename  value.i
         
]   
      
]
   
]

t
ag "nix
   
if not name? "%reset [%reset="]
   
if not name? "%animate [%animate="]
   
if not name? "%stop [%stop="]

   
fname=BitAnd butFirst genSym 63
   
local [txtname]
   
txtname=Word fname [.txt]
   
ifElse name? "%FrameNr [FrameNr=%FrameNr][FrameNr=0]
   
if not Number? FrameNr [pr FrameNr FrameNr=0]
   
ifElse (name? "%commandsand2 %reset !="reset
   
[   openWrite txtname
      
setWriter txtname
      
setCaseIgnored true
      
catch "error
      
[   (runSecure 
            
security_dlcall
            
+security_iodll
            
+security_shell
            
+security_filewrite 
            
;+security_fileread
            ;+security_dirs
            
+security_thread
            
;+security_keyboard
            
+security_gui
            
+security_erase
            
1024   ;stack size (in bytes)
            
1000000   ;graphic record size (in graphic primitives)
            
2000000   ;memory size (in bytes)
            
65536   ;max. number of nodes
            
10000   ;timeout (in milliseconds)
            
%commands)
      
]
      
setCaseIgnored false
      
changeDir [D:/Users/AndreasM/aucblogo]
      
err=error
      
ifElse not emptyP err
      
[   errout=(Word [
         
<tr><td style="color:yellow" bgcolor=red><b>
            
] 
            
first butFirst err 
            
"\ in\  first bF bF err
            
"( first bF bF bF bF err ")</br>
            
[
         
</b></td></tr>])
      
][   errout=[]
      
]
      
setWriter []
      
close txtname
   
][   errout=[]
   
]
   
setSaveSize [400 300]
   
saveScreen (Word dname fname [.png])
   
openRead (Word dname fname [.png])
   
close (Word dname fname [.png])

   
local [txt]
   
txt=" 
   
if File? txtname
   
[   openRead txtname
      
setReader txtname
      
txt=readChars FileSize txtname
      
setReader []
      
close txtname
      
eraseFile txtname
   
]
;      This is process number  GetProcessId ".
;      </br>)
   
out=(Word out [
   
<Head>
      
<style type="Text/css">
         
.output Background-color:#FFFFFF; font-size:80%; }
      
</style>
      
<script type="Text/javascript">
         
function setFocusRun()
         
{   ])
            
if %animate !="animate
            
[   out=(Word out [document.Form1.commands.focus();])
            
]
            
;out=(word out
            ;[document.Form1.commands.rows=
            ;   (window.innerHeight-500)/20;
            ;])
            
if %animate=="animate and2 %stop !="stop and2 empty? errout
            
[   out=Word out [document.Form1.submit();]
            
]
            
out=(Word out [               
         
}
         
Window.onresize=sizeit;
         
function sizeit()
         
{   document.Form1.commands.rows=
               
(Window.innerHeight-500)/20;
         
}
      
</Script>
   
</Head>
   
<Body OnLoad="setFocusRun()"
   
marginwidth="0" marginheight="0" topmargin="0" leftmargin="0">
      
<Table Border="0" rules="rows">] errout)
;         if name? "argCount
;         [   for [i 1 argCount]
;            [   out=(word out name.i "
= value.i "\ )
;            ]
;         ]
;         out=word out getEnvTable
         out=(Word out [

         
<tr><td>
            
<center>
               
<Image src="] fname [.png" 
               
width="400" height="300" tabindex="20">
            
</center>
         
</td></tr>
         
<tr><td>
            
<textarea class="output" name="commands" 
            
style="width:100%; height:150;" tabindex="10">]
            
txt 
            
[</textarea>
         
</td></tr>
         
<tr><td>
            
<Form action="cgitest3.lg" method="post" name="Form1">
               
<textarea name="commands" rows="15" cols="70" 
               
style="width:100%; font-size:14" border="0"
               
tabindex="0">
                  ifElse name? "%commands 
                  [   %commands
                  ][   []
                  ]
               [
</textarea>
               
])
               
ifElse %animate=="animate and2 %stop !="stop
               
[   out=(Word out 
               
[<input name="run" type="hidden" value="run">
               
<input name="animate" type="hidden" value="animate">
               
<input name="stop" type="submit" value="stop" tabindex="1" accesskey="s">
               
<Input name="FrameNr" size="10" border="0" value="]
                     FrameNr+1
                  [
tabindex="2">
                  
])
               
][   out=(Word out
               
[<input name="run" type="submit" value="run" tabindex="1" accesskey="r">
               
<input name="animate" type="submit" value="animate" tabindex="2" accesskey="a">
               
<input name="reset" type="submit" value="reset" tabindex="3" accesskey="0">
               
<Input name="FrameNr" size="10" border="0" value="]
                     FrameNr+1
                  [
tabindex="4">])
               ]
               out=(Word out [

               
<Input name="Time" type="hidden" value="] TimeFine [">
            
</Form>
         
</td></tr>
      
</Table>
   
</Body>
</HTML>
])
;updateVars
pr %commands
   
if %reset=="reset [output "reset]
   
output []
end

to decode_string str
   
local [length outpos ch1 ch2 n]
   
length=count str
   
outpos=1
   
for [length 1]
   
[   ifElse str.== "&
      
[;   str.outpos=" 
      ;   outpos=outpos+1
      
][   ifElse str.== "%
         
[   i=i+1   ch1=upperCase str.i
            
i=i+1   ch2=upperCase str.i
            
n=toInt  Word ch1 ch2  16
            
if != 10
            
[   str.outpos=Char n
               
outpos=outpos+1
            
]
         
][   str.outpos=str.i
            
outpos=outpos+1
         
]
      
]
   
]
   
output Items outpos-str
end

to reset
   
erase 
      
remove "cgitest3 
      
remove "cgi3proc 
      
remove "cgi3 
      
remove "decode_string 
      
remove "reset Procedures
   
erase 
      
remove "cgi3proc::out Names
   
erase (List [] [] 
      
remove "cgi3proc 
      
remove "cgi3
      
remove "decode_string
      
first bF bF Tables)

   
setCaseIgnored false
;   closeall
   
foreach allopen [close ?]
   
erase buried
   
clearShadows
   
setUpdateGraph true
   
setPenColor 0
   
setScreenColor 7
   
setFloodColor 0
   
setPenSize [1 1]
   
disableCylinderLines
   
disableTexture
   
enableLineSmooth
   
setDepthFunc 1
   
setLabelFont [Times]
   
setLabelAlign 0 0
   
showTurtle
   
PenDown
   
setLightAmbient RGB 0.1 0.1 0.1
   
setLightDiffuse RGB 1 1 1
   
unperspective
   
clearScreen
   
refresh
   
wrap
;   doubleBuffer
   
insertMode
   
notFullScreen
   
deleteTextures
   
(GC true)
end