home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Extra 1997 #5 / AmigaPlus_Extra-CD_5-97.iso / online-tools / mail / ems / rexx / tickaction.ems < prev   
Text File  |  1993-08-30  |  10KB  |  414 lines

  1. /******************************************/
  2. /* Handles file-related actions           */
  3. /******************************************/
  4. /*                                        */
  5. /* Commands:                              */
  6. /*                                        */
  7. /* UNARC                                  */
  8. /* CD|<directory>                         */
  9. /* EXEC|<AmigaDos command>                */
  10. /* ECHO|<string>                          */
  11. /* LOG|<file name>|<log line>             */
  12. /*                                        */
  13. /* IF|<file pattern>|<command>            */
  14. /* IFNOT|<file pattern>|<command>         */
  15. /* IFISARC|<archiver name>|<command>      */
  16. /* IFISNOTARC|<archiver name>|<command>   */
  17. /* GOTO|<label>                           */
  18. /* LABEL|<label>                          */
  19. /* END                                    */
  20. /*                                        */
  21. /******************************************/
  22. /*                                        */
  23. /* Patterns:                              */
  24. /*                                        */
  25. /* %fullfile                              */
  26. /* %path                                  */
  27. /* %file                                  */
  28. /* %size                                  */
  29. /* %area                                  */
  30. /* %from                                  */
  31. /* %date                                  */
  32. /* %desc                                  */
  33. /*                                        */
  34. /******************************************/
  35. /* $VER: TickAction.ems 1.0 (29.08.93)    */
  36. /******************************************/
  37.  
  38.  
  39. options results
  40. signal on syntax
  41.  
  42. parse arg opts
  43.  
  44. if( ~show( 'l', "rexxsupport.library" ) ) then
  45. do
  46.    if( ~addlib( "rexxsupport.library", 0, -30, 0 ) )then
  47.    do
  48.       say "Could not open rexxsupport.library"
  49.       exit 10
  50.    end
  51. end
  52.  
  53. if( ~show( 'l', "ems_rexx.library" ) ) then
  54. do
  55.    if( ~addlib( "ems_rexx.library", 0, -30, 0 ) )then
  56.    do
  57.       say "Could not open ems_rexx.library"
  58.       exit 10
  59.    end
  60. end
  61.  
  62. /* Save Current Directory */
  63. saved_CD = PRAGMA( 'D' )
  64.  
  65. global_onlyimported = 'TRUE'
  66. global_ignore_RCV   = 'FALSE'
  67. global_noEXEC       = 'FALSE'
  68. global_help         = 'FALSE'
  69.  
  70. /* Parse options */
  71. do while length( opts ) ~= 0
  72.  
  73.    parse var opts opt opts; opt = upper( opt )
  74.  
  75.    select
  76.       when opt = "FORCE"  then global_onlyimported = 'FALSE'
  77.       when opt = "NORCV"  then global_ignore_RCV   = 'TRUE'
  78.       when opt = "NOEXEC" then global_noEXEC       = 'TRUE'
  79.       when opt = "HELP"   then global_help         = 'TRUE'
  80.       otherwise           nop
  81.    end
  82.  
  83. end
  84.  
  85. if global_help = 'TRUE' then
  86. do
  87.  
  88.    say "Usage: Rx TickAction.ems [options]"
  89.    say
  90.    say "       options = FORCE   : process all the files, not only the new ones."
  91.    say "                 NORCV   : reprocess all the files."
  92.    say "                 NOEXEC  : don't apply EXEC/LOG commands."
  93.    say "                 HELP    : this banner."
  94.    say
  95.  
  96.    signal ScriptExit
  97.  
  98. end
  99.  
  100.  
  101. /* Get the required list of areas. */
  102. if global_onlyimported = 'TRUE' then call EMS_Areas_Imported( 'areas' )
  103. else                                 call EMS_Areas(          'areas' )
  104.  
  105.  
  106. /* Get the matching patterns */
  107. call EMS_CustomCfg_Get( 'TickAction', '', '', 'area_patterns' )
  108.  
  109.  
  110.  
  111. /*
  112. ** Scan areas.
  113. */
  114. do i=1 to areas.0
  115.  
  116.    area_kind = upper( EMS_Area_Type( areas.i ) )
  117.  
  118.    if area_kind ~= 'TICK' then iterate
  119.  
  120.    if global_ignore_RCV = 'TRUE' then call EMS_Area_Item_List_Flagged( areas.i, 'MSG', 'msg', 'FATT'      )
  121.    else                               call EMS_Area_Item_List_Flagged( areas.i, 'MSG', 'msg', '~RCV FATT' )
  122.  
  123.    do j=1 to msg.0
  124.  
  125.       call EMS_Item_Alloc( 'tic', areas.i, 'MSG', msg.j )
  126.  
  127.       file = EMS_Item_Header_AttachedFile( 'tic' )
  128.  
  129.       if file ~= '' then
  130.       do
  131.  
  132.          fullfile = EMS_Area_FullFileName( areas.i, file )
  133.  
  134.          if fullfile ~= '' then
  135.          do
  136.  
  137.             modifiers.1 = 'fullfile'; data.1 =           fullfile
  138.             modifiers.2 = 'path'    ; data.2 = left(     fullfile, length( fullfile ) - length( file ) )
  139.             modifiers.3 = 'file'    ; data.3 =               file
  140.             modifiers.4 = 'size'    ; data.4 = FileSize( fullfile )
  141.             modifiers.5 = 'area'    ; data.5 = areas.i
  142.             modifiers.6 = 'from'    ; data.6 = EMS_Item_Header_Address_From(  'tic'            )
  143.             modifiers.7 = 'date'    ; data.7 = EMS_Item_Header_Date_Received( 'tic'            )
  144.             modifiers.8 = 'desc'    ; data.8 = EMS_Item_Line(                 'tic', 'TEXT', 0 )
  145.             modifiers.0 = 8         ; data.0 = 8
  146.  
  147.  
  148.             dump.0 = 1
  149.             dump.1 = areas.i
  150.  
  151.             do k = 1 to area_patterns.0
  152.  
  153.                if EMS_Search_In_Stem( 'dump', area_patterns.k ) == 1 then
  154.                do
  155.  
  156.                   call PRAGMA( 'D', saved_CD ); call ExecCommands( area_patterns.k , file )
  157.  
  158.                end
  159.  
  160.             end
  161.  
  162.          end
  163.  
  164.       end
  165.  
  166.       call EMS_Item_Free( 'tic' )
  167.  
  168.       if global_noEXEC = 'FALSE' then call EMS_Area_Item_Flag( areas.i, 'MSG', msg.j, 'RCV', 'ON' )
  169.  
  170.    end
  171.  
  172. end
  173.  
  174.  
  175. ScriptExit:
  176.  
  177. /* Restore Current Directory */
  178. call PRAGMA( 'D', saved_CD )
  179.  
  180. call EMS_FreeScriptData()
  181. return 0
  182.  
  183.  
  184. syntax:
  185.  
  186. error_text = EMS_LastError()
  187.  
  188. if error_text = '' then error_text = rc ErrorText( rc )
  189.  
  190. say '| ***BREAK: error at' sigl error_text
  191.  
  192. /* Restore Current Directory */
  193. call PRAGMA( 'D', saved_CD )
  194.  
  195. call EMS_FreeScriptData()
  196. exit rc
  197.  
  198.  
  199. FileSize: procedure
  200.  
  201.    parse arg file
  202.  
  203.    status = STATEF( file )
  204.  
  205.    parse var status 'FILE' size .
  206.  
  207.    return size
  208.  
  209.  
  210. ExecCommands: procedure EXPOSE modifiers. data. global_noEXEC
  211.  
  212.    parse arg pattern , file
  213.  
  214.    call EMS_CustomCfg_Get( 'TickAction', pattern, 'CMD', 'cmds' )
  215.  
  216.    do i=1 to cmds.0
  217.  
  218.       parse var cmds.i cmd '|' args; cmd = upper( cmd )
  219.  
  220.       do forever
  221.  
  222.          /*
  223.          ** IF|<file pattern>|<command>
  224.          */
  225.          if cmd = 'IF' then
  226.          do
  227.  
  228.             parse var args pattern_file '|' cmd '|' args; cmd = upper( cmd )
  229.  
  230.             if FileMatch( file, pattern_file ) = 1 then iterate
  231.             else                                        leave
  232.  
  233.          end
  234.  
  235.          /*
  236.          ** IFNOT|<file pattern>|<command>
  237.          */
  238.          if cmd = 'IFNOT' then
  239.          do
  240.  
  241.             parse var args pattern_file '|' cmd '|' args; cmd = upper( cmd )
  242.  
  243.             if FileMatch( file, pattern_file ) ~= 1 then iterate
  244.             else                                         leave
  245.  
  246.          end
  247.  
  248.          /*
  249.          ** IFISARC|<archiver name>|<command>
  250.          */
  251.          if cmd = 'IFISARC' then
  252.          do
  253.  
  254.             parse var args arc '|' cmd '|' args; cmd = upper( cmd )
  255.  
  256.             arc   = upper(                     arc      )
  257.             match = upper( EMS_Archiver_Match( data.1 ) )
  258.  
  259.             if match = arc then iterate
  260.             else                leave
  261.  
  262.          end
  263.  
  264.          /*
  265.          ** IFISNOTARC|<archiver name>|<command>
  266.          */
  267.          if cmd = 'IFISNOTARC' then
  268.          do
  269.  
  270.             parse var args arc '|' cmd '|' args; cmd = upper( cmd )
  271.  
  272.             arc   = upper(                     arc      )
  273.             match = upper( EMS_Archiver_Match( data.1 ) )
  274.  
  275.             if match ~= arc then iterate
  276.             else                 leave
  277.  
  278.          end
  279.  
  280.          /*
  281.          ** GOTO|<label>
  282.          */
  283.          if cmd = 'GOTO' then
  284.          do
  285.  
  286.             args = upper( strip( args, 'B' ) )
  287.  
  288.             do j=i to cmds.0
  289.  
  290.                parse var cmds.j cmd '|' label .
  291.  
  292.                if upper( cmd ) ~= 'LABEL' then iterate
  293.  
  294.                if upper( label ) = args then leave
  295.  
  296.             end
  297.  
  298.             if j <= cmds.0 then i = j - 1
  299.             else                i = cmds.0
  300.  
  301.             leave
  302.  
  303.          end
  304.  
  305.          select
  306.  
  307.             /*
  308.             ** UNARC
  309.             */
  310.             when cmd = 'UNARC' then
  311.             do
  312.  
  313.                if global_noEXEC = 'FALSE' then call EMS_Unarc( data.1 ) 
  314.  
  315.             end
  316.  
  317.             /*
  318.             ** CD|<directory>
  319.             */
  320.             when cmd = 'CD' then
  321.             do
  322.  
  323.                line = EMS_Translate_Stem( args, 'modifiers', 'data' )
  324.  
  325.                if line ~= '' then call pragma( 'D', line )
  326.  
  327.             end
  328.  
  329.             /*
  330.             ** EXEC|<AmigaDos command>
  331.             */
  332.             when cmd = 'EXEC' then
  333.             do
  334.  
  335.                line = EMS_Translate_Stem( args, 'modifiers', 'data' )
  336.  
  337.                if global_noEXEC = 'FALSE' & line ~= '' then address command line
  338.  
  339.             end
  340.  
  341.             /*
  342.             ** ECHO|<string>
  343.             */
  344.             when cmd = 'ECHO' then
  345.             do
  346.  
  347.                line = EMS_Translate_Stem( args, 'modifiers', 'data' )
  348.  
  349.                say line
  350.  
  351.             end
  352.  
  353.             /*
  354.             ** LOG|<file name>|<log line>
  355.             */
  356.             when cmd = 'LOG' then
  357.             do
  358.  
  359.                parse var args work_file '|' args
  360.  
  361.                line = EMS_Translate_Stem( args, 'modifiers', 'data' )
  362.  
  363.                if global_noEXEC = 'FALSE' then
  364.                do
  365.  
  366.                   if work_file ~= '' then
  367.                   do
  368.  
  369.                      if open( 'cmd_io', work_file, 'APPEND' ) ~= 1 then
  370.                      do
  371.  
  372.                         if open( 'cmd_io', work_file, 'WRITE' ) ~= 1 then leave
  373.  
  374.                      end
  375.  
  376.                      call writeln( 'cmd_io', line )
  377.                      call close(   'cmd_io'       )
  378.  
  379.                   end
  380.  
  381.                end
  382.                else
  383.                do
  384.  
  385.                   say 'LOG:' line
  386.  
  387.                end
  388.  
  389.             end
  390.  
  391.             when cmd = 'END' then i = cmds.0
  392.  
  393.             otherwise nop
  394.  
  395.          end
  396.  
  397.          leave
  398.  
  399.       end
  400.  
  401.    end
  402.  
  403.    return 0
  404.  
  405.  
  406. FileMatch: procedure
  407.  
  408.    parse arg file , pattern
  409.  
  410.    dump.0 = 1
  411.    dump.1 = file
  412.  
  413.    return EMS_Search_In_Stem( 'dump', pattern )
  414.