[comp.sources.misc] v17i006: remind - A replacement for calendar, Part04/04

dfs@doe.carleton.ca (David F. Skoll) (02/20/91)

Submitted-by: David F. Skoll <dfs@doe.carleton.ca>
Posting-number: Volume 17, Issue 6
Archive-name: remind/part04

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then feed it
# into a shell via "sh file" or similar.  To overwrite existing files,
# type "sh file -c".
# The tool that generated this appeared in the comp.sources.unix newsgroup;
# send mail to comp-sources-unix@uunet.uu.net if you want that tool.
# If this archive is complete, you will see the following message at the end:
#		"End of archive 4 (of 4)."
# Contents:  COPYRIGHT Makefile WHATSNEW.23 cache.h defines.h kall
#   protos.h remind-all.csh remind-all.sh remind.mak
# Wrapped by kent@sparky on Tue Feb 19 10:16:41 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'COPYRIGHT' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'COPYRIGHT'\"
else
echo shar: Extracting \"'COPYRIGHT'\" \(997 characters\)
sed "s/^X//" >'COPYRIGHT' <<'END_OF_FILE'
XTHE REMIND COPYRIGHT
X
XREMIND refers to the entire set of files and documentation in the
XREMIND package.
X
XREMIND is Copyright (C) 1990, 1991 by David Skoll, except for the file
Xremind-all.sh, which is Copyright (C) 1990 by Bill Aten.
X
XYou may use REMIND for free, and may freely distribute it, providing
Xyou do not charge the recipients to whom you distribute REMIND.
X
XYou may modify REMIND.  However, you must clearly indicate such
Xmodifications when you distribute REMIND, and must tell the
Xrecipients of the modified version that it is modified.  Place that
Xnotice in the WHATSNEW.xx file.
X
XYou may incorporate parts of REMIND into your own programs, providing
Xyou do not sell these programs.  You must clearly indicate that the parts
Xof REMIND you have incorporated are Copyright (C) 1990 by David Skoll.
X
XI will attempt to support REMIND as much as possible.  However, you use
Xit at your own risk.  I am not responsible for any damages caused by
Xthe use or misuse of REMIND.
X--
XDavid F. Skoll
END_OF_FILE
if test 997 -ne `wc -c <'COPYRIGHT'`; then
    echo shar: \"'COPYRIGHT'\" unpacked with wrong size!
