/*
   $VER: Base64Decode.spot 1.1 (7.3.96)
   Written by Edmund Vermeulen (edmundv@grafix.xs4all.nl).

   ARexx script for Spot to use Base64Decode 1.1 to decode a base64 encoded
   file from the current message.
*/

outpath='RAM:'  /* default output path for decoding */


options results
options failat 21
cr='0d'x

ismessages
if rc=5 then do
   requestnotify 'PROMPT "Base64Decode.spot can only be used'cr'from the message window!"'
   exit
   end

requestpath 'TITLE "Select decode destination" PATH "'outpath'"'
if rc>0 then
   exit
outpath=result
saveascii 'TO "T:base64.temp" OVERWRITE NOHEADER NOTEARLINE NOORIGIN NOKLUDGES NOREFLOW'

address command 'Base64Decode >T:base64.output T:base64.temp "'outpath'" USEMINLEN'
if rc=10 then do
   requestfile 'TITLE "Select output filename" PATH "'outpath'"'
   if rc>0 then
      signal quitit
   outfilename=result
   address command 'Base64Decode >T:base64.output T:base64.temp "'outfilename'" USEMINLEN'
   end
if rc>0 then
   beep

call open('output','T:base64.output','r')
line=readln('output')
call close('output')
parse var line written ' "' filename '"'
requestnotify 'PROMPT "'written||cr||filename'"'


quitit:

   if ~show('l','rexxsupport.library') then
      call addlib('rexxsupport.library',0,-30)  /* needed for delete() */
   call delete('T:base64.temp')
   call delete('T:base64.output')
