Add two new options:

-W is like -A (number of days in the future to consider, but also
   specifies that we don't want special treatment at weekends.
-F changes our notion of "Friday" (the day before the weekend).

Arguably, calendar(1) is broken to have special treatment of weekends
by default, but this method maintains POLA.
This commit is contained in:
Greg Lehey 2002-06-13 21:20:56 +00:00
parent 76ce24fb29
commit b20a21a6c1
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=98181
4 changed files with 24 additions and 4 deletions

View File

@ -56,7 +56,8 @@ utility checks the current directory for a file named
.Pa calendar
and displays lines that begin with either today's date
or tomorrow's.
On Fridays, events on Friday through Monday are displayed.
On the day before a weekend (normally Friday), events for the next
three days are displayed.
.Pp
The following options are available:
.Bl -tag -width Ds
@ -72,6 +73,14 @@ days (forward, future).
Print lines from today and the previous
.Ar num
days (backward, past).
.It Fl F
Specify which day of the week is ``Friday'' (the day before the
weekend begins).
.It Fl W Ar num
Print lines from today and the next
.Ar num
days (forward, future).
Ignore weekends when calculating the number of days.
.It Fl f Pa calendarfile
Use
.Pa calendarfile

View File

@ -64,6 +64,7 @@ time_t f_time = 0;
int f_dayAfter = 0; /* days after current date */
int f_dayBefore = 0; /* days before current date */
int Friday = 5; /* day before weekend */
int
main(argc, argv)
@ -74,7 +75,7 @@ main(argc, argv)
(void) setlocale(LC_ALL, "");
while ((ch = getopt(argc, argv, "-af:t:A:B:")) != -1)
while ((ch = getopt(argc, argv, "-af:t:A:B:F:W:")) != -1)
switch (ch) {
case '-': /* backward contemptible */
case 'a':
@ -94,6 +95,10 @@ main(argc, argv)
f_time = Mktime (optarg);
break;
case 'W': /* we don't need no steenking Fridays */
Friday = -1;
/* FALLTHROUGH */
case 'A': /* days after current date */
f_dayAfter = atoi(optarg);
break;
@ -102,6 +107,10 @@ main(argc, argv)
f_dayBefore = atoi(optarg);
break;
case 'F':
Friday = atoi(optarg);
break;
case '?':
default:
usage();
@ -137,7 +146,8 @@ void
usage()
{
(void)fprintf(stderr,
"usage: calendar [-a] [-A days] [-B days] [-f calendarfile] [-t dd[.mm[.year]]]\n");
"usage: calendar [-a] [-A days] [-W days] [-F friday] [-B days]\n"
"\t[-f calendarfile] [-t dd[.mm[.year]]]\n");
exit(1);
}

View File

@ -67,6 +67,7 @@ void setnnames(void);
extern int f_dayAfter; /* days after current date */
extern int f_dayBefore; /* days bevore current date */
extern int Friday; /* day before weekend */
struct fixs {
char *name;

View File

@ -150,7 +150,7 @@ settime(now)
cumdays = daytab[0];
}
/* Friday displays Monday's events */
offset = tp->tm_wday == 5 ? 3 : 1;
offset = tp->tm_wday == Friday ? 3 : 1;
header[5].iov_base = dayname;
oldl = NULL;