fi
# end of 'COPYRIGHT'
fi
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(1339 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
X# Makefile for REMIND - simple file
X
X#--------------- BEGINNING OF THINGS YOU CAN CHANGE --------------
X
X#If you have a BSD system:
XCFLAGS= -O -DUNIX
X
X#If you have a SYSV system, comment previous line and uncomment next line:
X#CFLAGS= -O -DUNIX -DSYSV
X
X#If your system does not include <malloc.h>, uncomment next line:
X#CFLAGS += -DNO_MALLOC_H
X
X#If you have a SYSV system which does not implement the pid_t type,
X#uncomment the next line:
X#CFLAGS += -Dpid_t=int
X
X#If you want to use gcc:
X#CC= gcc
X
X#Where do you want it installed?
XBINDIR= /usr/local/bin
XKALLDIR= /usr/share/bin
XMANDIR= /usr/share/man
XMANSECTION= 1
X
X#What program does the installation?
XINSTALL= install
X#INSTALL= cp
X
X#--------------- SHOULDN'T CHANGE STUFF BELOW HERE ---------------
X
Xall: dorem.o files.o main.o nextdate.o init.o dosubst.o timed.o calendar.o cache.o omits.o
X	$(CC) -o remind dorem.o files.o main.o nextdate.o init.o dosubst.o timed.o calendar.o cache.o omits.o
X
Xdorem.o: dorem.c
X
Xfiles.o: files.c
X
Xmain.o:  main.c
X
Xomits.o: omits.c
X
Xnextdate.o: nextdate.c
X
Xinit.o: init.c
X
Xdosubst.o: dosubst.c
X
Xtimed.o: timed.c
X
Xcalendar.o: calendar.c
X
Xcache.o: cache.c
X
Xclean:
X	rm -f *.o core *~ remind
X
Xinstall:
X	$(INSTALL) remind $(BINDIR)
X
Xinstall.man:
X	$(INSTALL) remind.1 $(MANDIR)/man$(MANSECTION)/remind.$(MANSECTION)
X
Xinstall.kall:
X	$(INSTALL) kall $(KALLDIR)
X
END_OF_FILE
if test 1339 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'WHATSNEW.23' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'WHATSNEW.23'\"
else
echo shar: Extracting \"'WHATSNEW.23'\" \(1388 characters\)
sed "s/^X//" >'WHATSNEW.23' <<'END_OF_FILE'
XA BRIEF HISTORY OF REMIND:
X
XVersion 1.0 - never publicly released.
X
XVersion 2.0 - first public release.  Included advanced date specifications,
Xcharacter substitution, and the RUN keyword.
X
XVersion 2.1 - Added the "repeat" token for repeating reminders with a period
Xother than 7 days.  Also fixed some bugs from version 2.0
X
XVersion 2.2 - Added the AT keyword, the timed reminders daemon, and the
Xcalendar facility.
X
XVersion 2.2 - Patch 3  - Added the MSG or RUN tokens in an OMIT command; also
Xallowed RUN-type reminders to be explicitly included in the calendar by
Xusing the %" escape sequence.
X
XVersion 2.2 - Patch 5 - Added the BEFORE, AFTER and SKIP tokens to make the
Xhandling of holidays more sensible.  Also corrected a few more bugs.
X
XVersion 2.3 - Added the UNTIL keyword for forcing reminders to expire.
X
XAdded the "++" form of 'back' and the "--" form of 'delta' for
Xignoring OMIT information.
X
XAdded the CLEAR-OMIT-CONTEXT, PUSH-OMIT-CONTEXT and POP-OMIT-CONTEXT
Xkeywords for isolating personal or peculiar reminders from the global
XOMIT context.
X
XSpeeded up the parsing of tokens.
X
XChanged the source to recognize and exploit ANSI-C compilers which
Xaccept function prototypes.
X
XAdded the "-n" option to output the next occurrence of each reminder
Xin SimpleCalendar format
X
XModified the calendar and SimpleCalendar formats so that the % escape
Xsubstitutions ARE performed.
X
END_OF_FILE
if test 1388 -ne `wc -c <'WHATSNEW.23'`; then
    echo shar: \"'WHATSNEW.23'\" unpacked with wrong size!
fi
# end of 'WHATSNEW.23'
fi
if test -f 'cache.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'cache.h'\"
else
echo shar: Extracting \"'cache.h'\" \(785 characters\)
sed "s/^X//" >'cache.h' <<'END_OF_FILE'
X/***************************************************************/
X/*                                                             */
X/*  CACHE.H                                                    */
X/*                                                             */
X/*  Function prototypes, etc. for CACHE.C                      */
X/*                                                             */
X/*  By David Skoll - 15 November 1990                          */
X/*                                                             */
X/***************************************************************/
X#ifdef __STDC__
Xvoid InitCache(void);
Xint GetLine(void);
Xvoid ResetCache(void);
Xvoid DestroyCache(void);
X#else
Xvoid InitCache();
Xint GetLine();
Xvoid ResetCache();
Xvoid DestroyCache();
X#endif
END_OF_FILE
if test 785 -ne `wc -c <'cache.h'`; then
    echo shar: \"'cache.h'\" unpacked with wrong size!
fi
# end of 'cache.h'
fi
if test -f 'defines.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'defines.h'\"
else
echo shar: Extracting \"'defines.h'\" \(2313 characters\)
sed "s/^X//" >'defines.h' <<'END_OF_FILE'
X/***************************************************************/
X/*                                                             */
X/*  DEFINES.H                                                  */
X/*                                                             */
X/*  Contains macros and #defines for REMIND program.           */
X/*                                                             */
X/*  By David Skoll - 30 Sept 1990.                             */
X/*                                                             */
X/***************************************************************/
X
X/* User-definable variables.  BASE *must* be a year for which the
X   first of January is a Monday!!!  FOMITSIZE and POMITSIZE control
X   the number of fully-specified (dd-mm-yy) and partially-specified
X   (dd-mm) holidays. */
X#define BASE 1990
X#define FOMITSIZE 150
X#define POMITSIZE 75
X
X/* Useful macros */
X
X#define upper(c) ( ((c) >= 'a' && (c) <= 'z') ? ((c)-32) : (c) )
X#define DaysInYear(y) (((y) % 4) ? 365 : ((!((y) % 100) && ((y) % 400)) ? 365 : 366 ))
X#define IsLeapYear(y) (((y) % 4) ? 0 : ((!((y) % 100) && ((y) % 400)) ? 0 : 1 ))
X#define DaysInMonth(m, y) ((m) != 1 ? MonthDays[m] : 28 + IsLeapYear(y))
X#define TimeLess(h1, m1, h2, m2) (((h1) < (h2)) || (((h1) == (h2)) && ((m1) < (m2))))
X#define MAX(x, y) ((x) < (y) ? (y) : (x))
X#define MIN(x, y) ((x) < (y) ? (x) : (y))
X#ifndef ABS
X#define ABS(x) ((x) < 0 ? (-(x)) : (x))
X#endif
X
X/* Bit masks for constraint map */
X#define DAY_M 1
X#define MONTH_M 2
X#define YEAR_M 4
X#define WKDAY_M 8
X
Xenum Token_t { Unknown_t, Year_t, Month_t, Day_t, WkDay_t, Msg_t, Run_t,
X	       Omit_t, Banner_t, Rem_t, Delta_t, Back_t, Once_t, Include_t,
X               Repeat_t, At_t, Time_t, Skip_t, Until_t, Push_t, Pop_t,
X	       Clear_t, Eol_t };
X
X/* Define the Token structure */
X
Xtypedef struct {
X   char *str;
X   enum Token_t type;
X   int val;
X   char len;	/* Minimum length to match */
X} Token;
X
X#ifdef UNIX
X/* Define the structure of an AT entry */
Xtypedef struct AtEntry_t{
X   int time;      /* Time in minutes after midnight - 0 to 1439 */
X   int firsttime; /* Time of first triggering */
X   int repeat;    /* Repeat period */
X   int delta;     /* Delta time */
X   enum Token_t type;    /* Run_t or Msg_t */
X   char *text;
X   struct AtEntry_t *next;
X} AtEntry;
X#endif
X
END_OF_FILE
if test 2313 -ne `wc -c <'defines.h'`; then
    echo shar: \"'defines.h'\" unpacked with wrong size!
fi
# end of 'defines.h'
fi
if test -f 'kall' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kall'\"
else
echo shar: Extracting \"'kall'\" \(852 characters\)
sed "s/^X//" >'kall' <<'END_OF_FILE'
X#!/bin/sh
X#
X# kall - kill all processes belonging to this user that match
X#           specified string.
X
Xsignal=`echo $1 | grep '^\-.*'`
Xme=`basename $0`
X
Xif [ "$signal" != "" ]; then
X	shift
Xelse
X	signal="-TERM"
Xfi
X
Xif [ "$1" = "" ]; then
X	echo "usage: $me [-signal] string [string...]"
X	echo "       kills all of your processes where command name matches"
X	echo "       any of the given strings."
X	exit
Xfi
X
Xmsg="0"
X
Xwhile [ "$1" != "" ]; do
X
X# NOTE:  You may have to modify the next line, since PS is non-portable.
X# The 'awk' command picks out the process IDs to pass them on to kill.
X	rprocs=`ps -cx | awk '{if(prog == $5) print $1}' prog=$1 -`
X	if [ "$rprocs" != "" ]; then
X		msg="1"
X		echo -n "${me}: Sending $signal signal to $1 process(es)"
X		echo '...'
X		kill $signal $rprocs
X	fi
X	shift
Xdone
X
Xif [ $msg = "1" ]; then
X    echo "${me}: Done."
Xfi
END_OF_FILE
if test 852 -ne `wc -c <'kall'`; then
    echo shar: \"'kall'\" unpacked with wrong size!
fi
chmod +x 'kall'
# end of 'kall'
fi
if test -f 'protos.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'protos.h'\"
else
echo shar: Extracting \"'protos.h'\" \(2210 characters\)
sed "s/^X//" >'protos.h' <<'END_OF_FILE'
X
X/* Function Prototypes go here */
X
X#ifdef __STDC__
Xint   CheckDate   (int d,   int m,  int y);
Xvoid  ClearOmitContext(void);
Xvoid  CopyInts    (int *from, int *to, int count);
Xint   DoBanner    (char **s);
Xvoid  DoCalendar  (void);
Xint   DoGlobalOmit(char **s);
Xvoid  DoInclude   (char **s);
Xint   DoRem       (char **s);
Xint   DoSubst     (char *src, char *dst, int d, int m, int y, int jul, enum Token_t t, int tim, int mode);
Xint   FindTodaysDate(int *d, int *m, int *y);
Xvoid  FreeStackedOmits (void);
Xint   FromJulian  (int jul, int *d, int *m, int *y);
Xint   GetTriggerDate (int d, int m, int y, int wd, int cons, int back, int repeat, int omit, int skip);
Xint   IsOmitted   (int jul, int localomit);
Xvoid  HandleQueuedAts(void);
Xvoid  initialize  (int argc, char *argv[]);
Xint   int_comp    (int *, int *);
Xint   Julian      (int d,   int m,  int y);
Xint   MoveBack    (int jul, int back, int omit);
Xint   *my_bsearch (int key, int *array, int number);
Xvoid  OpenFile    (char *s);
Xvoid  Output      (char *s);
XToken ParseToken  (char **s);
Xint   PopOmitContext (void);
Xint   PushOmitContext (void);
Xint   ProcessLine (void);
Xint   ReadLine    (void);
Xvoid  SigIntHandler (void);
Xlong  SystemTime  (void);
Xint   TopLevel    (void);
Xint   TryNextDate(int *retday, int *retmon, int *retyr,
X		  int startday, int startmon, int startyr,
X		  int conday, int conmon, int conyr,
X		  int wkday, int cons, int inc);
X#else
Xint   CheckDate   ();
Xvoid  ClearOmitContext();
Xvoid  CopyInts    ();
Xint   DoBanner    ();
Xvoid  DoCalendar  ();
Xint   DoGlobalOmit();
Xvoid  DoInclude   ();
Xint   DoRem       ();
Xint   DoSubst     ();
Xint   FindTodaysDate();
Xvoid  FreeStackedOmits();
Xint   FromJulian  ();
Xint   GetTriggerDate();
Xint   IsOmitted   ();
Xvoid  HandleQueuedAts();
Xvoid  initialize  ();
Xint   int_comp    ();
Xint   Julian      ();
Xint   MoveBack    ();
Xint  *my_bsearch  ();
Xvoid  OpenFile    ();
Xvoid  Output      ();
XToken ParseToken  ();
Xint   PopOmitContext ();
Xint   ProcessLine ();
Xint   PushOmitContext ();
Xint   ReadLine    ();
Xvoid  SigIntHandler();
Xlong  SystemTime  ();
Xint   TopLevel    ();
Xint   TryNextDate ();
X#endif
X
X#ifndef UNIX
Xvoid  Eprint(const char *f, ...);
X#else
Xvoid  Eprint();
X#endif
END_OF_FILE
if test 2210 -ne `wc -c <'protos.h'`; then
    echo shar: \"'protos.h'\" unpacked with wrong size!
fi
# end of 'protos.h'
fi
if test -f 'remind-all.csh' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'remind-all.csh'\"
else
echo shar: Extracting \"'remind-all.csh'\" \(1568 characters\)
sed "s/^X//" >'remind-all.csh' <<'END_OF_FILE'
X#!/bin/csh -f
X
X# Shell script to mail all users reminders.
X
X# Run it AFTER MIDNIGHT so that date is correct!
X# On our system, we have the following in our crontab:
X# 05 5 * * * /usr/share/lib/remind/remind-all > /dev/null 2>&1
X
X# Also, you MUST use the -r and -q options on REMIND, otherwise SEVERE
X# security hole could develop.  I recommend making this script
X# readable and executable only by root to minimize security problems.
X# DO NOT make the script setuid!
X
X# The following line gets a list of users for systems using SUN's
X# NIS service:
Xset USERS  = `ypcat passwd | awk -F: '{print $1}'`
X
X# The following line gets a list of users by examining /etc/passwd:
X# set USERS = `awk -F: '{print $1}' /etc/passwd`
X
X# If neither of the above methods works, you must come up with some
X# way of getting a list of users on the system
X
X# Set the following variables as appropriate for your system
Xset REMIND = /usr/local/bin/remind
Xset MAIL   = /usr/ucb/mail
Xset CMP    = /usr/bin/cmp
Xset RM     = "/usr/bin/rm -f"
X
Xset EMPTY  = /tmp/Empty.$$
Xset FULL   = /tmp/Full.$$
X
X# Create the dummy empty reminder file
X$REMIND -rq /dev/null > $EMPTY
X
X# Scan each user's directory for a .reminders file
Xforeach i ($USERS)
X   if (-r ~$i/.reminders) then
X
X#     echo "$i has a .reminders file."     DEBUGGING PURPOSES ONLY
X
X      $REMIND -rq ~$i/.reminders > $FULL
X      $CMP -s $EMPTY $FULL
X      if ($status != 0) then
X
X#        echo "Sending mail to $i"         DEBUGGING PURPOSES ONLY
X
X         $MAIL -s "Reminders" $i < $FULL
X      endif
X      $RM $FULL
X   endif
Xend
X
X$RM $EMPTY
END_OF_FILE
if test 1568 -ne `wc -c <'remind-all.csh'`; then
    echo shar: \"'remind-all.csh'\" unpacked with wrong size!
fi
# end of 'remind-all.csh'
fi
if test -f 'remind-all.sh' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'remind-all.sh'\"
else
echo shar: Extracting \"'remind-all.sh'\" \(1589 characters\)
sed "s/^X//" >'remind-all.sh' <<'END_OF_FILE'
X# Shell script to mail all users reminders.
X
X# Thanks to Bill Aten for this script.
X
X# Run it AFTER MIDNIGHT so that date is correct!
X# On our system, we have the following in our crontab:
X# 02 00 * * * /usr/local/adm/remind-all >/dev/null 2>&1
X
X# Also, you MUST use the -r and -q options on REMIND, otherwise a SEVERE
X# security hole could develop.  I recommend making this script
X# readable and executable only by root to minimize security problems.
X# DO NOT make the script setuid!
X
X# The following line gets a list of users for systems using SUN's
X# NIS service:
X# USERS=`ypcat passwd | awk -F: '{print $1}'`
X
X# The following line gets a list of users by examining /etc/passwd:
XUSERS=`awk -F: '{print $1}' /etc/passwd`
X
X# If neither of the above methods works, you must come up with some
X# way of getting a list of users on the system
X
X# Set the following variables as appropriate for your system
XREMIND=/usr/local/bin/remind
XMAIL=/usr/bin/mail
XCMP=/bin/cmp
XRM="/bin/rm -f"
X
XEMPTY=/tmp/Empty.$$
XFULL=/tmp/Full.$$
X
X# Create the dummy empty reminder file
X$REMIND -rq /dev/null > $EMPTY
X
X# Scan each user's directory for a .reminders file
Xfor i in $USERS
Xdo
XHOME=`grep \^$i: /etc/passwd | awk -F: '{print $6}'`
X   if [ -r $HOME/.reminders ]; then
X
X#     echo "$i has a .reminders file."     DEBUGGING PURPOSES ONLY
X
X      $REMIND -rq $HOME/.reminders > $FULL
X      if `$CMP -s $EMPTY $FULL`; then
X         : do nothing
X      else
X
X#        echo "Sending mail to $i"         DEBUGGING PURPOSES ONLY
X
X         $MAIL -s "Reminders" $i < $FULL
X      fi
X      $RM $FULL
X   fi
Xdone
X
X$RM $EMPTY
END_OF_FILE
if test 1589 -ne `wc -c <'remind-all.sh'`; then
    echo shar: \"'remind-all.sh'\" unpacked with wrong size!
fi
# end of 'remind-all.sh'
fi
if test -f 'remind.mak' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'remind.mak'\"
else
echo shar: Extracting \"'remind.mak'\" \(940 characters\)
sed "s/^X//" >'remind.mak' <<'END_OF_FILE'
X# Simple-minded MAKE file.
X
XHEADERS = globals.h protos.h defines.h
XWARN = /W3
Xmain.obj: main.c $(HEADERS)
X   cl $(WARN) /AS /Fomain.obj /c main.c
X
Xomits.obj: omits.c $(HEADERS)
X   cl $(WARN) /AS /Foomits.obj /c omits.c
X
Xnextdate.obj: nextdate.c $(HEADERS)
X   cl $(WARN) /AS /Fonextdate.obj /c nextdate.c
X
Xdorem.obj: dorem.c $(HEADERS)
X   cl $(WARN) /AS /Fodorem.obj /c dorem.c
X
Xinit.obj: init.c $(HEADERS)
X   cl $(WARN) /AS /Foinit.obj /c init.c
X
Xdosubst.obj: dosubst.c
X   cl $(WARN) /AS /Fodosubst.obj /c dosubst.c
X
Xfiles.obj: files.c
X   cl $(WARN) /AS /Fofiles.obj /c files.c
X
Xcalendar.obj: calendar.c
X   cl $(WARN) /AS /Focalendar.obj /c calendar.c
X
Xcache.obj: cache.c
X   cl $(WARN) /AS /Focache.obj /c cache.c
X
Xremind.exe: main.obj nextdate.obj dorem.obj init.obj dosubst.obj files.obj calendar.obj cache.obj omits.obj
X   cl /Feremind.exe main.obj nextdate.obj dorem.obj init.obj dosubst.obj files.obj calendar.obj cache.obj omits.obj
X
END_OF_FILE
if test 940 -ne `wc -c <'remind.mak'`; then
    echo shar: \"'remind.mak'\" unpacked with wrong size!
fi
# end of 'remind.mak'
fi
echo shar: End of archive 4 \(of 4\).
cp /dev/null ark4isdone
MISSING=""
for I in 1 2 3 4 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 4 archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0
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.