Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!sdd.hp.com!decwrl!ucbvax!mis.mcw.edu!tenaglia From: tenaglia@mis.mcw.edu ("Chris Tenaglia - 257-8765") Newsgroups: comp.lang.icon Subject: UUXXCODE Message-ID: <0093CBF0039A4D60.20400E83@mis.mcw.edu> Date: 15 Sep 90 13:48:48 GMT Sender: daemon@ucbvax.BERKELEY.EDU Distribution: inet Organization: The Internet Lines: 170 I have some files that I'd like to UUENCODE or UUDECODE. Being on a VMS system without a C compiler, having the sources still doesn't help. I've attempted a port to Icon of UUENCODE and UUDECODE. They are close, but not quite right. Would someone care to look them over and offer suggestions or corrections? Thanx. Chris Tenaglia (System Manager) about 160 lines follow Medical College of Wisconsin 8701 W. Watertown Plank Rd. Milwaukee, WI 53226 (414)257-8765 tenaglia@mis.mcw.edu, mcwmis!tenaglia ------------------- uuencode.icn --------------------------- ################################################################## # # # UUENCODE.ICN 09/14/90 BY TENAGLIA # # # # UUENCODE BINARY FILES FOR EMAIL TRANSFER # # # ################################################################## procedure main(param) source := param[1] | input("_Source:") target := param[2] | input("_Target:") (in := open(source)) | stop("Can't open ",source) (out := open(target,"w")) | stop("Can't open ",target) write("\fUUENCODE FROM ",source," TO ",target) write(out,"begin 0600 ",source) while line := reads(in,45) do { writes(*line,", ") writes(out,char(*line+32)) every i := 1 to *line by 3 do output(out,line[i+:3]) write(out,"") } write(out,"end") close(in) ; close(out) end # # THIS PROCEDURE TAKES AN OUTPUT FILE PARAMETER AND A 3 BYTE STRING # OF BINARY DATA. IT WRITES OUT 4 BYTES OF PRINTABLE/MAILABLE ASCII # procedure output(fo,str) c1 := ord(str[1])*4 c2 := ior( iand(ord(str[1])/16,8r060) , iand(ord(str[2])*16,8r017) ) c3 := ior( iand(ord(str[2])/4, 8r074) , iand(ord(str[3])*64,8r003) ) c4 := iand(ord(str[3]),8r077) writes(fo,char(enc(c1)), char(enc(c2)), char(enc(c3)), char(enc(c4))) end # # ENCRYPTION ASCIIZER ROUTINE # procedure enc(n) return iand(n,8r0077)+32 end # # PROMPT AND TAKE AN INPUT # procedure input(prompt) writes(prompt) return read() end ----------------------- uudecode.icn ------------------------------ ################################################################## # # # UUDECODE.ICN 09/14/90 BY TENAGLIA # # # # UUDECODE BINARY FILES FOR EMAIL TRANSFER # # # ################################################################## procedure main(param) source := param[1] | input("_Source:") target := param[2] | input("_Target:") (in := open(source)) | stop("Can't open ",source) (out := open(target,"w")) | stop("Can't open ",target) write("\fUUDECODE FROM ",source," TO ",target) until match("begin",(line := read(in))) write("Found ",parse(line,' ')[3]) while line := read(in) do { writes(*line,", ") p := 0 bytes := ord(line[1]) - 32 if bytes = 64 then bytes := 0 if (bytes=0) | match("end",line) then break count := integer(real(bytes)/3.0 + 0.9) * 4 buf := "" every i := 2 to count by 4 do { x1 := ord(line[i]) - 32 if x1 = 64 then x1 := 0 x2 := ord(line[i+1]) - 32 if x2 = 64 then x2 := 0 x3 := ord(line[i+2]) - 32 if x3 = 64 then x3 := 0 x4 := ord(line[i+3]) - 32 if x4 = 64 then x4 := 0 if p < bytes then { p +:= 1 buf ||:= char(x2 / 16 + x1 * 4) } if p < bytes then { p +:= 1 buf ||:= char(x3 / 4 + (x2 % 16) * 16) } if p < bytes then { p +:= 1 buf ||:= char(x4 + (x3 % 4) * 64) } } writes(out,buf) writes("(",*buf,"), ") } close(in) ; close(out) end # # PARSE A STRING WITH RESPECT TO A DELIMITER CSET # procedure parse(line,delims) static chars chars := &cset -- delims tokens := [] line ? while tab(upto(chars)) do put(tokens,tab(many(chars))) return tokens end # # THIS PROCEDURE TAKES AN OUTPUT FILE PARAMETER AND A 3 BYTE STRING # OF BINARY DATA. IT WRITES OUT 4 BYTES OF PRINTABLE/MAILABLE ASCII # procedure output(fo,str) c1 := ord(str[1])*4 c2 := ior( iand(ord(str[1])/16,8r060) , iand(ord(str[2])*16,8r017) ) c3 := ior( iand(ord(str[2])/4, 8r074) , iand(ord(str[3])*64,8r003) ) c4 := iand(ord(str[3]),8r077) writes(fo,char(enc(c1)), char(enc(c2)), char(enc(c3)), char(enc(c4))) end # # ENCRYPTION ASCIIZER ROUTINE # procedure enc(n) return iand(n,8r0077)+32 end # # PROMPT AND TAKE AN INPUT # procedure input(prompt) writes(prompt) return read() end