From 3689484d240d075efd1fe02a6be045194dccf578 Mon Sep 17 00:00:00 2001 From: gdr-ftp Date: Tue, 7 Jul 1998 02:14:30 +0000 Subject: [PATCH] calendar.c: - fixed a bug introduced in 1.1 where getting an error while reading the calandar file could cause an infinite loop - added "ChangeLog" comments for all versions - added stack checking - eliminated "pragma stacksize" from the source file; it was too small (was 512 bytes, currently using 862 bytes) and overriding the value given on the command line during the GNO base build process README, calendar.info: - Moved the information in these files to the man page. Makefile, calendar.rez: - initial checkin calendar.1: - cleaned it up a bit and made it conform to the GNO base builds - added an example --- usr.bin/calendar/Makefile | 9 +++++ usr.bin/calendar/README | 4 -- usr.bin/calendar/calendar.1 | 70 +++++++++++++++++++++++++--------- usr.bin/calendar/calendar.c | 56 +++++++++++++++++++++------ usr.bin/calendar/calendar.info | 2 - usr.bin/calendar/calendar.rez | 29 ++++++++++++++ 6 files changed, 135 insertions(+), 35 deletions(-) create mode 100644 usr.bin/calendar/Makefile delete mode 100644 usr.bin/calendar/README delete mode 100644 usr.bin/calendar/calendar.info create mode 100644 usr.bin/calendar/calendar.rez diff --git a/usr.bin/calendar/Makefile b/usr.bin/calendar/Makefile new file mode 100644 index 0000000..d557487 --- /dev/null +++ b/usr.bin/calendar/Makefile @@ -0,0 +1,9 @@ +# +# $Id: Makefile,v 1.1 1998/07/07 02:14:29 gdr-ftp Exp $ +# + +PROG = calendar +BINDIR = /usr/games +STACK = 1024 # observed: 862 + +.INCLUDE: /src/gno/prog.mk diff --git a/usr.bin/calendar/README b/usr.bin/calendar/README deleted file mode 100644 index 7f88a1d..0000000 --- a/usr.bin/calendar/README +++ /dev/null @@ -1,4 +0,0 @@ -To install the calendar program, create a file called "Calendar" in your -home directory, and put a line: -:bin:calendar -in your "gshrc" file. diff --git a/usr.bin/calendar/calendar.1 b/usr.bin/calendar/calendar.1 index 19a3506..4c2aa41 100644 --- a/usr.bin/calendar/calendar.1 +++ b/usr.bin/calendar/calendar.1 @@ -1,25 +1,61 @@ - -.TH CALENDAR 1 "June 30, 1998" - -.SH NAME +.\" +.\" $Id: calendar.1,v 1.3 1998/07/07 02:14:29 gdr-ftp Exp $ +.\" +.TH CALENDAR 1 "6 July 1998" GNO "Commands and Applications" +.SH NAME .BR calendar \- reminder service -.SH SYNOPSIS +.SH SYNOPSIS calendar -.SH DESCRIPTION +.SH DESCRIPTION .BR calendar -consults the file calendar in the current directory +consults the file +.B calendar +in the current directory and prints out lines that contain today's or tomorrow's date anywhere in the line. Most reasonable month-day dates such as -Aug. 24, august 24, 8/24, and so on, are recognized, but not -24 August or 24/8. On weekends ``tomorrow'' extends through -Monday. +.IR "Aug. 24" , +.IR "august 24" , +.IR "8/24", +and so on, are recognized, but not +.IR "24 August" +or +.IR "24/8" . +On weekends ``tomorrow'' extends through Monday. .BR calendar can be invoked regularly by using the -crontab(1) or at(1) commands. -.SH REFERENCES -at(1), cron(1M), crontab(1), date(1) -.SH NOTICES -.BR calendar's -extended idea of ``tomorrow'' does not account for -holidays. +.BR crontab (1) +or +.BR at (1) +commands. +.SH EXAMPLE +A common way to run +.BR calendar +is to have the following line in your +.B gshrc +file: +.nf + + /usr/games/calendar + +.fi +If the file $HOME/calendar contains entries like +.nf + + Dec 25 No more shopping days until Christmas. + Jul 1 Dominion Day (Canada). + +.fi +then the appropriate calendar entries will be printed every time you +login in. +.SH CAVEATS +.BR calendar 's +extended idea of ``tomorrow'' does not account for holidays. +.SH "SEE ALSO" +.BR at (1), +.BR cron (1), +.BR crontab (1), +.BR date (1) +.SH AUTHOR +Written for GNO by Christopher Neufeld. +Updated by Marlin Allred. diff --git a/usr.bin/calendar/calendar.c b/usr.bin/calendar/calendar.c index 0a2f7b7..99b43a2 100644 --- a/usr.bin/calendar/calendar.c +++ b/usr.bin/calendar/calendar.c @@ -1,6 +1,32 @@ -/* Calendar file v1.0. Copyright 1994 by Christopher Neufeld */ -/* The executable for this file contains linked runtime libraries - copyrighted by The Byte Works. Used with permission. */ +/* + * Calendar file v1.0. Copyright 1994-1998 by Christopher Neufeld + * + * The executable for this file contains linked runtime libraries + * copyrighted by The Byte Works. Used with permission. + * + * Change Log: + * + * 1.0 -- [Christopher Neufeld, 1994] Initial version. + * + * 1.1 -- [Marlin Allred, 1 Jul 1998] + * + the date can now appear anywhere on the line + * + on the weekend, Monday events are also listed + * + man page was converted from preformatted ASCII to nroff source + * + binary linked with the v2.0.6 libraries + * + * 1.2 -- [Devin Reade, 6 Jul 1998] + * + fixed a bug introduced in 1.1 where getting an error while + * reading the calandar file could cause an infinite loop + * + added the describe entry and resource fork + * + added these "ChangeLog" comments for all versions + * + added this program to the GNO base distribution + * + eliminated "pragma stacksize" from the source file; it was too + * small (was 512 bytes, currently using 862 bytes) and overriding + * the value given on the command line during the GNO base build + * process + * + * $Id: calendar.c,v 1.3 1998/07/07 02:14:30 gdr-ftp Exp $ + */ #include #include @@ -8,8 +34,10 @@ #include #include #include - -#pragma stacksize 512 +#include +#ifdef __GNO__ +#include +#endif #define NMONTHS 12 #define NDAYS 31 @@ -31,13 +59,17 @@ int main(void) { FILE *ifile; time_t t1, t2; - struct tm st1, st2; + static struct tm st1, st2; int monthnum, daynum, dayschk, i, j; char *ptr1, *ptr2, holdmnth[4]; static char thislin[MAXLINELEN+1]; long deltat; long ldayschk; +#ifdef __GNO__ + __REPORT_STACK(); +#endif + if ((ifile = fopen(CALFILE, "r")) == NULL) exit(0); /* Open calendar file in CWD. If there is none, exit successfully */ t1 = time(NULL); /* Get the current time */ @@ -50,12 +82,9 @@ int main(void) tomorrow, unless tomorrow is on the weekend, in which case we check up to and including Monday */ thislin[MAXLINELEN] = 0; - while (!feof(ifile)) { - if (fgets(thislin, MAXLINELEN, ifile) == NULL) { /* Get a line from the calendar file */ - if (feof(ifile)) break; /* Didn't read a line, if we're done, quit */ - fprintf(stderr, "Can't happen\n"); - continue; /* Something funny happened on the read */ - } + + /* Get each line from the calendar file */ + while (fgets(thislin, MAXLINELEN, ifile) != NULL) { ptr1 = thislin; while (isspace(*ptr1) && *ptr1 != 0) ptr1++; /* Flush initial whitespace */ if (*ptr1 == 0) continue; /* Blank line */ @@ -104,6 +133,9 @@ int main(void) if (deltat <= dayschk * SECSPERDAY) printf(thislin); /* print the entire line if it is inside our acceptance window */ } + if (ferror(ifile)) { + err(1, "error while reading %s", CALFILE); + } fclose(ifile); exit(0); } diff --git a/usr.bin/calendar/calendar.info b/usr.bin/calendar/calendar.info deleted file mode 100644 index 1fbe10f..0000000 --- a/usr.bin/calendar/calendar.info +++ /dev/null @@ -1,2 +0,0 @@ -Dec 25 No more shopping days until Christmas. -Jul 1 A Canadian holiday diff --git a/usr.bin/calendar/calendar.rez b/usr.bin/calendar/calendar.rez new file mode 100644 index 0000000..7b59cd6 --- /dev/null +++ b/usr.bin/calendar/calendar.rez @@ -0,0 +1,29 @@ +/* + * $Id: calendar.rez,v 1.1 1998/07/07 02:14:30 gdr-ftp Exp $ + */ + +#define PROG "calendar" +#define DESC "Prints out upcoming events." + +#include "Types.rez" + +/* + * Version + */ +resource rVersion (1, purgeable3) { + { 1, 2, 0, /* Version */ + release, /* development|alpha|beta|final|release */ + 0 }, /* non-final release number */ + verUS, /* Country */ + PROG, /* Program name */ + DESC " Released with GNO/ME." +}; + + +/* + * Comment + */ +resource rComment (1, purgeable3) { + PROG " v1.2 (6 July 1998)\n" + "GNO utility: " DESC +};