match = EMS_Search_In_Stem( 'lines', 'begin #?', match )
if match = 0 then leave
line = lines.match
type = left( line, 9 )
select
when type = 'begin 777' then mode = 1
when type = 'begin 644' then mode = 2
otherwise iterate
end
name = right( line, length( line ) - 10 )
parse var name name1 ':' name2
if name2 ~= '' then name = name2
parse var name name1 '/' name2 .
if name2 ~= '' then name = name2
num = names.0 + 1
names.0 = num
names.num = name
if exists(temp_dir || name ) then
do
select = EMS_Do_Request( 'Found a UUENCODE HEADER'cr || cr'Original FileName :' name || cr || cr'A file with the same name exists'cr'in the' temp_dir 'directory.'cr"Should I rename it to '"name".EMS' ?", 'Yes|No' )
if select = 'Yes' then
do
name = name'.EMS'
names.num = name
end
else
do
select = EMS_Do_Request( 'Should I deleted the existing file ?', 'Yes|No' )
if select = 'No' then
do
call EMS_Do_Request( 'Extracting UUENCODE files has been stopped.' )
call QuitScript
end
address command delete_name temp_dir || name
end
end
if open( 'out', temp_file, 'W' ) ~= 1 then
do
call EMS_Do_Request( "Can't open '" || temp_file || "' file for output." )
call QuitScript
end
call writeln( 'out', type temp_dir || name )
last_empty = 0
do forever
match = match + 1
line = lines.match
if left( line, 3 ) = 'end' then
do
if last_empty = 0 then call writeln( 'out', ' ' )
call writeln( 'out', 'end' )
leave
end
line = translate( line, " ", "`" )
if length( line ) = 0 | left( line, 1 ) = ' ' then
do
if last_empty = 1 then iterate
last_empty = 1
end
call writeln( 'out', line )
end
call close( 'out' )
address command cmd temp_file
address command delete_name temp_file '>nil:'
end
say
QuitScript:
if names.0 > 0 then
do
string = 'Check' temp_dir 'directory for the file(s):'cr
do i = 1 to names.0
string = string || cr || names.i
end
call EMS_Do_Request( string )
end
call EMS_FreeScriptData()
exit 0
Usage:
say 'Usage: ExtractFile.ems <area name> <msg num>'
call EMS_FreeScriptData()
exit 0
error:
syntax:
error_text = EMS_LastError()
if error_text = '' then error_text = rc ErrorText( rc )