home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Extra 1997 #5 / AmigaPlus_Extra-CD_5-97.iso / online-tools / mail / ems / rexx / maintfiles.ems < prev    next >
Text File  |  1993-08-29  |  5KB  |  251 lines

  1. /******************/
  2. /* MaintFiles.ems */
  3. /***************************************/
  4. /* $VER: MaintFiles.ems 1.0 (29.08.93) */
  5. /***************************************/
  6.  
  7. options results
  8. signal on error
  9. signal on syntax
  10.  
  11. parse arg area_pattern ask .
  12.  
  13. if( ~show( 'l', "rexxsupport.library" ) ) then
  14. do
  15.    if( ~addlib( "rexxsupport.library", 0, -30, 0 ) )then
  16.    do
  17.       say "Could not open rexxsupport.library"
  18.       exit 10
  19.    end
  20. end
  21.  
  22. if( ~show( 'l', "ems_rexx.library" ) ) then
  23. do
  24.    if( ~addlib( "ems_rexx.library", 0, -30, 0 ) )then
  25.    do
  26.       say "Could not open ems_rexx.library"
  27.       exit 10
  28.    end
  29. end
  30.  
  31.  
  32. files.0 = 0
  33.  
  34. /*
  35. ** Build the list of pending files.
  36. */
  37. call EMS_Domains( 'doms' )
  38.  
  39. do i=1 to doms.0
  40.  
  41.    call EMS_Flow_Get( doms.i, 'file', 'addr', 'kind' )
  42.  
  43.    do j=1 to file.0
  44.  
  45.       if GetFileName( file.j ) ~= '' then call EMS_Add_To_Stem( 'files', file.j, 'UNIQUE' )
  46.  
  47.    end
  48.  
  49. end
  50.  
  51. drop doms. file. addr. kind.
  52.  
  53.  
  54. /*
  55. ** Scan areas.
  56. */
  57. call EMS_Areas( 'areas' )
  58. pos = 0
  59. ask = upper( ask )
  60.  
  61. select
  62.    when ask = 'YES'     then nop
  63.    when ask = 'NO'      then nop
  64.    when ask = 'PRETEND' then nop
  65.    when ask = 'LIST'    then nop
  66.    otherwise                 ask = 'YES'
  67. end
  68.  
  69. do forever
  70.  
  71.    pos = EMS_Search_In_Stem( 'areas', area_pattern, pos ); if pos = 0 then leave
  72.  
  73.    area = areas.pos
  74.    path = GetAreaPath( area )
  75.  
  76.    if path = '' then iterate
  77.  
  78.    /*
  79.    ** Don't delete the files with an entry in the database.
  80.    */
  81.    exclude.0 = 0
  82.  
  83.    if EMS_Area_Msg_DBname( area ) ~= '' then
  84.    do
  85.  
  86.       call EMS_Area_Item_List_Flagged( area, 'MSG', 'msg', 'FATT' )
  87.       do i=1 to msg.0
  88.  
  89.          file = EMS_Area_Item_Header_AttachedFile( area, 'MSG', msg.i )      
  90.          if file ~= '' then call EMS_Add_To_Stem( 'exclude', file, 'UNIQUE' )
  91.  
  92.       end
  93.  
  94.    end
  95.  
  96.    if EMS_Area_File_DBname( area ) ~= '' then
  97.    do
  98.  
  99.       call EMS_Area_Item_List_Flagged( area, 'FILE', 'msg', 'FATT' )
  100.       do i=1 to msg.0
  101.  
  102.          file = EMS_Area_Item_Header_AttachedFile( area, 'FILE', msg.i )      
  103.          if file ~= '' then call EMS_Add_To_Stem( 'exclude', file, 'UNIQUE' )
  104.  
  105.       end
  106.  
  107.    end
  108.  
  109.    /*
  110.    ** Scan all the files in the area.
  111.    */
  112.    del_list.0 = 0
  113.    dir_files  = showdir( path, 'F' )
  114.    do while length( dir_files ) ~= 0
  115.  
  116.       parse var dir_files file dir_files
  117.  
  118.       if file = "EMS_duplicates_database" then iterate
  119.  
  120.       if EMS_Search_In_Stem( 'exclude', file ) ~= 0 then iterate
  121.  
  122.       full_file = EMS_Area_FullFileName( area, file )
  123.       if full_file = '' | EMS_Search_In_Stem( 'files', full_file ) ~= 0 then iterate
  124.  
  125.       call EMS_Add_To_Stem( 'del_list', file, 'UNIQUE' )
  126.  
  127.    end
  128.  
  129.  
  130.    call EMS_Sort_Stem( 'del_list' )
  131.  
  132.    ask2 = ask
  133.    do i=1 to del_list.0
  134.  
  135.       if ask2 = 'YES' then
  136.       do
  137.  
  138.          res = EMS_Do_Request( "Delete '"del_list.i"' from area '"area"'?", 'Yes|No|List|All|None' )
  139.  
  140.          if res = 'None' then leave
  141.          if res = 'No'   then iterate
  142.  
  143.          if res = 'All'  then ask2 = 'NO'
  144.  
  145.          if res = 'List' then ask2 = 'LIST'
  146.  
  147.       end
  148.  
  149.       if ask2 = 'LIST' then
  150.       do
  151.  
  152.          num = 0
  153.          do j=i to del_list.0
  154.  
  155.             num        = num + 1
  156.             file.num   = del_list.j
  157.             status.num = 'TRUE'
  158.  
  159.          end
  160.          file.0   = num
  161.          status.0 = num
  162.  
  163.          res = EMS_Do_Choice_Multi( 'Choose files to delete from' area, 'file', 'status' )
  164.  
  165.          if res = 'OK' then
  166.          do
  167.  
  168.             do j=1 to file.0
  169.  
  170.                if status.j = 'TRUE' then call DeleteOneFile( area, file.j, 'YES' )
  171.  
  172.             end
  173.  
  174.          end
  175.  
  176.          leave
  177.  
  178.       end
  179.       else
  180.       do
  181.  
  182.          call DeleteOneFile( area, del_list.i, ask2 )
  183.  
  184.       end
  185.  
  186.    end
  187.  
  188. end
  189.  
  190. call EMS_FreeScriptData()
  191. exit 0
  192.  
  193. /*************************************************************/
  194. error:
  195. syntax:
  196.  
  197. error_text = EMS_LastError()
  198.  
  199. if error_text = '' then error_text = rc ErrorText( rc )
  200.  
  201. say '| ***BREAK: error at' sigl error_text
  202.  
  203. call EMS_FreeScriptData()
  204. exit rc
  205.  
  206.  
  207. GetFileName: procedure
  208.  
  209.    parse arg fullfile
  210.  
  211.    temp = strip( translate( fullfile, '  ', ':/' ), 'B' )
  212.    len  = words( temp )
  213.  
  214.    if len <= 1 then return ''
  215.  
  216.    return word( temp, len )
  217.  
  218. GetAreaPath: procedure
  219.  
  220.    parse arg name
  221.  
  222.    path = ''
  223.  
  224.    if EMS_Area_File_DBname( name ) ~= '' then
  225.    do
  226.                         path = EMS_Area_File_AltPath( name )
  227.       if path = '' then path = EMS_Area_File_Path(    name )
  228.    end
  229.  
  230.    if path = '' & EMS_Area_Msg_DBname( name ) ~= '' then
  231.    do
  232.                         path = EMS_Area_Msg_AltPath( name )
  233.       if path = '' then path = EMS_Area_Msg_Path(    name )
  234.    end
  235.  
  236.    return path
  237.  
  238. DeleteOneFile: procedure
  239.  
  240.    parse arg area , file , doit
  241.  
  242.    full_file = EMS_Area_FullFileName( area, file )
  243.  
  244.    if full_file = '' then return
  245.  
  246.    say 'Deleting - area' area ' file' file
  247.  
  248.    if doit = 'YES' then call DELETE( full_file )
  249.  
  250.    return
  251.