![[Toc]](../../toc.gif)
![[Index]](/idx.gif)
base64 decoder
/* ------------------------------------------------------------------ */
/* B64_2.CMD */
/* */
/* function: base64 decoder */
/* */
/* usage: b64_2.cmd b64_file [target_extension] */
/* */
/* */
/* parameters: b64_file - name of the file to convert */
/* target_extension - extension for the target file */
/* (optional, def.: bin) */
/* */
/* history: 21.06.2003 first release */
/* */
/* notes: This code is from Yury Pogrebnyak */
/* (see EMail Addresses) */
/* Parameter checking was added by Bernd Schemmer */
/* */
/* see also base64 encoder */
/* see also Template for an installation program */
/* see also Base64 Converting routine */
/* see also Base64 encode and decode routines */
/* see also UUDecoding files */
/* ------------------------------------------------------------------ */
parse arg in targetExtension
parse source . . thisProg
thisProg = fileSpec( 'N', thisProg )
if in = '' then
do
say thisProg || ' - Error: Parameter missing!'
say
say 'Usage: ' || thisProg || ' binary_file_to_convert '
say ''
exit 1
end /* if */
if stream( in, "C", "QUERY EXISTS" ) = '' then
do
say thisProg || ' - Error: File "' || in || '" not found!'
exit 1
end /* if */
if stream( in, "C", "QUERY SIZE" ) = 0 then
do
say thisProg || ' - Error: File "' || in || '" is empty!'
exit 1
end /* if */
if targetExtension = '' then
targetExtension = '.bin'
else
if right( targetExtension, 1 ) <> '.' then
targetExtension = '.' || targetExtension
fileLength = chars( in )
call charin in,,fileLength
i64 = translate( result,'0000'x,'0d0a'x )
call stream in,'c','close'
if length( i64 ) = 0 then
exit /* b64_2.cmd */
parse value filespec( 'n',in ) with out '.'
call lastpos '\',in
out = left( in,result ) || out'.bin'
'@del 'out' 2>nul 1>>&2'
d_code = xrange( '0'x,'3f'x )
s_code = xrange( 'A','Z' ) || xrange( 'a','z' ) || '0123456789+/'
ji = 1
call pos '0'x,i64
do while result \= 0
tmp_s = ''
if result > ji then
tmp_s = x2b( c2x( translate( substr( i64,ji,result-ji ),d_code,s_code ) ) )
ji = result+1
do while tmp_s \= ''
parse var tmp_s +2 bin.0 +6 +2 bin.1 +6 +2 bin.2 +6 +2 bin.3 +6 +2 bin.4 +6 +2 bin.5 +6 +2 bin.6 +6 +2 bin.7 +6 +2 bin.8 +6 +2 bin.9 +6 +2 bin.10 +6 +2 bin.11 +6 tmp_s
result = bin.0 || bin.1 || bin.2 || bin.3 || bin.4 || bin.5 || bin.6 || bin.7 || bin.8 || bin.9 || bin.10 || bin.11
if result \= '' then
call charout out, x2c( b2x( left( result,length( result )%8*8 ) ) )
end /* do while tmp_s \= '' */
call pos '0'x,i64,ji
end /* do while result \= 0 */
call charout out
exit /* b64_2.cmd */
Created using Inf-PHP v.2 (c) 2003 Yuri Prokushev
Created using Inf-HTML v.0.9b (c) 1995 Peter Childs