Play with calendar syntax a little, allowing both of month and day
to be wildcarded. As a side effect, this allows '**' in the date field to match every day of the year, which is very useful for TODO items. It's important to note that the syntax has a lot of hardcoded (and undocumented) ambiguity resolution stuff, and is crying out for a simplification, and maybe some use of yacc and lex. When this is done, a minor flag day (and probably a compatibility flag :-( ) should be included, for current users who are making use of some of the corner cases. I'll raise this on tech-userlevel before going there. CVS: ----------------------------------------------------------------------
This commit is contained in:
parent
568c053401
commit
4f1d9bdb73
|
@ -1,4 +1,4 @@
|
||||||
.\" $NetBSD: calendar.1,v 1.19 2004/11/30 10:41:20 wiz Exp $
|
.\" $NetBSD: calendar.1,v 1.20 2004/12/06 20:38:43 jwise Exp $
|
||||||
.\"
|
.\"
|
||||||
.\" Copyright (c) 1989, 1990, 1993
|
.\" Copyright (c) 1989, 1990, 1993
|
||||||
.\" The Regents of the University of California. All rights reserved.
|
.\" The Regents of the University of California. All rights reserved.
|
||||||
|
@ -119,7 +119,10 @@ They may be entered in almost any format, either numeric or as character
|
||||||
strings.
|
strings.
|
||||||
A single asterisk
|
A single asterisk
|
||||||
.Pq Sq *
|
.Pq Sq *
|
||||||
matches every month.
|
matches every month, or every day if a month has been provided. This means
|
||||||
|
that two asterisks
|
||||||
|
.Pq Sq **
|
||||||
|
matches every day of the year, and is thus useful for ToDo tasks.
|
||||||
A day without a month matches that day of every week.
|
A day without a month matches that day of every week.
|
||||||
A month without a day matches the first of that month.
|
A month without a day matches the first of that month.
|
||||||
Two numbers default to the month followed by the day.
|
Two numbers default to the month followed by the day.
|
||||||
|
@ -154,6 +157,9 @@ Jun. 15 ... June 15.
|
||||||
Thursday ... Every Thursday.
|
Thursday ... Every Thursday.
|
||||||
June ... Every June 1st.
|
June ... Every June 1st.
|
||||||
15 * ... 15th of every month.
|
15 * ... 15th of every month.
|
||||||
|
*15 ... 15th of every month.
|
||||||
|
June* ... Every day of June.
|
||||||
|
** ... Every day
|
||||||
.Ed
|
.Ed
|
||||||
.Sh FILES
|
.Sh FILES
|
||||||
The following default calendar files are provided:
|
The following default calendar files are provided:
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: calendar.c,v 1.34 2004/11/30 10:39:53 wiz Exp $ */
|
/* $NetBSD: calendar.c,v 1.35 2004/12/06 20:38:43 jwise Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1989, 1993, 1994
|
* Copyright (c) 1989, 1993, 1994
|
||||||
|
@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 1993\n\
|
||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)calendar.c 8.4 (Berkeley) 1/7/95";
|
static char sccsid[] = "@(#)calendar.c 8.4 (Berkeley) 1/7/95";
|
||||||
#endif
|
#endif
|
||||||
__RCSID("$NetBSD: calendar.c,v 1.34 2004/11/30 10:39:53 wiz Exp $");
|
__RCSID("$NetBSD: calendar.c,v 1.35 2004/12/06 20:38:43 jwise Exp $");
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
@ -245,7 +245,11 @@ isnow(endp)
|
||||||
|
|
||||||
#define F_ISMONTH 0x01
|
#define F_ISMONTH 0x01
|
||||||
#define F_ISDAY 0x02
|
#define F_ISDAY 0x02
|
||||||
|
#define F_WILDMONTH 0x04
|
||||||
|
#define F_WILDDAY 0x08
|
||||||
|
|
||||||
flags = 0;
|
flags = 0;
|
||||||
|
|
||||||
/* didn't recognize anything, skip it */
|
/* didn't recognize anything, skip it */
|
||||||
if (!(v1 = getfield(endp, &endp, &flags)))
|
if (!(v1 = getfield(endp, &endp, &flags)))
|
||||||
return (0);
|
return (0);
|
||||||
|
@ -270,6 +274,16 @@ isnow(endp)
|
||||||
day = v2 ? v2 : 1;
|
day = v2 ? v2 : 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (flags & (F_WILDMONTH|F_WILDDAY))
|
||||||
|
return (1);
|
||||||
|
|
||||||
|
if ((flags & (F_WILDMONTH|F_ISDAY)) && (day == tp->tm_mday))
|
||||||
|
return (1);
|
||||||
|
|
||||||
|
if ((flags & (F_ISMONTH|F_WILDDAY)) && (month == tp->tm_mon + 1))
|
||||||
|
return (1);
|
||||||
|
|
||||||
if (flags & F_ISDAY)
|
if (flags & F_ISDAY)
|
||||||
day = tp->tm_mday + (((day - 1) - tp->tm_wday + 7) % 7);
|
day = tp->tm_mday + (((day - 1) - tp->tm_wday + 7) % 7);
|
||||||
day = cumdays[month] + day;
|
day = cumdays[month] + day;
|
||||||
|
@ -297,9 +311,15 @@ getfield(p, endp, flags)
|
||||||
for (; FLDCHAR(*p); ++p)
|
for (; FLDCHAR(*p); ++p)
|
||||||
continue;
|
continue;
|
||||||
if (*p == '*') { /* `*' is current month */
|
if (*p == '*') { /* `*' is current month */
|
||||||
*flags |= F_ISMONTH;
|
if (!(*flags & F_ISMONTH)) {
|
||||||
*endp = p+1;
|
*flags |= F_ISMONTH|F_WILDMONTH;
|
||||||
return (tp->tm_mon + 1);
|
*endp = p+1;
|
||||||
|
return (tp->tm_mon + 1);
|
||||||
|
} else {
|
||||||
|
*flags |= F_ISDAY|F_WILDDAY;
|
||||||
|
*endp = p+1;
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (isdigit((unsigned char)*p)) {
|
if (isdigit((unsigned char)*p)) {
|
||||||
val = strtol(p, &p, 10); /* if 0, it's failure */
|
val = strtol(p, &p, 10); /* if 0, it's failure */
|
||||||
|
|
Loading…
Reference in New Issue