Compare commits

...

3 Commits

Author SHA1 Message Date
Dianne Skoll 7041e2cad8 Avoid warnings.
Remind unit tests / tests (push) Successful in 25s
2024-11-08 20:46:19 -05:00
Dianne Skoll b1b21e21b3 Untabify language files. 2024-11-08 20:42:00 -05:00
Dianne Skoll 533718b0a0 Massive whitespace cleanups: Untabify everything. 2024-11-08 20:30:13 -05:00
38 changed files with 7234 additions and 7239 deletions
+946 -947
View File
File diff suppressed because it is too large Load Diff
+795 -795
View File
File diff suppressed because it is too large Load Diff
+84 -84
View File
@@ -93,7 +93,7 @@ int DoSubst(ParsePtr p, DynamicBuffer *dbuf, Trigger *t, TimeTrig *tt, int dse,
mdiff = adiff % 60;
hdiff = adiff / 60;
#ifdef L_MPLU_OVER
#ifdef L_MPLU_OVER
L_MPLU_OVER
#else /* L_MPLU_OVER */
mplu = (mdiff == 1 ? "" : DynamicMplu);
@@ -205,47 +205,47 @@ int DoSubst(ParsePtr p, DynamicBuffer *dbuf, Trigger *t, TimeTrig *tt, int dse,
#endif
while(1) {
c = ParseChar(p, &err, 0);
if (err) {
DBufFree(dbuf);
return err;
}
if (c == '\n') continue;
if (!c) {
if (AddBlankLines &&
c = ParseChar(p, &err, 0);
if (err) {
DBufFree(dbuf);
return err;
}
if (c == '\n') continue;
if (!c) {
if (AddBlankLines &&
mode != CAL_MODE &&
mode != ADVANCE_MODE &&
t->typ != RUN_TYPE &&
t->typ != RUN_TYPE &&
!(MsgCommand && *MsgCommand)) {
if (DBufPutc(dbuf, '\n') != OK) return E_NO_MEM;
}
break;
}
if (c != '%') {
if (DBufPutc(dbuf, c) != OK) return E_NO_MEM;
continue;
}
altmode = 0;
s[0] = 0;
c = ParseChar(p, &err, 0);
if (err) {
DBufFree(dbuf);
return err;
}
if (!c) {
break;
}
if (c == '*') {
altmode = c;
c = ParseChar(p, &err, 0);
if (err) {
DBufFree(dbuf);
return err;
}
if (!c) {
break;
}
}
if (DBufPutc(dbuf, '\n') != OK) return E_NO_MEM;
}
break;
}
if (c != '%') {
if (DBufPutc(dbuf, c) != OK) return E_NO_MEM;
continue;
}
altmode = 0;
s[0] = 0;
c = ParseChar(p, &err, 0);
if (err) {
DBufFree(dbuf);
return err;
}
if (!c) {
break;
}
if (c == '*') {
altmode = c;
c = ParseChar(p, &err, 0);
if (err) {
DBufFree(dbuf);
return err;
}
if (!c) {
break;
}
}
if (c == '{') {
i = 0;
ss = s + snprintf(s, sizeof(s), "subst_");
@@ -291,7 +291,7 @@ int DoSubst(ParsePtr p, DynamicBuffer *dbuf, Trigger *t, TimeTrig *tt, int dse,
}
continue;
}
done = 0;
done = 0;
snprintf(uf, sizeof(uf), "subst_%c", tolower(c));
func = FindUserFunc(uf);
if (func && check_subst_args(func, 3)) {
@@ -316,55 +316,55 @@ int DoSubst(ParsePtr p, DynamicBuffer *dbuf, Trigger *t, TimeTrig *tt, int dse,
}
}
if (diff <= 1) {
switch(UPPER(c)) {
if (diff <= 1) {
switch(UPPER(c)) {
#ifndef L_NOTOMORROW_A
case 'A':
case 'A':
#endif
#ifndef L_NOTOMORROW_B
case 'B':
case 'B':
#endif
#ifndef L_NOTOMORROW_C
case 'C':
case 'C':
#endif
#ifndef L_NOTOMORROW_E
case 'E':
case 'E':
#endif
#ifndef L_NOTOMORROW_F
case 'F':
case 'F':
#endif
#ifndef L_NOTOMORROW_G
case 'G':
case 'G':
#endif
#ifndef L_NOTOMORROW_H
case 'H':
case 'H':
#endif
#ifndef L_NOTOMORROW_I
case 'I':
case 'I':
#endif
#ifndef L_NOTOMORROW_J
case 'J':
case 'J':
#endif
#ifndef L_NOTOMORROW_K
case 'K':
case 'K':
#endif
#ifndef L_NOTOMORROW_L
case 'L':
case 'L':
#endif
#ifndef L_NOTOMORROW_U
case 'U':
case 'U':
#endif
#ifndef L_NOTOMORROW_V
case 'V':
case 'V':
#endif
snprintf(s, sizeof(s), "%s", (diff ? DynamicTomorrow: DynamicToday));
SHIP_OUT(s);
done = 1;
break;
snprintf(s, sizeof(s), "%s", (diff ? DynamicTomorrow: DynamicToday));
SHIP_OUT(s);
done = 1;
break;
default: done = 0;
}
}
default: done = 0;
}
}
if (!done) {
@@ -849,13 +849,13 @@ int DoSubst(ParsePtr p, DynamicBuffer *dbuf, Trigger *t, TimeTrig *tt, int dse,
}
}
if (isupper(c)) {
os = DBufValue(dbuf);
os += strlen(os) - strlen(s);
if (os >= DBufValue(dbuf)) {
*os = UPPER(*os);
}
}
if (isupper(c)) {
os = DBufValue(dbuf);
os += strlen(os) - strlen(s);
if (os >= DBufValue(dbuf)) {
*os = UPPER(*os);
}
}
}
/* We're outside the big while loop. The only way to get here is for c to
@@ -866,11 +866,11 @@ int DoSubst(ParsePtr p, DynamicBuffer *dbuf, Trigger *t, TimeTrig *tt, int dse,
/* If there are NO quotes, then: If CAL_MODE && RUN_TYPE, we don't want the
reminder in the calendar. Zero the output buffer and quit. */
if (!has_quote) {
if ((mode == ADVANCE_MODE || mode == CAL_MODE) && t->typ == RUN_TYPE) {
*DBufValue(dbuf) = 0;
dbuf->len = 0;
}
return OK;
if ((mode == ADVANCE_MODE || mode == CAL_MODE) && t->typ == RUN_TYPE) {
*DBufValue(dbuf) = 0;
dbuf->len = 0;
}
return OK;
}
/* There ARE quotes. If in CAL_MODE, delete everything before first quote
@@ -879,22 +879,22 @@ int DoSubst(ParsePtr p, DynamicBuffer *dbuf, Trigger *t, TimeTrig *tt, int dse,
ss = DBufValue(dbuf) + origLen;
os = ss;
if (mode == NORMAL_MODE || mode == ADVANCE_MODE) {
while (*ss) {
if (*ss != QUOTE_MARKER) *os++ = *ss;
ss++;
}
*os = 0;
while (*ss) {
if (*ss != QUOTE_MARKER) *os++ = *ss;
ss++;
}
*os = 0;
} else {
/* Skip past the quote marker */
while (*ss && (*ss != QUOTE_MARKER)) ss++;
while (*ss && (*ss != QUOTE_MARKER)) ss++;
/* Security check... actually, *s must == QUOTE_MARKER at this point, but
it doesn't hurt to make it a bit robust. */
if (*ss) ss++;
if (*ss) ss++;
/* Copy the output until the next QUOTE_MARKER */
while (*ss && (*ss != QUOTE_MARKER)) *os++ = *ss++;
*os = 0;
while (*ss && (*ss != QUOTE_MARKER)) *os++ = *ss++;
*os = 0;
}
/* Violating encapsulation here!!!! */
@@ -914,7 +914,7 @@ int DoSubst(ParsePtr p, DynamicBuffer *dbuf, Trigger *t, TimeTrig *tt, int dse,
/* */
/***************************************************************/
int DoSubstFromString(char const *source, DynamicBuffer *dbuf,
int dse, int tim)
int dse, int tim)
{
Trigger tempTrig;
TimeTrig tempTime;
+15 -16
View File
@@ -38,7 +38,7 @@ static int DBufMakeRoom(DynamicBuffer *dbuf, size_t n)
if (size > n) return OK;
while (size <= n) {
size *= 2;
size *= 2;
}
/* Allocate memory */
@@ -85,7 +85,7 @@ void DBufInit(DynamicBuffer *dbuf)
int DBufPutcFN(DynamicBuffer *dbuf, char c)
{
if (dbuf->allocatedLen == dbuf->len+1) {
if (DBufMakeRoom(dbuf, dbuf->len+1) != OK) return E_NO_MEM;
if (DBufMakeRoom(dbuf, dbuf->len+1) != OK) return E_NO_MEM;
}
dbuf->buffer[dbuf->len++] = c;
dbuf->buffer[dbuf->len] = 0;
@@ -153,28 +153,27 @@ int DBufGets(DynamicBuffer *dbuf, FILE *fp)
we can usually save some unnecessary copying */
if (fgets(dbuf->buffer, dbuf->allocatedLen, fp) == NULL) {
return OK;
return OK;
}
if (!*(dbuf->buffer)) return OK;
dbuf->len = strlen(dbuf->buffer);
l = dbuf->len - 1;
if (dbuf->buffer[l] == '\n') {
dbuf->buffer[l] = 0;
dbuf->len = l;
return OK;
dbuf->buffer[l] = 0;
dbuf->len = l;
return OK;
}
while(busy) {
*tmp = 0;
if (fgets(tmp, 256, fp) == NULL) return OK;
if (!*tmp) return OK;
l = strlen(tmp) - 1;
if (tmp[l] == '\n') {
tmp[l] = 0;
busy = 0;
}
if (DBufPuts(dbuf, tmp) != OK) return E_NO_MEM;
*tmp = 0;
if (fgets(tmp, 256, fp) == NULL) return OK;
if (!*tmp) return OK;
l = strlen(tmp) - 1;
if (tmp[l] == '\n') {
tmp[l] = 0;
busy = 0;
}
if (DBufPuts(dbuf, tmp) != OK) return E_NO_MEM;
}
return OK;
}
+54 -54
View File
@@ -34,17 +34,17 @@
#define E_STACK_ERR 16
#define E_DIV_ZERO 17
#define E_NOSUCH_VAR 18
#define E_EOLN 19
#define E_EOF 20
#define E_EOLN 19
#define E_EOF 20
#define E_IO_ERR 21
#define E_LINE_2_LONG 22
#define E_SWERR 23
#define E_SWERR 23
#define E_BAD_DATE 24
#define E_2FEW_ARGS 25
#define E_2MANY_ARGS 26
#define E_BAD_TIME 27
#define E_2HIGH 28
#define E_2LOW 29
#define E_2FEW_ARGS 25
#define E_2MANY_ARGS 26
#define E_BAD_TIME 27
#define E_2HIGH 28
#define E_2LOW 29
#define E_CANT_OPEN 30
#define E_NESTED_INCLUDE 31
#define E_PARSE_ERR 32
@@ -64,56 +64,56 @@
as a REM statement, also. */
#define E_CANT_MODIFY 45
#define E_MKTIME_PROBLEM 46
#define E_REDEF_FUNC 47
#define E_REDEF_FUNC 47
#define E_CANTNEST_FDEF 48
#define E_REP_FULSPEC 49
#define E_YR_TWICE 50
#define E_MON_TWICE 51
#define E_DAY_TWICE 52
#define E_UNKNOWN_TOKEN 53
#define E_SPEC_MON 54
#define E_2MANY_PART 55
#define E_2MANY_FULL 56
#define E_PUSH_NOPOP 57
#define E_ERR_READING 58
#define E_EXPECTING_EOL 59
#define E_BAD_HEBDATE 60
#define E_IIF_ODD 61
#define E_MISS_ENDIF 62
#define E_EXPECT_COMMA 63
#define E_WD_TWICE 64
#define E_SKIP_ERR 65
#define E_YR_TWICE 50
#define E_MON_TWICE 51
#define E_DAY_TWICE 52
#define E_UNKNOWN_TOKEN 53
#define E_SPEC_MON 54
#define E_2MANY_PART 55
#define E_2MANY_FULL 56
#define E_PUSH_NOPOP 57
#define E_ERR_READING 58
#define E_EXPECTING_EOL 59
#define E_BAD_HEBDATE 60
#define E_IIF_ODD 61
#define E_MISS_ENDIF 62
#define E_EXPECT_COMMA 63
#define E_WD_TWICE 64
#define E_SKIP_ERR 65
#define E_CANT_NEST_RTYPE 66
#define E_REP_TWICE 67
#define E_DELTA_TWICE 68
#define E_BACK_TWICE 69
#define E_ONCE_TWICE 70
#define E_EXPECT_TIME 71
#define E_UNTIL_TWICE 72
#define E_INCOMPLETE 73
#define E_SCAN_TWICE 74
#define E_VAR 75
#define E_VAL 76
#define E_UNDEF 77
#define E_ENTER_FUN 78
#define E_LEAVE_FUN 79
#define E_EXPIRED 80
#define E_CANTFORK 81
#define E_CANTACCESS 82
#define M_BAD_SYS_DATE 83
#define M_BAD_DB_FLAG 84
#define M_BAD_OPTION 85
#define M_BAD_USER 86
#define M_NO_CHG_GID 87
#define M_NO_CHG_UID 88
#define M_NOMEM_ENV 89
#define E_MISS_EQ 90
#define E_MISS_VAR 91
#define E_MISS_EXPR 92
#define E_REP_TWICE 67
#define E_DELTA_TWICE 68
#define E_BACK_TWICE 69
#define E_ONCE_TWICE 70
#define E_EXPECT_TIME 71
#define E_UNTIL_TWICE 72
#define E_INCOMPLETE 73
#define E_SCAN_TWICE 74
#define E_VAR 75
#define E_VAL 76
#define E_UNDEF 77
#define E_ENTER_FUN 78
#define E_LEAVE_FUN 79
#define E_EXPIRED 80
#define E_CANTFORK 81
#define E_CANTACCESS 82
#define M_BAD_SYS_DATE 83
#define M_BAD_DB_FLAG 84
#define M_BAD_OPTION 85
#define M_BAD_USER 86
#define M_NO_CHG_GID 87
#define M_NO_CHG_UID 88
#define M_NOMEM_ENV 89
#define E_MISS_EQ 90
#define E_MISS_VAR 91
#define E_MISS_EXPR 92
#define M_CANTSET_ACCESS 93
#define M_I_OPTION 94
#define E_NOREMINDERS 95
#define M_QUEUED 96
#define M_I_OPTION 94
#define E_NOREMINDERS 95
#define M_QUEUED 96
#define E_EXPECTING_NUMBER 97
#define M_BAD_WARN_FUNC 98
#define E_CANT_CONVERT_TZ 99
+380 -380
View File
File diff suppressed because it is too large Load Diff
+351 -351
View File
File diff suppressed because it is too large Load Diff
+630 -630
View File
File diff suppressed because it is too large Load Diff
+42 -42
View File
@@ -42,12 +42,12 @@ EXTERN FILE *ErrFp;
#define DestroyValue(x) do { if ((x).type == STR_TYPE && (x).v.str) { free((x).v.str); (x).v.str = NULL; } (x).type = ERR_TYPE; } while (0)
EXTERN int DSEToday;
EXTERN int RealToday;
EXTERN int CurDay;
EXTERN int CurMon;
EXTERN int CurYear;
EXTERN int LineNo;
EXTERN int DSEToday;
EXTERN int RealToday;
EXTERN int CurDay;
EXTERN int CurMon;
EXTERN int CurYear;
EXTERN int LineNo;
EXTERN int FreshLine;
EXTERN int WarnedAboutImplicit;
EXTERN uid_t TrustedUsers[MAX_TRUSTED_USERS];
@@ -56,22 +56,22 @@ EXTERN INIT( int MaxLateMinutes, 0);
EXTERN INIT( int NumTrustedUsers, 0);
EXTERN INIT( char const *MsgCommand, NULL);
EXTERN INIT( char const *QueuedMsgCommand, NULL);
EXTERN INIT( int ShowAllErrors, 0);
EXTERN INIT( int DebugFlag, 0);
EXTERN INIT( int DoCalendar, 0);
EXTERN INIT( int ShowAllErrors, 0);
EXTERN INIT( int DebugFlag, 0);
EXTERN INIT( int DoCalendar, 0);
EXTERN INIT( int DoSimpleCalendar, 0);
EXTERN INIT( int DoSimpleCalDelta, 0);
EXTERN INIT( int DoPrefixLineNo, 0);
EXTERN INIT( int MondayFirst, 0);
EXTERN INIT( int MondayFirst, 0);
EXTERN INIT( int AddBlankLines, 1);
EXTERN INIT( int Iterations, 1);
EXTERN INIT( int Iterations, 1);
EXTERN INIT( int PsCal, 0);
EXTERN INIT( int CalWidth, 80);
EXTERN INIT( int CalWeeks, 0);
EXTERN INIT( int CalMonths, 0);
EXTERN INIT( int Hush, 0);
EXTERN INIT( int NextMode, 0);
EXTERN INIT( int InfiniteDelta, 0);
EXTERN INIT( int Hush, 0);
EXTERN INIT( int NextMode, 0);
EXTERN INIT( int InfiniteDelta, 0);
EXTERN INIT( int DefaultTDelta, 0);
EXTERN INIT( int DeltaOverride, 0);
EXTERN INIT( int RunDisabled, 0);
@@ -84,19 +84,19 @@ EXTERN INIT( int OnceDate, -1);
EXTERN INIT( int ProcessedOnce, 0);
EXTERN INIT( int SortByTime, SORT_NONE);
EXTERN INIT( int SortByDate, SORT_NONE);
EXTERN INIT( int SortByPrio, SORT_NONE);
EXTERN INIT( int SortByPrio, SORT_NONE);
EXTERN INIT( int UntimedBeforeTimed, 0);
EXTERN INIT( int DefaultPrio, NO_PRIORITY);
EXTERN INIT( int DefaultPrio, NO_PRIORITY);
EXTERN INIT( int SysTime, -1);
EXTERN INIT( int ParseUntriggered, 1);
EXTERN char const *InitialFile;
EXTERN int FileAccessDate;
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);
EXTERN INIT( int DontFork, 0);
EXTERN INIT( int DontQueue, 0);
EXTERN INIT( int NumQueued, 0);
EXTERN INIT( int DontIssueAts, 0);
EXTERN INIT( int Daemon, 0);
@@ -111,8 +111,8 @@ EXTERN INIT( int SynthesizeTags, 0);
EXTERN INIT( int ScFormat, SC_AMPM);
EXTERN INIT( int MaxSatIter, 1000);
EXTERN INIT( int MaxStringLen, MAX_STR_LEN);
EXTERN INIT( char *FileName, NULL);
EXTERN INIT( int UseStdin, 0);
EXTERN INIT( char *FileName, NULL);
EXTERN INIT( int UseStdin, 0);
EXTERN INIT( int PurgeMode, 0);
EXTERN INIT( int PurgeIncludeDepth, 0);
EXTERN INIT( FILE *PurgeFP, NULL);
@@ -141,28 +141,28 @@ EXTERN INIT( int UseTrueColors, 0);
EXTERN INIT( int TerminalBackground, TERMINAL_BACKGROUND_UNKNOWN);
/* Latitude and longitude */
EXTERN INIT( int LatDeg, 0);
EXTERN INIT( int LatMin, 0);
EXTERN INIT( int LatSec, 0);
EXTERN INIT( int LongDeg, 0);
EXTERN INIT( int LongMin, 0);
EXTERN INIT( int LongSec, 0);
EXTERN INIT( int LatDeg, 0);
EXTERN INIT( int LatMin, 0);
EXTERN INIT( int LatSec, 0);
EXTERN INIT( int LongDeg, 0);
EXTERN INIT( int LongMin, 0);
EXTERN INIT( int LongSec, 0);
EXTERN INIT( double Longitude, DEFAULT_LONGITUDE);
EXTERN INIT( double Latitude, DEFAULT_LATITUDE);
EXTERN INIT( char *Location, LOCATION);
EXTERN INIT( char *Location, LOCATION);
/* UTC calculation stuff */
EXTERN INIT( int MinsFromUTC, 0);
EXTERN INIT( int CalculateUTC, 1);
EXTERN INIT( int FoldYear, 0);
EXTERN INIT( int MinsFromUTC, 0);
EXTERN INIT( int CalculateUTC, 1);
EXTERN INIT( int FoldYear, 0);
/* Parameters for formatting MSGF reminders */
EXTERN INIT( int FormWidth, 72);
EXTERN INIT( int FirstIndent, 0);
EXTERN INIT( int SubsIndent, 0);
EXTERN INIT( char *EndSent, ".?!");
EXTERN INIT( char *EndSentIg, "\"')]}>");
EXTERN INIT( int FormWidth, 72);
EXTERN INIT( int FirstIndent, 0);
EXTERN INIT( int SubsIndent, 0);
EXTERN INIT( char *EndSent, ".?!");
EXTERN INIT( char *EndSentIg, "\"')]}>");
EXTERN DynamicBuffer Banner;
EXTERN DynamicBuffer LineBuffer;
@@ -187,7 +187,7 @@ EXTERN char *EnglishMonthName[]
#if LANG == ENGLISH
#define MonthName EnglishMonthName
#else
EXTERN char *MonthName[]
EXTERN char *MonthName[]
#ifdef MK_GLOBALS
= {L_JAN, L_FEB, L_MAR, L_APR, L_MAY, L_JUN,
L_JUL, L_AUG, L_SEP, L_OCT, L_NOV, L_DEC}
@@ -206,7 +206,7 @@ EXTERN char *DynamicMonthName[]
#endif
#endif
;
EXTERN char *EnglishDayName[]
EXTERN char *EnglishDayName[]
#ifdef MK_GLOBALS
= {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
"Saturday", "Sunday"}
@@ -216,7 +216,7 @@ EXTERN char *EnglishDayName[]
#if LANG == ENGLISH
#define DayName EnglishDayName
#else
EXTERN char *DayName[]
EXTERN char *DayName[]
#ifdef MK_GLOBALS
= {L_MONDAY, L_TUESDAY, L_WEDNESDAY, L_THURSDAY, L_FRIDAY,
L_SATURDAY, L_SUNDAY}
@@ -236,7 +236,7 @@ EXTERN char *DynamicDayName []
#endif
;
EXTERN int MonthDays[]
EXTERN int MonthDays[]
#ifdef MK_GLOBALS
= {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
#endif
@@ -245,7 +245,7 @@ EXTERN int MonthDays[]
/* The first day of each month expressed as number of days after Jan 1.
Second row is for leap years. */
EXTERN int MonthIndex[2][12]
EXTERN int MonthIndex[2][12]
#ifdef MK_GLOBALS
= {
{ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 },
+85 -85
View File
@@ -97,7 +97,7 @@ long DaysToHebYear(int y)
{
long m, nm, dw, s, l;
l = y*7+1; /* no. of leap months */
l = y*7+1; /* no. of leap months */
m = y*12+l/19; /* total no. of months */
nm = m*MONTH+M(1,779); /* molad at 197 cycles */
s = m*28+nm/DAY-2;
@@ -109,12 +109,12 @@ long DaysToHebYear(int y)
/* special cases of Molad Zaken */
if (nm >= 18*HOUR ||
(l < 12 && dw==3 && nm>=M(9,204)) ||
(l < 7 && dw==2 && nm>=M(15,589)))
s++,dw++;
(l < 12 && dw==3 && nm>=M(9,204)) ||
(l < 7 && dw==2 && nm>=M(15,589)))
s++,dw++;
/* ADU */
if(dw == 1 || dw == 4 || dw == 6)
s++;
s++;
return s;
}
@@ -146,12 +146,12 @@ int DaysInHebYear(int y)
char const *DaysInHebMonths(int ylen)
{
static char monlen[14] =
{30, 29, 30, 29, 30, 0, 29, 30, 29, 30, 29, 30, 29, 29};
{30, 29, 30, 29, 30, 0, 29, 30, 29, 30, 29, 30, 29, 29};
if (ylen > 355) {
monlen[ADARA] = 30;
ylen -= 30;
monlen[ADARA] = 30;
ylen -= 30;
} else monlen[ADARA] = 0;
if (ylen == 353) monlen[KISLEV] = 29; else monlen[KISLEV] = 30;
@@ -221,8 +221,8 @@ void DSEToHeb(int dse, int *hy, int *hm, int *hd)
monlen = DaysInHebMonths(ylen);
m = 0;
while((dse >= monlen[m]) || !monlen[m]) {
dse -= monlen[m];
m++;
dse -= monlen[m];
m++;
}
*hy = y;
@@ -244,10 +244,10 @@ int HebNameToNum(char const *mname)
int m=-1;
for (i=0; i<14; i++)
if (!StrCmpi(mname, HebMonthNames[i])) {
m = i;
break;
}
if (!StrCmpi(mname, HebMonthNames[i])) {
m = i;
break;
}
return m;
}
@@ -307,8 +307,8 @@ int GetValidHebDate(int yin, int min, int din, int adarbehave,
/* Do some error checking */
if (din < 1 || din > MaxMonLen[min] || min < 0 || min > 13) {
*dout = -1;
return E_BAD_HEBDATE;
*dout = -1;
return E_BAD_HEBDATE;
}
ylen = DaysInHebYear(yin);
@@ -316,17 +316,17 @@ int GetValidHebDate(int yin, int min, int din, int adarbehave,
/* Convert ADAR as necessary */
if (min == ADAR) {
switch(adarbehave) {
case ADAR2ADARA: if (monlen[ADARA]) *mout = min = ADARA;
else *mout = min = ADARB;
break;
switch(adarbehave) {
case ADAR2ADARA: if (monlen[ADARA]) *mout = min = ADARA;
else *mout = min = ADARB;
break;
case ADAR2ADARB: *mout = min = ADARB; break;
case ADAR2ADARB: *mout = min = ADARB; break;
default:
Eprint("GetValidHebDate: Bad adarbehave value %d", adarbehave);
return E_SWERR;
}
default:
Eprint("GetValidHebDate: Bad adarbehave value %d", adarbehave);
return E_SWERR;
}
}
if (din <= monlen[min]) return OK;
@@ -335,54 +335,54 @@ int GetValidHebDate(int yin, int min, int din, int adarbehave,
case JAHR_NONE: return E_BAD_DATE;
case JAHR_FORWARD:
if (min == KISLEV) {
if (min == KISLEV) {
*mout = TEVET;
*dout = 1;
return OK;
} else if (min == HESHVAN) {
} else if (min == HESHVAN) {
*mout = KISLEV;
*dout = 1;
return OK;
} else if (min == ADARA) {
} else if (min == ADARA) {
if (din > 29) {
*dout = 1;
*mout = NISAN;
*dout = 1;
*mout = NISAN;
} else {
*dout = din;
*mout = ADARB;
*dout = din;
*mout = ADARB;
}
return OK;
}
return OK;
}
Eprint("GetValidHebDate: (1) software error! %d", jahr);
return E_SWERR;
Eprint("GetValidHebDate: (1) software error! %d", jahr);
return E_SWERR;
case JAHR_BACKWARD:
if (min == KISLEV) {
if (min == KISLEV) {
*mout = KISLEV;
*dout = 29;
return OK;
} else if (min == HESHVAN) {
} else if (min == HESHVAN) {
*mout = HESHVAN;
*dout = 29;
return OK;
} else if (min == ADARA) {
if (din > 29) {
*dout = 30;
*mout = SHVAT;
} else if (min == ADARA) {
if (din > 29) {
*dout = 30;
*mout = SHVAT;
} else {
*mout = ADARB;
*dout = din;
*mout = ADARB;
*dout = din;
}
return OK;
}
return OK;
}
Eprint("GetValidHebDate: (2) software error! %d", jahr);
return E_SWERR;
Eprint("GetValidHebDate: (2) software error! %d", jahr);
return E_SWERR;
default:
Eprint("GetValidHebDate: (3) software error! %d", jahr);
return E_SWERR;
Eprint("GetValidHebDate: (3) software error! %d", jahr);
return E_SWERR;
}
}
@@ -397,7 +397,7 @@ int GetValidHebDate(int yin, int min, int din, int adarbehave,
/* */
/***************************************************************/
int GetNextHebrewDate(int dsestart, int hm, int hd,
int jahr, int adarbehave, int *ans)
int jahr, int adarbehave, int *ans)
{
int r, yout, mout, dout, dse=1;
int adarflag = adarbehave;
@@ -413,33 +413,33 @@ int GetNextHebrewDate(int dsestart, int hm, int hd,
r = 1;
while(r) {
r = GetValidHebDate(yout, hm, hd, adarflag, &mout, &dout, jahr);
if (dout == -1) return r;
if (r) {
if (adarbehave == ADAR2BOTH && hm == ADAR) {
if (adarflag == ADAR2ADARA) {
adarflag = ADAR2ADARB;
} else {
adarflag = ADAR2ADARA;
yout++;
}
} else yout++;
continue;
}
dse = HebToDSE(yout, mout, dout);
if (dse < 0) return E_DATE_OVER;
if (dse >= dsestart) break;
else {
if (adarbehave == ADAR2BOTH && hm == ADAR) {
if (adarflag == ADAR2ADARA) {
adarflag = ADAR2ADARB;
} else {
adarflag = ADAR2ADARA;
yout++;
}
} else yout++;
r=1; /* Force loop to continue */
}
r = GetValidHebDate(yout, hm, hd, adarflag, &mout, &dout, jahr);
if (dout == -1) return r;
if (r) {
if (adarbehave == ADAR2BOTH && hm == ADAR) {
if (adarflag == ADAR2ADARA) {
adarflag = ADAR2ADARB;
} else {
adarflag = ADAR2ADARA;
yout++;
}
} else yout++;
continue;
}
dse = HebToDSE(yout, mout, dout);
if (dse < 0) return E_DATE_OVER;
if (dse >= dsestart) break;
else {
if (adarbehave == ADAR2BOTH && hm == ADAR) {
if (adarflag == ADAR2ADARA) {
adarflag = ADAR2ADARB;
} else {
adarflag = ADAR2ADARA;
yout++;
}
} else yout++;
r=1; /* Force loop to continue */
}
}
*ans = dse;
return OK;
@@ -464,24 +464,24 @@ int ComputeJahr(int y, int m, int d, int *ans)
/* Check for Adar A */
if (m == ADARA && monlen[m] == 0) {
Eprint("No Adar A in %d", y);
return E_BAD_HEBDATE;
Eprint("No Adar A in %d", y);
return E_BAD_HEBDATE;
}
if (d < 1 || d > MaxMonLen[m] || m < 0 || m > 13) {
return E_BAD_HEBDATE;
return E_BAD_HEBDATE;
}
if (d > monlen[m]) {
Eprint("%d %s %d: %s", d, HebMonthNames[m], y, ErrMsg[E_BAD_HEBDATE]);
return E_BAD_HEBDATE;
Eprint("%d %s %d: %s", d, HebMonthNames[m], y, ErrMsg[E_BAD_HEBDATE]);
return E_BAD_HEBDATE;
}
/* If the jahrzeit was in Adar A, we always use JAHR_BACKWARD */
if (m == ADARA) {
*ans = JAHR_BACKWARD;
return OK;
*ans = JAHR_BACKWARD;
return OK;
}
/* Get lengths of months in year following jahrzeit */
+423 -423
View File
File diff suppressed because it is too large Load Diff
+695 -695
View File
File diff suppressed because it is too large Load Diff
+88 -88
View File
@@ -111,41 +111,41 @@ typedef struct _json_value
struct
{
unsigned int length;
json_char * ptr; /* null terminated */
unsigned int length;
json_char * ptr; /* null terminated */
} string;
struct
{
unsigned int length;
unsigned int length;
json_object_entry * values;
json_object_entry * values;
#if defined(__cplusplus) && __cplusplus >= 201103L
decltype(values) begin () const
{ return values;
}
decltype(values) end () const
{ return values + length;
}
#endif
#if defined(__cplusplus) && __cplusplus >= 201103L
decltype(values) begin () const
{ return values;
}
decltype(values) end () const
{ return values + length;
}
#endif
} object;
struct
{
unsigned int length;
struct _json_value ** values;
unsigned int length;
struct _json_value ** values;
#if defined(__cplusplus) && __cplusplus >= 201103L
decltype(values) begin () const
{ return values;
}
decltype(values) end () const
{ return values + length;
}
#endif
#if defined(__cplusplus) && __cplusplus >= 201103L
decltype(values) begin () const
{ return values;
}
decltype(values) end () const
{ return values + length;
}
#endif
} array;
@@ -173,95 +173,95 @@ typedef struct _json_value
public:
inline _json_value ()
{ memset (this, 0, sizeof (_json_value));
}
inline _json_value ()
{ memset (this, 0, sizeof (_json_value));
}
inline const struct _json_value &operator [] (int index) const
{
if (type != json_array || index < 0
|| ((unsigned int) index) >= u.array.length)
{
return json_value_none;
}
inline const struct _json_value &operator [] (int index) const
{
if (type != json_array || index < 0
|| ((unsigned int) index) >= u.array.length)
{
return json_value_none;
}
return *u.array.values [index];
}
return *u.array.values [index];
}
inline const struct _json_value &operator [] (const char * index) const
{
if (type != json_object)
return json_value_none;
inline const struct _json_value &operator [] (const char * index) const
{
if (type != json_object)
return json_value_none;
for (unsigned int i = 0; i < u.object.length; ++ i)
if (!strcmp (u.object.values [i].name, index))
return *u.object.values [i].value;
for (unsigned int i = 0; i < u.object.length; ++ i)
if (!strcmp (u.object.values [i].name, index))
return *u.object.values [i].value;
return json_value_none;
}
return json_value_none;
}
inline operator const char * () const
{
switch (type)
{
case json_string:
return u.string.ptr;
inline operator const char * () const
{
switch (type)
{
case json_string:
return u.string.ptr;
default:
return "";
};
}
default:
return "";
};
}
inline operator json_int_t () const
{
switch (type)
{
case json_integer:
return u.integer;
inline operator json_int_t () const
{
switch (type)
{
case json_integer:
return u.integer;
case json_double:
return (json_int_t) u.dbl;
case json_double:
return (json_int_t) u.dbl;
default:
return 0;
};
}
default:
return 0;
};
}
inline operator bool () const
{
if (type != json_boolean)
return false;
inline operator bool () const
{
if (type != json_boolean)
return false;
return u.boolean != 0;
}
return u.boolean != 0;
}
inline operator double () const
{
switch (type)
{
case json_integer:
return (double) u.integer;
inline operator double () const
{
switch (type)
{
case json_integer:
return (double) u.integer;
case json_double:
return u.dbl;
case json_double:
return u.dbl;
default:
return 0;
};
}
default:
return 0;
};
}
#endif
} json_value;
json_value * json_parse (const json_char * json,
size_t length);
size_t length);
#define json_error_max 128
json_value * json_parse_ex (json_settings * settings,
const json_char * json,
size_t length,
char * error);
const json_char * json,
size_t length,
char * error);
void json_value_free (json_value *);
@@ -270,7 +270,7 @@ void json_value_free (json_value *);
* use a custom mem_free.
*/
void json_value_free_ex (json_settings * settings,
json_value *);
json_value *);
#ifdef __cplusplus
+1 -1
View File
@@ -16,7 +16,7 @@
#define GERMAN 1 /* translated by Wolfgang Thronicke */
#define DUTCH 2 /* translated by Willem Kasdorp and Erik-Jan Vens */
#define FINNISH 3 /* translated by Mikko Silvonen */
#define FRENCH 4 /* translated by Laurent Duperval */
#define FRENCH 4 /* translated by Laurent Duperval */
#define NORWEGIAN 5 /* translated by Trygve Randen */
#define DANISH 6 /* translated by Mogens Lynnerup */
#define POLISH 7 /* translated by Jerzy Sobczyk */
+5 -5
View File
@@ -79,13 +79,13 @@
/* Define any overrides here, such as L_ORDINAL_OVERRIDE, L_A_OVER, etc.
See the file dosubst.c for more info. */
#define L_AMPM_OVERRIDE(ampm, hour) ampm = (hour < 12) ? (hour<5) ? " om natten" : " om formiddagen" : (hour > 17) ? " om aftenen" : " om eftermiddagen";
#define L_ORDINAL_OVERRIDE plu = ".";
#define L_AMPM_OVERRIDE(ampm, hour) ampm = (hour < 12) ? (hour<5) ? " om natten" : " om formiddagen" : (hour > 17) ? " om aftenen" : " om eftermiddagen";
#define L_ORDINAL_OVERRIDE plu = ".";
#define L_A_OVER if (altmode == '*') { sprintf(s, "%s, den %d. %s %d", DayName[dse%7], d, MonthName[m], y); } else { sprintf(s, "%s %s, den %d. %s %d", L_ON, DayName[dse%7], d, MonthName[m], y); }
#define L_E_OVER sprintf(s, "den %02d%c%02d%c%04d", d, DateSep, m+1, DateSep, y);
#define L_F_OVER sprintf(s, "den %02d%c%02d%c%04d", m+1, DateSep, d, DateSep, y);
#define L_G_OVER if (altmode == '*') { sprintf(s, "%s, den %d. %s", DayName[dse%7], d, MonthName[m]); } else { sprintf(s, "%s %s, den %d. %s", L_ON, DayName[dse%7], d, MonthName[m]); }
#define L_G_OVER if (altmode == '*') { sprintf(s, "%s, den %d. %s", DayName[dse%7], d, MonthName[m]); } else { sprintf(s, "%s %s, den %d. %s", L_ON, DayName[dse%7], d, MonthName[m]); }
#define L_H_OVER sprintf(s, "den %02d%c%02d", d, DateSep, m+1);
#define L_I_OVER sprintf(s, "den %02d%c%02d", m+1, DateSep, d);
#define L_U_OVER L_A_OVER
#define L_V_OVER L_G_OVER
#define L_U_OVER L_A_OVER
#define L_V_OVER L_G_OVER
+4 -4
View File
@@ -94,9 +94,9 @@ else if (mdiff == 0) \
sprintf(s, "%d %s %s", hdiff, \
((hdiff == 1) ? "uur" : "uren"), when); \
else sprintf(s, "%d %s %s %d %s %s", hdiff, \
(hdiff == 1 ? "uur" : "uren"), \
L_AND, mdiff, \
(mdiff == 1 ? "minuut" : "minuten"), \
when);
(hdiff == 1 ? "uur" : "uren"), \
L_AND, mdiff, \
(mdiff == 1 ? "minuut" : "minuten"), \
when);
+1 -1
View File
@@ -124,7 +124,7 @@ else { \
s[0] = '\0'; \
if (hdiff != 0) { \
if (tdiff < 0) \
sprintf(s, "%d %s%s ", hdiff, L_HOUR, hplu); \
sprintf(s, "%d %s%s ", hdiff, L_HOUR, hplu); \
else \
sprintf(s, "%d %s ", hdiff, L_HGEN); \
} \
+6 -6
View File
@@ -80,9 +80,9 @@
/* Define any overrides here, such as L_ORDINAL_OVERRIDE, L_A_OVER, etc.
See the file dosubst.c for more info. */
#define L_AMPM_OVERRIDE(ampm, hour) ampm = (hour < 12) ? (hour<5) ? " nachts" : " vormittags" : (hour > 17) ? " abends" : " nachmittags";
#define L_ORDINAL_OVERRIDE plu = ".";
#define L_A_OVER if (altmode == '*') { sprintf(s, "%s, den %d. %s %d", DayName[dse%7], d, MonthName[m], y); } else { sprintf(s, "%s %s, den %d. %s %d", L_ON, DayName[dse%7], d, MonthName[m], y); }
#define L_G_OVER if (altmode == '*') { sprintf(s, "%s, den %d. %s", DayName[dse%7], d, MonthName[m]); } else { sprintf(s, "%s %s, den %d. %s", L_ON, DayName[dse%7], d, MonthName[m]); }
#define L_U_OVER L_A_OVER
#define L_V_OVER L_G_OVER
#define L_AMPM_OVERRIDE(ampm, hour) ampm = (hour < 12) ? (hour<5) ? " nachts" : " vormittags" : (hour > 17) ? " abends" : " nachmittags";
#define L_ORDINAL_OVERRIDE plu = ".";
#define L_A_OVER if (altmode == '*') { sprintf(s, "%s, den %d. %s %d", DayName[dse%7], d, MonthName[m], y); } else { sprintf(s, "%s %s, den %d. %s %d", L_ON, DayName[dse%7], d, MonthName[m], y); }
#define L_G_OVER if (altmode == '*') { sprintf(s, "%s, den %d. %s", DayName[dse%7], d, MonthName[m]); } else { sprintf(s, "%s %s, den %d. %s", L_ON, DayName[dse%7], d, MonthName[m]); }
#define L_U_OVER L_A_OVER
#define L_V_OVER L_G_OVER
+14 -14
View File
@@ -82,33 +82,33 @@
#define L_P_OVER sprintf(s, (diff == 1 ? "o" : "i"));
#define L_Q_OVER sprintf(s, (diff == 1 ? "a" : "e"));
#define L_HPLU_OVER hplu = (hdiff == 1 ? "a" : "e");
#define L_MPLU_OVER mplu = (mdiff == 1 ? "o" : "i");
#define L_HPLU_OVER hplu = (hdiff == 1 ? "a" : "e");
#define L_MPLU_OVER mplu = (mdiff == 1 ? "o" : "i");
#define L_A_OVER sprintf(s, "%s, %d %s %d", DayName[dse%7], d,\
#define L_A_OVER sprintf(s, "%s, %d %s %d", DayName[dse%7], d,\
MonthName[m], y);
#define L_C_OVER sprintf(s, "%s", DayName[dse%7]);
#define L_C_OVER sprintf(s, "%s", DayName[dse%7]);
#define L_E_OVER sprintf(s, "%02d%c%02d%c%04d", d, DateSep,\
#define L_E_OVER sprintf(s, "%02d%c%02d%c%04d", d, DateSep,\
m+1, DateSep, y);
#define L_F_OVER sprintf(s, "%02d%c%02d%c%04d", m+1, DateSep, d, DateSep, y);
#define L_F_OVER sprintf(s, "%02d%c%02d%c%04d", m+1, DateSep, d, DateSep, y);
#define L_G_OVER sprintf(s, "%s, %d %s", DayName[dse%7], d, MonthName[m]);
#define L_G_OVER sprintf(s, "%s, %d %s", DayName[dse%7], d, MonthName[m]);
#define L_H_OVER sprintf(s, "%02d%c%02d", d, DateSep, m+1);
#define L_H_OVER sprintf(s, "%02d%c%02d", d, DateSep, m+1);
#define L_I_OVER sprintf(s, "%02d%c%02d", m+1, DateSep, d);
#define L_I_OVER sprintf(s, "%02d%c%02d", m+1, DateSep, d);
#define L_J_OVER sprintf(s, "%s, %d %s %d", DayName[dse%7], d, \
#define L_J_OVER sprintf(s, "%s, %d %s %d", DayName[dse%7], d, \
MonthName[m], y);
#define L_K_OVER sprintf(s, "%s, %d %s", DayName[dse%7], d, \
#define L_K_OVER sprintf(s, "%s, %d %s", DayName[dse%7], d, \
MonthName[m]);
#define L_L_OVER sprintf(s, "%04d%c%02d%c%02d", y, DateSep, m+1, DateSep, d);
#define L_L_OVER sprintf(s, "%04d%c%02d%c%02d", y, DateSep, m+1, DateSep, d);
#define L_U_OVER sprintf(s, "%s, %d %s %d", DayName[dse%7], d, \
#define L_U_OVER sprintf(s, "%s, %d %s %d", DayName[dse%7], d, \
MonthName[m], y);
#define L_V_OVER sprintf(s, "%s, %d %s", DayName[dse%7], d, \
#define L_V_OVER sprintf(s, "%s, %d %s", DayName[dse%7], d, \
MonthName[m]);
+9 -9
View File
@@ -95,11 +95,11 @@ ampm = (hour<12) ? \
: (hour<18) ? " po południu" \
: (hour<22) ? " wieczorem" \
: " w nocy";
#define L_ORDINAL_OVERRIDE plu = "";
#define L_A_OVER if (altmode == '*') { sprintf(s, "%s, %d. %s %d", DayName[dse%7], d, MonthName[m], y); } else { sprintf(s, "%s %s, %d. %s %d", L_ON, DayName[dse%7], d, MonthName[m], y); }
#define L_G_OVER if (altmode == '*') { sprintf(s, "%s, %d. %s", DayName[dse%7], d, MonthName[m]); } else { sprintf(s, "%s %s, %d. %s", L_ON, DayName[dse%7], d, MonthName[m]); }
#define L_U_OVER L_A_OVER
#define L_V_OVER L_G_OVER
#define L_ORDINAL_OVERRIDE plu = "";
#define L_A_OVER if (altmode == '*') { sprintf(s, "%s, %d. %s %d", DayName[dse%7], d, MonthName[m], y); } else { sprintf(s, "%s %s, %d. %s %d", L_ON, DayName[dse%7], d, MonthName[m], y); }
#define L_G_OVER if (altmode == '*') { sprintf(s, "%s, %d. %s", DayName[dse%7], d, MonthName[m]); } else { sprintf(s, "%s %s, %d. %s", L_ON, DayName[dse%7], d, MonthName[m]); }
#define L_U_OVER L_A_OVER
#define L_V_OVER L_G_OVER
#define L_0_OVER sprintf(s, L_NPLU(hdiff));
#define L_9_OVER sprintf(s, L_NPLU(mdiff));
@@ -109,12 +109,12 @@ sprintf(s, L_NOW); \
else if (tdiff > 0) \
{ \
if (hdiff == 0) \
sprintf(s, "za %d %s%s", mdiff, L_MINUTE, L_NPLU(mdiff)); \
sprintf(s, "za %d %s%s", mdiff, L_MINUTE, L_NPLU(mdiff)); \
else if (mdiff == 0) \
sprintf(s, "za %d %s%s", hdiff, L_HOUR, L_NPLU(hdiff)); \
else \
sprintf(s, "za %d %s%s %s %d %s%s", hdiff, L_HOUR, L_NPLU(hdiff), \
L_AND, mdiff, L_MINUTE, L_NPLU(mdiff)); \
sprintf(s, "za %d %s%s %s %d %s%s", hdiff, L_HOUR, L_NPLU(hdiff), \
L_AND, mdiff, L_MINUTE, L_NPLU(mdiff)); \
} \
else \
{ \
@@ -124,7 +124,7 @@ else \
sprintf(s, "%d %s%s temu", hdiff, L_HOUR, L_NPLU(hdiff)); \
else \
sprintf(s, "%d %s%s %s %d %s%s temu", hdiff, L_HOUR, L_NPLU(hdiff), \
L_AND, mdiff, L_MINUTE, L_NPLU(mdiff)); \
L_AND, mdiff, L_MINUTE, L_NPLU(mdiff)); \
}
/* The next ones are used only when MK_GLOBALS is set */
+14 -14
View File
@@ -92,10 +92,10 @@
sprintf(s, "%s %s, %d de %s de %d", _ON_WEEKDAY(dse), DayName[dse%7], d, MonthName[m], y);
#define L_C_OVER \
sprintf(s, "%s %s", _ON_WEEKDAY(dse), DayName[dse%7]);
sprintf(s, "%s %s", _ON_WEEKDAY(dse), DayName[dse%7]);
#define L_G_OVER \
sprintf(s, "%s %s, %d %s", _ON_WEEKDAY(dse), DayName[dse%7], d, MonthName[m]);
sprintf(s, "%s %s, %d %s", _ON_WEEKDAY(dse), DayName[dse%7], d, MonthName[m]);
#define L_J_OVER \
sprintf(s, "%s %s, %d de %s de %d", _ON_WEEKDAY(dse), DayName[dse%7], d, MonthName[m], y);
@@ -113,26 +113,26 @@
#define L_1_OVER \
{ \
if (tdiff == 0) \
sprintf(s, L_NOW); \
sprintf(s, L_NOW); \
else \
if (hdiff == 0) \
{ \
if (mdiff > 0) \
sprintf(s, "em %d %s%s", mdiff, L_MINUTE, mplu); \
else \
sprintf(s, "%d %s%s atras", mdiff, L_MINUTE, mplu); \
} \
if (mdiff > 0) \
sprintf(s, "em %d %s%s", mdiff, L_MINUTE, mplu); \
else \
sprintf(s, "%d %s%s atras", mdiff, L_MINUTE, mplu); \
} \
else if (mdiff == 0) \
{ \
if (hdiff > 0) \
sprintf(s, "em %d %s%s", hdiff, L_HOUR, hplu); \
if (hdiff > 0) \
sprintf(s, "em %d %s%s", hdiff, L_HOUR, hplu); \
else \
sprintf(s, "%d %s%s atras", hdiff, L_HOUR, hplu); \
sprintf(s, "%d %s%s atras", hdiff, L_HOUR, hplu); \
} else { \
if (tdiff > 0) \
sprintf(s, "em %d %s%s %s %d %s%s", hdiff, L_HOUR, hplu, L_AND, mdiff, L_MINUTE, mplu); \
if (tdiff > 0) \
sprintf(s, "em %d %s%s %s %d %s%s", hdiff, L_HOUR, hplu, L_AND, mdiff, L_MINUTE, mplu); \
else \
sprintf(s, "%d %s%s %s %d %s%s atras", hdiff, L_HOUR, hplu, L_AND, mdiff, L_MINUTE, mplu); \
sprintf(s, "%d %s%s %s %d %s%s atras", hdiff, L_HOUR, hplu, L_AND, mdiff, L_MINUTE, mplu); \
} \
}
+12 -12
View File
@@ -82,8 +82,8 @@
/* Define any overrides here, such as L_ORDINAL_OVERRIDE, L_A_OVER, etc.
See the file dosubst.c for more info. */
#define L_AMPM_OVERRIDE(ampm, hour) ampm = (hour < 12) ? (hour<4) ? " noaptea" : " dimineaţa" : (hour > 17) ? " seara" : " după-amiaza";
#define L_ORDINAL_OVERRIDE plu = "";
#define L_AMPM_OVERRIDE(ampm, hour) ampm = (hour < 12) ? (hour<4) ? " noaptea" : " dimineaţa" : (hour > 17) ? " seara" : " după-amiaza";
#define L_ORDINAL_OVERRIDE plu = "";
#define L_A_OVER sprintf(s, "%s, %d %s %d", DayName[dse%7], d, MonthName[m], y);
#define L_C_OVER sprintf(s, "%s", DayName[dse%7]);
@@ -93,13 +93,13 @@
#define L_S_OVER
#define L_U_OVER sprintf(s, "%s, %d %s %d", DayName[dse%7], d, MonthName[m], y);
#define L_V_OVER sprintf(s, "%s, %d %s", DayName[dse%7], d, MonthName[m]);
#define L_1_OVER \
if (tdiff == 0) \
sprintf(s, L_NOW); \
else if (hdiff == 0) \
sprintf(s, "%s %d %s%s", when, mdiff, L_MINUTE, mplu); \
else if (mdiff == 0) \
sprintf(s, "%s %d %s%s", when, hdiff, L_HOUR, hplu); \
else \
sprintf(s, "%s %d %s%s %s %d %s%s", when, hdiff, \
L_HOUR, hplu, L_AND, mdiff, L_MINUTE, mplu);
#define L_1_OVER \
if (tdiff == 0) \
sprintf(s, L_NOW); \
else if (hdiff == 0) \
sprintf(s, "%s %d %s%s", when, mdiff, L_MINUTE, mplu); \
else if (mdiff == 0) \
sprintf(s, "%s %d %s%s", when, hdiff, L_HOUR, hplu); \
else \
sprintf(s, "%s %d %s%s %s %d %s%s", when, hdiff, \
L_HOUR, hplu, L_AND, mdiff, L_MINUTE, mplu);
+476 -476
View File
File diff suppressed because it is too large Load Diff
+33 -33
View File
@@ -16,7 +16,7 @@
* needed on buffers full of bytes, and then call MD5Final, which
* will fill a supplied 16-byte array with the digest.
*/
#include <string.h> /* for memcpy() */
#include <string.h> /* for memcpy() */
#include "md5.h"
static void byteReverse(unsigned char *buf, unsigned longs);
@@ -29,10 +29,10 @@ byteReverse(unsigned char *buf, unsigned longs)
{
uint32 t;
do {
t = (uint32) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
((unsigned) buf[1] << 8 | buf[0]);
*(uint32 *) buf = t;
buf += 4;
t = (uint32) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
((unsigned) buf[1] << 8 | buf[0]);
*(uint32 *) buf = t;
buf += 4;
} while (--longs);
}
@@ -63,35 +63,35 @@ void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
t = ctx->bits[0];
if ((ctx->bits[0] = t + ((uint32) len << 3)) < t)
ctx->bits[1]++; /* Carry from low to high */
ctx->bits[1]++; /* Carry from low to high */
ctx->bits[1] += len >> 29;
t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */
t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */
/* Handle any leading odd-sized chunks */
if (t) {
unsigned char *p = (unsigned char *) ctx->in + t;
unsigned char *p = (unsigned char *) ctx->in + t;
t = 64 - t;
if (len < t) {
memcpy(p, buf, len);
return;
}
memcpy(p, buf, t);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (uint32 *) ctx->in);
buf += t;
len -= t;
t = 64 - t;
if (len < t) {
memcpy(p, buf, len);
return;
}
memcpy(p, buf, t);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (uint32 *) ctx->in);
buf += t;
len -= t;
}
/* Process data in 64-byte chunks */
while (len >= 64) {
memcpy(ctx->in, buf, 64);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (uint32 *) ctx->in);
buf += 64;
len -= 64;
memcpy(ctx->in, buf, 64);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (uint32 *) ctx->in);
buf += 64;
len -= 64;
}
/* Handle any remaining bytes of data. */
@@ -121,16 +121,16 @@ void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
/* Pad out to 56 mod 64 */
if (count < 8) {
/* Two lots of padding: Pad the first block to 64 bytes */
memset(p, 0, count);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (uint32 *) ctx->in);
/* Two lots of padding: Pad the first block to 64 bytes */
memset(p, 0, count);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (uint32 *) ctx->in);
/* Now fill the next block with 56 bytes */
memset(ctx->in, 0, 56);
/* Now fill the next block with 56 bytes */
memset(ctx->in, 0, 56);
} else {
/* Pad block to 56 bytes */
memset(p, 0, count - 8);
/* Pad block to 56 bytes */
memset(p, 0, count - 8);
}
byteReverse(ctx->in, 14);
@@ -141,7 +141,7 @@ void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
MD5Transform(ctx->buf, (uint32 *) ctx->in);
byteReverse((unsigned char *) ctx->buf, 4);
memcpy(digest, ctx->buf, 16);
memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */
memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */
}
#ifndef ASM_MD5
@@ -156,7 +156,7 @@ void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
/* This is the central step in the MD5 algorithm. */
#define MD5STEP(f, w, x, y, z, data, s) \
( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )
( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )
/*
* The core of the MD5 algorithm, this alters an existing MD5 hash to
+4 -4
View File
@@ -20,14 +20,14 @@ typedef unsigned long uint32;
#endif
struct MD5Context {
uint32 buf[4];
uint32 bits[2];
unsigned char in[64];
uint32 buf[4];
uint32 bits[2];
unsigned char in[64];
};
void MD5Init(struct MD5Context *context);
void MD5Update(struct MD5Context *context, unsigned char const *buf,
unsigned len);
unsigned len);
void MD5Final(unsigned char digest[16], struct MD5Context *context);
void MD5Transform(uint32 buf[4], uint32 const in[16]);
+121 -121
View File
@@ -82,27 +82,27 @@ static double phase (double, double *, double *, double *, double *, double *, d
/* Astronomical constants */
#define epoch 2444238.5 /* 1980 January 0.0 */
#define epoch 2444238.5 /* 1980 January 0.0 */
/* Constants defining the Sun's apparent orbit */
#define elonge 278.833540 /* Ecliptic longitude of the Sun
at epoch 1980.0 */
#define elongp 282.596403 /* Ecliptic longitude of the Sun at
perigee */
#define elonge 278.833540 /* Ecliptic longitude of the Sun
at epoch 1980.0 */
#define elongp 282.596403 /* Ecliptic longitude of the Sun at
perigee */
#define eccent 0.016718 /* Eccentricity of Earth's orbit */
#define sunsmax 1.495985e8 /* Semi-major axis of Earth's orbit, km */
#define sunangsiz 0.533128 /* Sun's angular size, degrees, at
semi-major axis distance */
semi-major axis distance */
/* Elements of the Moon's orbit, epoch 1980.0 */
#define mmlong 64.975464 /* Moon's mean lonigitude at the epoch */
#define mmlongp 349.383063 /* Mean longitude of the perigee at the
epoch */
#define mmlongp 349.383063 /* Mean longitude of the perigee at the
epoch */
#define mecc 0.054900 /* Eccentricity of the Moon's orbit */
#define mangsiz 0.5181 /* Moon's angular size at distance a
from Earth */
from Earth */
#define msmax 384401.0 /* Semi-major axis of Moon's orbit in km */
#define synmonth 29.53058868 /* Synodic month (new Moon to new Moon) */
@@ -117,13 +117,13 @@ static double phase (double, double *, double *, double *, double *, double *, d
#ifdef abs
#undef abs
#endif
#define abs(x) ((x) < 0 ? (-(x)) : (x)) /* Absolute val */
#define abs(x) ((x) < 0 ? (-(x)) : (x)) /* Absolute val */
#define fixangle(a) ((a) - 360.0 * (floor((a) / 360.0))) /* Fix angle */
#define torad(d) ((d) * (PI / 180.0)) /* Deg->Rad */
#define todeg(d) ((d) * (180.0 / PI)) /* Rad->Deg */
#define dsin(x) (sin(torad((x)))) /* Sin from deg */
#define dcos(x) (cos(torad((x)))) /* Cos from deg */
#define fixangle(a) ((a) - 360.0 * (floor((a) / 360.0))) /* Fix angle */
#define torad(d) ((d) * (PI / 180.0)) /* Deg->Rad */
#define todeg(d) ((d) * (180.0 / PI)) /* Rad->Deg */
#define dsin(x) (sin(torad((x)))) /* Sin from deg */
#define dcos(x) (cos(torad((x)))) /* Cos from deg */
/***************************************************************/
/* */
@@ -138,10 +138,10 @@ static long jdate(int y, int mon, int day)
m = mon+1;
if (m>2) {
m -= 3;
m -= 3;
} else {
m += 9;
y--;
m += 9;
y--;
}
c = y/100L; /* Century */
y -= 100L * c;
@@ -159,7 +159,7 @@ static long jdate(int y, int mon, int day)
static double jtime(int y, int mon, int day, int hour, int min, int sec)
{
return (jdate(y, mon, day)-0.5) +
(sec + 60L * (long) min + 3600L * (long) hour) / 86400.0;
(sec + 60L * (long) min + 3600L * (long) hour) / 86400.0;
}
/***************************************************************/
@@ -187,10 +187,10 @@ static void jyear(double td, int *yy, int *mm, int *dd)
d = floor((d + 5.0) / 5.0);
y = (100.0 * y) + j;
if (m < 10.0)
m = m + 2;
m = m + 2;
else {
m = m - 10;
y = y + 1;
m = m - 10;
y = y + 1;
}
*yy = y;
*mm = m;
@@ -220,16 +220,16 @@ static void jhms(double j, int *h, int *m, int *s)
/* meanphase */
/* */
/* Calculates mean phase of the Moon for a */
/* given base date and desired phase: */
/* 0.0 New Moon */
/* 0.25 First quarter */
/* 0.5 Full moon */
/* 0.75 Last quarter */
/* Beware!!! This routine returns meaningless */
/* results for any other phase arguments. Don't */
/* attempt to generalise it without understanding */
/* that the motion of the moon is far more complicated */
/* than this calculation reveals. */
/* given base date and desired phase: */
/* 0.0 New Moon */
/* 0.25 First quarter */
/* 0.5 Full moon */
/* 0.75 Last quarter */
/* Beware!!! This routine returns meaningless */
/* results for any other phase arguments. Don't */
/* attempt to generalise it without understanding */
/* that the motion of the moon is far more complicated */
/* than this calculation reveals. */
/* */
/***************************************************************/
static double meanphase(double sdate, double phase, double *usek)
@@ -246,14 +246,14 @@ static double meanphase(double sdate, double phase, double *usek)
/* Time in Julian centuries from 1900 January 0.5 */
t = (sdate - 2415020.0) / 36525.0;
t2 = t * t; /* Square for frequent use */
t3 = t2 * t; /* Cube for frequent use */
t2 = t * t; /* Square for frequent use */
t3 = t2 * t; /* Cube for frequent use */
*usek = k = floor(k) + phase;
nt1 = 2415020.75933 + synmonth * k
+ 0.0001178 * t2
- 0.000000155 * t3
+ 0.00033 * dsin(166.56 + 132.87 * t - 0.009173 * t2);
+ 0.0001178 * t2
- 0.000000155 * t3
+ 0.00033 * dsin(166.56 + 132.87 * t - 0.009173 * t2);
return nt1;
}
@@ -273,70 +273,70 @@ static double truephase(double k, double phase)
double t, t2, t3, pt, m, mprime, f;
int apcor = 0;
k += phase; /* Add phase to new moon time */
t = k / 1236.8531; /* Time in Julian centuries from
1900 January 0.5 */
t2 = t * t; /* Square for frequent use */
t3 = t2 * t; /* Cube for frequent use */
pt = 2415020.75933 /* Mean time of phase */
k += phase; /* Add phase to new moon time */
t = k / 1236.8531; /* Time in Julian centuries from
1900 January 0.5 */
t2 = t * t; /* Square for frequent use */
t3 = t2 * t; /* Cube for frequent use */
pt = 2415020.75933 /* Mean time of phase */
+ synmonth * k
+ 0.0001178 * t2
- 0.000000155 * t3
+ 0.00033 * dsin(166.56 + 132.87 * t - 0.009173 * t2);
m = 359.2242 /* Sun's mean anomaly */
+ 29.10535608 * k
- 0.0000333 * t2
- 0.00000347 * t3;
+ 29.10535608 * k
- 0.0000333 * t2
- 0.00000347 * t3;
mprime = 306.0253 /* Moon's mean anomaly */
+ 385.81691806 * k
+ 0.0107306 * t2
+ 0.00001236 * t3;
+ 385.81691806 * k
+ 0.0107306 * t2
+ 0.00001236 * t3;
f = 21.2964 /* Moon's argument of latitude */
+ 390.67050646 * k
- 0.0016528 * t2
- 0.00000239 * t3;
+ 390.67050646 * k
- 0.0016528 * t2
- 0.00000239 * t3;
if ((phase < 0.01) || (abs(phase - 0.5) < 0.01)) {
/* Corrections for New and Full Moon */
/* Corrections for New and Full Moon */
pt += (0.1734 - 0.000393 * t) * dsin(m)
+ 0.0021 * dsin(2 * m)
- 0.4068 * dsin(mprime)
+ 0.0161 * dsin(2 * mprime)
- 0.0004 * dsin(3 * mprime)
+ 0.0104 * dsin(2 * f)
- 0.0051 * dsin(m + mprime)
- 0.0074 * dsin(m - mprime)
+ 0.0004 * dsin(2 * f + m)
- 0.0004 * dsin(2 * f - m)
- 0.0006 * dsin(2 * f + mprime)
+ 0.0010 * dsin(2 * f - mprime)
+ 0.0005 * dsin(m + 2 * mprime);
apcor = 1;
pt += (0.1734 - 0.000393 * t) * dsin(m)
+ 0.0021 * dsin(2 * m)
- 0.4068 * dsin(mprime)
+ 0.0161 * dsin(2 * mprime)
- 0.0004 * dsin(3 * mprime)
+ 0.0104 * dsin(2 * f)
- 0.0051 * dsin(m + mprime)
- 0.0074 * dsin(m - mprime)
+ 0.0004 * dsin(2 * f + m)
- 0.0004 * dsin(2 * f - m)
- 0.0006 * dsin(2 * f + mprime)
+ 0.0010 * dsin(2 * f - mprime)
+ 0.0005 * dsin(m + 2 * mprime);
apcor = 1;
} else if ((abs(phase - 0.25) < 0.01 || (abs(phase - 0.75) < 0.01))) {
pt += (0.1721 - 0.0004 * t) * dsin(m)
+ 0.0021 * dsin(2 * m)
- 0.6280 * dsin(mprime)
+ 0.0089 * dsin(2 * mprime)
- 0.0004 * dsin(3 * mprime)
+ 0.0079 * dsin(2 * f)
- 0.0119 * dsin(m + mprime)
- 0.0047 * dsin(m - mprime)
+ 0.0003 * dsin(2 * f + m)
- 0.0004 * dsin(2 * f - m)
- 0.0006 * dsin(2 * f + mprime)
+ 0.0021 * dsin(2 * f - mprime)
+ 0.0003 * dsin(m + 2 * mprime)
+ 0.0004 * dsin(m - 2 * mprime)
- 0.0003 * dsin(2 * m + mprime);
if (phase < 0.5)
/* First quarter correction */
pt += 0.0028 - 0.0004 * dcos(m) + 0.0003 * dcos(mprime);
else
/* Last quarter correction */
pt += -0.0028 + 0.0004 * dcos(m) - 0.0003 * dcos(mprime);
apcor = 1;
pt += (0.1721 - 0.0004 * t) * dsin(m)
+ 0.0021 * dsin(2 * m)
- 0.6280 * dsin(mprime)
+ 0.0089 * dsin(2 * mprime)
- 0.0004 * dsin(3 * mprime)
+ 0.0079 * dsin(2 * f)
- 0.0119 * dsin(m + mprime)
- 0.0047 * dsin(m - mprime)
+ 0.0003 * dsin(2 * f + m)
- 0.0004 * dsin(2 * f - m)
- 0.0006 * dsin(2 * f + mprime)
+ 0.0021 * dsin(2 * f - mprime)
+ 0.0003 * dsin(m + 2 * mprime)
+ 0.0004 * dsin(m - 2 * mprime)
- 0.0003 * dsin(2 * m + mprime);
if (phase < 0.5)
/* First quarter correction */
pt += 0.0028 - 0.0004 * dcos(m) + 0.0003 * dcos(mprime);
else
/* Last quarter correction */
pt += -0.0028 + 0.0004 * dcos(m) - 0.0003 * dcos(mprime);
apcor = 1;
}
if (!apcor) return 0.0;
return pt;
@@ -356,8 +356,8 @@ static double kepler(double m, double ecc)
e = m = torad(m);
do {
delta = e - ecc * sin(e) - m;
e -= delta / (1 - ecc * cos(e));
delta = e - ecc * sin(e) - m;
e -= delta / (1 - ecc * cos(e));
} while (abs(delta) > EPSILON);
return e;
}
@@ -365,47 +365,47 @@ static double kepler(double m, double ecc)
/* */
/* PHASE -- Calculate phase of moon as a fraction: */
/* */
/* The argument is the time for which the phase is */
/* Requested, expressed as a Julian date and */
/* fraction. Returns the terminator phase angle as a */
/* percentage of a full circle (i.e., 0 to 1), and */
/* stores into pointer arguments the illuminated */
/* fraction of the Moon's disc, the Moon's age in */
/* days and fraction, the distance of the Moon from */
/* the centre of the Earth, and the angular diameter */
/* subtended by the Moon as seen by an observer at */
/* the centre of the Earth. */
/* The argument is the time for which the phase is */
/* Requested, expressed as a Julian date and */
/* fraction. Returns the terminator phase angle as a */
/* percentage of a full circle (i.e., 0 to 1), and */
/* stores into pointer arguments the illuminated */
/* fraction of the Moon's disc, the Moon's age in */
/* days and fraction, the distance of the Moon from */
/* the centre of the Earth, and the angular diameter */
/* subtended by the Moon as seen by an observer at */
/* the centre of the Earth. */
/* */
/***************************************************************/
static double phase(double pdate,
double *pphase,
double *mage,
double *dist,
double *angdia,
double *sudist,
double *suangdia)
double *pphase,
double *mage,
double *dist,
double *angdia,
double *sudist,
double *suangdia)
{
double Day, N, M, Ec, Lambdasun, ml, MM, Ev, Ae, A3, MmP,
mEc, A4, lP, V, lPP,
MoonAge, Phase,
MoonDist, MoonDFrac, MoonAng,
F, SunDist, SunAng;
mEc, A4, lP, V, lPP,
MoonAge, Phase,
MoonDist, MoonDFrac, MoonAng,
F, SunDist, SunAng;
/* Calculation of the Sun's position */
Day = pdate - epoch; /* Date within epoch */
Day = pdate - epoch; /* Date within epoch */
N = fixangle((360 / 365.2422) * Day); /* Mean anomaly of the Sun */
M = fixangle(N + elonge - elongp); /* Convert from perigee
coordinates to epoch 1980.0 */
coordinates to epoch 1980.0 */
Ec = kepler(M, eccent); /* Solve equation of Kepler */
Ec = sqrt((1 + eccent) / (1 - eccent)) * tan(Ec / 2);
Ec = 2 * todeg(atan(Ec)); /* 1 anomaly */
Lambdasun = fixangle(Ec + elongp); /* Sun's geocentric ecliptic
longitude */
longitude */
/* Orbital distance factor */
F = ((1 + eccent * cos(torad(Ec))) / (1 - eccent * eccent));
SunDist = sunsmax / F; /* Distance to Sun in km */
SunDist = sunsmax / F; /* Distance to Sun in km */
SunAng = F * sunangsiz; /* Sun's angular size in degrees */
@@ -455,7 +455,7 @@ static double phase(double pdate,
/* Calculate distance of moon from the centre of the Earth */
MoonDist = (msmax * (1 - mecc * mecc)) /
(1 + mecc * cos(torad(MmP + mEc)));
(1 + mecc * cos(torad(MmP + mEc)));
/* Calculate Moon's angular diameter */
@@ -529,11 +529,11 @@ void HuntPhase(int startdate, int starttim, int phas, int *date, int *time)
jd = jdorig - 45.0;
nt1 = meanphase(jd, 0.0, &k1);
while(1) {
jd += synmonth;
nt2 = meanphase(jd, 0.0, &k2);
if (nt1 <= jdorig && nt2 > jdorig) break;
nt1 = nt2;
k1 = k2;
jd += synmonth;
nt2 = meanphase(jd, 0.0, &k2);
if (nt1 <= jdorig && nt2 > jdorig) break;
nt1 = nt2;
k1 = k2;
}
jd = truephase(k1, phas/4.0);
if (jd < jdorig) jd = truephase(k2, phas/4.0);
+111 -112
View File
@@ -95,13 +95,13 @@ int DestroyOmitContexts(int print_unmatched)
Wprint("Unmatched PUSH-OMIT-CONTEXT at %s(%d)",
c->filename, c->lineno);
}
num++;
if (c->fullsave) free(c->fullsave);
if (c->partsave) free(c->partsave);
num++;
if (c->fullsave) free(c->fullsave);
if (c->partsave) free(c->partsave);
if (c->filename) free(c->filename);
d = c->next;
free(c);
c = d;
d = c->next;
free(c);
c = d;
}
SavedOmitContexts = NULL;
return num;
@@ -139,25 +139,25 @@ int PushOmitContext(ParsePtr p)
context->fullsave = malloc(NumFullOmits * sizeof(int));
if (NumFullOmits && !context->fullsave) {
free(context->filename);
free(context);
return E_NO_MEM;
free(context);
return E_NO_MEM;
}
context->partsave = malloc(NumPartialOmits * sizeof(int));
if (NumPartialOmits && !context->partsave) {
free(context->filename);
if (context->fullsave) {
if (context->fullsave) {
free(context->fullsave);
}
free(context);
return E_NO_MEM;
free(context);
return E_NO_MEM;
}
/* Copy the context over */
for (i=0; i<NumFullOmits; i++)
*(context->fullsave + i) = FullOmitArray[i];
*(context->fullsave + i) = FullOmitArray[i];
for (i=0; i<NumPartialOmits; i++)
*(context->partsave + i) = PartialOmitArray[i];
*(context->partsave + i) = PartialOmitArray[i];
/* Add the context to the stack */
context->next = SavedOmitContexts;
@@ -185,10 +185,10 @@ int PopOmitContext(ParsePtr p)
/* Copy the context over */
for (i=0; i<NumFullOmits; i++)
FullOmitArray[i] = *(c->fullsave + i);
FullOmitArray[i] = *(c->fullsave + i);
for (i=0; i<NumPartialOmits; i++)
PartialOmitArray[i] = *(c->partsave + i);
PartialOmitArray[i] = *(c->partsave + i);
/* Remove the context from the stack */
SavedOmitContexts = c->next;
@@ -217,29 +217,29 @@ int IsOmitted(int dse, int localomit, char const *omitfunc, int *omit)
/* If we have an omitfunc, we *only* use it and ignore local/global
OMITs */
if (omitfunc && *omitfunc && UserFuncExists(omitfunc)) {
char expr[VAR_NAME_LEN + 32];
char const *s;
int r;
Value v;
char expr[VAR_NAME_LEN + 32];
char const *s;
int r;
Value v;
FromDSE(dse, &y, &m, &d);
sprintf(expr, "%s('%04d-%02d-%02d')",
omitfunc, y, m+1, d);
s = expr;
r = EvalExpr(&s, &v, NULL);
if (r) return r;
if (v.type == INT_TYPE && v.v.val != 0) {
*omit = 1;
} else {
*omit = 0;
}
return OK;
FromDSE(dse, &y, &m, &d);
sprintf(expr, "%s('%04d-%02d-%02d')",
omitfunc, y, m+1, d);
s = expr;
r = EvalExpr(&s, &v, NULL);
if (r) return r;
if (v.type == INT_TYPE && v.v.val != 0) {
*omit = 1;
} else {
*omit = 0;
}
return OK;
}
/* Is it omitted because of local omits? */
if (localomit & (1 << (dse % 7))) {
*omit = 1;
return OK;
*omit = 1;
return OK;
}
/* Is it omitted because of global weekday omits? */
@@ -250,14 +250,14 @@ int IsOmitted(int dse, int localomit, char const *omitfunc, int *omit)
/* Is it omitted because of fully-specified omits? */
if (BexistsIntArray(FullOmitArray, NumFullOmits, dse)) {
*omit = 1;
return OK;
*omit = 1;
return OK;
}
FromDSE(dse, &y, &m, &d);
if (BexistsIntArray(PartialOmitArray, NumPartialOmits, (m << 5) + d)) {
*omit = 1;
return OK;
*omit = 1;
return OK;
}
/* Not omitted */
@@ -278,10 +278,10 @@ static int BexistsIntArray(int const array[], int num, int key)
int top=num-1, bot=0, mid;
while (top >= bot) {
mid = (top+bot)/2;
if (array[mid] == key) return 1;
else if (array[mid] > key) top = mid-1;
else bot=mid+1;
mid = (top+bot)/2;
if (array[mid] == key) return 1;
else if (array[mid] > key) top = mid-1;
else bot=mid+1;
}
return 0;
}
@@ -300,8 +300,8 @@ static void InsertIntoSortedArray(int *array, int num, int key)
int *cur = array+num;
while (cur > array && *(cur-1) > key) {
*cur = *(cur-1);
cur--;
*cur = *(cur-1);
cur--;
}
*cur = key;
}
@@ -333,72 +333,72 @@ int DoOmit(ParsePtr p)
/* Parse the OMIT. We need a month and day; year is optional. */
while(parsing) {
not_first_token++;
if ( (r=ParseToken(p, &buf)) ) return r;
FindToken(DBufValue(&buf), &tok);
switch (tok.type) {
not_first_token++;
if ( (r=ParseToken(p, &buf)) ) return r;
FindToken(DBufValue(&buf), &tok);
switch (tok.type) {
case T_WkDay:
DBufFree(&buf);
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();
return OK;
case T_Dumpvars:
DBufFree(&buf);
if (not_first_token) return E_PARSE_ERR;
r = VerifyEoln(p);
if (r != OK) return r;
DumpOmits();
return OK;
case T_Date:
DBufFree(&buf);
if (y[seen_through] != NO_YR) return E_YR_TWICE;
if (m[seen_through] != NO_MON) return E_MON_TWICE;
if (d[seen_through] != NO_DAY) return E_DAY_TWICE;
FromDSE(tok.val, &y[seen_through], &m[seen_through], &d[seen_through]);
break;
case T_Date:
DBufFree(&buf);
if (y[seen_through] != NO_YR) return E_YR_TWICE;
if (m[seen_through] != NO_MON) return E_MON_TWICE;
if (d[seen_through] != NO_DAY) return E_DAY_TWICE;
FromDSE(tok.val, &y[seen_through], &m[seen_through], &d[seen_through]);
break;
case T_Year:
DBufFree(&buf);
if (y[seen_through] != NO_YR) return E_YR_TWICE;
y[seen_through] = tok.val;
break;
case T_Year:
DBufFree(&buf);
if (y[seen_through] != NO_YR) return E_YR_TWICE;
y[seen_through] = tok.val;
break;
case T_Month:
DBufFree(&buf);
if (m[seen_through] != NO_MON) return E_MON_TWICE;
m[seen_through] = tok.val;
break;
case T_Month:
DBufFree(&buf);
if (m[seen_through] != NO_MON) return E_MON_TWICE;
m[seen_through] = tok.val;
break;
case T_Day:
DBufFree(&buf);
if (d[seen_through] != NO_DAY) return E_DAY_TWICE;
d[seen_through] = tok.val;
break;
case T_Day:
DBufFree(&buf);
if (d[seen_through] != NO_DAY) return E_DAY_TWICE;
d[seen_through] = tok.val;
break;
case T_Delta:
DBufFree(&buf);
break;
case T_Delta:
DBufFree(&buf);
break;
case T_Through:
DBufFree(&buf);
case T_Through:
DBufFree(&buf);
if (wd) return E_PARSE_ERR;
if (seen_through) return E_UNTIL_TWICE;
seen_through = 1;
break;
case T_Empty:
case T_Comment:
case T_RemType:
case T_Priority:
case T_Tag:
case T_Duration:
DBufFree(&buf);
parsing = 0;
break;
case T_Empty:
case T_Comment:
case T_RemType:
case T_Priority:
case T_Tag:
case T_Duration:
DBufFree(&buf);
parsing = 0;
break;
default:
default:
if (tok.type == T_Until) {
Eprint("OMIT: UNTIL not allowed; did you mean THROUGH?");
} else if (tok.type == T_Illegal && tok.val < 0) {
@@ -407,9 +407,9 @@ int DoOmit(ParsePtr p)
Eprint("%s: `%s' (OMIT)", ErrMsg[E_UNKNOWN_TOKEN],
DBufValue(&buf));
}
DBufFree(&buf);
return E_UNKNOWN_TOKEN;
}
DBufFree(&buf);
return E_UNKNOWN_TOKEN;
}
}
if (wd) {
@@ -460,8 +460,8 @@ int DoOmit(ParsePtr p)
if (y[0] == NO_YR) {
/* Partial OMITs */
if (d[0] > MonthDays[m[0]]) return E_BAD_DATE;
if (d[1] > MonthDays[m[1]]) return E_BAD_DATE;
if (d[0] > MonthDays[m[0]]) return E_BAD_DATE;
if (d[1] > MonthDays[m[1]]) return E_BAD_DATE;
dc = d[0];
mc = m[0];
while(1) {
@@ -487,8 +487,8 @@ int DoOmit(ParsePtr p)
}
} else {
/* Full OMITs */
if (d[0] > DaysInMonth(m[0], y[0])) return E_BAD_DATE;
if (d[1] > DaysInMonth(m[1], y[1])) return E_BAD_DATE;
if (d[0] > DaysInMonth(m[0], y[0])) return E_BAD_DATE;
if (d[1] > DaysInMonth(m[1], y[1])) return E_BAD_DATE;
start = DSE(y[0], m[0], d[0]);
end = DSE(y[1], m[1], d[1]);
if (end < start) {
@@ -528,23 +528,23 @@ DumpOmits(void)
int y, m, d;
printf("Global Full OMITs (%d of maximum allowed %d):\n", NumFullOmits, MAX_FULL_OMITS);
if (!NumFullOmits) {
printf("\tNone.\n");
printf("\tNone.\n");
} else {
for (i=0; i<NumFullOmits; i++) {
FromDSE(FullOmitArray[i], &y, &m, &d);
printf("\t%04d%c%02d%c%02d\n",
y, DateSep, m+1, DateSep, d);
}
for (i=0; i<NumFullOmits; i++) {
FromDSE(FullOmitArray[i], &y, &m, &d);
printf("\t%04d%c%02d%c%02d\n",
y, DateSep, m+1, DateSep, d);
}
}
printf("Global Partial OMITs (%d of maximum allowed %d):\n", NumPartialOmits, MAX_PARTIAL_OMITS);
if (!NumPartialOmits) {
printf("\tNone.\n");
printf("\tNone.\n");
} else {
for (i=0; i<NumPartialOmits; i++) {
m = PartialOmitArray[i] >> 5 & 0xf;
d = PartialOmitArray[i] & 0x1f;
printf("\t%02d%c%02d\n", m+1, DateSep, d);
}
for (i=0; i<NumPartialOmits; i++) {
m = PartialOmitArray[i] >> 5 & 0xf;
d = PartialOmitArray[i] & 0x1f;
printf("\t%02d%c%02d\n", m+1, DateSep, d);
}
}
printf("Global Weekday OMITs:\n");
if (WeekdayOmits == 0) {
@@ -557,4 +557,3 @@ DumpOmits(void)
}
}
}
-1
View File
@@ -249,4 +249,3 @@ void print_builtinfunc_tokens(void);
void print_remind_tokens(void);
void get_var_hash_stats(int *total, int *maxlen, double *avglen);
void get_userfunc_hash_stats(int *total, int *maxlen, double *avglen);
+208 -208
View File
@@ -197,22 +197,22 @@ int QueueReminder(ParsePtr p, Trigger *trig,
if (DontQueue ||
trig->noqueue ||
tim->ttime == NO_TIME ||
trig->typ == CAL_TYPE ||
tim->ttime < MinutesPastMidnight(0) ||
((trig->typ == RUN_TYPE) && RunDisabled)) return OK;
tim->ttime == NO_TIME ||
trig->typ == CAL_TYPE ||
tim->ttime < MinutesPastMidnight(0) ||
((trig->typ == RUN_TYPE) && RunDisabled)) return OK;
qelem = NEW(QueuedRem);
if (!qelem) {
return E_NO_MEM;
return E_NO_MEM;
}
qelem->red = DefaultColorR;
qelem->green = DefaultColorG;
qelem->blue = DefaultColorB;
qelem->text = StrDup(p->pos); /* Guaranteed that parser is not nested. */
if (!qelem->text) {
free(qelem);
return E_NO_MEM;
free(qelem);
return E_NO_MEM;
}
qelem->fname = QueueFilename(FileName);
if (!qelem->fname) {
@@ -230,7 +230,7 @@ int QueueReminder(ParsePtr p, Trigger *trig,
DBufInit(&(qelem->t.tags));
DBufPuts(&(qelem->t.tags), DBufValue(&(trig->tags)));
if (SynthesizeTags) {
AppendTag(&(qelem->t.tags), SynthesizeTag());
AppendTag(&(qelem->t.tags), SynthesizeTag());
}
qelem->next = QueueHead;
qelem->RunDisabled = RunDisabled;
@@ -273,14 +273,14 @@ SigContHandler(int d)
static void
print_num_queued(void)
{
int nqueued = 0;
QueuedRem *q = QueueHead;
while(q) {
if (q->tt.nexttime != NO_TIME) {
nqueued++;
}
q = q->next;
}
int nqueued = 0;
QueuedRem *q = QueueHead;
while(q) {
if (q->tt.nexttime != NO_TIME) {
nqueued++;
}
q = q->next;
}
if (DaemonJSON) {
printf("{");
PrintJSONKeyPairString("response", "queued");
@@ -289,7 +289,7 @@ print_num_queued(void)
} else {
printf("NOTE queued %d\n", nqueued);
}
fflush(stdout);
fflush(stdout);
}
/***************************************************************/
@@ -328,7 +328,7 @@ void HandleQueuedReminders(void)
/* If we are not connected to a tty, then we must close the
* standard file descriptors. This is to prevent someone
* doing:
* remind file | <filter> | >log
* remind file | <filter> | >log
* and have <filter> hung because the child (us) is still
* connected to it. This means the only commands that will be
* processed correctly are RUN commands, provided they mail
@@ -342,19 +342,19 @@ void HandleQueuedReminders(void)
/* If we're a daemon, get the mod time of initial file */
if (Daemon > 0) {
if (stat(InitialFile, &StatBuf)) {
fprintf(ErrFp, "Cannot stat %s - not running as daemon!\n",
InitialFile);
Daemon = 0;
} else FileModTime = StatBuf.st_mtime;
if (stat(InitialFile, &StatBuf)) {
fprintf(ErrFp, "Cannot stat %s - not running as daemon!\n",
InitialFile);
Daemon = 0;
} else FileModTime = StatBuf.st_mtime;
}
/* Initialize the queue - initialize all the entries time of issue */
while (q) {
q->tt.nexttime = MinutesPastMidnight(1) - 1;
q->tt.nexttime = CalculateNextTime(q);
q = q->next;
q->tt.nexttime = MinutesPastMidnight(1) - 1;
q->tt.nexttime = CalculateNextTime(q);
q = q->next;
}
if (ShouldFork || Daemon) {
@@ -371,31 +371,31 @@ void HandleQueuedReminders(void)
#endif
/* Sit in a loop, issuing reminders when necessary */
while(1) {
q = FindNextReminder();
q = FindNextReminder();
/* If no more reminders to issue, we're done unless we're a daemon. */
if (!q && !Daemon) break;
/* If no more reminders to issue, we're done unless we're a daemon. */
if (!q && !Daemon) break;
if (Daemon && !q) {
if (IsServerMode()) {
/* Sleep until midnight */
TimeToSleep = MINUTES_PER_DAY*60 - SystemTime(1);
} else {
TimeToSleep = 60*Daemon;
}
} else {
TimeToSleep = q->tt.nexttime * 60L - SystemTime(1);
}
if (Daemon && !q) {
if (IsServerMode()) {
/* Sleep until midnight */
TimeToSleep = MINUTES_PER_DAY*60 - SystemTime(1);
} else {
TimeToSleep = 60*Daemon;
}
} else {
TimeToSleep = q->tt.nexttime * 60L - SystemTime(1);
}
while (TimeToSleep > 0L) {
SleepTime = TimeToSleep;
while (TimeToSleep > 0L) {
SleepTime = TimeToSleep;
if (Daemon > 0 && SleepTime > (unsigned int) 60*Daemon) {
if (Daemon > 0 && SleepTime > (unsigned int) 60*Daemon) {
SleepTime = 60*Daemon;
}
if (IsServerMode()) {
/* Wake up on the next exact minute */
if (IsServerMode()) {
/* Wake up on the next exact minute */
gettimeofday(&tv, NULL);
sleep_tv.tv_sec = 60 - (tv.tv_sec % 60);
if (tv.tv_usec != 0 && sleep_tv.tv_sec != 0) {
@@ -404,56 +404,56 @@ void HandleQueuedReminders(void)
} else {
sleep_tv.tv_usec = 0;
}
ServerWait(&sleep_tv);
ServerWait(&sleep_tv);
/* A DEL command might have deleted our queued reminder! */
q = FindNextReminder();
} else {
sleep(SleepTime);
} else {
sleep(SleepTime);
}
if (GotSigInt()) {
PrintQueue();
}
/* If not in daemon mode and day has rolled around,
exit -- not much we can do. */
if (!Daemon) {
int y, m, d;
if (RealToday != SystemDate(&y, &m, &d)) {
exit(EXIT_SUCCESS);
}
}
/* If not in daemon mode and day has rolled around,
exit -- not much we can do. */
if (!Daemon) {
int y, m, d;
if (RealToday != SystemDate(&y, &m, &d)) {
exit(EXIT_SUCCESS);
}
}
if (Daemon > 0 && SleepTime) {
if (Daemon > 0 && SleepTime) {
CheckInitialFile();
}
if (Daemon && !q) {
if (IsServerMode()) {
/* Sleep until midnight */
TimeToSleep = MINUTES_PER_DAY*60 - SystemTime(1);
} else {
TimeToSleep = 60*Daemon;
}
} else {
TimeToSleep = q->tt.nexttime * 60L - SystemTime(1);
}
if (Daemon && !q) {
if (IsServerMode()) {
/* Sleep until midnight */
TimeToSleep = MINUTES_PER_DAY*60 - SystemTime(1);
} else {
TimeToSleep = 60*Daemon;
}
} else {
TimeToSleep = q->tt.nexttime * 60L - SystemTime(1);
}
}
}
/* Do NOT trigger the reminder if tt.nexttime is more than a
minute in the past. This can happen if the clock is
changed or a laptop awakes from hibernation.
However, DO trigger if tt.nexttime == tt.ttime and we're
/* Do NOT trigger the reminder if tt.nexttime is more than a
minute in the past. This can happen if the clock is
changed or a laptop awakes from hibernation.
However, DO trigger if tt.nexttime == tt.ttime and we're
within MaxLateTrigger minutes so all
queued reminders are triggered at least once. */
if ((SystemTime(1) - (q->tt.nexttime * 60) <= 60) ||
(q->tt.nexttime == q->tt.ttime &&
queued reminders are triggered at least once. */
if ((SystemTime(1) - (q->tt.nexttime * 60) <= 60) ||
(q->tt.nexttime == q->tt.ttime &&
(MaxLateMinutes == 0 || SystemTime(1) - (q->tt.nexttime * 60) <= 60 * MaxLateMinutes))) {
/* Trigger the reminder */
CreateParser(q->text, &p);
RunDisabled = q->RunDisabled;
if (IsServerMode() && q->typ != RUN_TYPE) {
/* Trigger the reminder */
CreateParser(q->text, &p);
RunDisabled = q->RunDisabled;
if (IsServerMode() && q->typ != RUN_TYPE) {
if (DaemonJSON) {
printf("{\"response\":\"reminder\",");
snprintf(qid, sizeof(qid), "%lx", (unsigned long) q);
@@ -471,11 +471,11 @@ void HandleQueuedReminders(void)
printf("%s\n", DBufValue(&(q->t.tags)));
}
}
}
}
/* Set up global variables so some functions like trigdate()
and trigtime() work correctly */
SaveAllTriggerInfo(&(q->t), &(q->tt), DSEToday, q->tt.ttime, 1);
/* Set up global variables so some functions like trigdate()
and trigtime() work correctly */
SaveAllTriggerInfo(&(q->t), &(q->tt), DSEToday, q->tt.ttime, 1);
FileName = (char *) q->fname;
DefaultColorR = q->red;
DefaultColorG = q->green;
@@ -497,15 +497,15 @@ void HandleQueuedReminders(void)
(void) TriggerReminder(&p, &tcopy, &q->tt, DSEToday, 1, NULL);
}
FileName = NULL;
if (IsServerMode() && !DaemonJSON && q->typ != RUN_TYPE) {
printf("NOTE endreminder\n");
}
fflush(stdout);
DestroyParser(&p);
}
if (IsServerMode() && !DaemonJSON && q->typ != RUN_TYPE) {
printf("NOTE endreminder\n");
}
fflush(stdout);
DestroyParser(&p);
}
/* Calculate the next trigger time */
q->tt.nexttime = CalculateNextTime(q);
/* Calculate the next trigger time */
q->tt.nexttime = CalculateNextTime(q);
if (q->tt.nexttime != NO_TIME) {
/* If trigger time is way in the past because computer has been
@@ -551,15 +551,15 @@ static int CalculateNextTime(QueuedRem *q)
/* Increment number of times this one has been triggered */
q->ntrig++;
if (q->sched[0]) {
r = CalculateNextTimeUsingSched(q);
if (r != NO_TIME) return r;
r = CalculateNextTimeUsingSched(q);
if (r != NO_TIME) return r;
}
if (delta == NO_DELTA) {
if (tim < curtime) {
return NO_TIME;
} else {
return tim;
}
if (tim < curtime) {
return NO_TIME;
} else {
return tim;
}
}
tim -= delta;
@@ -583,12 +583,12 @@ static QueuedRem *FindNextReminder(void)
QueuedRem *ans = NULL;
while (q) {
if (q->tt.nexttime != NO_TIME) {
if (!ans) ans = q;
else if (q->tt.nexttime < ans->tt.nexttime) ans = q;
}
if (q->tt.nexttime != NO_TIME) {
if (!ans) ans = q;
else if (q->tt.nexttime < ans->tt.nexttime) ans = q;
}
q = q->next;
q = q->next;
}
return ans;
}
@@ -596,7 +596,7 @@ static QueuedRem *FindNextReminder(void)
/***************************************************************/
/* */
/* PrintQueue */
/* PrintQueue */
/* */
/* For debugging: Print queue contents to STDOUT */
/* */
@@ -609,22 +609,22 @@ void PrintQueue(void)
printf("Contents of AT queue:%s", NL);
while (q) {
if (q->tt.nexttime != NO_TIME) {
printf("Trigger: %02d%c%02d Activate: %02d%c%02d Rep: %d Delta: %d Sched: %s",
q->tt.ttime / 60, TimeSep, q->tt.ttime % 60,
q->tt.nexttime / 60, TimeSep, q->tt.nexttime % 60,
q->tt.rep, q->tt.delta, q->sched);
if (*q->sched) printf("(%d)", q->ntrig+1);
printf("%s", NL);
printf("Text: %s %s%s%s%s%s", ((q->typ == MSG_TYPE) ? "MSG" :
((q->typ == MSF_TYPE) ? "MSF" :
((q->typ == RUN_TYPE) ? "RUN" : "SPECIAL"))),
q->passthru,
(*(q->passthru)) ? " " : "",
q->text,
NL, NL);
}
q = q->next;
if (q->tt.nexttime != NO_TIME) {
printf("Trigger: %02d%c%02d Activate: %02d%c%02d Rep: %d Delta: %d Sched: %s",
q->tt.ttime / 60, TimeSep, q->tt.ttime % 60,
q->tt.nexttime / 60, TimeSep, q->tt.nexttime % 60,
q->tt.rep, q->tt.delta, q->sched);
if (*q->sched) printf("(%d)", q->ntrig+1);
printf("%s", NL);
printf("Text: %s %s%s%s%s%s", ((q->typ == MSG_TYPE) ? "MSG" :
((q->typ == MSF_TYPE) ? "MSF" :
((q->typ == RUN_TYPE) ? "RUN" : "SPECIAL"))),
q->passthru,
(*(q->passthru)) ? " " : "",
q->text,
NL, NL);
}
q = q->next;
}
printf(NL);
printf("To terminate program, send SIGQUIT (probably Ctrl-\\ on the keyboard.)%s", NL);
@@ -664,8 +664,8 @@ static void CheckInitialFile(void)
#endif
if (stat(InitialFile, &StatBuf) == 0) tim = StatBuf.st_mtime;
if (tim != FileModTime ||
RealToday != SystemDate(&y, &m, &d)) {
reread();
RealToday != SystemDate(&y, &m, &d)) {
reread();
}
}
@@ -686,51 +686,51 @@ static int CalculateNextTimeUsingSched(QueuedRem *q)
int ThisTime;
if (UserFuncExists(q->sched) != 1) {
q->sched[0] = 0;
return NO_TIME;
q->sched[0] = 0;
return NO_TIME;
}
RunDisabled = q->RunDisabled; /* Don't want weird scheduling functions
to be a security hole! */
to be a security hole! */
while(1) {
char exprBuf[VAR_NAME_LEN+32];
sprintf(exprBuf, "%s(%d)", q->sched, q->ntrig);
s = exprBuf;
r = EvalExpr(&s, &v, NULL);
if (r) {
q->sched[0] = 0;
return NO_TIME;
}
if (v.type == TIME_TYPE) {
ThisTime = v.v.val;
} else if (v.type == INT_TYPE) {
if (v.v.val > 0)
if (LastTime >= 0) {
ThisTime = LastTime + v.v.val;
} else {
ThisTime = q->tt.nexttime + v.v.val;
}
else
ThisTime = q->tt.ttime + v.v.val;
char exprBuf[VAR_NAME_LEN+32];
sprintf(exprBuf, "%s(%d)", q->sched, q->ntrig);
s = exprBuf;
r = EvalExpr(&s, &v, NULL);
if (r) {
q->sched[0] = 0;
return NO_TIME;
}
if (v.type == TIME_TYPE) {
ThisTime = v.v.val;
} else if (v.type == INT_TYPE) {
if (v.v.val > 0)
if (LastTime >= 0) {
ThisTime = LastTime + v.v.val;
} else {
ThisTime = q->tt.nexttime + v.v.val;
}
else
ThisTime = q->tt.ttime + v.v.val;
} else {
DestroyValue(v);
q->sched[0] = 0;
return NO_TIME;
}
if (ThisTime < 0) ThisTime = 0; /* Can't be less than 00:00 */
if (ThisTime > (MINUTES_PER_DAY-1)) ThisTime = (MINUTES_PER_DAY-1); /* or greater than 11:59 */
if (DebugFlag & DB_PRTEXPR) {
fprintf(ErrFp, "SCHED: Considering %02d%c%02d\n",
ThisTime / 60, TimeSep, ThisTime % 60);
}
if (ThisTime > q->tt.nexttime) return ThisTime;
if (ThisTime <= LastTime) {
q->sched[0] = 0;
return NO_TIME;
}
LastTime = ThisTime;
q->ntrig++;
} else {
DestroyValue(v);
q->sched[0] = 0;
return NO_TIME;
}
if (ThisTime < 0) ThisTime = 0; /* Can't be less than 00:00 */
if (ThisTime > (MINUTES_PER_DAY-1)) ThisTime = (MINUTES_PER_DAY-1); /* or greater than 11:59 */
if (DebugFlag & DB_PRTEXPR) {
fprintf(ErrFp, "SCHED: Considering %02d%c%02d\n",
ThisTime / 60, TimeSep, ThisTime % 60);
}
if (ThisTime > q->tt.nexttime) return ThisTime;
if (ThisTime <= LastTime) {
q->sched[0] = 0;
return NO_TIME;
}
LastTime = ThisTime;
q->ntrig++;
}
}
@@ -745,15 +745,15 @@ json_queue(QueuedRem const *q)
printf("[");
char idbuf[64];
while(q) {
if (q->tt.nexttime == NO_TIME) {
q = q->next;
continue;
}
if (done) {
printf(",");
}
done = 1;
printf("{");
if (q->tt.nexttime == NO_TIME) {
q = q->next;
continue;
}
if (done) {
printf(",");
}
done = 1;
printf("{");
WriteJSONTrigger(&(q->t), 1, DSEToday);
WriteJSONTimeTrigger(&(q->tt));
snprintf(idbuf, sizeof(idbuf), "%lx", (unsigned long) q);
@@ -762,33 +762,33 @@ json_queue(QueuedRem const *q)
PrintJSONKeyPairInt("ntrig", q->ntrig);
PrintJSONKeyPairString("filename", q->fname);
PrintJSONKeyPairInt("lineno", q->lineno);
switch(q->typ) {
case NO_TYPE: PrintJSONKeyPairString("type", "NO_TYPE"); break;
case MSG_TYPE: PrintJSONKeyPairString("type", "MSG_TYPE"); break;
case RUN_TYPE: PrintJSONKeyPairString("type", "RUN_TYPE"); break;
case CAL_TYPE: PrintJSONKeyPairString("type", "CAL_TYPE"); break;
case SAT_TYPE: PrintJSONKeyPairString("type", "SAT_TYPE"); break;
case PS_TYPE: PrintJSONKeyPairString("type", "PS_TYPE"); break;
case PSF_TYPE: PrintJSONKeyPairString("type", "PSF_TYPE"); break;
case MSF_TYPE: PrintJSONKeyPairString("type", "MSF_TYPE"); break;
case PASSTHRU_TYPE:
switch(q->typ) {
case NO_TYPE: PrintJSONKeyPairString("type", "NO_TYPE"); break;
case MSG_TYPE: PrintJSONKeyPairString("type", "MSG_TYPE"); break;
case RUN_TYPE: PrintJSONKeyPairString("type", "RUN_TYPE"); break;
case CAL_TYPE: PrintJSONKeyPairString("type", "CAL_TYPE"); break;
case SAT_TYPE: PrintJSONKeyPairString("type", "SAT_TYPE"); break;
case PS_TYPE: PrintJSONKeyPairString("type", "PS_TYPE"); break;
case PSF_TYPE: PrintJSONKeyPairString("type", "PSF_TYPE"); break;
case MSF_TYPE: PrintJSONKeyPairString("type", "MSF_TYPE"); break;
case PASSTHRU_TYPE:
PrintJSONKeyPairString("type", "PASSTHRU_TYPE");
PrintJSONKeyPairString("passthru", q->passthru);
break;
default: PrintJSONKeyPairString("type", "?"); break;
}
default: PrintJSONKeyPairString("type", "?"); break;
}
/* Last one is a special case - no trailing comma */
printf("\"");
PrintJSONString("body");
printf("\":\"");
if (q->text) {
PrintJSONString(q->text);
} else {
PrintJSONString("");
}
printf("\"}");
q = q->next;
/* Last one is a special case - no trailing comma */
printf("\"");
PrintJSONString("body");
printf("\":\"");
if (q->text) {
PrintJSONString(q->text);
} else {
PrintJSONString("");
}
printf("\"}");
q = q->next;
}
printf("]");
if (DaemonJSON) {
@@ -832,8 +832,8 @@ static void ServerWait(struct timeval *sleep_tv)
} else {
printf("NOTE newdate\nNOTE reread\n");
}
fflush(stdout);
reread();
fflush(stdout);
reread();
}
/* If nothing readable or interrupted system call, return */
@@ -862,16 +862,16 @@ static void ServerWait(struct timeval *sleep_tv)
/* If EOF on stdin, exit */
if (feof(stdin)) {
exit(EXIT_SUCCESS);
exit(EXIT_SUCCESS);
}
/* Read a line from stdin and interpret it */
if (!fgets(cmdLine, sizeof(cmdLine), stdin)) {
exit(EXIT_SUCCESS);
exit(EXIT_SUCCESS);
}
if (!strcmp(cmdLine, "EXIT\n")) {
exit(EXIT_SUCCESS);
exit(EXIT_SUCCESS);
} else if (!strcmp(cmdLine, "STATUS\n")) {
print_num_queued();
} else if (!strcmp(cmdLine, "QUEUE\n")) {
@@ -901,27 +901,27 @@ static void ServerWait(struct timeval *sleep_tv)
q->text ? q->text : "NULL");
}
q = q->next;
}
}
printf("NOTE endqueue\n");
}
fflush(stdout);
}
fflush(stdout);
} else if (!strcmp(cmdLine, "JSONQUEUE\n")) {
if (!DaemonJSON) {
if (!DaemonJSON) {
printf("NOTE JSONQUEUE\n");
}
json_queue(QueueHead);
if (!DaemonJSON) {
json_queue(QueueHead);
if (!DaemonJSON) {
printf("NOTE ENDJSONQUEUE\n");
}
fflush(stdout);
fflush(stdout);
} else if (!strcmp(cmdLine, "REREAD\n")) {
if (DaemonJSON) {
printf("{\"response\":\"reread\",\"command\":\"REREAD\"}\n");
} else {
printf("NOTE reread\n");
}
fflush(stdout);
reread();
fflush(stdout);
reread();
} else if (!strncmp(cmdLine, "DEL ", 4)) {
unsigned long qid;
if (sscanf(cmdLine, "DEL %lx", &qid) == 1) {
@@ -941,7 +941,7 @@ static void ServerWait(struct timeval *sleep_tv)
} else {
printf("ERR Invalid daemon command: %s", cmdLine);
}
fflush(stdout);
fflush(stdout);
}
}
+580 -580
View File
File diff suppressed because it is too large Load Diff
+55 -55
View File
@@ -51,8 +51,8 @@ static Sortrem *MakeSortRem(int dse, int tim, char const *body, int typ, int pri
new->text = StrDup(body);
if (!new->text) {
free(new);
return NULL;
free(new);
return NULL;
}
new->trigdate = dse;
@@ -77,38 +77,38 @@ int InsertIntoSortBuffer(int dse, int tim, char const *body, int typ, int prio)
int ShouldGoAfter;
if (!new) {
Eprint("%s", ErrMsg[E_NO_MEM]);
IssueSortedReminders();
SortByDate = 0;
SortByTime = 0;
SortByPrio = 0;
UntimedBeforeTimed = 0;
return E_NO_MEM;
Eprint("%s", ErrMsg[E_NO_MEM]);
IssueSortedReminders();
SortByDate = 0;
SortByTime = 0;
SortByPrio = 0;
UntimedBeforeTimed = 0;
return E_NO_MEM;
}
/* Find the correct place in the sorted list */
if (!SortedQueue) {
SortedQueue = new;
return OK;
SortedQueue = new;
return OK;
}
while (cur) {
ShouldGoAfter = CompareRems(new->trigdate, new->trigtime, new->priority,
cur->trigdate, cur->trigtime, cur->priority,
SortByDate, SortByTime, SortByPrio, UntimedBeforeTimed);
ShouldGoAfter = CompareRems(new->trigdate, new->trigtime, new->priority,
cur->trigdate, cur->trigtime, cur->priority,
SortByDate, SortByTime, SortByPrio, UntimedBeforeTimed);
if (ShouldGoAfter <= 0) {
prev = cur;
cur = cur->next;
} else {
if (prev) {
prev->next = new;
new->next = cur;
} else {
SortedQueue = new;
new->next = cur;
}
return OK;
}
if (ShouldGoAfter <= 0) {
prev = cur;
cur = cur->next;
} else {
if (prev) {
prev->next = new;
new->next = cur;
} else {
SortedQueue = new;
new->next = cur;
}
return OK;
}
}
prev->next = new;
@@ -131,36 +131,36 @@ void IssueSortedReminders(void)
int olddate = NO_DATE;
while (cur) {
next = cur->next;
switch(cur->typ) {
case MSG_TYPE:
if (MsgCommand && *MsgCommand) {
DoMsgCommand(MsgCommand, cur->text, 0);
next = cur->next;
switch(cur->typ) {
case MSG_TYPE:
if (MsgCommand && *MsgCommand) {
DoMsgCommand(MsgCommand, cur->text, 0);
} else {
if (cur->trigdate != olddate) {
IssueSortBanner(cur->trigdate);
olddate = cur->trigdate;
}
printf("%s", cur->text);
if (cur->trigdate != olddate) {
IssueSortBanner(cur->trigdate);
olddate = cur->trigdate;
}
printf("%s", cur->text);
}
break;
break;
case MSF_TYPE:
case MSF_TYPE:
if (cur->trigdate != olddate) {
IssueSortBanner(cur->trigdate);
olddate = cur->trigdate;
}
FillParagraph(cur->text, NULL);
break;
FillParagraph(cur->text, NULL);
break;
case RUN_TYPE:
System(cur->text, 0);
break;
}
case RUN_TYPE:
System(cur->text, 0);
break;
}
free((char *) cur->text);
free(cur);
cur = next;
free((char *) cur->text);
free(cur);
cur = next;
}
SortedQueue = NULL;
}
@@ -189,8 +189,8 @@ static void IssueSortBanner(int dse)
if (DoCoerce(STR_TYPE, &v)) return;
DBufInit(&buf);
if (!DoSubstFromString(v.v.str, &buf, dse, NO_TIME)) {
if (*DBufValue(&buf)) printf("%s\n", DBufValue(&buf));
DBufFree(&buf);
if (*DBufValue(&buf)) printf("%s\n", DBufValue(&buf));
DBufFree(&buf);
}
DestroyValue(v);
}
@@ -206,9 +206,9 @@ static void IssueSortBanner(int dse)
/* */
/***************************************************************/
int CompareRems(int dat1, int tim1, int prio1,
int dat2, int tim2, int prio2,
int bydate, int bytime, int byprio,
int untimed_first)
int dat2, int tim2, int prio2,
int bydate, int bytime, int byprio,
int untimed_first)
{
int dafter, tafter, pafter, uafter;
@@ -221,11 +221,11 @@ int CompareRems(int dat1, int tim1, int prio1,
if (dat1 > dat2) return -dafter;
if (tim1 == NO_TIME && tim2 != NO_TIME) {
return -uafter;
return -uafter;
}
if (tim1 != NO_TIME && tim2 == NO_TIME) {
return uafter;
return uafter;
}
if (tim1 < tim2) return tafter;
+182 -182
View File
@@ -39,82 +39,82 @@ while (isdigit(*(string))) { \
Token TokArray[] = {
/* NAME MINLEN TYPE VALUE */
{ "addomit", 7, T_AddOmit, 0 },
{ "after", 5, T_Skip, AFTER_SKIP },
{ "april", 3, T_Month, 3 },
{ "at", 2, T_At, 0 },
{ "august", 3, T_Month, 7 },
{ "banner", 3, T_Banner, 0 },
{ "before", 6, T_Skip, BEFORE_SKIP },
{ "cal", 3, T_RemType, CAL_TYPE },
{ "after", 5, T_Skip, AFTER_SKIP },
{ "april", 3, T_Month, 3 },
{ "at", 2, T_At, 0 },
{ "august", 3, T_Month, 7 },
{ "banner", 3, T_Banner, 0 },
{ "before", 6, T_Skip, BEFORE_SKIP },
{ "cal", 3, T_RemType, CAL_TYPE },
{ "clear-omit-context", 5, T_Clr, 0 },
{ "debug", 5, T_Debug, 0 },
{ "december", 3, T_Month, 11 },
{ "do", 2, T_IncludeR, 0 },
{ "december", 3, T_Month, 11 },
{ "do", 2, T_IncludeR, 0 },
{ "dumpvars", 4, T_Dumpvars, 0 },
{ "duration", 8, T_Duration, 0 },
{ "else", 4, T_Else, 0 },
{ "endif", 5, T_EndIf, 0 },
{ "else", 4, T_Else, 0 },
{ "endif", 5, T_EndIf, 0 },
{ "errmsg", 6, T_ErrMsg, 0 },
{ "exit", 4, T_Exit, 0 },
{ "exit", 4, T_Exit, 0 },
{ "expr", 4, T_Expr, 0 },
{ "february", 3, T_Month, 1 },
{ "february", 3, T_Month, 1 },
{ "first", 5, T_Ordinal, 0 },
{ "flush", 5, T_Flush, 0 },
{ "flush", 5, T_Flush, 0 },
{ "fourth", 6, T_Ordinal, 3 },
{ "friday", 3, T_WkDay, 4 },
{ "from", 4, T_Scanfrom, FROM_TYPE },
{ "fset", 4, T_Fset, 0 },
{ "friday", 3, T_WkDay, 4 },
{ "from", 4, T_Scanfrom, FROM_TYPE },
{ "fset", 4, T_Fset, 0 },
{ "funset", 6, T_Funset, 0 },
{ "if", 2, T_If, 0 },
{ "iftrig", 6, T_IfTrig, 0 },
{ "if", 2, T_If, 0 },
{ "iftrig", 6, T_IfTrig, 0 },
{ "in", 2, T_In, 0 },
{ "include", 3, T_Include, 0 },
{ "include", 3, T_Include, 0 },
{ "includecmd", 10, T_IncludeCmd, 0 },
{ "january", 3, T_Month, 0 },
{ "july", 3, T_Month, 6 },
{ "june", 3, T_Month, 5 },
{ "january", 3, T_Month, 0 },
{ "july", 3, T_Month, 6 },
{ "june", 3, T_Month, 5 },
{ "last", 4, T_Ordinal, -1 },
{ "lastday", 7, T_BackAdj, -1 },
{ "lastworkday", 11, T_BackAdj, 1 },
{ "march", 3, T_Month, 2 },
{ "may", 3, T_Month, 4 },
{ "march", 3, T_Month, 2 },
{ "may", 3, T_Month, 4 },
{ "maybe-uncomputable", 5, T_MaybeUncomputable, 0},
{ "monday", 3, T_WkDay, 0 },
{ "msf", 3, T_RemType, MSF_TYPE },
{ "msg", 3, T_RemType, MSG_TYPE },
{ "monday", 3, T_WkDay, 0 },
{ "msf", 3, T_RemType, MSF_TYPE },
{ "msg", 3, T_RemType, MSG_TYPE },
{ "noqueue", 7, T_NoQueue, 0 },
{ "november", 3, T_Month, 10 },
{ "october", 3, T_Month, 9 },
{ "omit", 4, T_Omit, 0 },
{ "november", 3, T_Month, 10 },
{ "october", 3, T_Month, 9 },
{ "omit", 4, T_Omit, 0 },
{ "omitfunc", 8, T_OmitFunc, 0 },
{ "once", 4, T_Once, 0 },
{ "pop-omit-context", 3, T_Pop, 0 },
{ "once", 4, T_Once, 0 },
{ "pop-omit-context", 3, T_Pop, 0 },
{ "preserve", 8, T_Preserve, 0 },
{ "priority", 8, T_Priority, 0 },
{ "ps", 2, T_RemType, PS_TYPE },
{ "psfile", 6, T_RemType, PSF_TYPE },
{ "push-omit-context", 4, T_Push, 0 },
{ "rem", 3, T_Rem, 0 },
{ "run", 3, T_RemType, RUN_TYPE },
{ "satisfy", 7, T_RemType, SAT_TYPE },
{ "saturday", 3, T_WkDay, 5 },
{ "scanfrom", 4, T_Scanfrom, SCANFROM_TYPE },
{ "sched", 5, T_Sched, 0 },
{ "priority", 8, T_Priority, 0 },
{ "ps", 2, T_RemType, PS_TYPE },
{ "psfile", 6, T_RemType, PSF_TYPE },
{ "push-omit-context", 4, T_Push, 0 },
{ "rem", 3, T_Rem, 0 },
{ "run", 3, T_RemType, RUN_TYPE },
{ "satisfy", 7, T_RemType, SAT_TYPE },
{ "saturday", 3, T_WkDay, 5 },
{ "scanfrom", 4, T_Scanfrom, SCANFROM_TYPE },
{ "sched", 5, T_Sched, 0 },
{ "second", 6, T_Ordinal, 1 },
{ "september", 3, T_Month, 8 },
{ "set", 3, T_Set, 0 },
{ "skip", 4, T_Skip, SKIP_SKIP },
{ "september", 3, T_Month, 8 },
{ "set", 3, T_Set, 0 },
{ "skip", 4, T_Skip, SKIP_SKIP },
{ "special", 7, T_RemType, PASSTHRU_TYPE },
{ "sunday", 3, T_WkDay, 6 },
{ "sunday", 3, T_WkDay, 6 },
{ "tag", 3, T_Tag, 0 },
{ "third", 5, T_Ordinal, 2 },
{ "through", 7, T_Through, 0 },
{ "thursday", 3, T_WkDay, 3 },
{ "tuesday", 3, T_WkDay, 1 },
{ "unset", 5, T_UnSet, 0 },
{ "until", 5, T_Until, 0 },
{ "thursday", 3, T_WkDay, 3 },
{ "tuesday", 3, T_WkDay, 1 },
{ "unset", 5, T_UnSet, 0 },
{ "until", 5, T_Until, 0 },
{ "warn", 4, T_Warn, 0 },
{ "wednesday", 3, T_WkDay, 2 }
{ "wednesday", 3, T_WkDay, 2 }
};
static int TokStrCmp (Token const *t, char const *s);
@@ -152,7 +152,7 @@ char const *FindInitialToken(Token *tok, char const *s)
while (isempty(*s)) s++;
while (*s && !isempty(*s)) {
if (DBufPutc(&buf, *s++) != OK) return s;
if (DBufPutc(&buf, *s++) != OK) return s;
}
FindToken(DBufValue(&buf), tok);
@@ -176,56 +176,56 @@ void FindToken(char const *s, Token *tok)
init_token(tok);
if (! *s) {
tok->type = T_Empty;
return;
tok->type = T_Empty;
return;
}
if (*s == '#' || *s == ';') {
tok->type = T_Comment;
return;
tok->type = T_Comment;
return;
}
/* Quickly give up the search if first char not a letter */
if ( ! isalpha(*s)) {
FindNumericToken(s, tok);
return;
FindNumericToken(s, tok);
return;
}
l = strlen(s);
/* Ignore trailing commas */
if (l > 0 && s[l-1] == ',') {
l--;
l--;
}
bot = 0;
top = sizeof(TokArray) / sizeof(TokArray[0]) - 1;
max = sizeof(TokArray) / sizeof(TokArray[0]);
while(top >= bot) {
mid = (top + bot) / 2;
r = TokStrCmp(&TokArray[mid], s);
if (!r) {
if (l >= TokArray[mid].MinLen) {
tok->type = TokArray[mid].type;
tok->val = TokArray[mid].val;
return;
} else {
while (mid && !TokStrCmp(&TokArray[mid-1],s)) mid--;
while (mid < max &&
!TokStrCmp(&TokArray[mid], s) &&
l < TokArray[mid].MinLen) {
mid++;
}
if (mid < max &&
!TokStrCmp(&TokArray[mid], s)) {
tok->type = TokArray[mid].type;
tok->val = TokArray[mid].val;
return;
}
}
break;
}
if (r > 0) top = mid-1; else bot=mid+1;
mid = (top + bot) / 2;
r = TokStrCmp(&TokArray[mid], s);
if (!r) {
if (l >= TokArray[mid].MinLen) {
tok->type = TokArray[mid].type;
tok->val = TokArray[mid].val;
return;
} else {
while (mid && !TokStrCmp(&TokArray[mid-1],s)) mid--;
while (mid < max &&
!TokStrCmp(&TokArray[mid], s) &&
l < TokArray[mid].MinLen) {
mid++;
}
if (mid < max &&
!TokStrCmp(&TokArray[mid], s)) {
tok->type = TokArray[mid].type;
tok->val = TokArray[mid].val;
return;
}
}
break;
}
if (r > 0) top = mid-1; else bot=mid+1;
}
return;
@@ -252,15 +252,15 @@ void FindNumericToken(char const *s, Token *t)
init_token(t);
if (isdigit(*s)) {
PARSENUM(t->val, s);
PARSENUM(t->val, s);
/* If we hit a '-' or a '/', we may have a date or a datetime */
if (*s == '-' || *s == '/') {
char const *p = s_orig;
int dse, tim;
/* If we hit a '-' or a '/', we may have a date or a datetime */
if (*s == '-' || *s == '/') {
char const *p = s_orig;
int dse, tim;
r = ParseLiteralDateOrTime(&p, &dse, &tim);
if (r == OK) {
if (*p) {
if (r == OK) {
if (*p) {
if (tim == NO_TIME) {
t->val = -E_BAD_DATE;
} else {
@@ -268,146 +268,146 @@ void FindNumericToken(char const *s, Token *t)
}
return;
}
if (tim == NO_TIME) {
t->type = T_Date;
t->val = dse;
return;
}
if (tim == NO_TIME) {
t->type = T_Date;
t->val = dse;
return;
}
if (dse == NO_DATE) {
t->type = T_Time;
t->val = tim;
return;
}
t->type = T_DateTime;
t->val = MINUTES_PER_DAY * dse + tim;
} else {
t->type = T_DateTime;
t->val = MINUTES_PER_DAY * dse + tim;
} else {
token_error(t, r);
}
return;
}
return;
}
/* If we hit a comma, swallow it. This allows stuff
like Jan 6, 1998 */
if (*s == ',' && *(s+1) == 0) {
/* Classify the number we've got */
if (t->val >= BASE && t->val <= BASE+YR_RANGE) t->type = T_Year;
else if (t->val >= 1 && t->val <= 31) t->type = T_Day;
else t->type = T_Number;
return;
}
/* If we hit a colon or a period, we've probably got a time hr:min */
if (*s == ':' || *s == '.' || *s == TimeSep) {
s++;
hour = t->val;
/* If we hit a comma, swallow it. This allows stuff
like Jan 6, 1998 */
if (*s == ',' && *(s+1) == 0) {
/* Classify the number we've got */
if (t->val >= BASE && t->val <= BASE+YR_RANGE) t->type = T_Year;
else if (t->val >= 1 && t->val <= 31) t->type = T_Day;
else t->type = T_Number;
return;
}
/* If we hit a colon or a period, we've probably got a time hr:min */
if (*s == ':' || *s == '.' || *s == TimeSep) {
s++;
hour = t->val;
if (!isdigit(*s)) {
token_error(t, E_BAD_TIME);
return;
}
PARSENUM(min, s);
if (min > 59) {
PARSENUM(min, s);
if (min > 59) {
/* Illegal time */
token_error(t, E_BAD_TIME);
return;
}
/* Check for p[m] or a[m] */
if (*s == 'A' || *s == 'a' || *s == 'P' || *s == 'p') {
ampm = tolower(*s);
s++;
if (*s == 'm' || *s == 'M') {
s++;
}
}
if (*s) {
/* Check for p[m] or a[m] */
if (*s == 'A' || *s == 'a' || *s == 'P' || *s == 'p') {
ampm = tolower(*s);
s++;
if (*s == 'm' || *s == 'M') {
s++;
}
}
if (*s) {
token_error(t, E_BAD_TIME);
return;
}
if (ampm) {
if (hour < 1 || hour > 12) {
if (ampm) {
if (hour < 1 || hour > 12) {
token_error(t, E_BAD_TIME);
return;
}
if (ampm == 'a') {
if (hour == 12) {
hour = 0;
}
} else if (ampm == 'p') {
if (hour < 12) {
hour += 12;
}
}
}
if (ampm == 'a') {
if (hour == 12) {
hour = 0;
}
} else if (ampm == 'p') {
if (hour < 12) {
hour += 12;
}
}
}
t->val = hour*60 + min; /* Convert to minutes past midnight */
if (hour <= 23) {
t->type = T_Time;
} else {
t->type = T_LongTime;
}
return;
}
t->val = hour*60 + min; /* Convert to minutes past midnight */
if (hour <= 23) {
t->type = T_Time;
} else {
t->type = T_LongTime;
}
return;
}
/* If we hit a non-digit, error! */
if (*s) {
/* If we hit a non-digit, error! */
if (*s) {
token_error(t, E_BAD_NUMBER);
return;
}
/* Classify the number we've got */
if (t->val >= BASE && t->val <= BASE+YR_RANGE) t->type = T_Year;
else if (t->val >= 1 && t->val <= 31) t->type = T_Day;
else t->type = T_Number;
return;
/* Classify the number we've got */
if (t->val >= BASE && t->val <= BASE+YR_RANGE) t->type = T_Year;
else if (t->val >= 1 && t->val <= 31) t->type = T_Day;
else t->type = T_Number;
return;
}
switch (*s) {
case '*':
s++;
PARSENUM(t->val, s);
if (*s) {
s++;
PARSENUM(t->val, s);
if (*s) {
/* Illegal token if followed by non-numeric char */
token_error(t, E_BAD_NUMBER);
return;
}
t->type = T_Rep;
return;
t->type = T_Rep;
return;
case '+':
s++;
if (*s == '+') { mult = -1; s++; }
PARSENUM(t->val, s);
if (*s) {
s++;
if (*s == '+') { mult = -1; s++; }
PARSENUM(t->val, s);
if (*s) {
/* Illegal token if followed by non-numeric char */
token_error(t, E_BAD_NUMBER);
return;
}
t->type = T_Delta;
t->val *= mult;
return;
t->type = T_Delta;
t->val *= mult;
return;
case '-':
s++;
if (*s == '-') { mult = -1; s++; }
PARSENUM(t->val, s);
if (*s) {
s++;
if (*s == '-') { mult = -1; s++; }
PARSENUM(t->val, s);
if (*s) {
/* Illegal token if followed by non-numeric char */
token_error(t, E_BAD_NUMBER);
return;
}
t->type = T_Back;
t->val *= mult;
return;
t->type = T_Back;
t->val *= mult;
return;
case '~':
s++;
if (*s == '~') { mult = -1; s++; }
PARSENUM(t->val, s);
if (*s) {
s++;
if (*s == '~') { mult = -1; s++; }
PARSENUM(t->val, s);
if (*s) {
/* Illegal token if followed by non-numeric char */
token_error(t, E_BAD_NUMBER);
return;
}
t->type = T_BackAdj;
t->val *= mult;
return;
t->type = T_BackAdj;
t->val *= mult;
return;
default: return;
}
@@ -427,10 +427,10 @@ static int TokStrCmp(Token const *t, char const *s)
char const *tk = t->name;
while(*tk && *s && !(*s == ',' && *(s+1) == 0)) {
/* t->name is already lower-case */
r = *tk - tolower(*s);
tk++;
s++;
if (r) return r;
r = *tk - tolower(*s);
tk++;
s++;
if (r) return r;
}
/* Ignore trailing commas on s */
+376 -376
View File
@@ -63,211 +63,211 @@ static int NextSimpleTrig(int startdate, Trigger *trig, int *err)
return startdate;
case GOT_WD:
ADVANCE_TO_WD(startdate, trig->wd);
return startdate;
ADVANCE_TO_WD(startdate, trig->wd);
return startdate;
case GOT_DAY:
if (d > trig->d) {
m++;
if (m == 12) { m = 0; y++; }
}
while (trig->d > DaysInMonth(m, y)) {
if (d > trig->d) {
m++;
if (m == 12) { m = 0; y++; }
}
j = DSE(y, m, trig->d);
return j;
while (trig->d > DaysInMonth(m, y)) {
m++;
if (m == 12) { m = 0; y++; }
}
j = DSE(y, m, trig->d);
return j;
case GOT_MON:
if (m == trig->m) return startdate;
else if (m > trig->m) return DSE(y+1, trig->m, 1);
else return DSE(y, trig->m, 1);
if (m == trig->m) return startdate;
else if (m > trig->m) return DSE(y+1, trig->m, 1);
else return DSE(y, trig->m, 1);
case GOT_YR:
if (y == trig->y) return startdate;
else if (y < trig->y) return DSE(trig->y, 0, 1);
else return -1;
if (y == trig->y) return startdate;
else if (y < trig->y) return DSE(trig->y, 0, 1);
else return -1;
case GOT_DAY+GOT_MON:
if (trig->d > MonthDays[trig->m]) {
*err = E_BAD_DATE;
return -1;
}
if (trig->d > MonthDays[trig->m]) {
*err = E_BAD_DATE;
return -1;
}
if (m > trig->m || (m == trig->m && d > trig->d)) y++;
/* Take care of Feb. 29 */
while (trig->d > DaysInMonth(trig->m, y)) y++;
return DSE(y, trig->m, trig->d);
if (m > trig->m || (m == trig->m && d > trig->d)) y++;
/* Take care of Feb. 29 */
while (trig->d > DaysInMonth(trig->m, y)) y++;
return DSE(y, trig->m, trig->d);
case GOT_DAY+GOT_YR:
if (y < trig->y) return DSE(trig->y, 0, trig->d);
else if (y > trig->y) return -1;
if (y < trig->y) return DSE(trig->y, 0, trig->d);
else if (y > trig->y) return -1;
if (d > trig->d) {
m++;
if (m == 12) return -1;
}
while (trig->d > DaysInMonth(m, trig->y)) m++;
return DSE(trig->y, m, trig->d);
if (d > trig->d) {
m++;
if (m == 12) return -1;
}
while (trig->d > DaysInMonth(m, trig->y)) m++;
return DSE(trig->y, m, trig->d);
case GOT_MON+GOT_YR:
if (y > trig->y || (y == trig->y && m > trig->m)) return -1;
if (y < trig->y) return DSE(trig->y, trig->m, 1);
if (m == trig->m) return startdate;
return DSE(trig->y, trig->m, 1);
if (y > trig->y || (y == trig->y && m > trig->m)) return -1;
if (y < trig->y) return DSE(trig->y, trig->m, 1);
if (m == trig->m) return startdate;
return DSE(trig->y, trig->m, 1);
case GOT_DAY+GOT_MON+GOT_YR:
if (trig->d > DaysInMonth(trig->m, trig->y)) {
*err = E_BAD_DATE;
return -1;
}
return DSE(trig->y, trig->m, trig->d);
if (trig->d > DaysInMonth(trig->m, trig->y)) {
*err = E_BAD_DATE;
return -1;
}
return DSE(trig->y, trig->m, trig->d);
case GOT_YR+GOT_WD:
if (y > trig->y) return -1;
if (y < trig->y) j = DSE(trig->y, 0, 1);
else j = startdate;
ADVANCE_TO_WD(j, trig->wd);
if (DSEYear(j) > trig->y) return -1;
return j;
case GOT_MON+GOT_WD:
if (m == trig->m) {
j = startdate;
ADVANCE_TO_WD(j, trig->wd);
if (DSEMonth(j) == trig->m) return j;
}
if (m >= trig->m) j = DSE(y+1, trig->m, 1);
else j = DSE(y, trig->m, 1);
ADVANCE_TO_WD(j, trig->wd);
return j; /* Guaranteed to be within the month */
case GOT_DAY+GOT_WD:
if (m !=0 || y > BASE) {
m2 = m-1;
if (m2 < 0) { y2 = y-1; m2 = 11; }
/* If there are fewer days in previous month, no match */
if (trig->d <= DaysInMonth(m2, y2)) {
j = DSE(y2, m2, trig->d);
ADVANCE_TO_WD(j, trig->wd);
if (j >= startdate) return j;
}
}
/* Try this month */
if (trig->d <= DaysInMonth(m, y)) {
j = DSE(y, m, trig->d);
ADVANCE_TO_WD(j, trig->wd);
if (j >= startdate) return j;
}
/* Argh! Try next avail. month */
m2 = m+1;
if (m2 > 11) { m2 = 0; y++; }
while (trig->d > DaysInMonth(m2, y)) m2++;
j = DSE(y, m2, trig->d);
ADVANCE_TO_WD(j, trig->wd);
return j;
case GOT_WD+GOT_YR+GOT_DAY:
if (y > trig->y+1 || (y > trig->y && m>0)) return -1;
if (y > trig->y) {
j = DSE(trig->y, 11, trig->d);
ADVANCE_TO_WD(j, trig->wd);
if (j >= startdate) return j;
} else if (y < trig->y) {
j = DSE(trig->y, 0, trig->d);
ADVANCE_TO_WD(j, trig->wd);
return j;
} else {
/* Try last month */
if (m > 0) {
m2 = m-1;
while (trig->d > DaysInMonth(m2, trig->y)) m2--;
j = DSE(trig->y, m2, trig->d);
ADVANCE_TO_WD(j, trig->wd);
if (DSEYear(j) > trig->y) return -1;
if (j >= startdate) return j;
}
}
/* Try this month */
if (trig->d <= DaysInMonth(m, trig->y)) {
j = DSE(trig->y, m, trig->d);
ADVANCE_TO_WD(j, trig->wd);
if (DSEYear(j) > trig->y) return -1;
if (j >= startdate) return j;
}
/* Must be next month */
if (m == 11) return -1;
m++;
while (trig->d > DaysInMonth(m, trig->d)) m++;
j = DSE(trig->y, m, trig->d);
if (y > trig->y) return -1;
if (y < trig->y) j = DSE(trig->y, 0, 1);
else j = startdate;
ADVANCE_TO_WD(j, trig->wd);
if (DSEYear(j) > trig->y) return -1;
return j;
return j;
case GOT_MON+GOT_WD:
if (m == trig->m) {
j = startdate;
ADVANCE_TO_WD(j, trig->wd);
if (DSEMonth(j) == trig->m) return j;
}
if (m >= trig->m) j = DSE(y+1, trig->m, 1);
else j = DSE(y, trig->m, 1);
ADVANCE_TO_WD(j, trig->wd);
return j; /* Guaranteed to be within the month */
case GOT_DAY+GOT_WD:
if (m !=0 || y > BASE) {
m2 = m-1;
if (m2 < 0) { y2 = y-1; m2 = 11; }
/* If there are fewer days in previous month, no match */
if (trig->d <= DaysInMonth(m2, y2)) {
j = DSE(y2, m2, trig->d);
ADVANCE_TO_WD(j, trig->wd);
if (j >= startdate) return j;
}
}
/* Try this month */
if (trig->d <= DaysInMonth(m, y)) {
j = DSE(y, m, trig->d);
ADVANCE_TO_WD(j, trig->wd);
if (j >= startdate) return j;
}
/* Argh! Try next avail. month */
m2 = m+1;
if (m2 > 11) { m2 = 0; y++; }
while (trig->d > DaysInMonth(m2, y)) m2++;
j = DSE(y, m2, trig->d);
ADVANCE_TO_WD(j, trig->wd);
return j;
case GOT_WD+GOT_YR+GOT_DAY:
if (y > trig->y+1 || (y > trig->y && m>0)) return -1;
if (y > trig->y) {
j = DSE(trig->y, 11, trig->d);
ADVANCE_TO_WD(j, trig->wd);
if (j >= startdate) return j;
} else if (y < trig->y) {
j = DSE(trig->y, 0, trig->d);
ADVANCE_TO_WD(j, trig->wd);
return j;
} else {
/* Try last month */
if (m > 0) {
m2 = m-1;
while (trig->d > DaysInMonth(m2, trig->y)) m2--;
j = DSE(trig->y, m2, trig->d);
ADVANCE_TO_WD(j, trig->wd);
if (DSEYear(j) > trig->y) return -1;
if (j >= startdate) return j;
}
}
/* Try this month */
if (trig->d <= DaysInMonth(m, trig->y)) {
j = DSE(trig->y, m, trig->d);
ADVANCE_TO_WD(j, trig->wd);
if (DSEYear(j) > trig->y) return -1;
if (j >= startdate) return j;
}
/* Must be next month */
if (m == 11) return -1;
m++;
while (trig->d > DaysInMonth(m, trig->d)) m++;
j = DSE(trig->y, m, trig->d);
ADVANCE_TO_WD(j, trig->wd);
if (DSEYear(j) > trig->y) return -1;
return j;
case GOT_DAY+GOT_MON+GOT_WD:
if (trig->d > MonthDays[trig->m]) {
*err = E_BAD_DATE;
return -1;
}
/* Back up a year in case we'll cross a year boundary*/
if (y > BASE) {
y--;
}
if (trig->d > MonthDays[trig->m]) {
*err = E_BAD_DATE;
return -1;
}
/* Back up a year in case we'll cross a year boundary*/
if (y > BASE) {
y--;
}
/* Move up to the first valid year */
while (trig->d > DaysInMonth(trig->m, y)) y++;
/* Move up to the first valid year */
while (trig->d > DaysInMonth(trig->m, y)) y++;
/* Try last year */
j = DSE(y, trig->m, trig->d);
/* Try last year */
j = DSE(y, trig->m, trig->d);
ADVANCE_TO_WD(j, trig->wd);
if (j >= startdate) return j;
if (j >= startdate) return j;
/* Try this year */
y++;
while (trig->d > DaysInMonth(trig->m, y)) y++;
j = DSE(y, trig->m, trig->d);
/* Try this year */
y++;
while (trig->d > DaysInMonth(trig->m, y)) y++;
j = DSE(y, trig->m, trig->d);
ADVANCE_TO_WD(j, trig->wd);
if (j >= startdate) return j;
if (j >= startdate) return j;
/* Must be next year */
y++;
while (trig->d > DaysInMonth(trig->m, y)) y++;
j = DSE(y, trig->m, trig->d);
/* Must be next year */
y++;
while (trig->d > DaysInMonth(trig->m, y)) y++;
j = DSE(y, trig->m, trig->d);
ADVANCE_TO_WD(j, trig->wd);
return j;
return j;
case GOT_WD+GOT_MON+GOT_YR:
if (y > trig->y || (y == trig->y && m > trig->m)) return -1;
if (y > trig->y || (y == trig->y && m > trig->m)) return -1;
/* cppcheck-suppress knownConditionTrueFalse */
if (trig->y > y || (trig->y == y && trig->m > m)) {
j = DSE(trig->y, trig->m, 1);
if (trig->y > y || (trig->y == y && trig->m > m)) {
j = DSE(trig->y, trig->m, 1);
ADVANCE_TO_WD(j, trig->wd);
return j;
} else {
j = startdate;
return j;
} else {
j = startdate;
ADVANCE_TO_WD(j, trig->wd);
FromDSE(j, &y2, &m2, &d2);
if (m2 == trig->m) return j; else return -1;
}
FromDSE(j, &y2, &m2, &d2);
if (m2 == trig->m) return j; else return -1;
}
case GOT_WD+GOT_DAY+GOT_MON+GOT_YR:
if (trig->d > DaysInMonth(trig->m, trig->y)) {
*err = E_BAD_DATE;
return -1;
}
j = DSE(trig->y, trig->m, trig->d);
if (trig->d > DaysInMonth(trig->m, trig->y)) {
*err = E_BAD_DATE;
return -1;
}
j = DSE(trig->y, trig->m, trig->d);
ADVANCE_TO_WD(j, trig->wd);
return j;
return j;
default:
Eprint("NextSimpleTrig %s %d", ErrMsg[E_SWERR], typ);
*err = E_SWERR;
return -1;
Eprint("NextSimpleTrig %s %d", ErrMsg[E_SWERR], typ);
*err = E_SWERR;
return -1;
}
}
@@ -311,31 +311,31 @@ static int GetNextTriggerDate(Trigger *trig, int start, int *err, int *nextstart
/* First: Have we passed the UNTIL date? */
if (trig->until != NO_UNTIL &&
trig->until < start) {
trig->expired = 1;
return -1; /* expired */
trig->until < start) {
trig->expired = 1;
return -1; /* expired */
}
/* Next: If it's an "AFTER"-type skip, back up
until we're at the start of a block of holidays */
if (trig->skip == AFTER_SKIP) {
int iter = 0;
while (iter++ <= MaxSatIter) {
*err = IsOmitted(start-1, trig->localomit, trig->omitfunc, &omit);
if (*err) return -2;
if (!omit) {
break;
}
start--;
int iter = 0;
while (iter++ <= MaxSatIter) {
*err = IsOmitted(start-1, trig->localomit, trig->omitfunc, &omit);
if (*err) return -2;
if (!omit) {
break;
}
start--;
if (start < 0) {
break;
}
}
if (start < 0 || iter > MaxSatIter) {
/* omitfunc must have returned "true" too often */
*err = E_CANT_TRIG;
return -2;
}
}
if (start < 0 || iter > MaxSatIter) {
/* omitfunc must have returned "true" too often */
*err = E_CANT_TRIG;
return -2;
}
}
/* Find the next simple trigger */
@@ -349,77 +349,77 @@ static int GetNextTriggerDate(Trigger *trig, int start, int *err, int *nextstart
/* If there's a BACK, back up... */
if (trig->back != NO_BACK) {
mod = trig->back;
if (mod < 0) {
simple += mod;
}
else {
int iter = 0;
int max = MaxSatIter;
if (max < mod*2) {
max = mod*2;
}
while(iter++ <= max) {
if (!mod) {
break;
}
simple--;
*err = IsOmitted(simple, trig->localomit, trig->omitfunc, &omit);
if (*err) return -2;
if (!omit) mod--;
}
if (iter > max) {
*err = E_CANT_TRIG;
return -2;
}
}
mod = trig->back;
if (mod < 0) {
simple += mod;
}
else {
int iter = 0;
int max = MaxSatIter;
if (max < mod*2) {
max = mod*2;
}
while(iter++ <= max) {
if (!mod) {
break;
}
simple--;
*err = IsOmitted(simple, trig->localomit, trig->omitfunc, &omit);
if (*err) return -2;
if (!omit) mod--;
}
if (iter > max) {
*err = E_CANT_TRIG;
return -2;
}
}
}
/* If there's a REP, calculate the next occurrence */
if (trig->rep != NO_REP) {
if (simple < start) {
mod = (start - simple) / trig->rep;
simple = simple + mod * trig->rep;
if (simple < start) simple += trig->rep;
}
if (simple < start) {
mod = (start - simple) / trig->rep;
simple = simple + mod * trig->rep;
if (simple < start) simple += trig->rep;
}
}
/* If it's a "BEFORE"-type skip, back up */
if (trig->skip == BEFORE_SKIP) {
int iter = 0;
while(iter++ <= MaxSatIter) {
*err = IsOmitted(simple, trig->localomit, trig->omitfunc, &omit);
if (*err) return -2;
if (!omit) {
break;
}
simple--;
int iter = 0;
while(iter++ <= MaxSatIter) {
*err = IsOmitted(simple, trig->localomit, trig->omitfunc, &omit);
if (*err) return -2;
if (!omit) {
break;
}
simple--;
if (simple < 0) {
*err = E_CANT_TRIG;
return -2;
}
}
if (iter > MaxSatIter) {
*err = E_CANT_TRIG;
return -2;
}
}
if (iter > MaxSatIter) {
*err = E_CANT_TRIG;
return -2;
}
}
/* If it's an "AFTER"-type skip, jump ahead */
if (trig->skip == AFTER_SKIP) {
int iter = 0;
while (iter++ <= MaxSatIter) {
*err = IsOmitted(simple, trig->localomit, trig->omitfunc, &omit);
if (*err) return -2;
if (!omit) {
break;
}
simple++;
}
if (iter > MaxSatIter) {
*err = E_CANT_TRIG;
return -2;
}
int iter = 0;
while (iter++ <= MaxSatIter) {
*err = IsOmitted(simple, trig->localomit, trig->omitfunc, &omit);
if (*err) return -2;
if (!omit) {
break;
}
simple++;
}
if (iter > MaxSatIter) {
*err = E_CANT_TRIG;
return -2;
}
}
/* Return the date */
@@ -432,47 +432,47 @@ AdjustTriggerForDuration(int today, int r, Trigger *trig, TimeTrig *tim, int sav
int y, m, d;
/* If we have an AT, save the original event start */
if (tim->ttime != NO_TIME) {
trig->eventstart = MINUTES_PER_DAY * r + tim->ttime;
if (tim->duration != NO_TIME) {
trig->eventduration = tim->duration;
}
trig->eventstart = MINUTES_PER_DAY * r + tim->ttime;
if (tim->duration != NO_TIME) {
trig->eventduration = tim->duration;
}
}
/* Now potentially adjust */
if (r < today && r + trig->duration_days >= today) {
/* Adjust duration down */
tim->duration -= (today - r) * MINUTES_PER_DAY;
tim->duration += tim->ttime;
/* Adjust duration down */
tim->duration -= (today - r) * MINUTES_PER_DAY;
tim->duration += tim->ttime;
/* Start at midnight */
tim->ttime = 0;
/* Start at midnight */
tim->ttime = 0;
/* Change trigger date to today */
r = today;
if (DebugFlag & DB_PRTTRIG) {
FromDSE(r, &y, &m, &d);
fprintf(ErrFp, "%s(%d): Trig(adj) = %s, %d %s, %d",
FileName, LineNo,
get_day_name(r % 7),
d,
get_month_name(m),
y);
if (tim->ttime != NO_TIME) {
fprintf(ErrFp, " AT %02d:%02d",
(tim->ttime / 60),
(tim->ttime % 60));
if (tim->duration != NO_TIME) {
fprintf(ErrFp, " DURATION %02d:%02d",
(tim->duration / 60),
(tim->duration % 60));
}
}
fprintf(ErrFp, "\n");
}
/* Change trigger date to today */
r = today;
if (DebugFlag & DB_PRTTRIG) {
FromDSE(r, &y, &m, &d);
fprintf(ErrFp, "%s(%d): Trig(adj) = %s, %d %s, %d",
FileName, LineNo,
get_day_name(r % 7),
d,
get_month_name(m),
y);
if (tim->ttime != NO_TIME) {
fprintf(ErrFp, " AT %02d:%02d",
(tim->ttime / 60),
(tim->ttime % 60));
if (tim->duration != NO_TIME) {
fprintf(ErrFp, " DURATION %02d:%02d",
(tim->duration / 60),
(tim->duration % 60));
}
}
fprintf(ErrFp, "\n");
}
}
if (save_in_globals) {
SaveAllTriggerInfo(trig, tim, r, tim->ttime, 1);
SaveAllTriggerInfo(trig, tim, r, tim->ttime, 1);
}
return r;
}
@@ -486,30 +486,30 @@ AdjustTriggerForDuration(int today, int r, Trigger *trig, TimeTrig *tim, int sav
/* */
/***************************************************************/
int ComputeTrigger(int today, Trigger *trig, TimeTrig *tim,
int *err, int save_in_globals)
int *err, int save_in_globals)
{
int r = ComputeTriggerNoAdjustDuration(today, trig, tim, err, save_in_globals, 0);
if (*err != OK) {
return r;
return r;
}
if (r == today) {
if (tim->ttime != NO_TIME) {
trig->eventstart = MINUTES_PER_DAY * r + tim->ttime;
if (tim->duration != NO_TIME) {
trig->eventduration = tim->duration;
}
}
if (save_in_globals) {
SaveAllTriggerInfo(trig, tim, r, tim->ttime, 1);
}
return r;
if (tim->ttime != NO_TIME) {
trig->eventstart = MINUTES_PER_DAY * r + tim->ttime;
if (tim->duration != NO_TIME) {
trig->eventduration = tim->duration;
}
}
if (save_in_globals) {
SaveAllTriggerInfo(trig, tim, r, tim->ttime, 1);
}
return r;
}
if (trig->duration_days) {
r = ComputeTriggerNoAdjustDuration(today, trig, tim, err, save_in_globals, trig->duration_days);
if (*err != OK) {
return r;
}
r = ComputeTriggerNoAdjustDuration(today, trig, tim, err, save_in_globals, trig->duration_days);
if (*err != OK) {
return r;
}
}
r = AdjustTriggerForDuration(today, r, trig, tim, save_in_globals);
return r;
@@ -524,17 +524,17 @@ int ComputeTrigger(int today, Trigger *trig, TimeTrig *tim,
/* */
/***************************************************************/
int ComputeTriggerNoAdjustDuration(int today, Trigger *trig, TimeTrig *tim,
int *err, int save_in_globals, int duration_days)
int *err, int save_in_globals, int duration_days)
{
int nattempts = 0,
start = today - duration_days,
nextstart = 0,
y, m, d, omit,
result;
start = today - duration_days,
nextstart = 0,
y, m, d, omit,
result;
trig->expired = 0;
if (save_in_globals) {
LastTrigValid = 0;
LastTrigValid = 0;
}
/* Assume everything works */
@@ -542,124 +542,124 @@ int ComputeTriggerNoAdjustDuration(int today, Trigger *trig, TimeTrig *tim,
/* But check for obvious problems... */
if ((WeekdayOmits | trig->localomit) == 0x7F) {
*err = E_2MANY_LOCALOMIT;
return -1;
*err = E_2MANY_LOCALOMIT;
return -1;
}
if (start < 0) {
*err = E_DATE_OVER;
return -1;
*err = E_DATE_OVER;
return -1;
}
if (tim->duration != NO_TIME && tim->ttime == NO_TIME) {
*err = E_DURATION_NO_AT;
return -1;
*err = E_DURATION_NO_AT;
return -1;
}
if (trig->rep != NO_REP &&
(trig->d == NO_DAY ||
trig->m == NO_MON ||
trig->y == NO_YR)) {
Eprint("%s", ErrMsg[E_REP_FULSPEC]);
*err = E_REP_FULSPEC;
return -1;
(trig->d == NO_DAY ||
trig->m == NO_MON ||
trig->y == NO_YR)) {
Eprint("%s", ErrMsg[E_REP_FULSPEC]);
*err = E_REP_FULSPEC;
return -1;
}
/* Save the trigger */
if (save_in_globals) {
SaveLastTrigger(trig);
SaveLastTrigger(trig);
}
while (nattempts++ < TRIG_ATTEMPTS) {
result = GetNextTriggerDate(trig, start, err, &nextstart);
result = GetNextTriggerDate(trig, start, err, &nextstart);
/* If there's an error, die immediately */
if (*err) return -1;
if (result == -1) {
trig->expired = 1;
if (DebugFlag & DB_PRTTRIG) {
fprintf(ErrFp, "%s(%d): %s\n",
FileName, LineNo, ErrMsg[E_EXPIRED]);
}
return -1;
}
/* If there's an error, die immediately */
if (*err) return -1;
if (result == -1) {
trig->expired = 1;
if (DebugFlag & DB_PRTTRIG) {
fprintf(ErrFp, "%s(%d): %s\n",
FileName, LineNo, ErrMsg[E_EXPIRED]);
}
return -1;
}
/* If result is >= today, great! */
if (trig->skip == SKIP_SKIP) {
*err = IsOmitted(result, trig->localomit, trig->omitfunc, &omit);
if (*err) return -1;
} else {
omit = 0;
}
/* If result is >= today, great! */
if (trig->skip == SKIP_SKIP) {
*err = IsOmitted(result, trig->localomit, trig->omitfunc, &omit);
if (*err) return -1;
} else {
omit = 0;
}
/** FIXME: Fix bad interaction with SATISFY... need to rethink!!! */
if (result+duration_days >= today &&
(trig->skip != SKIP_SKIP || !omit)) {
if (save_in_globals) {
LastTriggerDate = result; /* Save in global var */
LastTrigValid = 1;
}
if (DebugFlag & DB_PRTTRIG) {
FromDSE(result, &y, &m, &d);
fprintf(ErrFp, "%s(%d): Trig = %s, %d %s, %d",
FileName, LineNo,
get_day_name(result % 7),
d,
get_month_name(m),
y);
if (tim->ttime != NO_TIME) {
fprintf(ErrFp, " AT %02d:%02d",
(tim->ttime / 60),
(tim->ttime % 60));
if (tim->duration != NO_TIME) {
fprintf(ErrFp, " DURATION %02d:%02d",
(tim->duration / 60),
(tim->duration % 60));
}
}
fprintf(ErrFp, "\n");
}
return result;
}
/** FIXME: Fix bad interaction with SATISFY... need to rethink!!! */
if (result+duration_days >= today &&
(trig->skip != SKIP_SKIP || !omit)) {
if (save_in_globals) {
LastTriggerDate = result; /* Save in global var */
LastTrigValid = 1;
}
if (DebugFlag & DB_PRTTRIG) {
FromDSE(result, &y, &m, &d);
fprintf(ErrFp, "%s(%d): Trig = %s, %d %s, %d",
FileName, LineNo,
get_day_name(result % 7),
d,
get_month_name(m),
y);
if (tim->ttime != NO_TIME) {
fprintf(ErrFp, " AT %02d:%02d",
(tim->ttime / 60),
(tim->ttime % 60));
if (tim->duration != NO_TIME) {
fprintf(ErrFp, " DURATION %02d:%02d",
(tim->duration / 60),
(tim->duration % 60));
}
}
fprintf(ErrFp, "\n");
}
return result;
}
/* If it's a simple trigger, no point in rescanning */
if (trig->back == NO_BACK &&
trig->skip == NO_SKIP &&
trig->rep == NO_REP) {
trig->expired = 1;
if (DebugFlag & DB_PRTTRIG) {
fprintf(ErrFp, "%s(%d): %s\n",
FileName, LineNo, ErrMsg[E_EXPIRED]);
}
/* If it's a simple trigger, no point in rescanning */
if (trig->back == NO_BACK &&
trig->skip == NO_SKIP &&
trig->rep == NO_REP) {
trig->expired = 1;
if (DebugFlag & DB_PRTTRIG) {
fprintf(ErrFp, "%s(%d): %s\n",
FileName, LineNo, ErrMsg[E_EXPIRED]);
}
if (save_in_globals) {
LastTriggerDate = result;
LastTrigValid = 1;
}
return -1;
}
return -1;
}
if (trig->skip == SKIP_SKIP &&
omit &&
nextstart <= start &&
result >= start) {
nextstart = result + 1;
}
if (trig->skip == SKIP_SKIP &&
omit &&
nextstart <= start &&
result >= start) {
nextstart = result + 1;
}
/* Keep scanning... unless there's no point in doing it.*/
if (nextstart <= start) {
/* Keep scanning... unless there's no point in doing it.*/
if (nextstart <= start) {
if (save_in_globals) {
LastTriggerDate = result;
LastTrigValid = 1;
}
trig->expired = 1;
if (DebugFlag & DB_PRTTRIG) {
fprintf(ErrFp, "%s(%d): %s\n",
FileName, LineNo, ErrMsg[E_EXPIRED]);
}
return -1;
}
else start = nextstart;
trig->expired = 1;
if (DebugFlag & DB_PRTTRIG) {
fprintf(ErrFp, "%s(%d): %s\n",
FileName, LineNo, ErrMsg[E_EXPIRED]);
}
return -1;
}
else start = nextstart;
}
+4 -5
View File
@@ -33,8 +33,8 @@ typedef struct udf_struct UserFunc;
typedef struct {
char type;
union {
char *str;
int val;
char *str;
int val;
} v;
} Value;
@@ -146,12 +146,12 @@ typedef struct {
/* The parse pointer */
typedef struct {
DynamicBuffer pushedToken; /* Pushed-back token */
DynamicBuffer pushedToken; /* Pushed-back token */
char const *text; /* Start of text */
char const *pos; /* Current position */
char const *etext; /* Substituted text */
char const *epos; /* Position in substituted text */
char const *tokenPushed; /* NULL if no pushed-back token */
char const *tokenPushed; /* NULL if no pushed-back token */
unsigned char isnested; /* Is it a nested expression? */
unsigned char allownested;
unsigned char expr_happened; /* Did we encounter an [expression] ? */
@@ -319,4 +319,3 @@ typedef struct udf_struct {
int lineno;
int recurse_flag;
} UserFunc;
+36 -36
View File
@@ -110,8 +110,8 @@ int DoFset(ParsePtr p)
/* Get the function name */
if ( (r=ParseIdentifier(p, &buf)) ) return r;
if (*DBufValue(&buf) == '$') {
DBufFree(&buf);
return E_BAD_ID;
DBufFree(&buf);
return E_BAD_ID;
}
orig_namelen = buf.len;
@@ -137,18 +137,18 @@ int DoFset(ParsePtr p)
/* Should be followed by '(' */
c = ParseNonSpaceChar(p, &r, 0);
if (r) {
DBufFree(&buf);
return r;
DBufFree(&buf);
return r;
}
if (c != '(') {
DBufFree(&buf);
return E_PARSE_ERR;
DBufFree(&buf);
return E_PARSE_ERR;
}
func = NEW(UserFunc);
if (!func) {
DBufFree(&buf);
return E_NO_MEM;
DBufFree(&buf);
return E_NO_MEM;
}
if (FileName) {
func->filename = StrDup(FileName);
@@ -164,9 +164,9 @@ int DoFset(ParsePtr p)
StrnCpy(func->name, DBufValue(&buf), VAR_NAME_LEN);
DBufFree(&buf);
if (!Hush) {
if (FindBuiltinFunc(func->name)) {
Eprint("%s: `%s'", ErrMsg[E_REDEF_FUNC], func->name);
}
if (FindBuiltinFunc(func->name)) {
Eprint("%s: `%s'", ErrMsg[E_REDEF_FUNC], func->name);
}
}
func->node = NULL;
func->nargs = 0;
@@ -177,16 +177,16 @@ int DoFset(ParsePtr p)
c=ParseNonSpaceChar(p, &r, 1);
if (r) return r;
if (c == ')') {
(void) ParseNonSpaceChar(p, &r, 0);
(void) ParseNonSpaceChar(p, &r, 0);
} else {
locals = local_array;
while(1) {
if ( (r=ParseIdentifier(p, &buf)) ) return r;
if (*DBufValue(&buf) == '$') {
DBufFree(&buf);
DestroyUserFunc(func);
return E_BAD_ID;
}
while(1) {
if ( (r=ParseIdentifier(p, &buf)) ) return r;
if (*DBufValue(&buf) == '$') {
DBufFree(&buf);
DestroyUserFunc(func);
return E_BAD_ID;
}
/* If we've already seen this local variable, error */
for (i=0; i<func->nargs; i++) {
if (!StrinCmp(DBufValue(&buf), local_array[i].name, VAR_NAME_LEN)) {
@@ -205,19 +205,19 @@ int DoFset(ParsePtr p)
StrnCpy(local_array[i].name, DBufValue(&buf), VAR_NAME_LEN);
local_array[i].next = &(local_array[i+1]);
local_array[i+1].next = NULL;
func->nargs++;
c = ParseNonSpaceChar(p, &r, 0);
func->nargs++;
c = ParseNonSpaceChar(p, &r, 0);
if (r) {
DBufFree(&buf);
DestroyUserFunc(func);
return r;
}
if (c == ')') break;
else if (c != ',') {
DestroyUserFunc(func);
return E_PARSE_ERR;
}
}
if (c == ')') break;
else if (c != ',') {
DestroyUserFunc(func);
return E_PARSE_ERR;
}
}
}
/* Allow an optional = sign: FSET f(x) = x*x */
@@ -227,12 +227,12 @@ int DoFset(ParsePtr p)
return r;
}
if (c == '=') {
(void) ParseNonSpaceChar(p, &r, 0);
(void) ParseNonSpaceChar(p, &r, 0);
}
if (p->isnested) {
Eprint("%s", ErrMsg[E_CANTNEST_FDEF]);
DestroyUserFunc(func);
return E_PARSE_ERR;
Eprint("%s", ErrMsg[E_CANTNEST_FDEF]);
DestroyUserFunc(func);
return E_PARSE_ERR;
}
while(*(p->pos) && isspace(*(p->pos))) {
@@ -274,8 +274,8 @@ int DoFset(ParsePtr p)
/* Add the function definition */
FSet(func);
if (orig_namelen > VAR_NAME_LEN) {
Wprint("Warning: Function name `%s...' truncated to `%s'",
func->name, func->name);
Wprint("Warning: Function name `%s...' truncated to `%s'",
func->name, func->name);
}
return OK;
}
@@ -327,9 +327,9 @@ static void FUnset(char const *name)
cur = FuncHash[h];
prev = NULL;
while(cur) {
if (! strncmp(name, cur->name, VAR_NAME_LEN)) break;
prev = cur;
cur = cur->next;
if (! strncmp(name, cur->name, VAR_NAME_LEN)) break;
prev = cur;
cur = cur->next;
}
if (!cur) return;
if (prev) prev->next = cur->next; else FuncHash[h] = cur->next;
+14 -14
View File
@@ -61,11 +61,11 @@ int StrinCmp(char const *s1, char const *s2, int n)
{
register int r;
while (n && *s1 && *s2) {
n--;
r = toupper(*s1) - toupper(*s2);
if (r) return r;
s1++;
s2++;
n--;
r = toupper(*s1) - toupper(*s2);
if (r) return r;
s1++;
s2++;
}
if (n) return (toupper(*s1) - toupper(*s2)); else return 0;
}
@@ -102,10 +102,10 @@ int StrCmpi(char const *s1, char const *s2)
{
int r;
while (*s1 && *s2) {
r = toupper(*s1) - toupper(*s2);
if (r) return r;
s1++;
s2++;
r = toupper(*s1) - toupper(*s2);
if (r) return r;
s1++;
s2++;
}
return toupper(*s1) - toupper(*s2);
}
@@ -122,11 +122,11 @@ int StrCmpi(char const *s1, char const *s2)
int DateOK(int y, int m, int d)
{
if (d < 1 ||
m < 0 ||
y < BASE ||
m > 11 ||
y > BASE + YR_RANGE ||
d > DaysInMonth(m, y) ) return 0;
m < 0 ||
y < BASE ||
m > 11 ||
y > BASE + YR_RANGE ||
d > DaysInMonth(m, y) ) return 0;
return 1;
}
+172 -172
View File
@@ -31,7 +31,7 @@
#define VAR_HASH_SIZE 67
#define VARIABLE ErrMsg[E_VAR]
#define VALUE ErrMsg[E_VAL]
#define UNDEF ErrMsg[E_UNDEF]
#define UNDEF ErrMsg[E_UNDEF]
static int IntMin = INT_MIN;
static int IntMax = INT_MAX;
@@ -224,10 +224,10 @@ static int trig_date_func(int do_set, Value *val)
UNUSED(do_set);
if (!LastTrigValid) {
val->type = INT_TYPE;
val->v.val = 0;
val->v.val = 0;
} else {
val->type = DATE_TYPE;
val->v.val = LastTriggerDate;
val->v.val = LastTriggerDate;
}
return OK;
}
@@ -237,8 +237,8 @@ static int trig_day_func(int do_set, Value *val)
UNUSED(do_set);
val->type = INT_TYPE;
if (!LastTrigValid) {
val->v.val = -1;
return OK;
val->v.val = -1;
return OK;
}
FromDSE(LastTriggerDate, &y, &m, &d);
@@ -252,8 +252,8 @@ static int trig_mon_func(int do_set, Value *val)
UNUSED(do_set);
val->type = INT_TYPE;
if (!LastTrigValid) {
val->v.val = -1;
return OK;
val->v.val = -1;
return OK;
}
FromDSE(LastTriggerDate, &y, &m, &d);
@@ -267,8 +267,8 @@ static int trig_year_func(int do_set, Value *val)
UNUSED(do_set);
val->type = INT_TYPE;
if (!LastTrigValid) {
val->v.val = -1;
return OK;
val->v.val = -1;
return OK;
}
FromDSE(LastTriggerDate, &y, &m, &d);
@@ -281,8 +281,8 @@ static int trig_wday_func(int do_set, Value *val)
val->type = INT_TYPE;
UNUSED(do_set);
if (!LastTrigValid) {
val->v.val = -1;
return OK;
val->v.val = -1;
return OK;
}
val->v.val = (LastTriggerDate + 1) % 7;
@@ -337,17 +337,17 @@ static int today_wday_func(int do_set, Value *val)
static int datetime_sep_func(int do_set, Value *val)
{
if (!do_set) {
val->v.str = malloc(2);
if (!val->v.str) return E_NO_MEM;
val->v.str[0] = DateTimeSep;
val->v.str[1] = 0;
val->type = STR_TYPE;
return OK;
val->v.str = malloc(2);
if (!val->v.str) return E_NO_MEM;
val->v.str[0] = DateTimeSep;
val->v.str[1] = 0;
val->type = STR_TYPE;
return OK;
}
if (val->type != STR_TYPE) return E_BAD_TYPE;
if (strcmp(val->v.str, "T") &&
strcmp(val->v.str, "@")) {
return E_BAD_TYPE;
strcmp(val->v.str, "@")) {
return E_BAD_TYPE;
}
DateTimeSep = val->v.str[0];
return OK;
@@ -397,10 +397,10 @@ static int default_color_func(int do_set, Value *val)
}
/* They either all have to be -1, or all between 0 and 255 */
if (col_r == -1 && col_g == -1 && col_b == -1) {
DefaultColorR = -1;
DefaultColorG = -1;
DefaultColorB = -1;
return OK;
DefaultColorR = -1;
DefaultColorG = -1;
DefaultColorB = -1;
return OK;
}
if (col_r < 0) return E_2LOW;
if (col_r > 255) return E_2HIGH;
@@ -418,17 +418,17 @@ static int default_color_func(int do_set, Value *val)
static int date_sep_func(int do_set, Value *val)
{
if (!do_set) {
val->v.str = malloc(2);
if (!val->v.str) return E_NO_MEM;
val->v.str[0] = DateSep;
val->v.str[1] = 0;
val->type = STR_TYPE;
return OK;
val->v.str = malloc(2);
if (!val->v.str) return E_NO_MEM;
val->v.str[0] = DateSep;
val->v.str[1] = 0;
val->type = STR_TYPE;
return OK;
}
if (val->type != STR_TYPE) return E_BAD_TYPE;
if (strcmp(val->v.str, "/") &&
strcmp(val->v.str, "-")) {
return E_BAD_TYPE;
strcmp(val->v.str, "-")) {
return E_BAD_TYPE;
}
DateSep = val->v.str[0];
return OK;
@@ -437,17 +437,17 @@ static int date_sep_func(int do_set, Value *val)
static int time_sep_func(int do_set, Value *val)
{
if (!do_set) {
val->v.str = malloc(2);
if (!val->v.str) return E_NO_MEM;
val->v.str[0] = TimeSep;
val->v.str[1] = 0;
val->type = STR_TYPE;
return OK;
val->v.str = malloc(2);
if (!val->v.str) return E_NO_MEM;
val->v.str[0] = TimeSep;
val->v.str[1] = 0;
val->type = STR_TYPE;
return OK;
}
if (val->type != STR_TYPE) return E_BAD_TYPE;
if (strcmp(val->v.str, ":") &&
strcmp(val->v.str, ".")) {
return E_BAD_TYPE;
strcmp(val->v.str, ".")) {
return E_BAD_TYPE;
}
TimeSep = val->v.str[0];
return OK;
@@ -492,9 +492,9 @@ Var *FindVar(char const *str, int create)
prev = NULL;
while(v) {
if (! StrinCmp(str, v->name, VAR_NAME_LEN)) return v;
prev = v;
v = v-> next;
if (! StrinCmp(str, v->name, VAR_NAME_LEN)) return v;
prev = v;
v = v-> next;
}
if (!create) return v;
@@ -529,9 +529,9 @@ int DeleteVar(char const *str)
prev = NULL;
while(v) {
if (! StrinCmp(str, v->name, VAR_NAME_LEN)) break;
prev = v;
v = v-> next;
if (! StrinCmp(str, v->name, VAR_NAME_LEN)) break;
prev = v;
v = v-> next;
}
if (!v) return E_NOSUCH_VAR;
DestroyValue(v->v);
@@ -572,8 +572,8 @@ int GetVarValue(char const *str, Value *val)
v=FindVar(str, 0);
if (!v) {
Eprint("%s: `%s'", ErrMsg[E_NOSUCH_VAR], str);
return E_NOSUCH_VAR;
Eprint("%s: `%s'", ErrMsg[E_NOSUCH_VAR], str);
return E_NOSUCH_VAR;
}
return CopyValue(val, &v->v);
}
@@ -600,7 +600,7 @@ int DoSet (Parser *p)
ch = ParseNonSpaceChar(p, &r, 1);
if (r) return r;
if (ch == '=') {
ParseNonSpaceChar(p, &r, 0);
ParseNonSpaceChar(p, &r, 0);
if (r) return r;
}
@@ -611,8 +611,8 @@ int DoSet (Parser *p)
r = EvaluateExpr(p, &v);
if (r) {
DBufFree(&buf);
return r;
DBufFree(&buf);
return r;
}
r = ParseToken(p, &buf2);
@@ -625,8 +625,8 @@ int DoSet (Parser *p)
if (*DBufValue(&buf) == '$') r = SetSysVar(DBufValue(&buf)+1, &v);
else r = SetVar(DBufValue(&buf), &v);
if (buf.len > VAR_NAME_LEN) {
Wprint("Warning: Variable name `%.*s...' truncated to `%.*s'",
VAR_NAME_LEN, DBufValue(&buf), VAR_NAME_LEN, DBufValue(&buf));
Wprint("Warning: Variable name `%.*s...' truncated to `%.*s'",
VAR_NAME_LEN, DBufValue(&buf), VAR_NAME_LEN, DBufValue(&buf));
}
DBufFree(&buf);
return r;
@@ -647,21 +647,21 @@ int DoUnset (Parser *p)
r = ParseToken(p, &buf);
if (r) return r;
if (!DBufLen(&buf)) {
DBufFree(&buf);
return E_EOLN;
DBufFree(&buf);
return E_EOLN;
}
(void) DeleteVar(DBufValue(&buf)); /* Ignore error - nosuchvar */
/* Keep going... */
while(1) {
r = ParseToken(p, &buf);
if (r) return r;
if (!DBufLen(&buf)) {
DBufFree(&buf);
return OK;
}
(void) DeleteVar(DBufValue(&buf));
r = ParseToken(p, &buf);
if (r) return r;
if (!DBufLen(&buf)) {
DBufFree(&buf);
return OK;
}
(void) DeleteVar(DBufValue(&buf));
}
}
@@ -684,35 +684,35 @@ int DoDump(ParsePtr p)
r = ParseToken(p, &buf);
if (r) return r;
if (!*DBufValue(&buf) ||
*DBufValue(&buf) == '#' ||
*DBufValue(&buf) == ';') {
DBufFree(&buf);
DumpVarTable();
return OK;
*DBufValue(&buf) == '#' ||
*DBufValue(&buf) == ';') {
DBufFree(&buf);
DumpVarTable();
return OK;
}
fprintf(ErrFp, "%s %s\n\n", VARIABLE, VALUE);
while(1) {
if (*DBufValue(&buf) == '$') {
DumpSysVarByName(DBufValue(&buf)+1);
} else {
v = FindVar(DBufValue(&buf), 0);
DBufValue(&buf)[VAR_NAME_LEN] = 0;
if (!v) fprintf(ErrFp, "%s %s\n",
DBufValue(&buf), UNDEF);
else {
fprintf(ErrFp, "%s ", v->name);
PrintValue(&(v->v), ErrFp);
fprintf(ErrFp, "\n");
}
}
r = ParseToken(p, &buf);
if (r) return r;
if (!*DBufValue(&buf) ||
*DBufValue(&buf) == '#' ||
*DBufValue(&buf) == ';') {
DBufFree(&buf);
return OK;
}
if (*DBufValue(&buf) == '$') {
DumpSysVarByName(DBufValue(&buf)+1);
} else {
v = FindVar(DBufValue(&buf), 0);
DBufValue(&buf)[VAR_NAME_LEN] = 0;
if (!v) fprintf(ErrFp, "%s %s\n",
DBufValue(&buf), UNDEF);
else {
fprintf(ErrFp, "%s ", v->name);
PrintValue(&(v->v), ErrFp);
fprintf(ErrFp, "\n");
}
}
r = ParseToken(p, &buf);
if (r) return r;
if (!*DBufValue(&buf) ||
*DBufValue(&buf) == '#' ||
*DBufValue(&buf) == ';') {
DBufFree(&buf);
return OK;
}
}
}
@@ -731,13 +731,13 @@ void DumpVarTable(void)
fprintf(ErrFp, "%s %s\n\n", VARIABLE, VALUE);
for (i=0; i<VAR_HASH_SIZE; i++) {
v = VHashTbl[i];
while(v) {
fprintf(ErrFp, "%s ", v->name);
PrintValue(&(v->v), ErrFp);
fprintf(ErrFp, "\n");
v = v->next;
}
v = VHashTbl[i];
while(v) {
fprintf(ErrFp, "%s ", v->name);
PrintValue(&(v->v), ErrFp);
fprintf(ErrFp, "\n");
v = v->next;
}
}
}
@@ -755,23 +755,23 @@ void DestroyVars(int all)
Var *v, *next, *prev;
for (i=0; i<VAR_HASH_SIZE; i++) {
v = VHashTbl[i];
VHashTbl[i] = NULL;
prev = NULL;
while(v) {
if (all || !v->preserve) {
DestroyValue(v->v);
next = v->next;
free(v);
} else {
if (prev) prev->next = v;
else VHashTbl[i] = v;
prev = v;
next = v->next;
v->next = NULL;
}
v = next;
}
v = VHashTbl[i];
VHashTbl[i] = NULL;
prev = NULL;
while(v) {
if (all || !v->preserve) {
DestroyValue(v->v);
next = v->next;
free(v);
} else {
if (prev) prev->next = v;
else VHashTbl[i] = v;
prev = v;
next = v->next;
v->next = NULL;
}
v = next;
}
}
}
@@ -807,8 +807,8 @@ int DoPreserve (Parser *p)
r = ParseToken(p, &buf);
if (r) return r;
if (!DBufLen(&buf)) {
DBufFree(&buf);
return E_EOLN;
DBufFree(&buf);
return E_EOLN;
}
r = PreserveVar(DBufValue(&buf));
@@ -817,15 +817,15 @@ int DoPreserve (Parser *p)
/* Keep going... */
while(1) {
r = ParseToken(p, &buf);
if (r) return r;
if (!DBufLen(&buf)) {
DBufFree(&buf);
return OK;
}
r = PreserveVar(DBufValue(&buf));
DBufFree(&buf);
if (r) return r;
r = ParseToken(p, &buf);
if (r) return r;
if (!DBufLen(&buf)) {
DBufFree(&buf);
return OK;
}
r = PreserveVar(DBufValue(&buf));
DBufFree(&buf);
if (r) return r;
}
}
@@ -978,15 +978,15 @@ int SetSysVar(char const *name, Value *value)
SysVar *v = FindSysVar(name);
if (!v) return E_NOSUCH_VAR;
if (!v->modifiable) {
Eprint("%s: `$%s'", ErrMsg[E_CANT_MODIFY], name);
return E_CANT_MODIFY;
Eprint("%s: `$%s'", ErrMsg[E_CANT_MODIFY], name);
return E_CANT_MODIFY;
}
if (v->type != SPECIAL_TYPE &&
v->type != value->type) return E_BAD_TYPE;
v->type != value->type) return E_BAD_TYPE;
if (v->type == SPECIAL_TYPE) {
SysVarFunc f = (SysVarFunc) v->value;
r = f(1, value);
SysVarFunc f = (SysVarFunc) v->value;
r = f(1, value);
DestroyValue(*value);
return r;
}
@@ -999,14 +999,14 @@ int SetSysVar(char const *name, Value *value)
}
/* If it's a string variable, special measures must be taken */
if (v->been_malloced) free(*((char **)(v->value)));
v->been_malloced = 1;
*((char **) v->value) = value->v.str;
value->type = ERR_TYPE; /* So that it's not accidentally freed */
if (v->been_malloced) free(*((char **)(v->value)));
v->been_malloced = 1;
*((char **) v->value) = value->v.str;
value->type = ERR_TYPE; /* So that it's not accidentally freed */
} else {
if (v->max != ANY && value->v.val > v->max) return E_2HIGH;
if (v->min != ANY && value->v.val < v->min) return E_2LOW;
*((int *)v->value) = value->v.val;
if (v->max != ANY && value->v.val > v->max) return E_2HIGH;
if (v->min != ANY && value->v.val < v->min) return E_2LOW;
*((int *)v->value) = value->v.val;
}
return OK;
}
@@ -1030,25 +1030,25 @@ int GetSysVar(char const *name, Value *val)
return OK;
}
if (v->type == SPECIAL_TYPE) {
SysVarFunc f = (SysVarFunc) v->value;
return f(0, val);
SysVarFunc f = (SysVarFunc) v->value;
return f(0, val);
} else if (v->type == STR_TYPE) {
if (! * (char **) v->value) {
val->v.str = StrDup("");
} else {
val->v.str = StrDup(*((char **) v->value));
}
if (!val->v.str) return E_NO_MEM;
if (!val->v.str) return E_NO_MEM;
} else {
val->v.val = *((int *) v->value);
val->v.val = *((int *) v->value);
}
val->type = v->type;
/* In "verbose" mode, print attempts to test $RunOff */
if (DebugFlag & DB_PRTLINE) {
if (v->value == (void *) &RunDisabled) {
Wprint("(Security note: $RunOff variable tested.)");
}
if (v->value == (void *) &RunDisabled) {
Wprint("(Security note: $RunOff variable tested.)");
}
}
return OK;
}
@@ -1067,11 +1067,11 @@ SysVar *FindSysVar(char const *name)
int r;
while (top >= bottom) {
r = StrCmpi(name, SysVarArr[mid].name);
if (!r) return &SysVarArr[mid];
else if (r>0) bottom = mid+1;
else top = mid-1;
mid = (top+bottom) / 2;
r = StrCmpi(name, SysVarArr[mid].name);
if (!r) return &SysVarArr[mid];
else if (r>0) bottom = mid+1;
else top = mid-1;
mid = (top+bottom) / 2;
}
return NULL;
}
@@ -1090,8 +1090,8 @@ void DumpSysVarByName(char const *name)
SysVar *v;
if (!name || !*name) {
for (i=0; i<NUMSYSVARS; i++) DumpSysVar(name, SysVarArr + i);
return;
for (i=0; i<NUMSYSVARS; i++) DumpSysVar(name, SysVarArr + i);
return;
}
v = FindSysVar(name);
@@ -1116,8 +1116,8 @@ static void DumpSysVar(char const *name, const SysVar *v)
buffer[0]='$'; buffer[1] = 0;
if (name && strlen(name) > VAR_NAME_LEN) {
fprintf(ErrFp, "$%s: Name too long\n", name);
return;
fprintf(ErrFp, "$%s: Name too long\n", name);
return;
}
if (name) strcat(buffer, name); else strcat(buffer, v->name);
fprintf(ErrFp, "%25s ", buffer);
@@ -1125,31 +1125,31 @@ static void DumpSysVar(char const *name, const SysVar *v)
if (v->type == CONST_INT_TYPE) {
fprintf(ErrFp, "%d\n", v->constval);
} else if (v->type == SPECIAL_TYPE) {
SysVarFunc f = (SysVarFunc) v->value;
f(0, &vtmp);
PrintValue(&vtmp, ErrFp);
putc('\n', ErrFp);
DestroyValue(vtmp);
} else if (v->type == STR_TYPE) {
SysVarFunc f = (SysVarFunc) v->value;
f(0, &vtmp);
PrintValue(&vtmp, ErrFp);
putc('\n', ErrFp);
DestroyValue(vtmp);
} else if (v->type == STR_TYPE) {
vtmp.type = STR_TYPE;
vtmp.v.str = * ((char **)v->value);
PrintValue(&vtmp, ErrFp);
putc('\n', ErrFp);
} else if (v->type == DATE_TYPE) {
vtmp.type = DATE_TYPE;
vtmp.v.val = * (int *) v->value;
PrintValue(&vtmp, ErrFp);
putc('\n', ErrFp);
} else {
if (!v->modifiable) fprintf(ErrFp, "%d\n", *((int *)v->value));
else {
fprintf(ErrFp, "%-10d ", *((int *)v->value));
if (v->min == ANY) fprintf(ErrFp, "(-Inf, ");
else fprintf(ErrFp, "[%d, ", v->min);
if (v->max == ANY) fprintf(ErrFp, "Inf)\n");
else fprintf(ErrFp, "%d]\n", v->max);
}
}
putc('\n', ErrFp);
} else if (v->type == DATE_TYPE) {
vtmp.type = DATE_TYPE;
vtmp.v.val = * (int *) v->value;
PrintValue(&vtmp, ErrFp);
putc('\n', ErrFp);
} else {
if (!v->modifiable) fprintf(ErrFp, "%d\n", *((int *)v->value));
else {
fprintf(ErrFp, "%-10d ", *((int *)v->value));
if (v->min == ANY) fprintf(ErrFp, "(-Inf, ");
else fprintf(ErrFp, "[%d, ", v->min);
if (v->max == ANY) fprintf(ErrFp, "Inf)\n");
else fprintf(ErrFp, "%d]\n", v->max);
}
}
} else fprintf(ErrFp, "%s\n", UNDEF);
return;
+208 -208
View File
@@ -64,239 +64,239 @@ set p a + " at " + vu
set a trigger(today()+7) + " ++7"
msg %_%_The following are the 7-day-in-advance substitutions:%
[a] msg [show("a")]
[a] msg [show("b")]
[a] msg [show("c")]
[a] msg [show("d")]
[a] msg [show("e")]
[a] msg [show("f")]
[a] msg [show("g")]
[a] msg [show("h")]
[a] msg [show("i")]
[a] msg [show("j")]
[a] msg [show("k")]
[a] msg [show("l")]
[a] msg [show("m")]
[a] msg [show("n")]
[a] msg [show("o")]
[a] msg [show("p")]
[a] msg [show("q")]
[a] msg [show("r")]
[a] msg [show("s")]
[a] msg [show("t")]
[a] msg [show("u")]
[a] msg [show("v")]
[a] msg [show("w")]
[a] msg [show("x")]
[a] msg [show("y")]
[a] msg [show("z")]
REM [a] MSG [show("a")]
REM [a] MSG [show("b")]
REM [a] MSG [show("c")]
REM [a] MSG [show("d")]
REM [a] MSG [show("e")]
REM [a] MSG [show("f")]
REM [a] MSG [show("g")]
REM [a] MSG [show("h")]
REM [a] MSG [show("i")]
REM [a] MSG [show("j")]
REM [a] MSG [show("k")]
REM [a] MSG [show("l")]
REM [a] MSG [show("m")]
REM [a] MSG [show("n")]
REM [a] MSG [show("o")]
REM [a] MSG [show("p")]
REM [a] MSG [show("q")]
REM [a] MSG [show("r")]
REM [a] MSG [show("s")]
REM [a] MSG [show("t")]
REM [a] MSG [show("u")]
REM [a] MSG [show("v")]
REM [a] MSG [show("w")]
REM [a] MSG [show("x")]
REM [a] MSG [show("y")]
REM [a] MSG [show("z")]
set a trigger(today()+6) + " ++6"
msg %_%_The following are the 6-day-in-advance substitutions:%
[a] msg [show("a")]
[a] msg [show("b")]
[a] msg [show("c")]
[a] msg [show("d")]
[a] msg [show("e")]
[a] msg [show("f")]
[a] msg [show("g")]
[a] msg [show("h")]
[a] msg [show("i")]
[a] msg [show("j")]
[a] msg [show("k")]
[a] msg [show("l")]
[a] msg [show("m")]
[a] msg [show("n")]
[a] msg [show("o")]
[a] msg [show("p")]
[a] msg [show("q")]
[a] msg [show("r")]
[a] msg [show("s")]
[a] msg [show("t")]
[a] msg [show("u")]
[a] msg [show("v")]
[a] msg [show("w")]
[a] msg [show("x")]
[a] msg [show("y")]
[a] msg [show("z")]
REM [a] MSG [show("a")]
REM [a] MSG [show("b")]
REM [a] MSG [show("c")]
REM [a] MSG [show("d")]
REM [a] MSG [show("e")]
REM [a] MSG [show("f")]
REM [a] MSG [show("g")]
REM [a] MSG [show("h")]
REM [a] MSG [show("i")]
REM [a] MSG [show("j")]
REM [a] MSG [show("k")]
REM [a] MSG [show("l")]
REM [a] MSG [show("m")]
REM [a] MSG [show("n")]
REM [a] MSG [show("o")]
REM [a] MSG [show("p")]
REM [a] MSG [show("q")]
REM [a] MSG [show("r")]
REM [a] MSG [show("s")]
REM [a] MSG [show("t")]
REM [a] MSG [show("u")]
REM [a] MSG [show("v")]
REM [a] MSG [show("w")]
REM [a] MSG [show("x")]
REM [a] MSG [show("y")]
REM [a] MSG [show("z")]
set a trigger(today()+5) + " ++5"
msg %_%_The following are the 5-day-in-advance substitutions:%
[a] msg [show("a")]
[a] msg [show("b")]
[a] msg [show("c")]
[a] msg [show("d")]
[a] msg [show("e")]
[a] msg [show("f")]
[a] msg [show("g")]
[a] msg [show("h")]
[a] msg [show("i")]
[a] msg [show("j")]
[a] msg [show("k")]
[a] msg [show("l")]
[a] msg [show("m")]
[a] msg [show("n")]
[a] msg [show("o")]
[a] msg [show("p")]
[a] msg [show("q")]
[a] msg [show("r")]
[a] msg [show("s")]
[a] msg [show("t")]
[a] msg [show("u")]
[a] msg [show("v")]
[a] msg [show("w")]
[a] msg [show("x")]
[a] msg [show("y")]
[a] msg [show("z")]
REM [a] MSG [show("a")]
REM [a] MSG [show("b")]
REM [a] MSG [show("c")]
REM [a] MSG [show("d")]
REM [a] MSG [show("e")]
REM [a] MSG [show("f")]
REM [a] MSG [show("g")]
REM [a] MSG [show("h")]
REM [a] MSG [show("i")]
REM [a] MSG [show("j")]
REM [a] MSG [show("k")]
REM [a] MSG [show("l")]
REM [a] MSG [show("m")]
REM [a] MSG [show("n")]
REM [a] MSG [show("o")]
REM [a] MSG [show("p")]
REM [a] MSG [show("q")]
REM [a] MSG [show("r")]
REM [a] MSG [show("s")]
REM [a] MSG [show("t")]
REM [a] MSG [show("u")]
REM [a] MSG [show("v")]
REM [a] MSG [show("w")]
REM [a] MSG [show("x")]
REM [a] MSG [show("y")]
REM [a] MSG [show("z")]
set a trigger(today()+4) + " ++4"
msg %_%_The following are the 4-day-in-advance substitutions:%
[a] msg [show("a")]
[a] msg [show("b")]
[a] msg [show("c")]
[a] msg [show("d")]
[a] msg [show("e")]
[a] msg [show("f")]
[a] msg [show("g")]
[a] msg [show("h")]
[a] msg [show("i")]
[a] msg [show("j")]
[a] msg [show("k")]
[a] msg [show("l")]
[a] msg [show("m")]
[a] msg [show("n")]
[a] msg [show("o")]
[a] msg [show("p")]
[a] msg [show("q")]
[a] msg [show("r")]
[a] msg [show("s")]
[a] msg [show("t")]
[a] msg [show("u")]
[a] msg [show("v")]
[a] msg [show("w")]
[a] msg [show("x")]
[a] msg [show("y")]
[a] msg [show("z")]
REM [a] MSG [show("a")]
REM [a] MSG [show("b")]
REM [a] MSG [show("c")]
REM [a] MSG [show("d")]
REM [a] MSG [show("e")]
REM [a] MSG [show("f")]
REM [a] MSG [show("g")]
REM [a] MSG [show("h")]
REM [a] MSG [show("i")]
REM [a] MSG [show("j")]
REM [a] MSG [show("k")]
REM [a] MSG [show("l")]
REM [a] MSG [show("m")]
REM [a] MSG [show("n")]
REM [a] MSG [show("o")]
REM [a] MSG [show("p")]
REM [a] MSG [show("q")]
REM [a] MSG [show("r")]
REM [a] MSG [show("s")]
REM [a] MSG [show("t")]
REM [a] MSG [show("u")]
REM [a] MSG [show("v")]
REM [a] MSG [show("w")]
REM [a] MSG [show("x")]
REM [a] MSG [show("y")]
REM [a] MSG [show("z")]
set a trigger(today()+3) + " ++3"
msg %_%_The following are the 3-day-in-advance substitutions:%
[a] msg [show("a")]
[a] msg [show("b")]
[a] msg [show("c")]
[a] msg [show("d")]
[a] msg [show("e")]
[a] msg [show("f")]
[a] msg [show("g")]
[a] msg [show("h")]
[a] msg [show("i")]
[a] msg [show("j")]
[a] msg [show("k")]
[a] msg [show("l")]
[a] msg [show("m")]
[a] msg [show("n")]
[a] msg [show("o")]
[a] msg [show("p")]
[a] msg [show("q")]
[a] msg [show("r")]
[a] msg [show("s")]
[a] msg [show("t")]
[a] msg [show("u")]
[a] msg [show("v")]
[a] msg [show("w")]
[a] msg [show("x")]
[a] msg [show("y")]
[a] msg [show("z")]
REM [a] MSG [show("a")]
REM [a] MSG [show("b")]
REM [a] MSG [show("c")]
REM [a] MSG [show("d")]
REM [a] MSG [show("e")]
REM [a] MSG [show("f")]
REM [a] MSG [show("g")]
REM [a] MSG [show("h")]
REM [a] MSG [show("i")]
REM [a] MSG [show("j")]
REM [a] MSG [show("k")]
REM [a] MSG [show("l")]
REM [a] MSG [show("m")]
REM [a] MSG [show("n")]
REM [a] MSG [show("o")]
REM [a] MSG [show("p")]
REM [a] MSG [show("q")]
REM [a] MSG [show("r")]
REM [a] MSG [show("s")]
REM [a] MSG [show("t")]
REM [a] MSG [show("u")]
REM [a] MSG [show("v")]
REM [a] MSG [show("w")]
REM [a] MSG [show("x")]
REM [a] MSG [show("y")]
REM [a] MSG [show("z")]
set a trigger(today()+2) + " ++2"
msg %_%_The following are the two-day-in-advance substitutions:%
[a] msg [show("a")]
[a] msg [show("b")]
[a] msg [show("c")]
[a] msg [show("d")]
[a] msg [show("e")]
[a] msg [show("f")]
[a] msg [show("g")]
[a] msg [show("h")]
[a] msg [show("i")]
[a] msg [show("j")]
[a] msg [show("k")]
[a] msg [show("l")]
[a] msg [show("m")]
[a] msg [show("n")]
[a] msg [show("o")]
[a] msg [show("p")]
[a] msg [show("q")]
[a] msg [show("r")]
[a] msg [show("s")]
[a] msg [show("t")]
[a] msg [show("u")]
[a] msg [show("v")]
[a] msg [show("w")]
[a] msg [show("x")]
[a] msg [show("y")]
[a] msg [show("z")]
REM [a] MSG [show("a")]
REM [a] MSG [show("b")]
REM [a] MSG [show("c")]
REM [a] MSG [show("d")]
REM [a] MSG [show("e")]
REM [a] MSG [show("f")]
REM [a] MSG [show("g")]
REM [a] MSG [show("h")]
REM [a] MSG [show("i")]
REM [a] MSG [show("j")]
REM [a] MSG [show("k")]
REM [a] MSG [show("l")]
REM [a] MSG [show("m")]
REM [a] MSG [show("n")]
REM [a] MSG [show("o")]
REM [a] MSG [show("p")]
REM [a] MSG [show("q")]
REM [a] MSG [show("r")]
REM [a] MSG [show("s")]
REM [a] MSG [show("t")]
REM [a] MSG [show("u")]
REM [a] MSG [show("v")]
REM [a] MSG [show("w")]
REM [a] MSG [show("x")]
REM [a] MSG [show("y")]
REM [a] MSG [show("z")]
msg %_%_The following are the one-day-in-advance substitutions:%
set a trigger(today()+1) + " ++1"
set d a + " at " + tt
set e a + " at " + tu
[a] msg [show("a")]
[a] msg [show("b")]
[a] msg [show("c")]
[a] msg [show("d")]
[a] msg [show("e")]
[a] msg [show("f")]
[a] msg [show("g")]
[a] msg [show("h")]
[a] msg [show("i")]
[a] msg [show("j")]
[a] msg [show("k")]
[a] msg [show("l")]
[a] msg [show("m")]
[a] msg [show("n")]
[a] msg [show("o")]
[a] msg [show("p")]
[a] msg [show("q")]
[a] msg [show("r")]
[a] msg [show("s")]
[a] msg [show("t")]
[a] msg [show("u")]
[a] msg [show("v")]
[a] msg [show("w")]
[a] msg [show("x")]
[a] msg [show("y")]
[a] msg [show("z")]
REM [a] MSG [show("a")]
REM [a] MSG [show("b")]
REM [a] MSG [show("c")]
REM [a] MSG [show("d")]
REM [a] MSG [show("e")]
REM [a] MSG [show("f")]
REM [a] MSG [show("g")]
REM [a] MSG [show("h")]
REM [a] MSG [show("i")]
REM [a] MSG [show("j")]
REM [a] MSG [show("k")]
REM [a] MSG [show("l")]
REM [a] MSG [show("m")]
REM [a] MSG [show("n")]
REM [a] MSG [show("o")]
REM [a] MSG [show("p")]
REM [a] MSG [show("q")]
REM [a] MSG [show("r")]
REM [a] MSG [show("s")]
REM [a] MSG [show("t")]
REM [a] MSG [show("u")]
REM [a] MSG [show("v")]
REM [a] MSG [show("w")]
REM [a] MSG [show("x")]
REM [a] MSG [show("y")]
REM [a] MSG [show("z")]
msg %_%_The following are the current-day substitutions:%
set a trigger(today())
set d a + " at " + tt
set e a + " at " + tu
[a] msg [show("a")]
[a] msg [show("b")]
[a] msg [show("c")]
[a] msg [show("d")]
[a] msg [show("e")]
[a] msg [show("f")]
[a] msg [show("g")]
[a] msg [show("h")]
[a] msg [show("i")]
[a] msg [show("j")]
[a] msg [show("k")]
[a] msg [show("l")]
[a] msg [show("m")]
[a] msg [show("n")]
[a] msg [show("o")]
[a] msg [show("p")]
[a] msg [show("q")]
[a] msg [show("r")]
[a] msg [show("s")]
[a] msg [show("t")]
[a] msg [show("u")]
[a] msg [show("v")]
[a] msg [show("w")]
[a] msg [show("x")]
[a] msg [show("y")]
[a] msg [show("z")]
REM [a] MSG [show("a")]
REM [a] MSG [show("b")]
REM [a] MSG [show("c")]
REM [a] MSG [show("d")]
REM [a] MSG [show("e")]
REM [a] MSG [show("f")]
REM [a] MSG [show("g")]
REM [a] MSG [show("h")]
REM [a] MSG [show("i")]
REM [a] MSG [show("j")]
REM [a] MSG [show("k")]
REM [a] MSG [show("l")]
REM [a] MSG [show("m")]
REM [a] MSG [show("n")]
REM [a] MSG [show("o")]
REM [a] MSG [show("p")]
REM [a] MSG [show("q")]
REM [a] MSG [show("r")]
REM [a] MSG [show("s")]
REM [a] MSG [show("t")]
REM [a] MSG [show("u")]
REM [a] MSG [show("v")]
REM [a] MSG [show("w")]
REM [a] MSG [show("x")]
REM [a] MSG [show("y")]
REM [a] MSG [show("z")]
MSG %_Time substitutions for [now()] where now() = [now()]
REM AT [now()] MSG [show("1")]