66 lines
973 B
Plaintext
66 lines
973 B
Plaintext
PROC Append(CHAR ARRAY s CHAR c)
|
|
s(0)==+1
|
|
s(s(0))=c
|
|
RETURN
|
|
|
|
CHAR FUNC GetCharFromHex(CHAR c1,c2)
|
|
CHAR ARRAY hex=['0 '1 '2 '3 '4 '5 '6 '7 '8 '9 'A 'B 'C 'D 'E 'F]
|
|
BYTE i,res
|
|
|
|
res=0
|
|
FOR i=0 TO 15
|
|
DO
|
|
IF c1=hex(i) THEN res==+i LSH 4 FI
|
|
IF c2=hex(i) THEN res==+i FI
|
|
OD
|
|
RETURN (res)
|
|
|
|
PROC Decode(CHAR ARRAY in,out)
|
|
BYTE i
|
|
CHAR c
|
|
|
|
out(0)=0
|
|
i=1
|
|
WHILE i<=in(0)
|
|
DO
|
|
c=in(i)
|
|
i==+1
|
|
IF c='+ THEN
|
|
Append(out,' )
|
|
ELSEIF c='% THEN
|
|
c=GetCharFromHex(in(i),in(i+1))
|
|
i==+2
|
|
Append(out,c)
|
|
ELSE
|
|
Append(out,c)
|
|
FI
|
|
OD
|
|
RETURN
|
|
|
|
PROC PrintInv(CHAR ARRAY a)
|
|
BYTE i
|
|
|
|
IF a(0)>0 THEN
|
|
FOR i=1 TO a(0)
|
|
DO
|
|
Put(a(i)%$80)
|
|
OD
|
|
FI
|
|
RETURN
|
|
|
|
PROC Test(CHAR ARRAY in)
|
|
CHAR ARRAY out(256)
|
|
|
|
PrintInv("input ")
|
|
PrintF(" %S%E",in)
|
|
|
|
Decode(in,out)
|
|
PrintInv("decoded")
|
|
PrintF(" %S%E%E",out)
|
|
RETURN
|
|
|
|
PROC Main()
|
|
Test("http%3A%2F%2Ffoo%20bar%2F")
|
|
Test("http%3A%2F%2Ffoo+bar%2F*_-.html")
|
|
RETURN
|