-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom-quote.pl
More file actions
executable file
·118 lines (100 loc) · 2.16 KB
/
random-quote.pl
File metadata and controls
executable file
·118 lines (100 loc) · 2.16 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/perl
#
# Print a random signature.
# The file has the format
# -- [keywords]
# sig, may be multiple lines
#
# - Cameron Simpson, March 1993
#
($cmd=$0) =~ s:.*/::;
$usage="Usage: $cmd [-{a|u}] [-g good|/pattern/] [files...]
-a Print all entries in files.
-u Sort all entries, emit unique list.
-g good Only consider entries satisfying Perl code 'good'.
/pattern/ Only consider entries containing pattern.
";
$aflag=0;
$uflag=0;
$GOODSIG='length';
if ($ARGV[0] eq '-a') { $aflag=1; shift; }
elsif ($ARGV[0] eq '-u') { $uflag=1; shift; }
if ($ARGV[0] eq '-g') { shift; $GOODSIG=shift; }
elsif ($ARGV[0] =~ m;^/;)
{ if ( ! -f $ARGV[0] )
{ $GOODSIG=shift(@ARGV);
$GOODSIG.='/' unless $GOODSIG =~ m:/$:;
$GOODSIG.='i';
}
}
# how to stash a sig
eval '
sub sig
{ local($_)=@_;
push(@sigs,$_) if '.$GOODSIG.';
}';
die $@ if $@;
if (! @ARGV) { if (!length($ENV{SIGS}))
{ $ENV{SIGS}='/usr/apache/htdocs/kinscoe/quotes.txt';
}
@ARGV=$ENV{SIGS};
}
@sigs=();
SIGFILE:
for (@ARGV)
{ if ($_ eq '-')
{ $FILE='STDIN'; }
elsif (!open(SIG,"< $_\0"))
{ print STDERR "$cmd: can't open $_: $!\n";
next SIGFILE;
}
else
{ $FILE='SIG';
}
$sig='';
while (<$FILE>)
{ if (/^--/)
{ &sig($sig);
$sig=$_;
}
else
{ $sig.=$_;
}
}
if ($FILE ne 'STDIN')
{ close($FILE);
}
&sig($sig);
$sig='';
}
if ($aflag)
{ for (@sigs)
{ &psig($_);
}
}
elsif ($uflag)
{ local(%sigs,$sig,$_);
for $sig (@sigs)
{ $_=$sig;
s/^--[^\n]*\n//;
s/\W+/ /g;
s/\s+/ /g;
s/^ //;
s/ $//;
tr/A-Z/a-z/;
$sigs{$_}=$sig;
}
for (sort keys %sigs)
{ &psig($sigs{$_});
}
}
else
{ srand(time^(40503*$$));
$ndx=int(rand($#sigs-1));
&psig($sigs[$ndx]);
}
sub psig
{ local($_)=shift;
s/^--[^\n]*\n+// unless $uflag || $aflag;
print;
}