3 # Copyright (C) 2000-2003 Simon Huggins
4 # simple just chooses a random tagline in the simplest possible way
7 # This program is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by the Free
9 # Software Foundation; either version 2 of the License, or (at your option)
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc., 59
19 # Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 # srand( time() ^ ($$ + ($$ << 15) )); # Since 5.004 not required.
28 open(SIG, "<$cfg{'tmpsigfile'}") or htagdie "$0: Could not open $cfg{'tmpsigfile'}: $!\n";
34 if (grep { /\@NOTAG\@/ } $sig) {
39 htagdie <<EOF if (not defined $cfg{'tagfile'} and not defined $cfg{'tagfiles'} and not defined $cfg{'fortune'} and not defined $cfg{'tagdir'});
40 No tagfile defined! I'm good but I'm not psychic
41 Did you configure me at all? Look at the sample.htrc
44 htagdie <<EOF if ($cfg{'tagfiles'} && $cfg{'tagfile'});
45 You have defined both \$cfg{'tagfile'} and \$cfg{'tagfiles'} in your config
46 file(s). Please use one or the other.
49 if (defined $cfg{'tagfile'}) {
50 push @{$cfg{'tagfiles'}}, $cfg{'tagfile'};
53 if (defined $cfg{'tagdir'}) {
54 opendir(DIR, $cfg{'tagdir'})
55 or htagdie "Could not open directory $cfg{'tagdir'}: $!\n";
56 if (not defined $cfg{'tagmatch'}) {
57 push @{$cfg{'tagfiles'}},
58 map { $cfg{'tagdir'} . "/" . $_ }
62 # Check regexp wouldn't kill us
63 exec { "" =~ $cfg{'tagmatch'};}
64 htagdie "tagmatch contained bad pattern. perl said: $@" if $@;
65 push @{$cfg{'tagfiles'}},
66 grep { m,$cfg{'tagmatch'}, }
67 map { $cfg{'tagdir'} . "/" . $_ }
69 htagdie <<EOF if (not @{$cfg{'tagfiles'}});
70 tagdir didn't match anything and you had no tagfiles defined.
79 if ($cfg{'fortune'} && $cfg{'fortuneval'} && $cfg{'fortuneval'} > rand()) {
80 my $cmd = $cfg{'fortune'};
81 $cmd .= " ".$cfg{'fortuneargs'} if defined $cfg{'fortuneargs'};
84 htagdie "fortune died: $!" if $?;
86 foreach (@{$cfg{'tagfiles'}}) {
88 or htagdie "Could not open $_: $!\n";
92 if ($cfg{'tagline_comment_char'}) {
93 @tags = grep { ! /^$cfg{'tagline_comment_char'}/ } @tags;
95 $tag = $tags[rand(@tags)];
98 open(OUT, ">$cfg{'tmptagfile'}") or htagdie "$0: Could not open $cfg{'tmptagfile'}: $!\n";
99 reg_deletion("$cfg{'tmptagfile'}");