home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sources.misc
- From: mgleason@cse.unl.edu (Mike Gleason)
- Subject: v23i104: sigrnd - signature randomizer v4.0, Part01/01
- Message-ID: <1991Oct22.033901.2170@sparky.imd.sterling.com>
- X-Md4-Signature: d59824a28359926011ab30707bf5a81d
- Date: Tue, 22 Oct 1991 03:39:01 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: mgleason@cse.unl.edu (Mike Gleason)
- Posting-number: Volume 23, Issue 104
- Archive-name: sigrnd/part01
- Environment: UNIX, News
-
- sigrnd 4.0: yet another .signature randomizer, by mike gleason, NCEMRSoft.
-
- Features:
- + Not a shell script.
- + You are no longer limited to one puny .signature!
- + It doesn't have to know how many sigs you have in advance.
- + It can choose a signature for a specific newsgroup, if you use
- the 'nn' newsreader.
- + For nn users, comes with a patch for the aux script, so you can
- randomize every time you post, instead of everytime you read news.
- The aux script (theoretically) works for all users whether they are
- aware of sigrnd or not; so if you can edit the global aux script, or
- are the superuser, you can make sigrnd available to everyone by patching
- the aux script and putting sigrnd in a public directory.
- + Falls back to the regular .signature file if an error occurs or the user
- doesn't have extra sigs.
- + Can be used to randomly pick quotes, fortunes, etc.
-
- Flags:
- 1. By default, sigrnd picks a signature from a directory called ".sigs"
- in the user's home directory, and outputs the picked sig to standard
- out.
- 2. If you use the -d (or -g) flag, sigrnd will look in that directory,
- and pick a file.
- 3. If you use the -n flag, sigrnd won't print the selected file, but
- instead it will only print the name of the file it picked.
-
- Setup:
- 1. Unshar/Untar this archive if necessary.
- 2. If you are using the nn newsreader, grab a copy of the 'aux' script.
- This should be located somewhere around where the 'nn' executable is.
- For me, 'nn' is in /usr/local/news/bin, and the 'aux' script is in
- /usr/local/news/lib.
- 3. Type 'make.' If you get errors, you may need to try different
- combinations of including <sys/dir.h>, <sys/dirent.h>, and <dirent.h>.
- 4. If you're using the patched aux script for yourself (i.e. not system
- wide) store the script in a nice place. Then, in your nn 'init' file,
- add these lines: "set news-script /my/path/aux", and
- "set mail-script /my/path/aux," substituting the real path of the
- patched aux script. (Note: you MAY need to edit the aux script
- depending what program appends the signature to the post. If it lets
- inews do it (the default), have sigrnd replace the regular sig file,
- like "sigrnd > $HOME/.signature." If the aux script did it by
- "cat .signature >> $WORK", use "sigrnd >> $WORK.")
- 5. Create a whole bunch of signatures, and stash them in a directory
- called ".sigs". If you're using nn, you can get sigrnd to pick from
- different sets of sigs by creating subdirectories within ~/.sigs.
- For example, I could create a subdirectory called "comp.sys.amiga.misc,"
- and put specific signatures related to that group only in there. Then,
- when I post to comp.sys.amiga.misc, sigrnd gets called with
- "sigrnd -g comp.sys.amiga.misc" and only picks from that set of sigs.
- This could come in handy if I don't want my "Macs rule" signatures
- getting tacked on to posts in the amiga forums :-) Also, if I post to
- news.software.nn, and I don't have a corresponding subdirectory, sigrnd
- looks at the top level of ~/.sigs, and picks; so put signatures that
- apply to any group in ~/.sigs, and make subdirectories for groups that
- you want to use specific signatures with.
- 6. If you aren't using nn, I recommend making a csh alias like:
- alias readnews "sigrnd > ~/.signature ; rn"
- Of course, substitute "rn" with the name of the newsreader you use.
-
- Happy randomizing,
- mike gleason = mgleason@cse.unl.edu
-
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of shell archive."
- # Contents: sigrnd.readme sigrnd.c aux.patch Makefile
- # Wrapped by mgleason@cse on Wed Oct 16 05:24:51 1991
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'sigrnd.readme' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'sigrnd.readme'\"
- else
- echo shar: Extracting \"'sigrnd.readme'\" \(3603 characters\)
- sed "s/^X//" >'sigrnd.readme' <<'END_OF_FILE'
- Xsigrnd 4.0: yet another .signature randomizer, by mike gleason, NCEMRSoft.
- X
- XFeatures:
- X + Not a shell script.
- X + You are no longer limited to one puny .signature!
- X + It doesn't have to know how many sigs you have in advance.
- X + It can choose a signature for a specific newsgroup, if you use
- X the 'nn' newsreader.
- X + For nn users, comes with a patch for the aux script, so you can
- X randomize every time you post, instead of everytime you read news.
- X The aux script (theoretically) works for all users whether they are
- X aware of sigrnd or not; so if you can edit the global aux script, or
- X are the superuser, you can make sigrnd available to everyone by patching
- X the aux script and putting sigrnd in a public directory.
- X + Falls back to the regular .signature file if an error occurs or the user
- X doesn't have extra sigs.
- X + Can be used to randomly pick quotes, fortunes, etc.
- X
- XFlags:
- X 1. By default, sigrnd picks a signature from a directory called ".sigs"
- X in the user's home directory, and outputs the picked sig to standard
- X out.
- X 2. If you use the -d (or -g) flag, sigrnd will look in that directory,
- X and pick a file.
- X 3. If you use the -n flag, sigrnd won't print the selected file, but
- X instead it will only print the name of the file it picked.
- X
- XSetup:
- X 1. Unshar/Untar this archive if necessary.
- X 2. If you are using the nn newsreader, grab a copy of the 'aux' script.
- X This should be located somewhere around where the 'nn' executable is.
- X For me, 'nn' is in /usr/local/news/bin, and the 'aux' script is in
- X /usr/local/news/lib.
- X 3. Type 'make.' If you get errors, you may need to try different
- X combinations of including <sys/dir.h>, <sys/dirent.h>, and <dirent.h>.
- X 4. If you're using the patched aux script for yourself (i.e. not system
- X wide) store the script in a nice place. Then, in your nn 'init' file,
- X add these lines: "set news-script /my/path/aux", and
- X "set mail-script /my/path/aux," substituting the real path of the
- X patched aux script. (Note: you MAY need to edit the aux script
- X depending what program appends the signature to the post. If it lets
- X inews do it (the default), have sigrnd replace the regular sig file,
- X like "sigrnd > $HOME/.signature." If the aux script did it by
- X "cat .signature >> $WORK", use "sigrnd >> $WORK.")
- X 5. Create a whole bunch of signatures, and stash them in a directory
- X called ".sigs". If you're using nn, you can get sigrnd to pick from
- X different sets of sigs by creating subdirectories within ~/.sigs.
- X For example, I could create a subdirectory called "comp.sys.amiga.misc,"
- X and put specific signatures related to that group only in there. Then,
- X when I post to comp.sys.amiga.misc, sigrnd gets called with
- X "sigrnd -g comp.sys.amiga.misc" and only picks from that set of sigs.
- X This could come in handy if I don't want my "Macs rule" signatures
- X getting tacked on to posts in the amiga forums :-) Also, if I post to
- X news.software.nn, and I don't have a corresponding subdirectory, sigrnd
- X looks at the top level of ~/.sigs, and picks; so put signatures that
- X apply to any group in ~/.sigs, and make subdirectories for groups that
- X you want to use specific signatures with.
- X 6. If you aren't using nn, I recommend making a csh alias like:
- X alias readnews "sigrnd > ~/.signature ; rn"
- X Of course, substitute "rn" with the name of the newsreader you use.
- X
- XHappy randomizing,
- Xmike gleason = mgleason@cse.unl.edu
- X
- X
- END_OF_FILE
- if test 3603 -ne `wc -c <'sigrnd.readme'`; then
- echo shar: \"'sigrnd.readme'\" unpacked with wrong size!
- fi
- # end of 'sigrnd.readme'
- fi
- if test -f 'sigrnd.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'sigrnd.c'\"
- else
- echo shar: Extracting \"'sigrnd.c'\" \(4606 characters\)
- sed "s/^X//" >'sigrnd.c' <<'END_OF_FILE'
- X/*
- X * sigrnd 4.0
- X * (C) 1989, 1991 by mike gleason, NCEMRSoft. (mgleason@cse.unl.edu)
- X */
- X
- X#include <sys/types.h>
- X#include <sys/param.h>
- X#include <sys/dir.h> /* May need to use <sys/dirent.h> and/or <dirent.h> too. */
- X#include <sys/stat.h>
- X#include <stdio.h>
- X#define SIGNATUREDIR ".sigs"
- X#define DOSUBDIRS /* wanna look in subdirectories too? */
- X
- Xint printname = 0;
- Xchar *prog;
- Xint recurse = 1;
- Xchar path[MAXPATHLEN], homedir[MAXPATHLEN];
- Xextern char *getwd(), *getenv(), *optarg;
- Xextern void *malloc();
- X
- Xmain(argc, argv)
- X int argc; char **argv;
- X{
- X char *sigdir, *cp, *defsigdir;
- X int flag, verbose;
- X
- X if ((cp = getenv("HOME")) == NULL) {
- X defsigdir = SIGNATUREDIR;
- X strcpy(homedir,"./");
- X } else {
- X strcpy(path, cp);
- X strcat(path, "/");
- X strcpy(homedir, path);
- X strcat(path, SIGNATUREDIR);
- X defsigdir = path;
- X }
- X sigdir = defsigdir; /* look for sigs here if you don't specify */
- X printname = 0; /* cat file by default */
- X prog = *argv; /* save name of this program */
- X
- X while ((flag = getopt(argc, argv, "d:g:ncv")) != EOF) switch (flag) {
- X case 'd':
- X case 'g':
- X sigdir = optarg;
- X break;
- X case 'n':
- X printname = 1;
- X break;
- X case 'c':
- X printname = 0;
- X break;
- X case 'v':
- X verbose++;
- X break;
- X default:
- X (void) fprintf(stderr,
- X"usages:\t%s [-d rootsigdir] [-v] > a.signature.file\n\
- X\t%s -n [-d rootsigdir] [-v] (prints name of file picked only)\n\
- X\tDefault directory to randomize from is:\n\t\t\"%s\"\n\
- X\tVersion 4 brought to you by Mike Gleason, NCEMRSoft.\n",
- X prog, prog, defsigdir);
- X exit (1);
- X }
- X
- X /*
- X * Don't report errors, because sigrnd could be a system-wide
- X * standard. If the users don't want to use (or don't know about)
- X * sigrnd, just go ahead and use what they would expect,
- X * ~/.signature.
- X */
- X srand((int) getpid());
- X
- X
- X if (chdir(sigdir) < 0) {
- X if (chdir(defsigdir) < 0) exit(1);
- X sigdir = defsigdir;
- X }
- X
- X#ifdef DOSUBDIRS
- X if (strcmp(getwd(sigdir), defsigdir)==0) {
- X /* If we are using the root sig directory, we don't want
- X to recurse, or else we might use a custom sig intended
- X for a specific newsgroup (and not this one). */
- X recurse = 0;
- X }
- X#endif
- X if (thrashdir()) {
- X strcat(homedir, ".signature");
- X printfile(homedir);
- X if (verbose) {
- X (void) fprintf(stderr, "By default, appended \"%s.\"\n", homedir);
- X sleep(2);
- X }
- X } else if (verbose) {
- X (void) fprintf(stderr, "Used custom signature \"%s.\"\n", path);
- X sleep(2);
- X }
- X exit (0);
- X} /* main */
- X
- X
- X
- Xthrashdir()
- X{
- X register DIR *dirp;
- X register struct direct *dp;
- X register int c, numentries, pick;
- X struct stat st;
- X int safeguard;
- X
- X if ((dirp = opendir(".")) == NULL)
- X return(1);
- X numentries = 0;
- X while ((dp = readdir(dirp)) != NULL)
- X numentries++;
- X if (numentries < 3) {
- X /* consider "." and ".." non-entries */
- X closedir(dirp);
- X return (-1);
- X }
- X#define MAXLOOPS 1000
- X for (safeguard=0, dp=NULL; safeguard<MAXLOOPS && dp==NULL; safeguard++) {
- X rewinddir(dirp);
- X pick = rand() % numentries + 1;
- X while (--pick >= 0)
- X if ((dp = readdir(dirp)) == NULL)
- X break;
- X if (dp != NULL) { /* if we could open the dir entry */
- X if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
- X dp = NULL;
- X else { /* if we have a non-dot entry */
- X if (stat(dp->d_name, &st) < 0) {
- Xgak:
- X (void) closedir(dirp);
- X return (1);
- X }
- X if (S_ISDIR(st.st_mode)) {
- X#ifdef DOSUBDIRS
- X char *saved;
- X
- X if (recurse) {
- X if ((saved = malloc((size_t) MAXPATHLEN)))
- X (void) getwd(saved);
- X /* do subdirectories :-) */
- X if (chdir(dp->d_name) < 0)
- X goto gak;
- X if ((c = thrashdir()) == 1)
- X goto gak;
- X else if (c == -1) {
- X /* the one we picked was an empty dir. try again. */
- X dp = NULL;
- X if (saved) {
- X (void) chdir(saved);
- X free(saved);
- X saved = NULL;
- X }
- X }
- X } else
- X dp = NULL;
- X#else
- X dp = NULL;
- X#endif
- X } else { /* end dir; we have a file */
- X (void) getwd(path);
- X (void) strcat(path, "/");
- X (void) strcat(path, dp->d_name);
- X if (printname)
- X (void) puts(path);
- X else printfile(path);
- X } /* end file */
- X } /* end if we have a non-dot entry */
- X } /* if we could open the dir entry */
- X } /* end loop until we find a sig */
- X
- X if (safeguard >= MAXLOOPS)
- X (void) fprintf(stderr, "%s: infinite loop!\n", prog);
- X (void) closedir(dirp);
- X return (0);
- X} /* thrashdir */
- X
- X
- X
- X
- Xprintfile(name)
- X char *name;
- X{
- X register int c;
- X FILE *fp;
- X
- X if ((fp = fopen(name, "r")) == NULL)
- X return (1);
- X while ((c = fgetc(fp)) != EOF)
- X (void) putchar(c);
- X (void) fclose(fp);
- X return (0);
- X}
- X
- X/* eof */
- END_OF_FILE
- if test 4606 -ne `wc -c <'sigrnd.c'`; then
- echo shar: \"'sigrnd.c'\" unpacked with wrong size!
- fi
- # end of 'sigrnd.c'
- fi
- if test -f 'aux.patch' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'aux.patch'\"
- else
- echo shar: Extracting \"'aux.patch'\" \(1576 characters\)
- sed "s/^X//" >'aux.patch' <<'END_OF_FILE'
- X*** aux Wed Oct 16 04:04:41 1991
- X--- aux.sigrnd Wed Oct 16 03:59:34 1991
- X***************
- X*** 109,115 ****
- X
- X loop=true
- X prompt=false
- X! pr="a)bort"
- X if [ -n "${POSTER_ADR}" ] ; then
- X pr="$pr c)c"
- X fi
- X--- 109,115 ----
- X
- X loop=true
- X prompt=false
- X! pr="** a)bort"
- X if [ -n "${POSTER_ADR}" ] ; then
- X pr="$pr c)c"
- X fi
- X***************
- X*** 314,321 ****
- X fi
- X case $ans in
- X ''|y*|Y*)
- X! echo "-- " >> $WORK
- X! cat $HOME/.signature >> $WORK
- X ;;
- X esac
- X fi
- X--- 314,340 ----
- X fi
- X case $ans in
- X ''|y*|Y*)
- X! # Depending on how your nn is configured, you will need to either concat
- X! # the signature into $WORK, or replace the ~/.signature file. I _think_
- X! # if you aren't using NNTP, you must replace the ~/.sig file (otherwise this
- X! # script would append a signature, THEN inews would append one). If you're
- X! # using NNTP, you will probably use this script to add the sig file to the
- X! # post.
- X!
- X! # Set SIGRND to your signature randomizer, along with necessary flags. Note
- X! # that if the randomizer fails for some reason, it should use default to an
- X! # existing ~/.signature. Also, if your randomizer has can handle sigs for
- X! # different newsgroups, it should try the default sig directory if that
- X! # group doesn't exist.
- X!
- X! SIGRND="/user/students/ugrad/mgleason/bin/sigrnd -g $HOME/.sigs/$GROUP"
- X!
- X! # If NNTP: add sig dashes, then signature.
- X! # echo "-- " >> $WORK
- X! # $SIGRND >> $WORK
- X!
- X! # else: replace the signature file. Inews will append it on it's own.
- X! $SIGRND > $HOME/.signature
- X ;;
- X esac
- X fi
- END_OF_FILE
- if test 1576 -ne `wc -c <'aux.patch'`; then
- echo shar: \"'aux.patch'\" unpacked with wrong size!
- fi
- # end of 'aux.patch'
- fi
- if test -f 'Makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'Makefile'\"
- else
- echo shar: Extracting \"'Makefile'\" \(516 characters\)
- sed "s/^X//" >'Makefile' <<'END_OF_FILE'
- X# Compiled exectuable's name.
- XFILE=sigrnd
- X
- X# Patch file to make the aux script run sigrnd. If you aren't using nn,
- X# or don't want to patch it, simply make sure a file called aux isn't in
- X# this directory.
- XPCH=aux.patch
- X
- X# location of the nn 'aux' script to patch.
- XAUX=./aux
- X
- X# Your favorite C Compiler, and flags.
- XCC=cc
- XCFLAGS=-O
- XLFLAGS=-s
- X
- Xall:
- X $(CC) $(CFLAGS) sigrnd.c -o $(FILE) $(LFLAGS)
- X -patch -c $(AUX) < $(PCH)
- X
- Xshar:
- X shar sigrnd.readme sigrnd.c aux.patch Makefile | \
- X cat sigrnd.readme - > sigrnd.shar
- END_OF_FILE
- if test 516 -ne `wc -c <'Makefile'`; then
- echo shar: \"'Makefile'\" unpacked with wrong size!
- fi
- # end of 'Makefile'
- fi
- echo shar: End of shell archive.
- exit 0
- --
- mike gleason, NCEMRSoft. mgleason@cse.unl.edu
- "Fock you oss hoel" -- A. Schwartzenegger
-
- exit 0 # Just in case...
- --
- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
- Sterling Software, IMD UUCP: uunet!sparky!kent
- Phone: (402) 291-8300 FAX: (402) 291-4362
- Please send comp.sources.misc-related mail to kent@uunet.uu.net.
-