REMIND 2.3.0 4/4

David F. Skoll dfs at doe.carleton.ca
Tue Feb 19 05:19:22 AEST 1991


#!/bin/sh
# This is part 04 of Remind 2.3.0
if touch 2>&1 | fgrep 'amc' > /dev/null
 then TOUCH=touch
 else TOUCH=true
fi
# ============= remind.mak ==============
if test X"$1" != X"-c" -a -f 'remind.mak'; then
	echo "File already exists: skipping 'remind.mak'"
else
echo "x - extracting remind.mak (Text)"
sed 's/^X//' << 'SHAR_EOF' > remind.mak &&
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
SHAR_EOF
$TOUCH -am 0218130591 remind.mak &&
chmod 0600 remind.mak ||
echo "restore of remind.mak failed"
set `wc -c remind.mak`;Wc_c=$1
if test "$Wc_c" != "940"; then
	echo original size 940, current size $Wc_c
fi
fi
# ============= test.rem ==============
if test X"$1" != X"-c" -a -f 'test.rem'; then
	echo "File already exists: skipping 'test.rem'"
else
echo "x - extracting test.rem (Text)"
sed 's/^X//' << 'SHAR_EOF' > test.rem &&
X# Test file for REMIND
X#
X# Use this file to test the date calculation routines
X# of the REMIND program by typing:
X#
X# (UNIX version):
X# 	remind -dv test.rem 16 FEB 1991 >& temp 
X#
X# (DOS version):
X#	e2o remind -dv test.rem 16 FEB 1991 > temp
X#
X# and comparing the results with test.out.
X#
X# The only differences should be the date of last
X# modification/access
X
X# Test each possible case of the basic reminders.
X
XREM MSG Every Day
X
XREM 18 MSG Every 18th 
XREM 15 MSG Every 15th
X
XREM Feb MSG February
XREM Jan MSG January
XREM March MSG March
X
XREM 13 Jan MSG 13 Jan
XREM 15 Feb MSG 15 Feb
XREM 28 Feb MSG 28 Feb
XREM 29 Feb MSG 29 Feb
XREM 5 Mar MSG 5 Mar
X
XREM 1990 MSG 1990
XREM 1991 MSG 1991
XREM 1992 MSG 1991
X
XREM 1 1990 MSG 1 1990
XREM 29 1991 MSG 29 1991
XREM 29 1992 MSG 29 1992
XREM 16 1991 MSG 16 1991
X
XREM Jan 1990 MSG Jan 1990
XREM Feb 1991 MSG Feb 1991
XREM Dec 1991 MSG Dec 1991
XREM May 1992 MSG May 1992
X
XREM 1 Jan 1991 MSG 1 Jan 1991
XREM 16 Feb 1991 MSG 16 Feb 1991
XREM 29 Dec 1992 MSG 29 Dec 1992
X
XREM Sun MSG Sun
XREM Fri Sat Tue MSG Fri Sat Tue
X
XREM Sun 16 MSG Sun 16
XREM Mon Tue Wed Thu Fri 1 MSG Mon Tue Wed Thu Fri 1
X
XREM Sun Feb MSG Sun Feb
XREM Mon Tue March MSG Mon Tue March
X
XREM Sun 16 Feb MSG Sun 16 Feb
XREM Mon Tue 10 March MSG Mon Tue 10 March
X
XREM Sat Sun 1991 MSG Sat Sun 1991
XREM Mon Tue 1992 MSG Mon Tue 1992
X
XREM Sun 16 1991 MSG Sun 16 1991
XREM Mon Tue Wed Thu Fri 1 1992 MSG Mon Tue Wed Thu Fri 1 1992
X
XREM Mon Feb 1991 MSG Mon Feb 1991
XREM Tue Jan 1992 MSG Tue Jan 1992
X
XREM Sun Mon 16 Feb 1991 MSG Sun Mon 16 Feb 1991
XREM Tue 28 Jan 1992 MSG Tue 28 Jan 1992
X
X# Try some Backs
XCLEAR-OMIT-CONTEXT
XREM 1 -1 OMIT sat sun MSG 1 -1 OMIT Sat Sun
XREM 1 --1 OMIT sat sun MSG 1 --1 OMIT Sat Sun
X
XOMIT 28 Feb
XREM 1 -1 OMIT sat sun MSG 1 -1 OMIT Sat Sun (28 Feb omitted)
XREM 1 --1 OMIT sat sun MSG 1 --1 OMIT Sat Sun (28 Feb omitted)
X
XCLEAR-OMIT-CONTEXT
X
X# Try out UNTIL
XREM Wed UNTIL 21 Feb 1991 MSG Wed UNTIL 21 Feb 1991
X
X# Try playing with the OMIT context
X
XOMIT 28 Feb 1991
XREM 1 Mar -1 MSG 1 mar -1 (28feb91 omitted)
XREM 1 Mar --1 MSG 1 mar --1 (28Feb91 omitted)
XREM 28 Feb BEFORE MSG 28 Feb BEFORE (28Feb91 omitted)
XREM 28 Feb SKIP MSG 28 Feb SKIP (28Feb91 omitted)
XREM 28 Feb AFTER MSG 28 Feb AFTER (28Feb91 omitted)
X
XPUSH-OMIT-CONTEXT
XCLEAR-OMIT-CONTEXT
XREM 1 Mar -1 MSG 1 mar -1
XREM 1 Mar --1 MSG 1 mar --1
XREM 28 Feb BEFORE MSG 28 Feb BEFORE
XREM 28 Feb SKIP MSG 28 Feb SKIP 
XREM 28 Feb AFTER MSG 28 Feb AFTER
X
XPOP-OMIT-CONTEXT
XREM 1 Mar -1 MSG 1 mar -1 (28feb91 omitted)
XREM 1 Mar --1 MSG 1 mar --1 (28Feb91 omitted)
XREM 28 Feb BEFORE MSG 28 Feb BEFORE (28Feb91 omitted)
XREM 28 Feb SKIP MSG 28 Feb SKIP (28Feb91 omitted)
XREM 28 Feb AFTER MSG 28 Feb AFTER (28Feb91 omitted)
X
X
XREM 13 March 1991 *1 UNTIL 19 March 1991 MSG 13-19 Mar 91
X 
X# Test BACK
XCLEAR-OMIT-CONTEXT
XREM 18 Feb 1991 +1 MSG 18 Feb 1991 +1
X
XOMIT 17 Feb 1991
XREM 18 Feb 1991 +1 MSG 18 Feb 1991 +1 (17Feb91 omitted)
XREM 18 Feb 1991 ++1 MSG 18 Feb 1991 ++1 (17Feb91 omitted)
X
XCLEAR-OMIT-CONTEXT
X
SHAR_EOF
$TOUCH -am 0218130591 test.rem &&
chmod 0600 test.rem ||
echo "restore of test.rem failed"
set `wc -c test.rem`;Wc_c=$1
if test "$Wc_c" != "2975"; then
	echo original size 2975, current size $Wc_c
