home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk1.iso
/
altsrc
/
articles
/
11287
< prev
next >
Wrap
Text File
|
1994-09-29
|
11KB
|
324 lines
Newsgroups: alt.sources
Path: wupost!psuvax1!news.pop.psu.edu!news.cac.psu.edu!howland.reston.ans.net!news.sprintlink.net!sunserver.insinc.net!cuugnet!barkers
From: barkers@cuug.ab.ca (Scott Barker)
Subject: Automatic Sig changer - wow an update already :)
Sender: usenet@cuug.ab.ca
Message-ID: <Cwvs0H.EM1@cuug.ab.ca>
Date: Thu, 29 Sep 1994 07:41:04 GMT
Organization: Calgary UNIX User's Group
X-Newsreader: TIN [version 1.2 PL0]
Lines: 312
Well, here's a sort-of, semi-official, virtually-bug-free,
needs-lots-of-neat-features-added version of my Sig changer. It's attached as
a self-extracting sh archive on the end of this post. Hope you get long hours
of mindless enjoyment out of it :)
From the README:
In the past, I've seen many different sig changers - but none really suited my
needs. So I wrote a _very_ short, _very_ simple one which did.
The program spits out a signature, with a quote from a list of quotes in
$HOME/.Quotes, on every read from the named pipe $HOME/.Sig
The quotes in .Quotes are separated by a single '%' on a line by itself (no
white space on the separating line, either).
The most sophisticated part of the program is that it keeps track of the quote
it is on in a file called .Quotenum (I use the quotes sequentially from the
quote file - if you want to change how the quote is picked, it shouldn't be
hard). So when you kill and restart Sig, it remembers where it left off. Also,
if you want to continue with a particular quote, just edit .Quotenum to
reflect its position in .Quotes
Another nice thing about it (at least under Linux), is that the pipe
implementation causes Sig to block when opening the pipe to write until
another process opens the pipe to read. Thus, Sig puts essentially zero load
on the system.
--- cut here ---
#!/bin/sh
echo x - COPYRIGHT
sed 's/^X//' >COPYRIGHT <<'*-*-END-of-COPYRIGHT-*-*'
XI wrote it, it's mine. Don't take credit for it, and I'll be happy :)
X
XSeriously, just follow the usual GNU Public License stuff - add to it, change
Xit, re-write it - just make sure that you always provide source and don't
Xlimit re-distribution. A little note saying where it originally came from
Xwould be nice, too.
X
XScott Barker
Xbarkers@cuug.ab.ca
Xscott@galileo.cuug.ab.ca
*-*-END-of-COPYRIGHT-*-*
echo x - README
sed 's/^X//' >README <<'*-*-END-of-README-*-*'
XIn the past, I've seen many different sig changers - but none really suited my
Xneeds. So I wrote a _very_ short, _very_ simple one which did.
X
XThe program spits out a signature, with a quote from a list of quotes in
X$HOME/.Quotes, on every read from the named pipe $HOME/.Sig
X
XThe quotes in .Quotes are separated by a single '%' on a line by itself (no
Xwhite space on the separating line, either).
X
XThe most sophisticated part of the program is that it keeps track of the quote
Xit is on in a file called .Quotenum (I use the quotes sequentially from the
Xquote file - if you want to change how the quote is picked, it shouldn't be
Xhard). So when you kill and restart Sig, it remembers where it left off. Also,
Xif you want to continue with a particular quote, just edit .Quotenum to
Xreflect its position in .Quotes
X
XAnother nice thing about it (at least under Linux), is that the pipe
Ximplementation causes Sig to block when opening the pipe to write until
Xanother process opens the pipe to read. Thus, Sig puts essentially zero load
Xon the system.
X
XSo how do you use it?
X
XFirst, edit Sig.h for any compile time parameters you want to change. I think
XSig.h is pretty straightforward and the comments should give you all the help
Xyou need.
X
XThen compile it: 'cc Sig.c -o Sig'
X
XTo use it, put something like this in your .login:
X
Xif (`who | grep -c $USER` == 1) then
X Sigstart
Xendif
X
Xand something like this in your .logout:
X
Xif (`who | grep -c $USER` == 1) then
X Sigkill
Xendif
X
XMake sure that Sigstart, Sigkill and Sig are all in your path and are
Xexecutable.
X
XThe if..then..endif just makes sure that concurrent login sessions don't cause
Xmultiple instances of Sig to start, and makes sure that only the _last_ logout
Xfrom concurrent sessions kills Sig. This assumes, of course, that you only
Xwant to run it when you're logged in. I really can't see any reason why you'd
Xwant to run it when you're not logged in. Unless for some reason you maybe
Xwant others to read your quotes as well.
X
XSigstart and Sigkill are just simple shell scripts. Sigstart kills all
Xinstances of Sig which are currently running in the user's process space,
Xchecks that .Sig exists, and is a pipe, and then runs Sig in the background
Xand exits. Sigkill just kills all instances of Sig currently running in the
Xuser's process space. Both shell scripts use 'ps' to determine the pid's of
Xthe currently running instances of Sig, so you should probably check to make
Xsure that they're doing what they're supposed to (different vendors seem to
Xenjoy implementing ps with their own unique output style).
X
XIf you change .Quotes or .Quotenum, you must rerun Sigstart so that Sig can
Xrecalibrate itself.
X
XQuestions? Comments? Dirty jokes? Send them to:
XScott Barker
Xbarkers@cuug.ab.ca
Xscott@galileo.cuug.ab.ca
*-*-END-of-README-*-*
echo x - Sig.c
sed 's/^X//' >Sig.c <<'*-*-END-of-Sig.c-*-*'
X/* Sig.c: the automatic signature generator
X * Copyright (C) 1994 by Scott Barker
X * First revision: September 28, 1994
X */
X
X#include <stdio.h>
X#include <errno.h>
X#include <unistd.h>
X#include "Sig.h"
X
X#define LINELEN 80 /* arbitrary length - any number would do */
X
Xchar *progname; /* so every functions knows it's master :) */
X
Xvoid main(int argc, char *argv[])
X{
X FILE *fp_quotes, *fp_pipe, *fp_quotenum; /* various file pointers */
X char *quotefile, *quotenumfile, *sigpipe; /* various file names */
X char *delim, *msg; /* delimiter and constant message strings */
X char linebuf[LINELEN]; /* temp storage for file reads */
X long int quotepos[MAXQUOTES]; /* array holding the file offset to each
X quote as returned by ftell () */
X char *got_line; /* check mechanism for valid line reads */
X int quotenum; /* current quote */
X int quotecount; /* total quote count */
X
X/* assign all the various string arguments - be nice if they could be
X controlled from the command line, but I'm lazy */
X
X progname = argv[0];
X
X quotefile = QUOTEFILE;
X quotenumfile = QUOTENUMFILE;
X sigpipe = SIGPIPE;
X delim = DELIM;
X msg = MSG;
X
X/* open the quote file and scan through it, getting the offset to the start of
X each quote. Mediocre error checking for file access failures. */
X
X if ((fp_quotes = fopen(quotefile,"r")) == NULL)
X exitSig("Could not open", quotefile, errno);
X
X quotepos[quotecount=0] = 0;
X while (quotecount < MAXQUOTES-1 && !feof(fp_quotes)) {
X while ((got_line = fgets(linebuf,LINELEN,fp_quotes))
X && strcmp(linebuf,delim)) {}
X if (got_line) quotepos[++quotecount] = ftell(fp_quotes);
X }
X
X if (!got_line && !feof(fp_quotes))
X exitSig("Error scanning", quotefile, errno);
X
X fclose(fp_quotes);
X
X/* get where we left off when Sig was last killed, or start from ground zero
X if no record of last position */
X
X quotenum = 0;
X
X if ((fp_quotenum = fopen(quotenumfile,"r")) != NULL) {
X fscanf(fp_quotenum,"%d","enum);
X fclose(fp_quotenum);
X }
X
X/* main loop -
X endlessly spit out the constant message, and the next quote to each
X process which tries to read the pipe. Again, some mediocre error
X checking for file errors. */
X
X while(1) {
X/* open pipe for writing */
X if ((fp_pipe = fopen(sigpipe,"w")) == NULL)
X exitSig("Error opening pipe", sigpipe, errno);
X
X/* dump out the constant message when a read finally comes along */
X if (fprintf(fp_pipe,"%s",msg) == 0)
X exitSig("Error writing to pipe", sigpipe, errno);
X
X/* open up the quote file */
X if ((fp_quotes = fopen(quotefile,"r")) == NULL)
X exitSig("Could not open", quotefile, errno);
X
X/* seek to next quote */
X if (fseek(fp_quotes, quotepos[quotenum], SEEK_SET) != 0)
X exitSig("error seeking", quotefile, errno);
X
X/* spit out next quote to process reading pipe */
X while ((got_line = fgets(linebuf,LINELEN,fp_quotes))
X && strcmp(linebuf,delim))
X if (fprintf(fp_pipe,"%s",linebuf) == 0)
X exitSig("Error writing to pipe", sigpipe, errno);
X
X if (!got_line && !feof(fp_quotes))
X exitSig("Error reading", quotefile, errno);
X
X fclose(fp_quotes);
X fclose(fp_pipe);
X
X/* update the current quote number so we can pick up where we left off if
X Sig gets killed */
X if (++quotenum > quotecount) quotenum = 0;
X if ((fp_quotenum = fopen(quotenumfile,"w")) == NULL)
X exitSig("Could not open", sigpipe, errno);
X
X if (fprintf(fp_quotenum,"%d\n",quotenum) == 0)
X exitSig("Error writing to", quotenumfile, errno);
X
X fclose(fp_quotenum);
X
X/* a little delay to make sure that the reading process has noticed that the
X pipe has been closed and stops trying to get more data. I'm not sure this
X is needed, but it can't hurt. */
X sleep(2);
X }
X}
X
X/* error handling function to make all the code above a little prettier :) */
X
XexitSig(char *msg1, char *msg2, int error)
X{
X fprintf(stderr,"%s: %s %s\n", progname, msg1, msg2);
X exit(error);
X}
X
*-*-END-of-Sig.c-*-*
echo x - Sig.h
sed 's/^X//' >Sig.h <<'*-*-END-of-Sig.h-*-*'
X/* Sig.h: user adjusted compile time parameters
X * Copyright (C) 1994 by Scott Barker
X * /
X
X/* Make this reflect whatever constant part of your signature you want to
X * show up with every quote.
X */
X#define MSG "Scott Barker\nscott@galileo.cuug.ab.ca\n\n"
X
X/* The maximum number of quotes scanned from .Quotes
X * It would have been nicer to not have a limit, but assigning a static array
X * is easy - and I'm lazy.
X */
X#define MAXQUOTES 4000
X
X/* Locations of the various files - change them if you want.
X * Make sure that the pipe is used by all of your mailers and newsreaders,
X * though.
X */
X#define SIGPIPE ".Sig"
X#define QUOTEFILE ".Quotes"
X#define QUOTENUMFILE ".Quotenum"
X
X/* The delimiting line to search for between quotes when initially scanning
X * the quote file.
X */
X#define DELIM "%\n"
X
*-*-END-of-Sig.h-*-*
echo x - Sigkill
sed 's/^X//' >Sigkill <<'*-*-END-of-Sigkill-*-*'
Xkill -9 `ps -hcx | grep -w 'Sig' | awk '{ print $1 }'`
*-*-END-of-Sigkill-*-*
echo x - Sigstart
sed 's/^X//' >Sigstart <<'*-*-END-of-Sigstart-*-*'
X#!/bin/csh
X
Xkill -9 `ps -hcx | grep -w 'Sig' | awk '{ print $1 }'`
X
Xcd $HOME
X
Xif (! -e .Sig ) then
X mknod .Sig p
Xendif
Xif ( ! -p .Sig ) then
X echo "startSig: .Sig does not exist or is not a pipe!"
X exit 1
Xendif
XSig &
*-*-END-of-Sigstart-*-*
echo x - quotes.ex
sed 's/^X//' >quotes.ex <<'*-*-END-of-quotes.ex-*-*'
X"What you have is God's gift to you. What you do with what you have is your
X gift to God."
X - (?)
X%
X"[End of diatribe. We now return you to your regularly scheduled
X programming...]"
X - Larry Wall in Configure from the perl distribution
X%
X"Children are a great comfort in your old age - and they help you reach it
X faster, too."
X - Lionel Kauffman
*-*-END-of-quotes.ex-*-*
exit
--
Scott Barker
barkers@cuug.ab.ca