home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / mpm1_28.zip / announce.cmd < prev    next >
OS/2 REXX Batch file  |  1995-10-05  |  12KB  |  355 lines

  1. /* ANNOUNCE.CMD - REXX program to generate a File Announcement
  2. with MaxFile/PM for new files. Also formats file descriptions, sorts
  3. files.bbs', purges dupes (new!) and re-archives to desired packer (new!).
  4. (Still doesn't wash windows, though. Darn! <g>)
  5.  
  6.  Modify as desired.  Version 1.4
  7.  
  8. Includes snippets from code of Craig Morrison, identified.
  9.  
  10.   - 12 January, 1995 by Elliott Goodman, 1:102/1319 - 805-264-0200
  11.                            Miles Enterprises BBS
  12. */
  13.  
  14. /* gracefully exit if problems */
  15. signal on halt name Halt1
  16. signal on syntax name Halt2
  17.                                                                  
  18. /* check whether RxFuncs are loaded. If not, load them. */       
  19. if RxFuncQuery('SysLoadFuncs') then                              
  20. do                                                               
  21.         call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  22.         call SysLoadFuncs                                        
  23. end                                                              
  24.  
  25. /* Just to let the user know what's going on.... */
  26. say 'Searching thru file areas for new files to announce.'
  27. say 'Please wait....';
  28. say ' ';
  29.  
  30. /* create a tracking file */
  31. report = 'd:\lora\file\mpbeta\1anounce.txt'
  32.  
  33. /* delete old tracking file, if present */
  34. call SysFileDelete(report)
  35.  
  36. m_txt = 'Report of ANNOUNCE.CMD activity'
  37. call lineout report, m_txt
  38. m_txt = date('U')
  39. call lineout report, m_txt
  40.  
  41. /* get and set date index for today */
  42. parse var m_txt month '/' day '/' year        
  43. mm = word('1 2 3 4 5 6 7 8 9 10 11 12', month)
  44. new_date = mm || '/' || day || '/' || year    
  45.  
  46. m_txt = ''
  47. call lineout report, m_txt
  48.  
  49. /* set some defaults */
  50.  
  51. files.0 = 0            /* will increment */
  52. file_index = 0
  53.  
  54. lmargin = 16         /* how far from the left margin the ED Marker should be */
  55. llength = 45                 /* this is how long each line segment should be */
  56. EDMarker = '>'        /* Set EDMarker to your extended description character */
  57.  
  58. /* Creates string of spaces with the EDMarker at the end */
  59. spaces = SubStr(Copies(' ', 80), 1, lmargin)||EDMarker||' '
  60.  
  61. /* set up the array elements of FILES which will be used by
  62. MPM_AnnounceFiles() at the end of all this processing.
  63. See TANN.CMD included with MaxFile/PM for details.
  64. Modify this area for your own use.   */
  65.  
  66. files.msgpath = 'D:\LORA\MSG\USERS'
  67. files.msgtype = 'SQUISH'
  68. files.msgflag = 'CRASH'
  69. files.to = 'ALL'
  70. files.toaddr = '1:102/1316.0'
  71. files.header = 'New files online at Miles Enterprises BBS'
  72. files.from = 'Elliott Goodman'
  73. files.fromaddr = '1:102/1319.0'
  74. files.footer = '- Elliott'
  75.  
  76. /* your origin info */
  77. files.origin = 'Miles Enterprises * 805-264-0200 *'
  78.  
  79. rc = MPM_QueryAreaList('arealist')         
  80.  
  81. /* cycle thru all areas. If Hide-CD is selected, they won't be searched. */
  82. do impm = 1 to arealist.0
  83.  
  84.    mpmarea = arealist.impm.area
  85.  
  86. /* get drive/subdir of next file area */
  87.    area_path = arealist.impm.path
  88.  
  89. /* notify user of our progress */
  90.    say  mpmarea area_path
  91.    say ' '
  92.  
  93. /* use SysFileTree here to check for new files */
  94.    call SysFileTree area_path, stuff, 'F'
  95.  
  96. /* reset before each file area */
  97.    found_new = 0
  98.    nfile.0 = 0
  99.  
  100. /* assume at least one file in the file area (files.bbs!) */
  101.    do i = 1 to stuff.0        /* cycle thru files in one area */
  102.  
  103. /* get info on each file in the area */
  104.    parse var stuff.i,
  105.          file_date,
  106.          file_time,
  107.          file_size,
  108.          file_attr,
  109.          file_name
  110.  
  111. /* test if next file is dated today, hence NEW */
  112.    if file_date = new_date then do
  113.  
  114. /* remove trailing space */
  115.      file_name = strip( file_name )
  116.  
  117. /* remove drive/subdir info from filename */
  118.      parse var file_name (area_path) file_name
  119.  
  120. /* convert to caps, in case it's lower cased */
  121.      file_name = translate( file_name )
  122.  
  123. /* get extention. We don't want to announce FILES.BBS or FILES.BAK! 
  124. Doing this here before setting the found flag will skip announcing 
  125. them.  We're also going to need the extension to check archive type. */
  126.      parse var file_name junk '.' extn
  127.  
  128.      if extn = 'BAK' | extn = 'BBS' then do
  129.         iterate
  130.         end
  131.  
  132. /* set flag if new file found */
  133.         found_new = 1
  134.  
  135. /* increment number of new files found */
  136.         nfile.0 = nfile.0 + 1
  137.  
  138. /* update index and save file name */
  139.         t_index = nfile.0
  140.         nfile.t_index = file_name
  141.  
  142. /* save extension for testing later on */
  143.         nfile.t_index.ext = extn
  144.  
  145.         end /* if file_test = day_index */
  146.      end /* do i = 1 to stuff.0 */
  147.  
  148. /* now, if we found one or more new files in this area... */
  149.    if found_new = 1 then do
  150.  
  151. /* we have to open the files.bbs file so we can get the
  152. description */
  153.       rc = MPM_OpenArea(mpmarea)
  154.  
  155. /* This gives the system time to open the file. Necessary, at least
  156. on my system. */
  157. Call SysSleep 1
  158.  
  159. /* ....cycle thru the new files for this area */
  160.       do k = 1 to nfile.0
  161.  
  162. /* rearchive if not ZIP - New Function! ***********/
  163.           if nfile.k.ext = 'ARJ' |,
  164.              nfile.k.ext = 'LZH' |,
  165.              nfile.k.ext = 'ARC' |,
  166.              nfile.k.ext = 'ZOO' then do
  167.                 rc = MPM_SelectFile(mpmarea, nfile.k)
  168.                 rc = MPM_ReArchive(mpmarea, ZIP)
  169.  
  170. /* display for Sysop */
  171.                 say 'old name: ' nfile.k
  172.  
  173. /* if successful changing to ZIP, change name in array so
  174. announcement will be for correct filename */
  175.                 if rc = 'OK' then do
  176.                    parse var nfile.k first '.' old_extn
  177.                    nfile.k = first||'.'||'ZIP'
  178.  
  179. /* display in case Sysop is looking.... */
  180.                    say 'new name: ' nfile.k
  181.                 end /* if rc = ok */
  182.  
  183. /* not successful re-archiving. Note in tracking file. */
  184.                 else do
  185.                    m_txt = 'Error re-archiving 'nfile.k
  186.                    call lineout report, m_txt
  187.                 end /* else if */
  188.              end /* if nfile.k.ext = */
  189.  
  190. /* continue storing elements in Files array */
  191.          files.0 = files.0 + 1
  192.          file_index = file_index + 1
  193.          files.file_index.path = area_path
  194.          files.file_index.file = nfile.k
  195.  
  196. /* get file description so we can format it */
  197.          text = MPM_QueryFileInfo(mpmarea, nfile.k, '3')
  198.  
  199. /* just in case no description was Tic'd... */
  200.          if text = 'ERROR' then do
  201.             text = '*****   No Description!'
  202.             end
  203.  
  204. /* here's where we format the file description! This routine was
  205. written by Craig Morrison (with slight changes on my part). */
  206.  
  207. /* Translate all CRs, LFs and Extended Description Markers into spaces */
  208.          ntext = Translate(text, '   ', x2c('0d')||x2c('0a')||EDMarker)                 
  209.  
  210. /* do first part of description */
  211.          text = GetOneLine(llength, ntext)
  212.          ntext = Space(DelWord(ntext, 1, Words(text)), 1)     
  213.  
  214. /* do the rest of the description */
  215.          Do While Length(ntext) \= 0                          
  216.  
  217. /* Add some extra length to remaining lines since there is no
  218. filename on those lines */
  219.             wText = GetOneLine((llength + 10), ntext)
  220.  
  221.             text = text||x2c('0a')||spaces||wtext
  222.  
  223. /* I'm getting extra carriage returns in my listing even though it displays
  224. okay in Lora. So I used the above line. If you are missing one, use the
  225. below line and comment out the above one. */
  226. /*         text = text||x2c('0d')||x2c('0a')||spaces||wText */
  227.  
  228.             ntext = Space(DelWord(ntext, 1, Words(wText)), 1)
  229.             End
  230.  
  231. /* the following two lines replace the extra space between
  232. parentesis that was removed: (  0) */
  233.          text = overlay(' ',text,1,1)
  234.          text = '('||text            
  235.  
  236. /* write formatted file description into files.bbs */
  237.          rc = MPM_SetFileInfo(mpmarea, nfile.k, '2', text)
  238.  
  239. /* save formatted description for announcement after first
  240. cleaning it up a little */
  241.          text = Space(Translate(text, ' ', '>'), 1)
  242.          files.file_index.desc = text
  243.  
  244.          end /* do k to nfile.0 */
  245.  
  246. /* New Sort Function! */
  247.    rc = MPM_FileAreaSort(mpmarea, 'Name', 'Asc', 'All') 
  248.  
  249. /* New Purge Dupes function! ***************/
  250.    rc = MPM_PurgeDupes(mpmarea)
  251.  
  252. /* write updated files.bbs to disk before closing window */
  253.    rc = MPM_SaveFilesBBS(mpmarea)                       
  254.  
  255. /* close the files.bbs file to avoid problems */
  256.       rc = MPM_CloseArea(mpmarea)
  257.  
  258. /* give system time to write files.bbs */
  259.       Call SysSleep 1
  260.       end /* if  found = 1 */
  261.  
  262.    end /* do impm (cycling thru file areas) */
  263.  
  264. /* if no new files: exit */
  265. if files.0 = 0 then do
  266.    m_txt = 'No new files found'
  267.    call lineout report, m_txt
  268.    call lineout report
  269.    call SysSleep 2
  270.    exit
  271.    end
  272.  
  273. /* there are new files. Save the info so we can use the
  274. list for a new files announcement, locally */
  275.  
  276. m_txt = 'List of New Files'
  277. call lineout report, m_txt
  278. m_txt = ' '
  279. call lineout report, m_txt
  280.  
  281. do j = 1 to files.0
  282.    m_txt = '**    File Name = ' files.j.file
  283.    call lineout report, m_txt
  284.    m_txt = 'File Path = ' files.j.path
  285.    call lineout report, m_txt
  286.    m_txt = 'File Description = ' files.j.desc
  287.    call lineout report, m_txt
  288.    m_txt = ' '
  289.    call lineout report, m_txt
  290.    end  
  291.  
  292. /* actually make the announcement */
  293. rc = MPM_AnnounceFiles('files')
  294.  
  295. if files.0 = 1 then
  296.    m_txt = 'One new file found!'
  297.    else
  298.    m_txt = files.0 'new files found!'
  299. call lineout report, m_txt
  300.  
  301. /* close the report file */
  302. call lineout report
  303.  
  304. /* this pause seems to be needed, at least on my system */
  305. call SysSleep 2
  306.  
  307. /* and we're done */
  308. exit
  309.  
  310. /*   This subroutine and all format description routines written by
  311.       Craig Morrison, author of MaxFilePM. Description is his:
  312.  
  313.     GetOneLine takes a variable length string and returns a blank delimited   
  314.     string that is a substring of inText and is no longer than llen           
  315.     characters.                                                               
  316.                                                                               
  317.     A single word that is longer than llen is simply truncated at llen when it
  318.     would be the only word in a line segment and not wrappable. Its cheesy and
  319.     cheap, but hey, it works.. ;-)                                            
  320. */                                                                            
  321.  
  322. GetOneLine:                                        
  323.                                                    
  324.     Parse Arg llen, inText                         
  325.                                                    
  326.     cText = ''                                     
  327.     Do While Length(cText' 'Word(inText, 1)) < llen
  328.         cText = cText' 'Word(inText, 1)            
  329.         inText = DelWord(inText, 1, 1)             
  330.         If inText = '' Then Leave                  
  331.     End                                            
  332.                                                    
  333.     if cText = '' Then Do                          
  334.         cText = Left(inText, llen)                 
  335.     End                                            
  336.                                                    
  337. Return Space(cText, 1)                             
  338.  
  339. Halt1:
  340.  
  341. m_txt = 'Signal called for Halt condition'
  342. call lineout report, m_txt
  343. call lineout report
  344. call SysSleep 2
  345. exit
  346.  
  347. Halt2:
  348.  
  349. m_txt = 'Signal called for Syntax condition'
  350. call lineout report, m_txt
  351. call lineout report
  352. call SysSleep 2
  353. exit
  354.  
  355.