; UUDECODE
;
; Program for Proteus
;
; (C) 1998-2004 Simone Zanella Productions
;
; This program decodes a UUENCODED text file.
; If destination exists, it is overwritten; multiple sections are not allowed.
; Implicit parameters: input and output NULL
;!proteus -z
IF ISEMPTY(ARGV(5))
CONSOLELN "Syntax: " ARGV(1) " " ARGV(2) " filename [destination]"
CONSOLELN ""
CONSOLELN "Purpose: decodes a UUENCODED text file."
CONSOLELN "Input is not verified."
CONSOLELN "If destination exists, it is overwritten."
CONSOLELN "If \"destination\" is specified, it is used"
CONSOLELN "for output. Multiple sections are not allowed."
ABORT 0
FI
H = FOPEN(ARGV(5), 1)
IF EQ(H, -1)
CONSOLELN "File \"" ARGV(5) "\" not found."
ABORT 1
FI
S = FREADLN(H)
WHILE AND(NOT(FEOF(H)), NOT(IMATCH(S, "begin*")))
S = FREADLN(H)
LOOP
IF FEOF(H)
CONSOLELN "Error: no UUENCODED section found in \"" ARGV(5) "\"."
ABORT 1
FI
IF ISNOTEMPTY(ARGV(6))
DstName = ARGV(6)
ELSE
DstName = RESTFROM(S, POSTOKEN(S, 3, " "))
ALLTRIM(@DstName, " ")
STRIPQUOTES(@DstName)
FI
!ifdef UNIX
Attribs = TOKEN(S, 2, " ")
!endif
HD = FOPEN(DstName, 26)
IF EQ(HD, -1)
CONSOLELN "Unable to create \"" DstName "\"."
ABORT 1
FI
WHILE NOT(FEOF(H))
S = FREADLN(H)
IF NOT(IMATCH(S, "end*"))
UUDECODE(@S)
FWRITE(HD, S)
ELSE
BREAK
FI
LOOP
FCLOSE(H)
FCLOSE(HD)
!ifdef UNIX
CHMOD(DstName, Attribs)
!endif
IF NOT(IMATCH(S, "end*"))
CONSOLELN "End of UUENCODED section not found."
CONSOLELN "The file \"" ARGV(5) "\" is corrupted."
FI
CONSOLELN "File \"" DstName "\" created."
ABORT 0