3 # Copyright (C) 2000-2001 Simon Huggins
4 # catsig deals with choosing a sig
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by the Free
8 # Software Foundation; either version 2 of the License, or (at your option)
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 # You should have received a copy of the GNU General Public License along
17 # with this program; if not, write to the Free Software Foundation, Inc., 59
18 # Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # You can either specify sigs with
23 # An arrayref to an array of filenames of sigs.
25 # A scalar containing a directory of all your sig files.
27 # A scalar containing a pattern to match the files in sigdir
28 # (full path) against.
30 # So specifying sigdir without sigmatch takes all the files in that
31 # directory that don't start with a fullstop (period) and specifying
32 # it with sigmatch only takes those that match.
33 # Note that if you specify sigs *AND* sigdir you'll get all of sigs
34 # and anything that sigdir/sigmatch matches.
35 # The program dies if after trying to match it comes up with nothing.
39 if (defined $cfg{'sigdir'}) {
40 opendir(DIR, $cfg{'sigdir'})
41 or htagdie "Could not open directory $cfg{'sigdir'}: $!\n";
42 if (not defined $cfg{'sigmatch'}) {
43 push @{$cfg{'sigs'}}, map { $cfg{'sigdir'} . "/" . $_ }
47 # Check regexp wouldn't kill us
48 exec { "" =~ $cfg{'sigmatch'};}
49 htagdie "sigmatch contained bad pattern. perl said: $@" if $@;
50 push @{$cfg{'sigs'}}, grep { m,$cfg{'sigmatch'}, }
51 map { $cfg{'sigdir'} . "/" . $_ }
53 print STDERR "Got sigmatch == $cfg{'sigmatch'}\n";
58 htagdie <<EOF if (not defined $cfg{'sigs'} or scalar @{$cfg{'sigs'}} == 0);
59 No signatures found. Either you didn't specify sigs, or there weren't any
60 files in sigdir or your sigmatch didn't match anything.
70 open(OUT, ">$cfg{'tmpsigfile'}") or htagdie "Couldn't open $cfg{'tmpsigfile'}";
73 open(OUT, ">$cfg{'tmpsigfile'}.old") or htagdie "Couldn't open $cfg{'tmpsigfile'}.old";
79 ### Choose a sig and read it into $sig for grepping for @72@ or whatever.
80 my ($sigfile,@oldsiglist,@siglist,$num,$sig);
82 @oldsiglist = @siglist = @{$cfg{'sigs'}};
89 $sigfile=splice(@siglist,rand(@siglist),1);
90 } elsif (-r "$cfg{'HOME'}/.sig") {
91 print STDERR "Falling back on ~/.sig\n" if $cfg{'debug'};
92 $sigfile="$cfg{'HOME'}/.sig";
94 print STDERR "No sigs specified and no ~/.sig! Using simple tag method\n";
103 print STDERR "Using $sigfile\n" if $cfg{'debug'};
105 open(HANDLE, "<$sigfile") or htagdie "Could not open $sigfile: $!\n";
106 while(<HANDLE>) { $sig .= $_ };
109 if ($cfg{'asksig'}) {
110 print STDERR $sig . "\nUse this sig? ([y]/n/q)";
112 if ($_ =~ /q(?:uit)?/i) { return &quit; }
113 if (not @siglist and $_ =~ /no?/i) {
114 print STDERR "That was the last sig. Reset siglist or quit? ([r]/q)";
116 if ($_ =~ /q(?:uit)?/i) { return &quit; }
117 @siglist = @oldsiglist;
123 } while ($cfg{'asksig'} and $_ !~ /y(?:es)?/i and $_ !~ /^\n$/);
128 reg_deletion($cfg{'tmpsigfile'});
129 reg_deletion("$cfg{'tmpsigfile'}.old");