fi
fi
# ============= timed.c ==============
if test X"$1" != X"-c" -a -f 'timed.c'; then
	echo "File already exists: skipping 'timed.c'"
else
echo "x - extracting timed.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > timed.c &&
X#include <stdio.h>
X#include <signal.h>
X#include <string.h>
X#ifndef NO_MALLOC_H
X#include <malloc.h>
X#endif
X#include "defines.h"
X#include "globals.h"
X#include "protos.h"
X
X/***************************************************************/
X/*                                                             */
X/*  TIMED.C                                                    */
X/*                                                             */
X/*  Contains routines for triggering timed reminders           */
X/*                                                             */
X/*  By David Skoll - 12 Nov 1990                               */
X/*                                                             */
X/*  (C) 1990 by David Skoll                                    */
X/*                                                             */
X/***************************************************************/
X
X/* Global pointer to AT reminders */
X 
Xstatic AtEntry AtQueue =
X{
X   0, 0, 0, 0, Unknown_t, NULL, NULL
X};
X
X/***************************************************************/
X/*                                                             */
X/*  AddEntry                                                   */
X/*                                                             */
X/*  Add an entry to the AT queue, keeping things sorted by     */
X/*  trigger time.                                              */
X/*                                                             */
X/*  Returns 0 for success, nonzero for failure                 */
X/*                                                             */
X/***************************************************************/
X#ifdef __STDC__
Xint AddEntry(AtEntry *e)
X#else
Xint AddEntry(e)
XAtEntry *e;
X#endif
X{
X   AtEntry *current, *prev;
X   prev = &AtQueue;
X   current = prev->next;
X   while (current) {
X      if (e->firsttime < current->firsttime) {
X         prev->next = e;
X         e->next = current;
X         break;
X      } else {
X         prev = current;
X         current = prev->next;
X      }
X   }
X   if (!current) {
X      prev->next = e;
X      e->next = NULL;
X   }
X}
X
X/***************************************************************/
X/*                                                             */
X/* DoAt                                                        */
X/* Creates an entry for an At reminder, puts it on the queue   */
X/* Updates the global variable NumAtsQueued                    */
X/*                                                             */
X/***************************************************************/
X#ifdef __STDC__
Xint DoAt(int tim, int tdelta, int trep, char *body, enum Token_t type)
X#else
Xint DoAt(tim, tdelta, trep, body, type)
Xint tim, tdelta, trep;
Xchar *body;
Xenum Token_t type;
X#endif
X{
X   AtEntry *e;
X   int curtime;
X
X   curtime = (int) (SystemTime() / 60);
X   
X   /* If the trigger time is in the past, don't add to the at queue */     
X   if (tim < curtime) return 0;
X
X   /* Allocate space for the entry */
X   e = (AtEntry *) malloc(sizeof(AtEntry));
X   if (e == (AtEntry *) NULL) {
X      Eprint("Can't malloc memory for AT!\n");
X      return 1;
X   }
X   e->text = malloc(strlen(body)+1);
X   if (e->text == NULL) {
X      Eprint("Can't malloc memory for body of AT!\n");
X      return 1;
X   }
X   strcpy(e->text, body);
X
X   /* Find out the next trigger time */
X   e->firsttime = FindNextTriggerTime(tim, trep, tdelta, curtime);
X   e->repeat    = trep;
X   e->type      = type;
X   e->time      = tim;
X   e->delta     = tdelta;
X   AddEntry(e);
X   NumAtsQueued++;
X   return 0;
X}
X
X/***************************************************************/
X/*                                                             */
X/* int FindNextTriggerTime                                     */
X/*                                                             */
X/* Returns the next time a queued AT should be triggered.      */
X/* Returns -1 if the AT has expired.                           */
X/*                                                             */
X/***************************************************************/
X#ifdef __STDC__
Xint FindNextTriggerTime(int tim, int rep, int delta, int curtime)
X#else
Xint FindNextTriggerTime(tim, rep, delta, curtime)
Xint tim, rep, delta, curtime;
X#endif
X{
X   int trigger = tim;
X   
X   if (delta <= 0)
X      if (trigger < curtime) return -1; else return trigger;
X   
X   trigger -= delta;
X   if (rep == -1) rep = delta;
X
X   if (trigger < curtime) trigger += ((curtime - trigger) / rep) * rep;
X   if (trigger < curtime) trigger += rep;
X   if (trigger > tim) trigger = tim;
X   if (trigger < curtime) return -1; else return trigger;
X}
X
X/***************************************************************/
X/*                                                             */
X/* HandleQueuedAts                                             */
X/*                                                             */
X/* Handles all the queued AT reminders.  Sits in a sleep loop  */
X/* to trigger reminders.                                       */
X/*                                                             */
X/***************************************************************/
X#ifdef __STDC__
Xvoid HandleQueuedAts(void)
X#else
Xvoid HandleQueuedAts()
X#endif
X{
X   AtEntry *e;
X   long TimeToSleep;
X   unsigned SleepTime;
X   long now;
X
X   signal(SIGINT, SigIntHandler);
X
X   while (e = AtQueue.next) {
X      now = SystemTime();
X      TimeToSleep = (long) e->firsttime * 60L - now;
X      if (TimeToSleep < 0L) TimeToSleep = 0L;
X
X      /* Be paranoid and assume that unsigneds are only two bytes long -
X         therefore, do the sleeping in 30000-second chunks. */
X
X      while (TimeToSleep) {
X         if (TimeToSleep > 30000L) SleepTime = 30000;
X                              else SleepTime = (unsigned) TimeToSleep;
X         sleep(SleepTime);
X         TimeToSleep -= (long) SleepTime;
X      }
X
X      /* Over here, we trigger the reminder */
X      DoSubst(e->text, WorkBuf, CurDay, CurMon, CurYear, JulianToday, e->type, e->time, 0);
X      if (e->type == Run_t) system(WorkBuf);
X      else printf("%s\n", WorkBuf);
X
X      /* Remove the entry from the queue */
X      AtQueue.next = e->next;
X
X      /* Check if this reminder should be re-triggered */
X      e->firsttime = FindNextTriggerTime(e->time, e->repeat, 
X                                        e->delta, e->firsttime + 1);
X
X      if (e->firsttime != -1) AddEntry(e);
X      else {
X      /* Not to be added - free the memory */
X         free(e->text);
X         free(e);
X      }
X   }
X}
X
X/***************************************************************/
X/*                                                             */
X/* SigIntHandler                                               */
X/*                                                             */
X/* For debugging purposes, when sent a SIGINT, we print the    */
X/* contents of the queue.                                      */
X/*                                                             */
X/***************************************************************/
Xvoid SigIntHandler()
X{
X   AtEntry *e;
X
X   printf("Contents of AT queue:\n");
X
X   e = AtQueue.next;
X   while (e) {
X      printf("Trigger: %02d:%02d  Activate: %02d:%02d  Rep: %d  Delta: %d\n",
X              e->time / 60, e->time % 60, e->firsttime / 60, e->firsttime % 60,
X              e->repeat, e->delta);
X      printf("Text: %s %s\n\n", ((e->type == Msg_t) ? "MSG" : "RUN"), e->text);
X      e = e->next;
X   }
X   printf("\n");
X}
SHAR_EOF
$TOUCH -am 0218130591 timed.c &&
chmod 0600 timed.c ||
echo "restore of timed.c failed"
set `wc -c timed.c`;Wc_c=$1
if test "$Wc_c" != "7484"; then
	echo original size 7484, current size $Wc_c
fi
fi
exit 0



More information about the Alt.sources mailing list