home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / bnews96.zip / cleanover.cmd < prev    next >
OS/2 REXX Batch file  |  1997-03-09  |  8KB  |  189 lines

  1. /* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  2.  *  Cleanover.cmd
  3.  *  Cleans trash from *.over.txt files created by Bnews.
  4.  * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-  */
  5.  
  6.   i = RxFuncAdd('RexxLoadFuncs', 'REXXUTIL', 'RexxLoadFuncs')
  7.   i = SysLoadFuncs()
  8.  
  9.   MIN_BODY_LINES = 100          /* Trash articles with less than this       */
  10.                                 /* number of lines in the message body      */
  11.                                 /* to help eliminate discussion and         */
  12.                                 /* keep only binary articles.               */
  13.  
  14.   drop keep.                    /* Stem variable of articles to keep.       */
  15.   drop trash.                   /* "                "        to trash.      */
  16.  
  17.                                 /* keep.0 and trash.0 are the total         */
  18.                                 /* number of items in the stem variables    */
  19.  
  20.   keep.0    = 6                 /* Number of items in stem variable keep.   */
  21.   keep.1    = ".AVI"            /* keep.1 to keep.x are strings to keep     */
  22.   keep.2    = ".MPG"            /* must be UPPER CASE                       */
  23.   keep.3    = ".MOV"
  24.   keep.4    = ".ZIP"
  25.   keep.5    = ".JPG"
  26.   keep.6    = ".GIF"
  27.  
  28.   trash.0   = 17                /* Number of items in stem variable trash.  */
  29.   trash.1   = "CASH"            /* trash.1 to trash.x are strings to trash  */
  30.   trash.2   = "*** DOT"         /* must be UPPER CASE                       */
  31.   trash.3   = ".WAV"
  32.   trash.4   = "BONDAGE"
  33.   trash.5   = "CLINTON"
  34.   trash.6   = "FREE"
  35.   trash.7   = "GAY"
  36.   trash.8   = "HOT TEEN"
  37.   trash.9   = "NIGGER"
  38.   trash.10  = "SCREENSAVER"
  39.   trash.11  = "SITE"
  40.   trash.12  = "SPAM"
  41.   trash.13  = "STRIP POKER"
  42.   trash.14  = "UPSKIRT"
  43.   trash.15  = "HOT MEN"
  44.   trash.16  = "MCARTH"
  45.   trash.17  = "STUD"
  46.  
  47.   fmask = '*.over.txt'                /* File mask of files to clean */
  48.  
  49.   signal on Halt
  50.   signal on NoValue
  51.  
  52.   drop file.
  53.   call SysFileTree fmask, 'file', 'f'   /* Find all matching files */
  54.   if file.0 = 0 then do
  55.     say ''
  56.     say 'No matching files:  'fmask
  57.     exit 0
  58.   end
  59.  
  60.   call SysCurState 'Off'
  61.  
  62.   call time 'e'
  63.  
  64.   trashcurrent = ""                       /* debug what gets trashed */
  65.  
  66.   do fcount = 1 to file.0                 /* Clean all matched files */
  67.     fnameover   = substr(file.fcount, 38)
  68.     fnametmp    = fnameover||'.clean.tmp'
  69.     fnametrash  = fnameover||'.trash'
  70.     notready = stream(fnameover, 'c', 'open')   /* check if file is ready */
  71.     if pos("NOTREADY", notready) \= 0 then do
  72.       say notready' 'fnameover
  73.     end
  74.     else
  75.       call Clean
  76.   end
  77.  
  78.   say "Elapsed time:  "time('e')
  79.   call SysCurState 'On'
  80.   return 0
  81.   /****************************************************************************/
  82.   /*  End of main                                                             */
  83.   /****************************************************************************/
  84.  
  85.  
  86.   /****************************************************************************/
  87.   /*  Clean reads each line of the file looking for lines to keep.            */
  88.   /*  If a line is found it is checked for trash.                             */
  89.   /*  If the line has no trash it is saved.                                   */
  90.   /****************************************************************************/
  91.   Clean:
  92.     cr = '0d'x                      /* carriage return                        */
  93.     call SysFileDelete fnametmp     /* delete old files if they exist         */
  94.     call SysFileDelete fnametrash
  95.     say '' ; say 'Cleaning 'fnameover
  96.     iline     = 0
  97.     ideleted  = 0
  98.     ikept     = 0
  99.     do while lines(fnameover) \= 0
  100.       line0 = linein(fnameover)         /* preserve case in line0             */
  101.       line  = translate(line0)          /* to upper case for comparison       */
  102.       iline = iline + 1                 /* no. lines read                     */
  103.  
  104.       bodylines = CountTabs()           /* trash articles < MIN_BODY_LINES    */
  105.       if bodylines < MIN_BODY_LINES & bodylines \= -1 then do
  106.         call lineout fnametrash, line0
  107.         ideleted = ideleted + 1         /* no. lines trashed                  */
  108.         call charout , cr'Lines read:  'iline'  Kept:  'ikept'  Trashed:  'ideleted
  109.         iterate
  110.       end
  111.  
  112.       ikeepline = 0                     /* keep flag                          */
  113.       do i = 1 to keep.0
  114.         if pos(keep.i, line) > 0 then   /* look for things to keep            */
  115.           ikeepline = Filter()          /* determine if its trash             */
  116.       end
  117.       if ikeepline == 1 then do         /* keep good articles                 */
  118.         call lineout fnametmp, line0
  119.         ikept = ikept + 1               /* no. lines kept                     */
  120.       end
  121.       else do                           /* discard trash                      */
  122.         call lineout fnametrash, line0
  123.         ideleted = ideleted + 1         /* no. lines trashed                  */
  124.       end
  125.                                         /* Show progress                      */
  126.       call charout , cr'Lines read:  'iline'  Kept:  'ikept'  Trashed:  'ideleted
  127.     end
  128.     say ''
  129.     call lineout fnameover              /* close files  */
  130.     call lineout fnametrash
  131.     call lineout fnametmp
  132.     fs = stream(fnametrash,'c','query size')
  133.     if fs == 0 then
  134.       call SysFileDelete fnametrash
  135.     call SysFileDelete fnameover
  136.    '@ren 'fnametmp' 'filespec('name', fnameover)
  137.     return 0
  138.  
  139.   /****************************************************************************/
  140.   /*  Filter looks at each line for trash.                                    */
  141.   /*  Returns: 0 if trash is found.                                           */
  142.   /*           1 if no trash is found.                                        */
  143.   /****************************************************************************/
  144.   Filter:                                 /* Look for trash */
  145.     do j = 1 to trash.0
  146.       if pos(trash.j, line) > 0 then do
  147.         trashcurrent = trash.j
  148.         return 0                          /* found trash */
  149.       end
  150.     end
  151.     return 1                              /* no trash */
  152.  
  153.   /****************************************************************************/
  154.   /* Count the tabs in the overview to find the number of lines in the        */
  155.   /* article body.                                                            */
  156.   /* Returns: number of lines in the message body                             */
  157.   /*          -1 if error                                                     */
  158.   /****************************************************************************/
  159.   CountTabs: procedure expose line
  160.  
  161.     i = 1
  162.     bodylines = -1;                 /* error flag, could not find body lines */
  163.  
  164.     i = pos('09'x||'09'x, line, i)  /* find the two tabs */
  165.     if i == 0 then
  166.       return bodylines
  167.  
  168.     i = pos('09'x, line, i+2)       /* next tab is the body lines */
  169.     if i == 0 then
  170.       return bodylines
  171.  
  172.     bodylines = substr(line, i+1, 10) /* extract body lines */
  173.  
  174.     p = pos('09'x, bodylines)         /* delete remaining */
  175.     if p \= 0 then
  176.       bodylines = delstr(bodylines, p, 99999)
  177.  
  178.     return bodylines
  179.  
  180.  
  181.   Halt:
  182.     say ''
  183.     say 'ouch...'
  184.     exit 1
  185.  
  186.   NoValue:
  187.     say 'novalue at line 'sigl
  188.     exit 0
  189.