aUCBLogo Demos and Tests / cgitest2
#!C:/aucblogo/aucblogo_client.exe
to cgitest2
local [out err]
out=(word [Content-type: text/html; charset=iso-8859-1
])
catch "error
[ changeDir "C:/aucblogo
cgi2userproc
[C:/Programme/Apache2.2/htdocs/]
BitAnd getProcessID 63
&out
]
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 cgi2userproc dname fname &out
local [request_method query_string content_length
query_length maxArgs argCount name value
start_name start_value end_value end_name
namename i]
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_method) or2 empty? query_string
[ goto "nix
]
query_length=0
if request_method==" [stop]
if request_method=="GET
[ if query_string==" [stop]
ifelse content_length=="
[ query_length=count query_string
][ query_length=Int content_length
]
]
if request_method=="POST
[ if content_length==0 [stop]
query_length=Int content_length
setReader "stdin
query_string=readRawLine
setReader []
]
maxArgs=10
name=Array maxArgs
value=Array maxArgs
for [i 1 maxArgs]
[ 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-1 query_string
name.argCount=decode_string name.argCount
start_value=end_name+1
end_value=start_value
while [end_value<query_length and2 query_string.end_value !="&]
[ end_value=end_value+1
]
value.argCount=Items start_value end_value query_string
value.argCount=decode_string value.argCount
argCount=argCount+1
]
argCount=argCount-1
local [%heading]
for [i 1 argCount]
[ if not empty? name.i
[ namename=word "% name.i
make namename value.i
]
]
Tag "nix
if not name? "%heading [local [%heading] %heading=0]
fname=%heading
; if not file? (word dname fname ".png)
; [
hideTurtle
clearScreen
load "tree.lg
setHeading %heading
(tree 6 100)
showTurtle
setSaveSize [400 300]
saveScreen (word dname fname ".png)
; ]
out=(word out "
<HTML>
<Head>
<meta http-equiv="refresh" content="0;
URL=cgitest2.lg?heading=
mod %heading+10 360 "">
</Head>
<Body>
<H1>Aha,</H1>
<H2>soso,</H2>
<H3>blabla.</H3>
[This is process number\ ] GetProcessId ". Time= TimeFine "
</br>)
if name? "argCount
[ for [i 1 argCount]
[ out=(word out name.i "= value.i "\ )
]
]
out=(word out "</br>
<Image src=" fname ".png">
</Body>
</HTML>
)
end
to decode_string str
local [length outpos ch1 ch2 n]
length=count str
outpos=1
for [i 1 length 1]
[ ifelse str.i == "&
[; str.outpos="
; outpos=outpos+1
][ ifelse str.i == "%
[ i=i+1 ch1=uppercase str.i
i=i+1 ch2=uppercase str.i
n=toInt word ch1 ch2 16
if n != 10
[ str.outpos=Char n
outpos=outpos+1
]
][ str.outpos=str.i
outpos=outpos+1
]
]
]
output items 1 outpos-1 str
end