a "cute .siggie" random inserter for csh.

Kent Paul Dolan xanthian at zorch.SF-Bay.ORG
Mon Jul 9 10:05:46 AEST 1990


Here is something trivial but fun.  If you put a constant signature file
in home directory file .siggie, and a set of "quotable quotes" in home
directory files .sig01, .sig02, etc., then csh script "catsig" will write
file .siggie, write a line with "--" on it, and write a random file selected
from the .sig[0-9]* set of quotes.  Program catsig can be used from within
mail or vi to put a personal tag on a letter or news article.  Also included
is program timemod.c, which accepts the number of .sig[0-9]* files from
stdin, and uses it as a modulus with the current system time in seconds to
produce a number from 1 to the file count.  This is good enough for a "random"
selection of a signature for your mail or postings.

Example output:  ;-)

Kent the man from xanth.
<xanthian at Zorch.SF-Bay.ORG> <xanthian at well.sf.ca.us>
--
When someone has broken off a relationship with you, you become very
unattractive, which confirms all the reasons they had for leaving you.
     -- Laurie Moore, Starving Again, in: Like Life

-----------------------------8<--cut here-->8------------------------
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	catsig
#	timemod.c
# This archive created: Sun Jul  8 17:02:28 1990
export PATH; PATH=/bin:$PATH
echo shar: extracting "'catsig'" '(2308 characters)'
if test -f 'catsig'
then
       echo shar: will not over-write existing file "'catsig'"
else
sed 's/^XX//' << \SHAR_EOF > 'catsig'
XX#! /bin/csh
XX#
XX#   csh script program "catsig", Copyright 1990 by Kent Paul Dolan, 94039-0755.
XX#
XX#   The purpose of catsig is to add to the end of a letter or news article
XX#   (from the editor) a signature block consisting of the contents of
XX#   home directory file ".siggie", and the contents of a "random" member of
XX#   a list of home directory files with names of the form ".sig[0-9]*".  The
XX#   .sig[0-9]* file names do not have to be sequentially numbered.
XX#
XX#   Uses:  from within mail, say "~r !catsig"; from within vi, say
XX#   ":r !catsig".  Executables "catsig" and "timemod" must be in your
XX#   executable file path list.
XX#
XX#   catsig uses two auxiliary files in the home directory, .sigtemp and
XX#   .sigpick, sets a csh environmental variable SIGPICK, and requires 
XX#   at least the old version of "awk", and program "timemod"by the current
XX#   author, distributed with this program.
XX#
XX#   Permission to use and disseminate this file for any use, except sale as
XX#   part of a commercial product, so long as this header remains intact, is
XX#   hereby granted by the author.  As for any free software, this comes with
XX#   no guarantees of useablity.  "It worked for me!"
XX#
XX#   Write file .siggie to the standard output.
XX#
XXcat ~/.siggie
XX#
XX#   Separate it from the random ~/.sig[0-9]* file with the usual "--" alone
XX#   on a line, written to the standard output.
XX#
XXecho "--"
XX#
XX#   Inventory the files with names of format .sig[0-9]* into file ~/.sigtemp.
XX#
XXls ~/.sig[0-9]* > ~/.sigtemp
XX#
XX#   Use the number of lines in ~/sigtemp as a count of the .sig[0-9]* files,
XX#   and hand that count to "timemod" to get back a random number from 1 to
XX#   that count.  Store that number in envronmental variable SIGPICK.
XX#
XXsetenv SIGPICK `wc -l ~/.sigtemp | timemod`
XX#
XX#   Create a one line awk program to pick the line with this line number from
XX#   .sigtemp.  [Can you guess that my system doesn't support "head"?  ;-)]
XX#
XXecho "NR==$SIGPICK {print}" > ~/.sigpick
XX#
XX#   Use awk to dump this file name into a cat command's file list, and use this
XX#   cat command in turn to copy the random .sig[0-9]* to the standard output.
XX#
XXcat `awk -f ~/.sigpick ~/.sigtemp`
XX#
XX#   That's it.  Slow as molasses and ugly as sin, but it works.  Sorry to use
XX#   csh instead of sh, but perhaps some kind person will translate this.
SHAR_EOF
if test 2308 -ne "`wc -c < 'catsig'`"
then
       echo shar: error transmitting "'catsig'" '(should have been 2308 characters)'
fi
chmod +x 'catsig'
fi # end of overwriting check
echo shar: extracting "'timemod.c'" '(1568 characters)'
if test -f 'timemod.c'
then
       echo shar: will not over-write existing file "'timemod.c'"
else
sed 's/^XX//' << \SHAR_EOF > 'timemod.c'
XX/*
XX    timemod.c -- Copyright 1990 Kent Paul Dolan, Mountain View, CA 94039-0755.
XX
XX    Main program timemod accepts a strictly positive (long) integer from
XX    the standard input.  Error checking is not performed on the input.
XX
XX    It uses this integer as a modulus base MOD.
XX
XX    Using the system time in seconds from time(3f), it performs the long
XX    integer equivalent of "time() % MOD".
XX
XX    It adds 1 to the result and writes a number in the range 1 to MOD to
XX    the standard output.  
XX
XX    Program timemod is useful for producing small "random" numbers during
XX    interactive operations, for example to choose an element from a list
XX    based on the (reasonably) random time when the user calls timemod.
XX
XX    Timemod requires function time(3f), which can be in one of several
XX    libraries depending on the site's OS and libraries.  At the developer's
XX    site, it was found in /usr/lib/libc-nofp.a, and this program was
XX    compiled using "cc -o timemod timemod.c -lc-nofp".
XX
XX    Permission to use this program for any purpose except sale as part of
XX    a commercial product, and to disseminate it so long as the source
XX    including this credit comment is included with the executable, is
XX    hereby granted by the author.
XX
XX    As usual, this free software comes with no guarantees of useability, nor
XX    does the author accept any liability for its use by others.
XX
XX*/
XX
XX#include <stdio.h>
XX
XXmain ()
XX{
XX  long count,timehold,temp;
XX  scanf("%ld",&count);
XX  timehold = time();
XX  temp = timehold/count;
XX  printf("%ld\n",timehold - (temp*count) + 1);
XX  exit (0);
XX}
SHAR_EOF
if test 1568 -ne "`wc -c < 'timemod.c'`"
then
       echo shar: error transmitting "'timemod.c'" '(should have been 1568 characters)'
fi
fi # end of overwriting check
#	End of shell archive
exit 0



More information about the Alt.sources mailing list