Thread View: news.software.readers
2 messages
2 total messages
Started by Steven King
Thu, 09 Dec 1993 13:35
TRN: Different sigs for different newsgroups.
Author: Steven King
Date: Thu, 09 Dec 1993 13:35
Date: Thu, 09 Dec 1993 13:35
98 lines
4629 bytes
4629 bytes
newlight@comtch.iea.com (New Light Industries LTD) writes:
>Emily M. Breed (emilyb@netcom.com) wrote:
>: Does this work with trn? If it does, what's the init file to edit? I
>: checked, but didn't see any file called "init". (Well, this is
>
>The correct file to edit is _probably_ called trnrc. If you have a trn
>directory, it will probably be in that.
Well, first off, trn doesn't work the same way as nn. So the little
trick described a few messages back won't really work with trn. Trn
does have an init file, usually called ".trninit" or sometimes ".rninit"
(a hold over from the days of 'rn'). Actually the init file can be
called "Joes_Bar_And_Grill" if you like, so long as you point the
TRNINIT environment variable to it. Read the man page for more info.
So, how to get a different signature with every newsgroup? Here's a
little script I whipped up a while back. Works great for me. I ought
to send it to Wayne Davison to see he'll include it in future versions
of trn. There's probably a fancy macro string you can use instead, but
I find trn's macros only slightly less cryptic than the Dead Sea
Scrolls.
Documentation is in the header block, and the whole thing's pretty
self-obvious if you know perl. Looking it over I can see a couple
places where it can be tuned up a bit. I coded this a couple years ago
and I know much more about perl now. But hey, it works!
---=== Cut Here ===--- ---=== Cut Here ===---
#! /usr/bin/perl
#
# Steven King, 18 Dec 91
# veck@pshrink.chi.il.us
#
# Synopsis: Psig newsgroup [Pnews-parms]
# (Though this should only be called from a newsreader...)
#
# Selects a signature based on the current newsgroup. Psig will
# read the News directory tree in the user's home directory
# ($HOME/News/...) to find a file called "signature" in the
# current newsgroup. If that file doesn't exist, the directory
# tree will be followed backwards through the hierarchy looking for
# a signature. If none are found a random signature will be picked
# out of $sigdir
#
# When a signature is found it is copied to $HOME/.signature for
# inclusion in the article by inews. Pnews is then called to
# create and post the article.
#
# The $sigdir variable can be pointed to any directory. That
# directory should contain ONLY files you want to use as .signatures,
# and nothing else. Any file in $sigdir is fair game for inclusion.
#
# To get this to work from (t)rn, set the NEWSPOSTER environment
# variable to "Psig %C -h %h".
$home = $ENV{'HOME'};
$sigdir = "$home/.sigs";
@group = ("News",split(/\./,shift(@ARGV)));
$count = @group;
$found = 0;
while (@group) {
$gname = join('/',@group);
if (-f "$home/$gname/signature") {
print "(Using signature from $home/$gname)\n";
system("cp $home/$gname/signature $home/.signature");
$found = 1;
@group = ("dummy");
}
pop(@group);
}
if (! $found) {
opendir(SIGS,$sigdir);
@siglist = grep(!/^\./,readdir(SIGS));
closedir(SIGS);
$seed = time % ($$ * $$); # Seems to provide a good seed.
srand($seed);
$chosen = int((rand() * @siglist));
print "(Using random signature)\n";
system("cp $sigdir/@siglist[$chosen] $home/.signature");
}
if ($ENV{'DOTDIR'} && ($ENV{'DOTDIR'} ne $home)) {
system("cp $home/.signature $ENV{'DOTDIR'}/.signature");
}
system("cat $home/.signature");
system("Pnews @ARGV");
---=== Cut Here ===--- ---=== Cut Here ===---
--
----------------------------------------<Steven King, veck@pshrink.chi.il.us>--
You don't know how much you don't know until you know a lot.
(Nick Holland)
Re: TRN: Different sigs for different newsgroups.
Author: Tom Christiansen
Date: Thu, 09 Dec 1993 14:50
Date: Thu, 09 Dec 1993 14:50
157 lines
5184 bytes
5184 bytes
:-> In news.software.readers, veck@pshrink.chi.il.us writes:
:newlight@comtch.iea.com (New Light Industries LTD) writes:
:>Emily M. Breed (emilyb@netcom.com) wrote:
:>: Does this work with trn? If it does, what's the init file to edit? I
:>: checked, but didn't see any file called "init". (Well, this is
:>
:>The correct file to edit is _probably_ called trnrc. If you have a trn
:>directory, it will probably be in that.
:
:Well, first off, trn doesn't work the same way as nn. So the little
:trick described a few messages back won't really work with trn.
Right. People keep coming up with little tricks for their newsreaders.
They're all different. And what happens when you have a mailreader
instead? That's why my solution is better.
--tom
#!/usr/bin/perl
#
# sigrand -- supply random fortunes for .signature file
################################################################
# 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";
$GLOBRAND = 1/4; # chance to use global sigs anyway
# end configuration section -- HOME and FORTUNE get autoconf'd
################################################################
&setup;
&justme;
fork && exit; # be a daemon
open (SEMA, ">$SEMA") || die "can't write $SEMA: $!";
print SEMA "$$\n";
close SEMA || die "can't close $SEMA: $!";
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 2; # to avoid dup sigs
}
################################################################
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/&/\u\L$user/g; # can't believe some folks still do this
$name = "\t$name\t$user\@$host\n";
}
&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 {
(rand(1.0) > ($GLOBRAND) && 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";
#warn "COOL: no $pid: $!";
close SEMA;
}
}
--
Tom Christiansen tchrist@cs.colorado.edu
"Will Hack Perl for Fine Food and Fun"
Boulder Colorado 303-444-3212
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