3 # Copyright (C) 2001 Simon Huggins
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the Free
7 # Software Foundation; either version 2 of the License, or (at your option)
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc., 59
17 # Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 my (@tags,%words,%blacklist);
23 if (defined $cfg{'grep_debug'} and $cfg{'grep_debug'}) {
24 open(DEBUG, ">$cfg{'grep_debugfile'}");
27 open(HANDLE, "<$cfg{'tagfile'}") or htagdie "Could not open $cfg{'tagfile'}: $!\n";
37 open(MSG, "<$cfg{'msgfile'}");
40 tr/A-Za-z0-9 //dc; # delete non-alphanumeric
46 $words{$_}++ if not exists $blacklist{$_};
53 foreach my $key (sort { $words{$b} <=> $words{$a} }
55 print DEBUG "$key occurred $words{$key} times\n" if $cfg{'grep_debug'};
56 my @foundtags = grep { /\b$key\b/i } @tags;
57 push @goodtags,@foundtags; # Tags with more than one matching word will get
58 # pushed on more than one time
59 print DEBUG join "\n",@foundtags if $cfg{'grep_debug'};
64 open(OUT, ">$cfg{'tmptagfile'}")
65 or htagdie "$0: Could not open $cfg{'tmptagfile'}: $!\n";
66 reg_deletion("$cfg{'tmptagfile'}");
68 print OUT $goodtags[rand(@goodtags)];
76 if ($cfg{'grep_debug'}) {