home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / lorautil.zip / MSGCNT.CMD < prev    next >
OS/2 REXX Batch file  |  1995-05-08  |  6KB  |  185 lines

  1. /* MSGCNT.CMD - Program to count messages received 
  2.     version 1.0, 19 February, 1995 by Elliott Goodman 
  3.  
  4. I run this from my LOG.CMD program, run nightly during
  5. Lora's 'auto-maint' phase, the only time the logfile is free.
  6. If you are going to use LOG.CMD to run it, place it as follows:
  7.  
  8.         say 'Door Tracker....'                   
  9.         call Door_tracker                        
  10.                                                  
  11.         say "Running MSGCNT.CMD. Please wait...."
  12.         call "d:\lora\lang\msgcnt.cmd"
  13.                                                  
  14.         say 'Remove routine....'                 
  15.         call remove_stuff                        
  16.  
  17. Locate the two routines above and place it between them as
  18. shown with correct drive/path info.
  19.  
  20. Feel free to modify as needed.
  21.  
  22. Donations for this program may be sent to:
  23.  
  24.      Elliott Goodman        
  25.      PO Box 500038          
  26.      Palmdale, CA 93591-0038
  27.  
  28. */
  29.  
  30. /* trace ?a */
  31.  
  32. say 'Starting MSGCNT.CMD....'
  33.  
  34. /* load if not already loaded */
  35. if RxFuncQuery('SysLoadFuncs') then
  36. do
  37.         call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  38.         call SysLoadFuncs
  39. end
  40.  
  41. /* save directory info */
  42. old_dir = directory()
  43.  
  44. /* modify as necessary */
  45. call directory('D:\LORA\LANG')
  46.  
  47. /* initialize variables */
  48. phrase1 = 'Tossing'
  49. phrase2 = 'packet(s):'
  50.  
  51. in_name = 'lora.log'
  52. out_name = 'MSGCOUNT.TXT'
  53. toss_flag = 0
  54. toss_pattern = '(Toss='
  55. area_names = 0
  56. temp_name = ' '
  57. temp_count = 0
  58. total_count = 0
  59.  
  60. /* remove previous Output file, if present */
  61. call SysFileDelete(out_name)
  62.  
  63. drop messages.
  64.  
  65. /* Initialize Output file with date/time */
  66. m_txt = 'Message Count v1.0 by Elliott Goodman'
  67. call lineout out_name, m_txt
  68. m_txt = '  '
  69. call lineout out_name, m_txt
  70. m_txt = 'Messages received yesterday'
  71. call lineout out_name, m_txt
  72. time_string = time('C')
  73. date_string = date('N')
  74. m_txt = 'Current time:' time_string || ',' date_string
  75. call lineout out_name, m_txt
  76. m_txt = '  '
  77. call lineout out_name, m_txt
  78.  
  79. /* cycle thru LORA.LOG */
  80. do until lines(in_name) = 0
  81.     work_line = linein(in_name)
  82.  
  83. /* set further-work flag. This should avoid messing with
  84. irrelevant lines and speed things up */
  85.  
  86.     if toss_flag = 0 then do
  87.         j = wordpos(phrase1, work_line)
  88.         if j \= 0 then
  89.             toss_flag = 1
  90.         end /* if toss_flag <> 1 */
  91.  
  92.     if toss_flag = 1 then do
  93.         j = wordpos(phrase2, work_line)
  94.         if j \= 0 then
  95.             toss_flag = 0
  96.         end /* if toss_flag = 1 */
  97.  
  98. /* found block of lines headed by 'Tossing */
  99.     if toss_flag = 1 then do
  100. /* break up line into elements */
  101.         parse var work_line . . area_tag toss_count stuff
  102. /* if line contains (Toss=xxxx) then work on it */
  103.         if left(toss_count, 6) = '(Toss=' then do
  104.  
  105. /* remove trailing space, if present */
  106.             toss_count = strip(toss_count)
  107. /* remove leading '(Toss=' stuff */
  108.             parse var toss_count (toss_pattern) toss_count
  109. /* remove trailing ')' - should now be of form '000x' */
  110.             toss_count = strip(toss_count, 'T', ')' )
  111.  
  112. /* search thru array for area tag and increment if found */
  113.             found = 0
  114.             do index = 1 to area_names
  115.                 if messages.index = area_tag then do
  116.                     messages.index.count = messages.index.count + toss_count
  117.                     found = 1
  118.                     leave
  119.                     end /* if */
  120.                 end /* do index = 1 to area_names */
  121.  
  122. /* area tag not found; add to array */
  123.              if found = 0 then do
  124.                  area_names = area_names + 1
  125.                  messages.area_names = area_tag
  126.                  messages.area_names.count = toss_count
  127.                  end /* if found = 0 */
  128.             end /* if left = (Toss */
  129.         end /* if toss_flag = 1 */
  130.     end /* do until lines() = 0 */
  131.  
  132. /* sort routine - not fast but it works */
  133. swap = 1
  134. do until swap = 0
  135.     swap = 0
  136.     do index = 1 to area_names -1
  137.         t_index = index + 1
  138.         if messages.t_index.count > messages.index.count then do
  139.             temp_name = messages.index
  140.             temp_count = messages.index.count
  141.             messages.index = messages.t_index
  142.             messages.index.count = messages.t_index.count
  143.             messages.t_index = temp_name
  144.             messages.t_index.count = temp_count
  145.             swap = 1
  146.             end /* if */
  147.         end /* do */
  148.     end /* do until */
  149.  
  150. /* Now output sorted results after formatting a little */
  151. do index = 1 to area_names
  152.    select
  153.       when messages.index.count > 9999 then
  154.          m_txt = space(messages.index,
  155.             trunc(messages.index.count),(22-length(messages.index)),'.')
  156.       when messages.index.count > 999 then
  157.          m_txt = space(messages.index,
  158.             trunc(messages.index.count),(23-length(messages.index)),'.')
  159.       when messages.index.count > 99 then
  160.          m_txt = space(messages.index,
  161.             trunc(messages.index.count),(24-length(messages.index)),'.')
  162.       when messages.index.count > 9 then
  163.          m_txt = space(messages.index,
  164.             trunc(messages.index.count),(25-length(messages.index)),'.')
  165.       otherwise
  166.          m_txt = space(messages.index,
  167.             trunc(messages.index.count),(26-length(messages.index)),'.')
  168.       end
  169.    call lineout out_name, m_txt
  170.    total_count = total_count + messages.index.count
  171.    end
  172.  
  173. m_txt = '  '
  174. call lineout out_name, m_txt
  175.  
  176. m_txt = space('Total' total_count,18,'.')
  177. call lineout out_name, m_txt
  178.  
  179. /* close files, return to starting directory, copy output to
  180. bulletin file */
  181. call lineout in_name
  182. call lineout out_name
  183. '@copy' out_name 'd:\lora\misc\BULLET6.BBS 1>NUL 2>&1'
  184. call directory(old_dir)
  185.