2 # Search for bad words in strings
4 # Copyright (c) 2000 Dirk Koopman
20 use vars qw($badword $regexcode);
22 my $oldfn = "$main::data/badwords";
23 my $regex = "$main::data/badw_regex";
24 my $bwfn = "$main::data/badword";
26 # copy issue ones across
27 filecopy("$regex.gb.issue", $regex) unless -e $regex;
28 filecopy("$bwfn.issue", $bwfn) unless -e $bwfn;
30 $badword = new DXHash "badword";
32 use vars qw($VERSION $BRANCH);
33 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
34 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
35 $main::build += $VERSION;
36 $main::branch += $BRANCH;
38 # load the badwords file
42 my $fh = new IO::File $oldfn;
57 push @out, create_regex();
64 my $fh = new IO::File $regex;
67 my $s = "sub { my \$str = shift; my \@out; \n";
73 # create a closure for each word so that it matches stuff with spaces/punctuation
74 # and repeated characters in it
77 my $e = join '+[\s\W]*', @l;
78 $s .= "push \@out, \$1 if \$str =~ /\\b($e)/;\n";
81 $s .= "return \@out;\n}";
83 dbg($s) if isdbg('badword');
91 my $l = "can't open $regex $!";
99 # check the text against the badwords list
105 push @out, &$regexcode($s) if $regexcode;
109 for (split(/\b/, $s)) {
110 push @out, $_ if $badword->in($_);