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

  1. /* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  2.  *  bnewsfilter.cmd
  3.  *
  4.  *  Filter for bnews.
  5.  *
  6.  *  bnews -covernew -o | bnewsfilter | bnews -cart -o > art.uue
  7.  *  bnews -covernew -o | bnewsfilter | bnews -cart -o | uudeview -io -
  8.  *  type <group>.get.txt | bnews -cart -o | uudeview -io -
  9.  *
  10.  * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
  11.  
  12.   i = RxFuncAdd('SysLoadFuncs', 'REXXUTIL', 'SysLoadFuncs')
  13.   i = SysLoadFuncs()
  14.  
  15.   MIN_BODY_LINES = 100          /* Trash articles with less than this       */
  16.                                 /* number of lines in the message body      */
  17.                                 /* to help eliminate discussion and         */
  18.                                 /* keep only binary articles.               */
  19.  
  20.   drop keep.                    /* Stem variable of articles to keep.       */
  21.   drop trash.                   /* "                "        to trash.      */
  22.  
  23.                                 /* keep.0 and trash.0 are the total         */
  24.                                 /* number of items in the stem variables    */
  25.  
  26.   keep.0    = 6                 /* Number of items in stem variable keep.   */
  27.   keep.1    = ".AVI"            /* keep.1 to keep.x are strings to keep     */
  28.   keep.2    = ".MPG"            /* must be UPPER CASE                       */
  29.   keep.3    = ".MOV"
  30.   keep.4    = ".ZIP"
  31.   keep.5    = ".JPG"
  32.   keep.6    = ".GIF"
  33.  
  34.   trash.0   = 17                /* Number of items in stem variable trash.  */
  35.   trash.1   = "CASH"            /* trash.1 to trash.x are strings to trash  */
  36.   trash.2   = "*** DOT"         /* must be UPPER CASE                       */
  37.   trash.3   = ".WAV"
  38.   trash.4   = "BONDAGE"
  39.   trash.5   = "CLINTON"
  40.   trash.6   = "FREE"
  41.   trash.7   = "GAY"
  42.   trash.8   = "HOT TEEN"
  43.   trash.9   = "NIGGER"
  44.   trash.10  = "SCREENSAVER"
  45.   trash.11  = "SITE"
  46.   trash.12  = "SPAM"
  47.   trash.13  = "STRIP POKER"
  48.   trash.14  = "UPSKIRT"
  49.   trash.15  = "HOT MEN"
  50.   trash.16  = "MCARTH"
  51.   trash.17  = "STUD"
  52.  
  53.   signal on Halt
  54.   signal on NoValue
  55.  '@echo off'
  56.   parse arg arg0
  57.  
  58.   drop oline.                       /* overview line after parsing          */
  59.   iread = 0                         /* count of total lines read            */
  60.   isave = 0                         /* count of total lines saved           */
  61.   line0 = ""                        /* line read from stdin                 */
  62.   line  = ""                        /* line used for comparison upper case  */
  63.  
  64.   call SysCurState 'Off'
  65.   do forever                        /* main loop */
  66.     line0 = linein()                /* preserve case in line0 */
  67.     iread = iread + 1
  68.     if lines() == 0 then leave
  69.     if pos("Elapsed time:", line0) > 0
  70.       then leave
  71.     line = translate(line0)         /* to upper case for comparison */
  72.     oline.0 = ParseLine(line0)
  73.  
  74.     /*  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-  */
  75.     /*  After ParseLine, oline contains the following if oline.0 > 1         */
  76.     /*  oline.1   article number                                             */
  77.     /*  oline.2   subject                                                    */
  78.     /*  oline.3   from                                                       */
  79.     /*  oline.4   date/time                                                  */
  80.     /*  oline.5   reply to?                                                  */
  81.     /*  oline.6   msg id?                                                    */
  82.     /*  oline.7   number of bytes in body of message                         */
  83.     /*  oline.8   number of lines in body of message                         */
  84.     /*  oline.9   xref:                                                      */
  85.     /*  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-  */
  86.  
  87.     /* this loop only check the subjects for keep/kill strings */
  88.  
  89.     if oline.0 > 1 then do
  90.       if oline.8 > MIN_BODY_LINES then do
  91.         linecmp = translate(oline.2)
  92.         do i = 1 to keep.0
  93.           if pos(keep.i, linecmp) > 0 then do /* look at subject for things to keep */
  94.             do j = 1 to trash.0               /* look for trash in the subject */
  95.               if pos(trash.j, linecmp) > 0 then do /* found trash, leave */
  96.                 i = keep.0
  97.                 leave
  98.               end
  99.               else do                         /* no trash, keep line */
  100.                 say line0
  101.                 isave = isave + 1
  102.                 i = keep.0
  103.                 leave
  104.               end
  105.             end
  106.           end
  107.         end
  108.       end
  109.     end
  110.     /* couldn't parse tabs, save line just incase */
  111.     else do
  112.       say line0
  113.     end
  114.   end
  115.   return 0
  116.  /* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
  117.  /*                              End of main                            */
  118.  /* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
  119.  
  120.  /*
  121.   * ParseLine - tokenize line by tabs - 09H
  122.   *
  123.   * results are in the stem variable oline.1 to oline.x
  124.   * oline.0 contains total number of items.
  125.   *
  126.   */
  127.  
  128.   ParseLine:
  129.     parse arg line
  130.     tabcnt = 1
  131.     tabpos = 1
  132.     tabposlast = 1
  133.  
  134.     do forever
  135.       tabpos = pos('09'x, line, tabpos)
  136.       if tabpos == 0 then leave
  137. /*    say 'tabcnt='tabcnt' tabpos='tabpos' tabposlast='tabposlast*/
  138.       oline.tabcnt = substr(line, tabposlast + 1, tabpos - tabposlast - 1)
  139.       tabcnt = tabcnt + 1
  140.       tabposlast = tabpos;
  141.       tabpos = tabpos + 1
  142.     end
  143.     oline.tabcnt = substr(line, tabposlast + 1)
  144.     oline.0 = tabcnt
  145.     return oline.0
  146.  
  147.  
  148.  /*
  149.   * Ctrl- Break catcher
  150.   */
  151.  
  152.   Halt:
  153.     call SysCurState 'On'
  154.     say 'ouch... line 'sigl
  155.     exit 1
  156.  
  157.  
  158.  /*
  159.   * Initialization error handler
  160.   */
  161.  
  162.   NoValue:
  163.     say 'no value at line 'sigl
  164.     exit 1
  165.