Add global OMIT of the form:

OMIT wkday [wkday...]

For example:  OMIT Saturday Sunday
This commit is contained in:
Dianne Skoll
2022-10-05 14:12:53 -04:00
parent 588d9debe8
commit fba9f139ed
7 changed files with 707 additions and 634 deletions

View File

@@ -1562,6 +1562,10 @@ In addition to being a keyword in the \fBREM\fR command,
\fBOMIT\fR is a command in its own right. Its syntax is:
.PP
.RS
\fBOMIT\fR \fIweekday\fR [\fIweekday\fR...]
.PP
or:
.PP
\fBOMIT\fR [\fIday\fR] \fImonth\fR [\fIyear\fR]
.PP
or:
@@ -1575,6 +1579,7 @@ The \fBOMIT\fR command is used to "globally" omit certain days
"\-\-" and "\+\+" forms. Some examples:
.PP
.nf
OMIT Saturday Sunday
OMIT 1 Jan
OMIT 7 Sep 1992
OMIT 15 Jan THROUGH 14 Feb
@@ -1584,8 +1589,13 @@ The \fBOMIT\fR command is used to "globally" omit certain days
OMIT Jun THROUGH July # Equivalent to OMIT Jun 1 THROUGH July 31
.fi
.PP
The first example specifies a holiday that occurs on the same date each
year - New Year's Day. The second example specifies a holiday that
The first example omits every Saturday and Sunday. This is useful for
reminders that shouldn't trigger on weekends.
.PP
The second example specifies a holiday that occurs on the same date each
year - New Year's Day.
.PP
The third example specifies a holiday that
changes each year - Labour Day. For these types of holidays, you
must create an \fBOMIT\fR command for each year. (Later, in the
description of expressions and some of the more advanced features of

View File

@@ -3004,11 +3004,11 @@ FSlide(func_info *info)
}
/* If ALL weekdays are omitted... barf! */
if (localomit == 127 && amt != 0) return E_2MANY_LOCALOMIT;
if ((WeekdayOmits | localomit) == 0x7F && amt != 0) return E_2MANY_LOCALOMIT;
if (amt > 0) {
while(amt) {
d++;
r = IsOmitted(d, localomit, NULL,&omit);
r = IsOmitted(d, localomit, NULL, &omit);
if (r) return r;
if (!omit) amt--;
}
@@ -3016,7 +3016,7 @@ FSlide(func_info *info)
while(amt) {
d--;
if (d < 0) return E_DATE_OVER;
r = IsOmitted(d, localomit, NULL,&omit);
r = IsOmitted(d, localomit, NULL, &omit);
if (r) return r;
if (!omit) amt++;
}

View File

@@ -80,6 +80,7 @@ EXTERN INIT( long SysTime, -1L);
EXTERN char const *InitialFile;
EXTERN int FileAccessDate;
EXTERN INIT( int WeekdayOmits, 0);
EXTERN INIT( int DontSuppressQuoteMarkers, 0);
EXTERN INIT( int DontFork, 0);
EXTERN INIT( int DontQueue, 0);

View File

@@ -28,6 +28,8 @@ static void InsertIntoSortedArray (int *array, int num, int key);
static int FullOmitArray[MAX_FULL_OMITS];
static int PartialOmitArray[MAX_PARTIAL_OMITS];
/* WeekdayOmits is declared in global.h */
/* How many of each omit types do we have? */
static int NumFullOmits, NumPartialOmits;
@@ -37,6 +39,7 @@ typedef struct omitcontext {
int numfull, numpart;
int *fullsave;
int *partsave;
int weekdaysave;
} OmitContext;
/* The stack of saved omit contexts */
@@ -52,6 +55,7 @@ static OmitContext *SavedOmitContexts = NULL;
int ClearGlobalOmits(void)
{
NumFullOmits = NumPartialOmits = 0;
WeekdayOmits = 0;
return OK;
}
@@ -113,6 +117,7 @@ int PushOmitContext(ParsePtr p)
context->numfull = NumFullOmits;
context->numpart = NumPartialOmits;
context->weekdaysave = WeekdayOmits;
context->fullsave = malloc(NumFullOmits * sizeof(int));
if (NumFullOmits && !context->fullsave) {
free(context);
@@ -154,6 +159,7 @@ int PopOmitContext(ParsePtr p)
if (!c) return E_POP_NO_PUSH;
NumFullOmits = c->numfull;
NumPartialOmits = c->numpart;
WeekdayOmits = c->weekdaysave;
/* Copy the context over */
for (i=0; i<NumFullOmits; i++)
@@ -213,6 +219,12 @@ int IsOmitted(int jul, int localomit, char const *omitfunc, int *omit)
return OK;
}
/* Is it omitted because of global weekday omits? */
if (WeekdayOmits & (1 << (jul % 7))) {
*omit = 1;
return OK;
}
/* Is it omitted because of fully-specified omits? */
if (BexistsIntArray(FullOmitArray, NumFullOmits, jul)) {
*omit = 1;
@@ -289,6 +301,7 @@ int DoOmit(ParsePtr p)
int syndrome;
int not_first_token = -1;
int start, end, tmp;
int wd = 0;
int mc, dc;
@@ -301,9 +314,15 @@ int DoOmit(ParsePtr p)
if ( (r=ParseToken(p, &buf)) ) return r;
FindToken(DBufValue(&buf), &tok);
switch (tok.type) {
case T_Dumpvars:
if (not_first_token) return E_PARSE_ERR;
case T_WkDay:
DBufFree(&buf);
if (wd & (1 << tok.val)) return E_WD_TWICE;
wd |= (1 << tok.val);
break;
case T_Dumpvars:
DBufFree(&buf);
if (not_first_token) return E_PARSE_ERR;
r = VerifyEoln(p);
if (r != OK) return r;
DumpOmits();
@@ -341,6 +360,7 @@ int DoOmit(ParsePtr p)
case T_Through:
DBufFree(&buf);
if (wd) return E_PARSE_ERR;
if (seen_through) return E_UNTIL_TWICE;
seen_through = 1;
break;
@@ -363,6 +383,18 @@ int DoOmit(ParsePtr p)
}
}
if (wd) {
if (y[0] != NO_YR || m[0] != NO_MON || d[0] != NO_DAY) {
return E_PARSE_ERR;
}
if ((WeekdayOmits | wd) == 0x7F) {
return E_2MANY_LOCALOMIT;
}
WeekdayOmits |= wd;
if (tok.type == T_Tag || tok.type == T_Duration || tok.type == T_RemType || tok.type == T_Priority) return E_PARSE_AS_REM;
return OK;
}
if (!seen_through) {
/* We must have at least a month */
if (m[0] == NO_MON) return E_SPEC_MON;
@@ -482,5 +514,15 @@ DumpOmits(void)
printf("\t%02d%c%02d\n", m+1, DateSep, d);
}
}
printf("Globally omitted weekdays:\n");
if (WeekdayOmits == 0) {
printf("\tNone.\n");
} else {
for (i=0; i<7; i++) {
if (WeekdayOmits & (1<<i)) {
printf("\t%s\n", DynamicDayName[i]);
}
}
}
}

