1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
#!/usr/bin/perl -w
# Copyright (C) 2000-2003 Simon Huggins
# simple just chooses a random tagline in the simplest possible way
# or uses fortune(1)
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc., 59
# Temple Place, Suite 330, Boston, MA 02111-1307 USA
use strict;
my (@tags);
# srand( time() ^ ($$ + ($$ << 15) )); # Since 5.004 not required.
my $sig="";
open(SIG, "<$cfg{'tmpsigfile'}") or htagdie "$0: Could not open $cfg{'tmpsigfile'}: $!\n";
while(<SIG>) {
$sig .= $_;
}
close(SIG);
if (grep { /\@NOTAG\@/ } $sig) {
$cfg{'notag'}=1;
return 15;
}
htagdie <<EOF if (not defined $cfg{'tagfile'} and not defined $cfg{'tagfiles'} and not defined $cfg{'fortune'} and not defined $cfg{'tagdir'});
No tagfile defined! I'm good but I'm not psychic
Did you configure me at all? Look at the sample.htrc
EOF
htagdie <<EOF if ($cfg{'tagfiles'} && $cfg{'tagfile'});
You have defined both \$cfg{'tagfile'} and \$cfg{'tagfiles'} in your config
file(s). Please use one or the other.
EOF
if (defined $cfg{'tagfile'}) {
push @{$cfg{'tagfiles'}}, $cfg{'tagfile'};
}
if (defined $cfg{'tagdir'}) {
opendir(DIR, $cfg{'tagdir'})
or htagdie "Could not open directory $cfg{'tagdir'}: $!\n";
if (not defined $cfg{'tagmatch'}) {
push @{$cfg{'tagfiles'}},
map { $cfg{'tagdir'} . "/" . $_ }
grep { ! /^\./ }
readdir(DIR);
} else {
# Check regexp wouldn't kill us
exec { "" =~ $cfg{'tagmatch'};}
htagdie "tagmatch contained bad pattern. perl said: $@" if $@;
push @{$cfg{'tagfiles'}},
grep { m,$cfg{'tagmatch'}, }
map { $cfg{'tagdir'} . "/" . $_ }
readdir(DIR);
htagdie <<EOF if (not @{$cfg{'tagfiles'}});
tagdir didn't match anything and you had no tagfiles defined.
EOF
}
closedir(DIR);
}
my $tag;
if ($cfg{'fortune'} && $cfg{'fortuneval'} && $cfg{'fortuneval'} > rand()) {
my $cmd = $cfg{'fortune'};
$cmd .= " ".$cfg{'fortuneargs'} if defined $cfg{'fortuneargs'};
$tag = `$cmd`;
htagdie "fortune died: $!" if $?;
} else {
foreach (@{$cfg{'tagfiles'}}) {
open(HANDLE, "<$_")
or htagdie "Could not open $_: $!\n";
push @tags, <HANDLE>;
close(HANDLE);
}
if ($cfg{'tagline_comment_char'}) {
@tags = grep { ! /^$cfg{'tagline_comment_char'}/ } @tags;
}
$tag = $tags[rand(@tags)];
}
open(OUT, ">$cfg{'tmptagfile'}") or htagdie "$0: Could not open $cfg{'tmptagfile'}: $!\n";
reg_deletion("$cfg{'tmptagfile'}");
chomp $tag;
print OUT $tag;
close(OUT);
return;
|