![[Toc]](../../toc.gif)
![[Index]](/idx.gif)
base64 encoder
/* ------------------------------------------------------------------ */
/* 2_B64.CMD */
/* */
/* function: base64 encoder */
/* */
/* */
/* usage: 2_b64.cmd bin_file [target_extension] */
/* */
/* */
/* parameters: bin_file - name of the file to convert */
/* target_extension - extension for the target file */
/* (optional, def.: b64) */
/* */
/* */
/* 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 decoder */
/* see also Base64 Converting routine */
/* see also Template for an installation program */
/* see also Base64 encode and decode routines */
/* see also UUDecoding files */
/* ------------------------------------------------------------------ */
parse arg in targetExtension
if targetExtension = '' then
targetExtension = '.b64'
else
if left( targetExtension, 1 ) <> '.' then
targetExtension = '.' || 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 */
fileLength = chars( in )
call charin in,,fileLength
in_d = result
in_l = length( in_d )
parse value filespec( 'n',in ) with out '.'
call lastpos '\',in
out = left( in,result ) || out || targetExtension
'@del 'out' 2>nul 1>>&2'
in_l = length( in_d )-1
in_d = x2b( c2x( in_d ) )
i0 = xrange( "A", "Z" ) || xrange( "a", "z" ) || "0123456789+/"
v0 = xrange( "00"x, "3f"x )
a4 = ''
do ji = 0 to in_l
select
when ji//3 = 0 then
do
a4 = a4 || '00' || substr( in_d,ji*8+1,6 ) || '00' || substr( in_d,ji*8+7,2 )
if ji = in_l then
a4 = a4'0000'
end /* when ji//3 = 0 then do */
when ji//3 = 1 then
do
a4 = a4 || substr( in_d,ji*8+1,4 ) || '00' || substr( in_d,ji*8+5,4 )
if ji = in_l then
a4 = a4'00'
end /* when ji//3 = 1 then do */
otherwise
a4 = a4 || substr( in_d,ji*8+1,2 ) || '00' || substr( in_d,ji*8+3,6 )
end /* select */
if ji//57 = 56 | ji = in_l then
do
call lineout out,translate( x2c( b2x( a4 ) ),i0,v0 )
a4 = ''
end /* if ji//57 = 56 | ji = in_l then do */
end /* do ji = 0 to in_l */
call lineout out
exit /* 2_b64.cmd */
Created using Inf-PHP v.2 (c) 2003 Yuri Prokushev
Created using Inf-HTML v.0.9b (c) 1995 Peter Childs