View File

@@ -530,7 +530,7 @@ int ComputeTriggerNoAdjustDuration(int today, Trigger *trig, TimeTrig *tim,
*err = OK;
/* But check for obvious problems... */
if (trig->localomit == 1 + 2 + 4 + 8 + 16 + 32 + 64) {
if ((WeekdayOmits | trig->localomit) == 0x7F) {
*err = E_2MANY_LOCALOMIT;
return -1;
}

File diff suppressed because it is too large Load Diff

View File

@@ -146,8 +146,14 @@ REM Tue 28 Jan 1992 MSG Tue 28 Jan 1992
# Try some Backs
CLEAR-OMIT-CONTEXT
REM 1 -1 OMIT sat sun MSG 1 -1 OMIT Sat Sun
REM 1 --1 OMIT sat sun MSG 1 --1 OMIT Sat Sun
REM 1 -1 OMIT thu MSG 1 -1 OMIT Thu
REM 1 --1 OMIT thu MSG 1 --1 OMIT Thu
PUSH-OMIT-CONTEXT
OMIT Thu
REM 1 -1 MSG 1 -1 OMIT Thu globally
REM 1 --1 MSG 1 --1 OMIT Thu globally
POP-OMIT-CONTEXT
OMIT 28 Feb
REM 1 -1 OMIT sat sun MSG 1 -1 OMIT Sat Sun (28 Feb omitted)