mirror of
https://github.com/GnoConsortium/gno.git
synced 2024-12-22 14:30:29 +00:00
calendar.1, calendar.c:
Updates for v1.1 as submitted by Marlin Allred. His comments: "I compiled calendar with the 2.0.6 libraries and fixed it so the date could be put anywhere on the line. I also fix[ed] the program so that tomorrow's and Monday's activity was also being listed. The man page for calendar was also updated. [...] I did not update the source file to indicate the changes made." calendar.desc: Updated for v1.1.
This commit is contained in:
parent
5a9733461b
commit
b40c451852
@ -1,21 +1,25 @@
|
|||||||
|
|
||||||
CALENDAR(1) CALENDAR(1)
|
.TH CALENDAR 1 "June 30, 1998"
|
||||||
|
|
||||||
NAME
|
.SH NAME
|
||||||
calendar - reminder service
|
.BR calendar
|
||||||
|
\- reminder service
|
||||||
SYNOPSIS
|
.SH SYNOPSIS
|
||||||
calendar
|
calendar
|
||||||
|
.SH DESCRIPTION
|
||||||
DESCRIPTION
|
.BR calendar
|
||||||
calendar consults the file calendar in the current directory and prints
|
consults the file calendar in the current directory
|
||||||
out lines that contain today's or tomorrow's date anywhere in the line.
|
and prints out lines that contain today's or tomorrow's date
|
||||||
Most reasonable month-day dates such as ``Aug. 24,'' ``august 24,''
|
anywhere in the line. Most reasonable month-day dates such as
|
||||||
``8/24,'' etc., are recognized, but not ``24 August'' or ``24/8''. On
|
Aug. 24, august 24, 8/24, and so on, are recognized, but not
|
||||||
weekends ``tomorrow'' extends through Monday.
|
24 August or 24/8. On weekends ``tomorrow'' extends through
|
||||||
|
Monday.
|
||||||
BUGS
|
.BR calendar
|
||||||
calendar's extended idea of ``tomorrow'' does not account for holidays.
|
can be invoked regularly by using the
|
||||||
|
crontab(1) or at(1) commands.
|
||||||
Page 1 Release 4.0.5 May 1992
|
.SH REFERENCES
|
||||||
|
at(1), cron(1M), crontab(1), date(1)
|
||||||
|
.SH NOTICES
|
||||||
|
.BR calendar's
|
||||||
|
extended idea of ``tomorrow'' does not account for
|
||||||
|
holidays.
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#pragma stacksize 512
|
#pragma stacksize 512
|
||||||
|
|
||||||
@ -16,11 +17,16 @@
|
|||||||
|
|
||||||
#define CALFILE "calendar"
|
#define CALFILE "calendar"
|
||||||
|
|
||||||
#define SECSPERDAY (24 * 60 * 60)
|
#define SECSPERDAY (24 * 60 * (long)60)
|
||||||
|
|
||||||
const char months[NMONTHS][] = {"jan", "feb", "mar", "apr", "may", "jun",
|
const char months[NMONTHS][4] = {"jan", "feb", "mar", "apr", "may", "jun",
|
||||||
"jul", "aug", "sep", "oct", "nov", "dec"};
|
"jul", "aug", "sep", "oct", "nov", "dec"};
|
||||||
|
|
||||||
|
#ifdef NODIFFTIME
|
||||||
|
#define difftime(x1,x2) (double)((x1) - (x2))
|
||||||
|
#endif /* Note that this is not necessarily portable, but works with */
|
||||||
|
/* some systems which don't have 'difftime' */
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
FILE *ifile;
|
FILE *ifile;
|
||||||
@ -30,52 +36,73 @@ int main(void)
|
|||||||
char *ptr1, *ptr2, holdmnth[4];
|
char *ptr1, *ptr2, holdmnth[4];
|
||||||
static char thislin[MAXLINELEN+1];
|
static char thislin[MAXLINELEN+1];
|
||||||
long deltat;
|
long deltat;
|
||||||
|
long ldayschk;
|
||||||
|
|
||||||
if ((ifile = fopen(CALFILE, "r")) == NULL) exit(0);
|
if ((ifile = fopen(CALFILE, "r")) == NULL) exit(0); /* Open calendar file
|
||||||
t1 = time(NULL);
|
in CWD. If there is none, exit successfully */
|
||||||
st1 = *localtime(&t1);
|
t1 = time(NULL); /* Get the current time */
|
||||||
st1.tm_sec = st1.tm_min = st1.tm_hour = 0;
|
st1 = *localtime(&t1); /* Convert to formatted date/time */
|
||||||
t1 = mktime(&st1);
|
st1.tm_sec = st1.tm_min = st1.tm_hour = 0; /* Pretend it's midnight, it
|
||||||
dayschk = (st1.tm_wday >= 5) ? 8 - st1.tm_wday : 1;
|
makes the checking later much easier */
|
||||||
|
t1 = mktime(&st1); /* Make an internal representation for that midnight
|
||||||
|
(the one which heralded today's date) */
|
||||||
|
dayschk = (st1.tm_wday >= 5) ? 8 - st1.tm_wday : 2; /* Check today and
|
||||||
|
tomorrow, unless tomorrow is on the weekend, in
|
||||||
|
which case we check up to and including Monday */
|
||||||
thislin[MAXLINELEN] = 0;
|
thislin[MAXLINELEN] = 0;
|
||||||
while (!feof(ifile)) {
|
while (!feof(ifile)) {
|
||||||
fgets(thislin, MAXLINELEN, 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 */
|
||||||
|
}
|
||||||
ptr1 = thislin;
|
ptr1 = thislin;
|
||||||
while (isspace(*ptr1) && *ptr1 != 0) ptr1++;
|
while (isspace(*ptr1) && *ptr1 != 0) ptr1++; /* Flush initial whitespace */
|
||||||
if (*ptr1 == 0) continue; /* Blank line */
|
if (*ptr1 == 0) continue; /* Blank line */
|
||||||
monthnum = -1;
|
monthnum = -1;
|
||||||
|
while (*ptr1) {
|
||||||
if (isdigit(*ptr1)) { /* month/day format */
|
if (isdigit(*ptr1)) { /* month/day format */
|
||||||
monthnum = strtoul(ptr1, &ptr2, 10) - 1;
|
monthnum = strtoul(ptr1, &ptr2, 10) - 1;
|
||||||
daynum = strtoul(ptr2+1, NULL, 10);
|
daynum = strtoul(ptr2+1, NULL, 10);
|
||||||
if (monthnum < 0 || monthnum >= NMONTHS || daynum < 0 || daynum > NDAYS)
|
/* We've now parsed a month/day format line */
|
||||||
continue;
|
if (monthnum && monthnum < NMONTHS && daynum && daynum <= NDAYS)
|
||||||
|
break; /* Valid date, print line of the file */
|
||||||
} else {
|
} else {
|
||||||
for (i=0; i<3; i++) holdmnth[i] = tolower(ptr1[i]);
|
for (i=0; i<3; i++) holdmnth[i] = tolower(ptr1[i]); /* make the search
|
||||||
|
case-insensitive */
|
||||||
holdmnth[3] = 0;
|
holdmnth[3] = 0;
|
||||||
for (i = 0; i < NMONTHS; i++)
|
for (i = 0; i < NMONTHS; i++)
|
||||||
if (!(strcmp(holdmnth, months[i]))) {
|
if (!(strcmp(holdmnth, months[i]))) {
|
||||||
monthnum = i;
|
monthnum = i; /* look for "jan", "feb", etc. */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (monthnum == -1) continue;
|
if (monthnum != -1) { /* found a valid month, get day */
|
||||||
while (!isspace(*ptr1) && *ptr1 != 0) ptr1++;
|
while (!isspace(*ptr1) && *ptr1 != 0) ptr1++; /* flush text */
|
||||||
if (*ptr1 == 0) continue;
|
if (*ptr1 == 0) break;
|
||||||
while (isspace(*ptr1) && *ptr1 != 0) ptr1++;
|
while (isspace(*ptr1) && *ptr1 != 0) ptr1++; /* flush whitespace */
|
||||||
if (*ptr1 == 0) continue;
|
if (*ptr1 == 0) break; /* No day number, go to next line in file */
|
||||||
daynum = atoi(ptr1);
|
daynum = atoi(ptr1); /* get day number */
|
||||||
if (daynum < 1 || daynum > NDAYS) continue;
|
if (daynum >= 1 && daynum <= NDAYS) break; /* Valid, go print line */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ptr1++;
|
||||||
}
|
}
|
||||||
st2.tm_sec = st2.tm_min = st2.tm_hour = st2.tm_isdst = 0;
|
st2.tm_sec = st2.tm_min = st2.tm_hour = st2.tm_isdst = 0;
|
||||||
st2.tm_mday = daynum;
|
st2.tm_mday = daynum;
|
||||||
st2.tm_mon = monthnum;
|
st2.tm_mon = monthnum;
|
||||||
st2.tm_year = st1.tm_year;
|
st2.tm_year = st1.tm_year;
|
||||||
t2 = mktime(&st2);
|
/* We've now set up the time for midnight at the
|
||||||
if ((deltat = difftime(t2, t1)) < 0) { /* Next year */
|
beginning of the day represented by the line we
|
||||||
|
found in the calendar file */
|
||||||
|
t2 = mktime(&st2); /* Change to internal format */
|
||||||
|
if ((deltat = difftime(t2, t1)) < 0) { /* The day was in the past, check
|
||||||
|
the same date next year */
|
||||||
st2.tm_year++;
|
st2.tm_year++;
|
||||||
t2 = mktime(&st2);
|
t2 = mktime(&st2);
|
||||||
deltat = difftime(t2, t1);
|
deltat = difftime(t2, t1);
|
||||||
}
|
}
|
||||||
if (deltat <= dayschk * SECSPERDAY) printf(thislin);
|
if (deltat <= dayschk * SECSPERDAY) printf(thislin);
|
||||||
|
/* print the entire line if it is inside our acceptance window */
|
||||||
}
|
}
|
||||||
fclose(ifile);
|
fclose(ifile);
|
||||||
exit(0);
|
exit(0);
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
Name: calendar
|
Name: calendar
|
||||||
Version: 1.0
|
Version: 1.1
|
||||||
Shell: GNO
|
Shell: GNO
|
||||||
Author: Christopher Neufeld
|
Author: Christopher Neufeld, Marlin Allred
|
||||||
Contact: neufeld@physics.utoronto.ca
|
Contact: neufeld@physics.utoronto.ca, Marlin.Allred@unisys.com
|
||||||
Where: /usr/local/games
|
Where: /usr/games
|
||||||
FTP: ftp.gno.org, ground.isca.uiowa.edu
|
FTP: ftp.gno.org
|
||||||
|
|
||||||
This program consults a calandar database, and prints out entries
|
This program consults a calandar database, and prints out entries
|
||||||
corresponding to today's or tomorrow's entries. On weekends, "tomorrow"
|
corresponding to today's or tomorrow's entries. On weekends, "tomorrow"
|
||||||
|
Loading…
Reference in New Issue
Block a user