Subject: Re: BASIC uudecode

From: Craig Bruce <[email-masked]>
Date: Fri, 4 Mar 94 00:35:40 -0500

Yo!

In comp.binaries.cbm you wrote:

>This is a BASIC uudecode program. It would be good for uudecoding
>files until something faster could be obtained. It ignores everything
>until it finds the "begin" statement at the start of a uuencoded file.
>The file must be a sequential PETASCII file and converts it to a
>program file. Since it is in BASIC it is easy to change.
>
>10 input"enter input file name";fi$
>20 input"enter input device #";di
>[...]

I tried it out and found five things to improve about it:

(1) It asks you for the output filename when that is readily available from
    the uuencoded data.

(2) It only decodes the first file found in the uuencoded data; for decoding
    ACE, which is what the BASIC decoder is presumably for (to decode a faster
    uudecoder), you'll want to decode multiple files from uuencoded data.

(3) The program uses the variable "do", which is a keyword in BASIC 7.0
    which causes syntax errors when the program is run in 128 mode.

(4) The program cannot handle the back-quote (`) character that is often used
    in place of the troublesome space character in uuencoding (although
    we want the decoder to handle space also).

(5) The program produces output that is the wrong size if a line (the
    last line) contains a number of data bytes that is not a multiple of 3.

So, not being one to complain without having a solution (well, here anyway),
here is a new and improved version of the BASIC uudecoder that corrects all
five of the above problems.  Feel free to post it to comp.binaries.cbm.

10 input"enter input file name";fi$
20 input"enter input device #";di
30 input"enter output device #";dp
40 open2,di,2,fi$+",s,r"
50 print"searching for uu-data start"
60 gosub360
70 ifleft$(w$,5)="begin"then90
80 printw$:goto60
90 print"beginning data conversion"
100 print w$
110 fo$=mid$(w$,11)
120 open3,dp,3,"@0:"+fo$+",p,w":lc=1
130 gosub360:print"line ";lc;"  "
140 ifleft$(w$,3)="end"then330
150 x=2:dl=(asc(left$(w$,1))-32)and63
160 ifasc(left$(w$,1))=192thendl=0
170 ob$=""
180 ifdl=0then130
190 ll=int((dl+2)/3)*4
200 forz=0to3
210 ifx+z-2>=llthenb(z)=0:goto250
220 c=asc(mid$(w$,x+z,1))
230 ifc=192thenb(z)=0:goto250
240 b(z)=(c-32)and63
250 next:x=x+4
260 c1=b(0)*4+int(b(1)/16)
270 c2=((b(1)*16)and240)+int(b(2)/4)
280 c3=((b(2)*64)and192)+b(3)
290 ob$=ob$+chr$(c1)+chr$(c2)+chr$(c3)
300 ifx-2<llthen200
310 print#3,left$(ob$,dl);:lc=lc+1
320 goto130
330 close3
340 print"conversion complete":goto50
350 close3:close2:end
360 w$=""
370 get#2,x$:ifx$=""thenx$=chr$(0)
380 ifst<>0andw$<>""thenreturn
390 ifst<>0thenprint"eof":goto350
400 ifasc(x$)=13orasc(x$)=10thenreturn
410 w$=w$+x$
420 iflen(w$)=254thenreturn
430 goto370

Keep on Hackin'!

-Craig Bruce
[email-masked]
"From each according to his ability, to each according to his ability."