"Fossies" - the Fresh Open Source Software Archive

Member "tin-2.4.1/tools/opt-case.pl" (28 Aug 2013, 2789 Bytes) of archive /linux/misc/tin-2.4.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #! /usr/bin/perl -w
    2 #
    3 # reads a tin filter file with regexp filters on STDIN and turns all case
    4 # insensitive regexp into case sensitive ones whenever possible, as case
    5 # sensitive regexp are (a bit) faster.
    6 #
    7 # 2000-04-27 <urs@tin.org>
    8 #
    9 # NOTE: the case= line must come before any line with a regexp pattern,
   10 #       (that is the order tin saves the filter file, if you created the
   11 #       filter by hand and never let tin rewrite the file, you might want to
   12 #       check that first)
   13 #
   14 # NOTE: don't use opt-case.pl on wildmat filters, transform them into regexp
   15 #       filter via w2r.pl first
   16 
   17 # version number
   18 # $VERSION = "0.2.2";
   19 
   20 # perl 5 is needed for lookahead assertions and perl < 5.004 is known to be
   21 # buggy
   22 require 5.004;
   23 
   24 $mod="";    # (?i) modifer
   25 
   26 while (defined($line = <>)) {
   27     chomp $line;
   28 
   29     # ignore comments
   30     if ($line =~ m/^[#\s]/o) {
   31         print "$line\n";
   32         next;
   33     }
   34 
   35     # skip 'empty' patterns, they are nonsense
   36     next if ($line =~ m/^[^=]+=$/o);
   37 
   38     # new scope || case sensitive rule
   39     if ($line =~ m/^group=/o || $line =~ m/^case=0/) {
   40         $mod="";    # clean modifier
   41         print "$line\n";
   42         next;
   43     }
   44 
   45     # case insensitive rule
   46     if ($line =~ m/^case=1/o) {
   47         $mod="(?i)";    # set modifier
   48         print "case=0\n";   # set case to sensitive
   49         next;
   50     }
   51 
   52     # check if regexp-line needs (?i)-modifer
   53     # [^\W\d_] is just a charset independent way to look for any
   54     # upper/lowercase letters, this will miss a few possible
   55     # optimizations (on lines with \s, \S, \d, \D as only 'letters') but
   56     # that won't hurt, it just doesn't optimize'em
   57     if ($line =~ m/^(subj|from|msgid(?:|_last|_only)|refs_only|xref)=(.*[^\W\d_].*)$/o) {
   58         print "# rule rewritten, it might be possible that it can be further optimized\n";
   59         print "# check lines with (?i) if they really need to be case insensitve and if\n";
   60         print "# not remove leading (?i) manually\n";
   61         print "$1=$mod$2\n";
   62         next;
   63         }
   64 
   65     # other lines don't need to be translated
   66     print "$line\n";
   67 }
   68 
   69 __END__
   70 
   71 =head1 NAME
   72 
   73 opt-case.pl - Optimize case insensitive regexp filters for tin
   74 
   75 =head1 SYNOPSIS
   76 
   77 B<opt-case.pl> E<lt> I<input> [E<gt> I<output>]
   78 
   79 =head1 DESCRIPTION
   80 
   81 B<opt-case.pl> reads a B<tin>(1) filter-file (B<tin>(5)) with regexp
   82 filters on STDIN and turns all case insensitive regexp into case
   83 sensitive ones whenever possible, as case sensitive regexp are (a
   84 bit) faster.
   85 
   86 =head1 NOTES
   87 
   88 The case= line must come before any line with a regexp pattern, (that
   89 is the order B<tin>(1) saves the filter file, if you created the
   90 filter by hand and never let B<tin>(1) rewrite the file, you might
   91 want to check that first).
   92 
   93 Don't use B<opt-case.pl> on wildmat filters, transform them into
   94 regexp filter via B<w2r.pl>(1) first.
   95 
   96 =head1 AUTHOR
   97 
   98 Urs Janssen E<lt>urs@tin.orgE<gt>
   99 
  100 =head1 SEE ALSO
  101 
  102 B<tin>(1), B<tin>(5), B<w2r.pl>(1)
  103 
  104 =cut