Thread View: news.software.readers
1 messages
1 total messages
Started by Tom Christiansen
Fri, 26 Jun 1992 23:43
SIGRAND: generate random signatures
Author: Tom Christiansen
Date: Fri, 26 Jun 1992 23:43
Date: Fri, 26 Jun 1992 23:43
199 lines
6671 bytes
6671 bytes
Archive-name: sigrand
Submitted-by: Tom Christiansen <tchrist@convex.com>
Tired of the same old signature? Want different signatures for
different newsgroups? Here's a program to help you out.
The way it works is to have .signature be a named pipe, so if you
don't have named points, just say 'n'.
The sigrand program then feeds stuff down the pipe everytime someone wants
to read it. That way it works for more than just news, but for anything
that wants to read your .signature, like a mailer.
You have your choice of three kinds of signatures:
1) random (short) fortune from "fortune -s"; you get these if
you don't have a global sig file.
2) random fortune from ~/News/SIGNATURES [global sig file]
3) random fortune form ~/News/(newsgroup)/SIGNATURES [local sig files]
The last should can be of the form ~/News/comp/lang/perl/SIGNATURES or
~/News/comp.lang.perl/SIGNATURES based on the config section. Other
possibility (like ~/.news/Comp.lang.perl/SIGNATURES) are trivially added.
The SIGNATURES files are in fortune format, and should contain no more
than three lines, so that we can have one for the real address information,
which is derived either from ~/.fullname if present, or figured out on
the fly otherwise.
For example:
$ head ~/News/SIGNATURES
"So much mail, so little time."
%%
"A witty saying proves nothing."
-- Voltaire
%%
"GUIs normally make it simple to accomplish simple actions and impossible
to accomplish complex actions." --Doug Gwyn (22/Jun/91 in comp.unix.wizards)
%%
"Hey, did you hear Stallman has replaced /vmunix with /vmunix.el? Now
he can finally have the whole O/S built-in to his editor like he always wanted.
%%
"His super power is to turn into a scotch terrier."
%%
The way the local SIG files work is that we look at the first entry
in the newsgroups line of the current ~/.article if it exist. This,
too, is configurable.
Start up sigrand from your .login file. It makes sure only one copy
of itself is running, or tries to.
Suggestions welcome.
--tom
#!/usr/bin/perl
#
# sigrand -- supply random fortunes for .signature file
# Tom Christiansen <tchrist@convex.com>
# version 1.0; Fri Jun 26 18:41:10 CDT 1992
################################################################
# begin configuration section
$MKNOD = "/etc/mknod";
&gethome;
# for rec/humor/funny instead of rec.humor.funny
$NG_IS_DIR = 1;
$FULLNAME = "$HOME/.fullname";
$FIFO = "$HOME/.signature";
$ART = "$HOME/.article";
$NEWS = "$HOME/News";
$SIGS = "$NEWS/SIGNATURES";
$SEMA = "$HOME/.sigrandpid";
# end configuration section -- HOME and FORTUNE get autoconf'd
################################################################
&setup;
fork && exit; # be a daemon
MAIN: while (1) {
open (FIFO, "> $FIFO") || die "can't write $FIFO: $!";
&load_sigs;
$sig = $sig[rand @sig];
print FIFO $name, "\n" x (3 - ($sig =~ tr/\n//)), $sig;
close FIFO;
sleep 1;
}
################################################################
sub setup {
if (-e $FULLNAME) {
$name = `cat $FULLNAME`;
die "$FULLNAME should contain only 1 line, aborting"
if $name =~ tr/\n// > 1;
} else {
chop($host = `hostname`);
($host) = gethostbyname($host) unless $host =~ /\./;
$user = $ENV{USER} || $ENV{LOGNAME} || $pw[0] || die "intruder alert";
($name = $pw[6]) =~ s/,.*//;
$name =~ s/&/$user/g; # can't believe some folks still do this
$name = "\t$name\t$user\@$host\n";
}
&justme;
&check_fortunes if !-e $SIGS;
unless (-p $FIFO) {
if (!-e _) {
system("$MKNOD $FIFO p") && die "can't mknod $FIFO";
warn "created $FIFO as a named pipe\n";
} else {
die "$0: won't overwrite file .signature\n";
}
}
srand(time|$$);
}
sub load_sigs {
local($sigfile) = &ng;
if (!-e $sigfile) {
@sig = (&fortune);
return;
}
open (SIGS,$sigfile) || die "can't open $sigfile";
local($/) = "%%\n";
undef @sig;
while (<SIGS>) {
s!$/$!!o;
push(@sig,$_);
}
close SIGS;
}
sub ng {
open ART || return $SIGS;
local($/) = '';
$_ = <ART>;
($ng) = /Newsgroups:\s*([^,\s]*)/;
$ng =~ s!\.!/!g if $NG_IS_DIR; # if rn -/, or SAVEDIR=%p/%c
$ng = "$NEWS/$ng/SIGNATURES";
-f $ng ? $ng : $SIGS;
}
sub fortune {
local($_, $tries);
do {
$_ = `$FORTUNE -s`;
} until tr/\n// < 4 || $tries++ > 20;
local($*) = 1;
s/^/ /g;
$_ || " SIGRAND: deliver random signals to all processes.\n";
}
sub check_fortunes {
return if $FORTUNE;
foreach $dir (split(/:/, $ENV{PATH}), '/usr/games') {
return if -x ($FORTUNE = "$dir/fortune");
}
die "Need either $SIGS or a fortune program, bailing out";
}
sub gethome {
@pw = getpwuid($<);
$HOME = $ENV{HOME} || $ENV{LOGDIR} || $pw[7]
|| die "no home directory for user $<";
}
# "There can be only one." --the Highlander
sub justme {
if (open SEMA) {
chop($pid = <SEMA>);
kill(0, $pid) || die "$0 already running (pid $pid)\n";
close SEMA;
}
open (SEMA, ">$SEMA") || die "can't write $SEMA: $!";
print SEMA "$$\n";
close SEMA || die "can't close $SEMA: $!";
}
--
Tom Christiansen tchrist@pixel.convex.com
if (rsfp = mypopen("/bin/mail root","w")) { /* heh, heh */
--Larry Wall in perl.c from the perl source code
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads