posted December 13, 2002 02:37 PM
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
' Purpose: UUdecode a given UUencoded text and return the result.
'
' Original code was not 100% correct, so have replaced it with code
' from Peter Redei. Thank you Peter! Your routine is much more correct. 
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
FUNCTION uuDecode(strIn AS STRING) AS STRING
ON ERROR RESUME NEXT
DIM strLine AS STRING
DIM strDecoded AS STRING
DIM i AS LONG
DIM j AS LONG
DIM sOut AS STRING
IF LEFT$(strIn, 6) = "begin " THEN 'check if it is a encoded file
strIn = MID$(strIn, INSTR(1, strIn, $LF) + 1)
END IF
IF RIGHT$(strIn, 4) = "end" + $LF THEN 'check if "end" is available
strIn = LEFT$(strIn, LEN(strIn) - 7)
END IF
FOR j = 1 TO PARSECOUNT(strIn, $LF)
strLine = PARSE$(strIn, $LF, j)
strLine = MID$(strLine, 2)
REPLACE "`" WITH " " IN strLine
IF RIGHT$(strLine, 1) = CHR$(13) THEN strLine = LEFT$(strLine, LEN(strLine) - 1)
FOR i = 1 TO LEN(strLine) STEP 4
'now some decoding
strDecoded = strDecoded + CHR$((ASC(MID$(strLine, i, 1)) - 32) * 4 + _
(ASC(MID$(strLine, i + 1, 1)) - 32) \ 16)
strDecoded = strDecoded + CHR$((ASC(MID$(strLine, i + 1, 1)) MOD 16) * 16 + _
(ASC(MID$(strLine, i + 2, 1)) - 32) \ 4)
strDecoded = strDecoded + CHR$((ASC(MID$(strLine, i + 2, 1)) MOD 4) * 64 + _
ASC(MID$(strLine, i + 3, 1)) - 32)
NEXT i
sOut = sOut & strDecoded
strDecoded = ""
NEXT
FUNCTION = sOut
END FUNCTION
------------------
[This message has been edited by Borje Hagsten (edited January 28, 2003).]