aUCBLogo Demos and Tests / cgicounter
#!D:/Users/AndreasM/aucblogo/aucblogo_client.exe
setCaseIgnored false
be cgicounter
bury [cgicounter cgiproc cgi cgi5call]
tmp=runSecure security_connect [cgiproc]
output tmp
be cgiproc
local [out err result]
buryname "out
catch "error
[
out=(Word "Content-Type: image/png
)
changeDir "D:/Users/AndreasM/aucblogo
result=cgi
"D:/Apache2.2/htdocs/
&out
; closeall
(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 "))
]
output out
end
be cgi dname &out
;comment [
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 ch1 ch2
fname
graphhtml graphhtmlpath
consolehtml consolehtmlpath
outputhtml
framename framepath
txt o
]
;]
%username="guest
%errout="
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
;(type "A query_string "E)(print)
if (empty? request_method) or2 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
; ]
]
;pr query_length
;pr count query_string
; if request_method=="POST
; [ if content_length==0 [output []]
; query_length=Int content_length
; setReader "stdin
; query_string=readRawLine
; setReader []
; ]
maxArgs=20
name=Array maxArgs
value=Array maxArgs
for [i 1 maxArgs 1]
[ name.i=[]
value.i=[]
]
end_value=0
argCount=1
;pause
while [end_value < query_length]
[ start_name=end_value+1
end_name=start_name
while [and [end_name<=query_length][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]
[ 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 [i 1 argCount 1]
[ if not empty? name.i
[ namename=Word "% name.i
make namename value.i
bury namelist namename
]
]
]
tag "nix
if not Name? "graphs
[ graphs=[]
frames=[]
users=
[ guest andreas sapev
]
bury [[][users]]
]
;pr %username
if not Member? %username users
[ %username="guest
]
if empty? graphs
[ frames=Frame [] "cgicounter wxdefault_frame_style [0 0][80 60]
graphs=Graph frames
FrameSetClientSize frames 80 60
FrameIconize frames true
]
GraphSetCurrent graphs
hideTurtle
clearScreen
setLabelSize [400 400]
setHeading 90
local [cname]
cname=(Word dname %username "_counter.dat)
ifelse File? cname
[ openRead cname
setReader cname
counter=first readList
setReader []
close cname
][ counter=0
]
counter=counter+1
openWrite cname
setWriter cname
print counter
setWriter []
close cname
cname=(Word dname %username "_counter.log)
openAppend cname
setWriter cname
t=Time
(type counter "\
t.1 ": t.2 ": t.3 ". t.4 "\
t.6 ". t.7 ". t.8 "
)
setWriter []
close cname
Label counter
setLabelSize [150 150]
comment [
PenUp
setXY 0 200
Label "counted by
setXY 0 -200
Label "aUCBLogo
]
local [screenname]
screenname=(Word dname %username ".png)
setSaveSize [80 60]
saveScreen screenname
openReadBin screenname
setReader screenname
setCharConversion screenname 0
c=readChars FileSize screenname
;::i=intarray ::c
out=(word out c)
;::i2=intarray out
;show out
setReader []
close screenname
GraphSetCurrent []
output []
end
be 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
be strip_html in
inmax=count in
inp=1
outp=1
while [inp <= inmax]
[ ifelse in.inp=="<
[ ifelse and [inp+5<=inmax][(items inp inp+5 in)=="<br />]
[ in.outp=Char 13
inp=inp+6
outp=outp+1
][
ifelse and [inp+3<=inmax][(items inp inp+3 in)=="</p>]
[ in.outp=Char 13
inp=inp+4
outp=outp+1
][
while [and [inp <=inmax][in.inp != ">]]
[ inp=inp+1
]
inp=inp+1
]]
][
ifelse in.inp=="&
[ ifelse and [inp+5<=inmax][(items inp inp+5 in)==" ]
[ inp=inp+6
in.outp="\
outp=outp+1
][ ifelse and [inp+5<=inmax][(items inp inp+5 in)==""]
[ inp=inp+6
in.outp=""
outp=outp+1
][ inp=inp+1
]]
][
ifelse (or (in.inp==char 13)
(and in.inp=="\ [inp+6<=inmax][(items inp+1 inp+6 in)=="<br />])
(and in.inp=="\ inp+1>inmax))
[ inp=inp+1
][
in.outp=in.inp
inp=inp+1
outp=outp+1
]]]
]
output items 1 outp-1 in
end
be test_strip
foreach strip_html "a<b>c<br />d e
[ (pr ? ascii ?)
]
s=strip_html
"to p1<br /> pr 5<br />end<br />p1
pr s
foreach s
[ (pr ? ascii ?)
]
end
end ;cgicounter