home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2792 < prev    next >
Encoding:
Internet Message Format  |  1991-02-20  |  13.1 KB

  1. From: dfs@doe.carleton.ca (David F. Skoll)
  2. Newsgroups: alt.sources
  3. Subject: REMIND 2.3.0 4/4
  4. Message-ID: <dfs.666901162@data>
  5. Date: 18 Feb 91 18:19:22 GMT
  6.  
  7. #!/bin/sh
  8. # This is part 04 of Remind 2.3.0
  9. if touch 2>&1 | fgrep 'amc' > /dev/null
  10.  then TOUCH=touch
  11.  else TOUCH=true
  12. fi
  13. # ============= remind.mak ==============
  14. if test X"$1" != X"-c" -a -f 'remind.mak'; then
  15.     echo "File already exists: skipping 'remind.mak'"
  16. else
  17. echo "x - extracting remind.mak (Text)"
  18. sed 's/^X//' << 'SHAR_EOF' > remind.mak &&
  19. X# Simple-minded MAKE file.
  20. X
  21. XHEADERS = globals.h protos.h defines.h
  22. XWARN = /W3
  23. Xmain.obj: main.c $(HEADERS)
  24. X   cl $(WARN) /AS /Fomain.obj /c main.c
  25. X
  26. Xomits.obj: omits.c $(HEADERS)
  27. X   cl $(WARN) /AS /Foomits.obj /c omits.c
  28. X
  29. Xnextdate.obj: nextdate.c $(HEADERS)
  30. X   cl $(WARN) /AS /Fonextdate.obj /c nextdate.c
  31. X
  32. Xdorem.obj: dorem.c $(HEADERS)
  33. X   cl $(WARN) /AS /Fodorem.obj /c dorem.c
  34. X
  35. Xinit.obj: init.c $(HEADERS)
  36. X   cl $(WARN) /AS /Foinit.obj /c init.c
  37. X
  38. Xdosubst.obj: dosubst.c
  39. X   cl $(WARN) /AS /Fodosubst.obj /c dosubst.c
  40. X
  41. Xfiles.obj: files.c
  42. X   cl $(WARN) /AS /Fofiles.obj /c files.c
  43. X
  44. Xcalendar.obj: calendar.c
  45. X   cl $(WARN) /AS /Focalendar.obj /c calendar.c
  46. X
  47. Xcache.obj: cache.c
  48. X   cl $(WARN) /AS /Focache.obj /c cache.c
  49. X
  50. Xremind.exe: main.obj nextdate.obj dorem.obj init.obj dosubst.obj files.obj calendar.obj cache.obj omits.obj
  51. X   cl /Feremind.exe main.obj nextdate.obj dorem.obj init.obj dosubst.obj files.obj calendar.obj cache.obj omits.obj
  52. X
  53. SHAR_EOF
  54. $TOUCH -am 0218130591 remind.mak &&
  55. chmod 0600 remind.mak ||
  56. echo "restore of remind.mak failed"
  57. set `wc -c remind.mak`;Wc_c=$1
  58. if test "$Wc_c" != "940"; then
  59.     echo original size 940, current size $Wc_c
  60. fi
  61. fi
  62. # ============= test.rem ==============
  63. if test X"$1" != X"-c" -a -f 'test.rem'; then
  64.     echo "File already exists: skipping 'test.rem'"
  65. else
  66. echo "x - extracting test.rem (Text)"
  67. sed 's/^X//' << 'SHAR_EOF' > test.rem &&
  68. X# Test file for REMIND
  69. X#
  70. X# Use this file to test the date calculation routines
  71. X# of the REMIND program by typing:
  72. X#
  73. X# (UNIX version):
  74. X#     remind -dv test.rem 16 FEB 1991 >& temp 
  75. X#
  76. X# (DOS version):
  77. X#    e2o remind -dv test.rem 16 FEB 1991 > temp
  78. X#
  79. X# and comparing the results with test.out.
  80. X#
  81. X# The only differences should be the date of last
  82. X# modification/access
  83. X
  84. X# Test each possible case of the basic reminders.
  85. X
  86. XREM MSG Every Day
  87. X
  88. XREM 18 MSG Every 18th 
  89. XREM 15 MSG Every 15th
  90. X
  91. XREM Feb MSG February
  92. XREM Jan MSG January
  93. XREM March MSG March
  94. X
  95. XREM 13 Jan MSG 13 Jan
  96. XREM 15 Feb MSG 15 Feb
  97. XREM 28 Feb MSG 28 Feb
  98. XREM 29 Feb MSG 29 Feb
  99. XREM 5 Mar MSG 5 Mar
  100. X
  101. XREM 1990 MSG 1990
  102. XREM 1991 MSG 1991
  103. XREM 1992 MSG 1991
  104. X
  105. XREM 1 1990 MSG 1 1990
  106. XREM 29 1991 MSG 29 1991
  107. XREM 29 1992 MSG 29 1992
  108. XREM 16 1991 MSG 16 1991
  109. X
  110. XREM Jan 1990 MSG Jan 1990
  111. XREM Feb 1991 MSG Feb 1991
  112. XREM Dec 1991 MSG Dec 1991
  113. XREM May 1992 MSG May 1992
  114. X
  115. XREM 1 Jan 1991 MSG 1 Jan 1991
  116. XREM 16 Feb 1991 MSG 16 Feb 1991
  117. XREM 29 Dec 1992 MSG 29 Dec 1992
  118. X
  119. XREM Sun MSG Sun
  120. XREM Fri Sat Tue MSG Fri Sat Tue
  121. X
  122. XREM Sun 16 MSG Sun 16
  123. XREM Mon Tue Wed Thu Fri 1 MSG Mon Tue Wed Thu Fri 1
  124. X
  125. XREM Sun Feb MSG Sun Feb
  126. XREM Mon Tue March MSG Mon Tue March
  127. X
  128. XREM Sun 16 Feb MSG Sun 16 Feb
  129. XREM Mon Tue 10 March MSG Mon Tue 10 March
  130. X
  131. XREM Sat Sun 1991 MSG Sat Sun 1991
  132. XREM Mon Tue 1992 MSG Mon Tue 1992
  133. X
  134. XREM Sun 16 1991 MSG Sun 16 1991
  135. XREM Mon Tue Wed Thu Fri 1 1992 MSG Mon Tue Wed Thu Fri 1 1992
  136. X
  137. XREM Mon Feb 1991 MSG Mon Feb 1991
  138. XREM Tue Jan 1992 MSG Tue Jan 1992
  139. X
  140. XREM Sun Mon 16 Feb 1991 MSG Sun Mon 16 Feb 1991
  141. XREM Tue 28 Jan 1992 MSG Tue 28 Jan 1992
  142. X
  143. X# Try some Backs
  144. XCLEAR-OMIT-CONTEXT
  145. XREM 1 -1 OMIT sat sun MSG 1 -1 OMIT Sat Sun
  146. XREM 1 --1 OMIT sat sun MSG 1 --1 OMIT Sat Sun
  147. X
  148. XOMIT 28 Feb
  149. XREM 1 -1 OMIT sat sun MSG 1 -1 OMIT Sat Sun (28 Feb omitted)
  150. XREM 1 --1 OMIT sat sun MSG 1 --1 OMIT Sat Sun (28 Feb omitted)
  151. X
  152. XCLEAR-OMIT-CONTEXT
  153. X
  154. X# Try out UNTIL
  155. XREM Wed UNTIL 21 Feb 1991 MSG Wed UNTIL 21 Feb 1991
  156. X
  157. X# Try playing with the OMIT context
  158. X
  159. XOMIT 28 Feb 1991
  160. XREM 1 Mar -1 MSG 1 mar -1 (28feb91 omitted)
  161. XREM 1 Mar --1 MSG 1 mar --1 (28Feb91 omitted)
  162. XREM 28 Feb BEFORE MSG 28 Feb BEFORE (28Feb91 omitted)
  163. XREM 28 Feb SKIP MSG 28 Feb SKIP (28Feb91 omitted)
  164. XREM 28 Feb AFTER MSG 28 Feb AFTER (28Feb91 omitted)
  165. X
  166. XPUSH-OMIT-CONTEXT
  167. XCLEAR-OMIT-CONTEXT
  168. XREM 1 Mar -1 MSG 1 mar -1
  169. XREM 1 Mar --1 MSG 1 mar --1
  170. XREM 28 Feb BEFORE MSG 28 Feb BEFORE
  171. XREM 28 Feb SKIP MSG 28 Feb SKIP 
  172. XREM 28 Feb AFTER MSG 28 Feb AFTER
  173. X
  174. XPOP-OMIT-CONTEXT
  175. XREM 1 Mar -1 MSG 1 mar -1 (28feb91 omitted)
  176. XREM 1 Mar --1 MSG 1 mar --1 (28Feb91 omitted)
  177. XREM 28 Feb BEFORE MSG 28 Feb BEFORE (28Feb91 omitted)
  178. XREM 28 Feb SKIP MSG 28 Feb SKIP (28Feb91 omitted)
  179. XREM 28 Feb AFTER MSG 28 Feb AFTER (28Feb91 omitted)
  180. X
  181. X
  182. XREM 13 March 1991 *1 UNTIL 19 March 1991 MSG 13-19 Mar 91
  183. X# Test BACK
  184. XCLEAR-OMIT-CONTEXT
  185. XREM 18 Feb 1991 +1 MSG 18 Feb 1991 +1
  186. X
  187. XOMIT 17 Feb 1991
  188. XREM 18 Feb 1991 +1 MSG 18 Feb 1991 +1 (17Feb91 omitted)
  189. XREM 18 Feb 1991 ++1 MSG 18 Feb 1991 ++1 (17Feb91 omitted)
  190. X
  191. XCLEAR-OMIT-CONTEXT
  192. X
  193. SHAR_EOF
  194. $TOUCH -am 0218130591 test.rem &&
  195. chmod 0600 test.rem ||
  196. echo "restore of test.rem failed"
  197. set `wc -c test.rem`;Wc_c=$1
  198. if test "$Wc_c" != "2975"; then
  199.     echo original size 2975, current size $Wc_c
  200. fi
  201. fi
  202. # ============= timed.c ==============
  203. if test X"$1" != X"-c" -a -f 'timed.c'; then
  204.     echo "File already exists: skipping 'timed.c'"
  205. else
  206. echo "x - extracting timed.c (Text)"
  207. sed 's/^X//' << 'SHAR_EOF' > timed.c &&
  208. X#include <stdio.h>
  209. X#include <signal.h>
  210. X#include <string.h>
  211. X#ifndef NO_MALLOC_H
  212. X#include <malloc.h>
  213. X#endif
  214. X#include "defines.h"
  215. X#include "globals.h"
  216. X#include "protos.h"
  217. X
  218. X/***************************************************************/
  219. X/*                                                             */
  220. X/*  TIMED.C                                                    */
  221. X/*                                                             */
  222. X/*  Contains routines for triggering timed reminders           */
  223. X/*                                                             */
  224. X/*  By David Skoll - 12 Nov 1990                               */
  225. X/*                                                             */
  226. X/*  (C) 1990 by David Skoll                                    */
  227. X/*                                                             */
  228. X/***************************************************************/
  229. X
  230. X/* Global pointer to AT reminders */
  231. Xstatic AtEntry AtQueue =
  232. X{
  233. X   0, 0, 0, 0, Unknown_t, NULL, NULL
  234. X};
  235. X
  236. X/***************************************************************/
  237. X/*                                                             */
  238. X/*  AddEntry                                                   */
  239. X/*                                                             */
  240. X/*  Add an entry to the AT queue, keeping things sorted by     */
  241. X/*  trigger time.                                              */
  242. X/*                                                             */
  243. X/*  Returns 0 for success, nonzero for failure                 */
  244. X/*                                                             */
  245. X/***************************************************************/
  246. X#ifdef __STDC__
  247. Xint AddEntry(AtEntry *e)
  248. X#else
  249. Xint AddEntry(e)
  250. XAtEntry *e;
  251. X#endif
  252. X{
  253. X   AtEntry *current, *prev;
  254. X   prev = &AtQueue;
  255. X   current = prev->next;
  256. X   while (current) {
  257. X      if (e->firsttime < current->firsttime) {
  258. X         prev->next = e;
  259. X         e->next = current;
  260. X         break;
  261. X      } else {
  262. X         prev = current;
  263. X         current = prev->next;
  264. X      }
  265. X   }
  266. X   if (!current) {
  267. X      prev->next = e;
  268. X      e->next = NULL;
  269. X   }
  270. X}
  271. X
  272. X/***************************************************************/
  273. X/*                                                             */
  274. X/* DoAt                                                        */
  275. X/* Creates an entry for an At reminder, puts it on the queue   */
  276. X/* Updates the global variable NumAtsQueued                    */
  277. X/*                                                             */
  278. X/***************************************************************/
  279. X#ifdef __STDC__
  280. Xint DoAt(int tim, int tdelta, int trep, char *body, enum Token_t type)
  281. X#else
  282. Xint DoAt(tim, tdelta, trep, body, type)
  283. Xint tim, tdelta, trep;
  284. Xchar *body;
  285. Xenum Token_t type;
  286. X#endif
  287. X{
  288. X   AtEntry *e;
  289. X   int curtime;
  290. X
  291. X   curtime = (int) (SystemTime() / 60);
  292. X   
  293. X   /* If the trigger time is in the past, don't add to the at queue */     
  294. X   if (tim < curtime) return 0;
  295. X
  296. X   /* Allocate space for the entry */
  297. X   e = (AtEntry *) malloc(sizeof(AtEntry));
  298. X   if (e == (AtEntry *) NULL) {
  299. X      Eprint("Can't malloc memory for AT!\n");
  300. X      return 1;
  301. X   }
  302. X   e->text = malloc(strlen(body)+1);
  303. X   if (e->text == NULL) {
  304. X      Eprint("Can't malloc memory for body of AT!\n");
  305. X      return 1;
  306. X   }
  307. X   strcpy(e->text, body);
  308. X
  309. X   /* Find out the next trigger time */
  310. X   e->firsttime = FindNextTriggerTime(tim, trep, tdelta, curtime);
  311. X   e->repeat    = trep;
  312. X   e->type      = type;
  313. X   e->time      = tim;
  314. X   e->delta     = tdelta;
  315. X   AddEntry(e);
  316. X   NumAtsQueued++;
  317. X   return 0;
  318. X}
  319. X
  320. X/***************************************************************/
  321. X/*                                                             */
  322. X/* int FindNextTriggerTime                                     */
  323. X/*                                                             */
  324. X/* Returns the next time a queued AT should be triggered.      */
  325. X/* Returns -1 if the AT has expired.                           */
  326. X/*                                                             */
  327. X/***************************************************************/
  328. X#ifdef __STDC__
  329. Xint FindNextTriggerTime(int tim, int rep, int delta, int curtime)
  330. X#else
  331. Xint FindNextTriggerTime(tim, rep, delta, curtime)
  332. Xint tim, rep, delta, curtime;
  333. X#endif
  334. X{
  335. X   int trigger = tim;
  336. X   
  337. X   if (delta <= 0)
  338. X      if (trigger < curtime) return -1; else return trigger;
  339. X   
  340. X   trigger -= delta;
  341. X   if (rep == -1) rep = delta;
  342. X
  343. X   if (trigger < curtime) trigger += ((curtime - trigger) / rep) * rep;
  344. X   if (trigger < curtime) trigger += rep;
  345. X   if (trigger > tim) trigger = tim;
  346. X   if (trigger < curtime) return -1; else return trigger;
  347. X}
  348. X
  349. X/***************************************************************/
  350. X/*                                                             */
  351. X/* HandleQueuedAts                                             */
  352. X/*                                                             */
  353. X/* Handles all the queued AT reminders.  Sits in a sleep loop  */
  354. X/* to trigger reminders.                                       */
  355. X/*                                                             */
  356. X/***************************************************************/
  357. X#ifdef __STDC__
  358. Xvoid HandleQueuedAts(void)
  359. X#else
  360. Xvoid HandleQueuedAts()
  361. X#endif
  362. X{
  363. X   AtEntry *e;
  364. X   long TimeToSleep;
  365. X   unsigned SleepTime;
  366. X   long now;
  367. X
  368. X   signal(SIGINT, SigIntHandler);
  369. X
  370. X   while (e = AtQueue.next) {
  371. X      now = SystemTime();
  372. X      TimeToSleep = (long) e->firsttime * 60L - now;
  373. X      if (TimeToSleep < 0L) TimeToSleep = 0L;
  374. X
  375. X      /* Be paranoid and assume that unsigneds are only two bytes long -
  376. X         therefore, do the sleeping in 30000-second chunks. */
  377. X
  378. X      while (TimeToSleep) {
  379. X         if (TimeToSleep > 30000L) SleepTime = 30000;
  380. X                              else SleepTime = (unsigned) TimeToSleep;
  381. X         sleep(SleepTime);
  382. X         TimeToSleep -= (long) SleepTime;
  383. X      }
  384. X
  385. X      /* Over here, we trigger the reminder */
  386. X      DoSubst(e->text, WorkBuf, CurDay, CurMon, CurYear, JulianToday, e->type, e->time, 0);
  387. X      if (e->type == Run_t) system(WorkBuf);
  388. X      else printf("%s\n", WorkBuf);
  389. X
  390. X      /* Remove the entry from the queue */
  391. X      AtQueue.next = e->next;
  392. X
  393. X      /* Check if this reminder should be re-triggered */
  394. X      e->firsttime = FindNextTriggerTime(e->time, e->repeat, 
  395. X                                        e->delta, e->firsttime + 1);
  396. X
  397. X      if (e->firsttime != -1) AddEntry(e);
  398. X      else {
  399. X      /* Not to be added - free the memory */
  400. X         free(e->text);
  401. X         free(e);
  402. X      }
  403. X   }
  404. X}
  405. X
  406. X/***************************************************************/
  407. X/*                                                             */
  408. X/* SigIntHandler                                               */
  409. X/*                                                             */
  410. X/* For debugging purposes, when sent a SIGINT, we print the    */
  411. X/* contents of the queue.                                      */
  412. X/*                                                             */
  413. X/***************************************************************/
  414. Xvoid SigIntHandler()
  415. X{
  416. X   AtEntry *e;
  417. X
  418. X   printf("Contents of AT queue:\n");
  419. X
  420. X   e = AtQueue.next;
  421. X   while (e) {
  422. X      printf("Trigger: %02d:%02d  Activate: %02d:%02d  Rep: %d  Delta: %d\n",
  423. X              e->time / 60, e->time % 60, e->firsttime / 60, e->firsttime % 60,
  424. X              e->repeat, e->delta);
  425. X      printf("Text: %s %s\n\n", ((e->type == Msg_t) ? "MSG" : "RUN"), e->text);
  426. X      e = e->next;
  427. X   }
  428. X   printf("\n");
  429. X}
  430. SHAR_EOF
  431. $TOUCH -am 0218130591 timed.c &&
  432. chmod 0600 timed.c ||
  433. echo "restore of timed.c failed"
  434. set `wc -c timed.c`;Wc_c=$1
  435. if test "$Wc_c" != "7484"; then
  436.     echo original size 7484, current size $Wc_c
  437. fi
  438. fi
  439. exit 0
  440.