#!/home/tony/d4/cp/d4x

DO_CGI

Z<-DO_CGI;F;N;J;S;Q
|initialisations
EV.KB<-"CGI_ERROR"
UPALPHA<- #av i 256 & UPALPHA[97+i26]<-ALPHA<-#av 65+i26
PRINT"Context-type: text/plain"
PRINT""
PRINT"D4X GCI-BIN"
I<-0 & N<-1tr:Z<-Z[#sort Z<-#sstomat #use "$ENVP"]
WHILE I<N
S<-#deb Z[I++ :]
PRINT S,"=",$ENVP[S]
WEND
Q<-$ENVP["QUERY_STRING"]
IF 0=rQ; #quit
PRINT "QUERY"
PRINT Q<-#sstomat "&",Q
J<-c/y "file=" #find Q & Q<-Q[J/i1tr:Q]
PRINT Q
F<-URL_DECODE #deb 5dQ
PRINT "file= ", F
IF #fstat F; PRINT #zload F
#quit

Z<-PRINT X
$VA[0]<-X, #av 10
Z<-""

Z<-CGI_ERROR
PRINT"cgi error ****"
#quit


Z<-CHARS URL_ENCODE STR;J;U;X
|Url encode by changing characters to %xx
CHARS<-" #!%()[]<>" #ifndef "CHARS"
J<-(U<-STR e CHARS)/irSTR
Z<-(1+2*U)/STR
X<-,"%","0123456789ABCDEF"[16 16 n #av STR[J]]
J<-J+2*irJ
Z[,J #outer+ i3 ]<-X

Z<-URL_DECODE STR;J;K;U
|Use % as escape character for hex strings
J<-("%"=STR)/irSTR
X<-UPALPHA [#av STR[K<-J #outer+ 1 2]]
X<-#av 16 16 b "0123456789ABCDEF"iX
STR[J]<-X
U<-(rSTR)r1  & U[,K]<-0 & Z<-U/STR




