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