3 # Copyright (C) 2000-2001 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 htagdie <<EOF if (not defined $cfg{'tagfile'} and not defined $cfg{'tagfiles'} and not defined $cfg{'fortune'} and not defined $cfg{'tagdir'});
29 No tagfile defined! I'm good but I'm not psychic
30 Did you configure me at all? Look at the sample.htrc
33 htagdie <<EOF if ($cfg{'tagfiles'} && $cfg{'tagfile'});
34 You have defined both \$cfg{'tagfile'} and \$cfg{'tagfiles'} in your config
35 file(s). Please use one or the other.
38 if (defined $cfg{'tagfile'}) {
39 push @{$cfg{'tagfiles'}}, $cfg{'tagfile'};
42 if (defined $cfg{'tagdir'}) {
43 opendir(DIR, $cfg{'tagdir'})
44 or htagdie "Could not open directory $cfg{'tagdir'}: $!\n";
45 if (not defined $cfg{'tagmatch'}) {
46 push @{$cfg{'tagfiles'}},
47 map { $cfg{'tagdir'} . "/" . $_ }
51 # Check regexp wouldn't kill us
52 exec { "" =~ $cfg{'tagmatch'};}
53 htagdie "tagmatch contained bad pattern. perl said: $@" if $@;
54 push @{$cfg{'tagfiles'}},
55 grep { m,$cfg{'tagmatch'}, }
56 map { $cfg{'tagdir'} . "/" . $_ }
58 htagdie <<EOF if (not @{$cfg{'tagfiles'}});
59 tagdir didn't match anything and you had no tagfiles defined.
68 if ($cfg{'fortune'} && $cfg{'fortuneval'} && $cfg{'fortuneval'} > rand()) {
69 my $cmd = $cfg{'fortune'};
70 $cmd .= " ".$cfg{'fortuneargs'} if defined $cfg{'fortuneargs'};
73 htagdie "fortune died: $!" if $?;
75 foreach (@{$cfg{'tagfiles'}}) {
77 or htagdie "Could not open $_: $!\n";
81 if ($cfg{'tagline_comment_char'}) {
82 @tags = grep { ! /^$cfg{'tagline_comment_char'}/ } @tags;
84 $tag = $tags[rand(@tags)];
87 open(OUT, ">$cfg{'tmptagfile'}") or htagdie "$0: Could not open $cfg{'tmptagfile'}: $!\n";
88 reg_deletion("$cfg{'tmptagfile'}");