Compare commits

...

6 Commits

Author SHA1 Message Date
Dianne Skoll
8453e17c6c Add a guard to avoid calling free(NULL)
All checks were successful
Remind unit tests / tests (push) Successful in 29s
2024-09-12 11:50:11 -04:00
Dianne Skoll
76c1e2abb3 Avoid unnecessary double-initialization. 2024-09-12 11:38:59 -04:00
Dianne Skoll
3389f1c91b Refactor init_token and token_error. 2024-09-12 10:58:35 -04:00
Dianne Skoll
b2d47ae979 Initialize token.val in a few places. 2024-09-12 10:51:00 -04:00
Dianne Skoll
e2c615f310 Fix comment. 2024-09-12 10:16:01 -04:00
Dianne Skoll
e8492a4303 Add Chinese New Year file. 2024-09-11 12:09:57 -04:00
5 changed files with 61 additions and 28 deletions

View File

@@ -0,0 +1,29 @@
REM 1 Feb 2022 MSG Chinese New Year (Tiger)
REM 22 Jan 2023 MSG Chinese New Year (Rabbit)
REM 10 Feb 2024 MSG Chinese New Year (Dragon)
REM 29 Jan 2025 MSG Chinese New Year (Snake)
REM 17 Feb 2026 MSG Chinese New Year (Horse)
REM 6 Feb 2027 MSG Chinese New Year (Goat)
REM 26 Jan 2028 MSG Chinese New Year (Monkey)
REM 13 Feb 2029 MSG Chinese New Year (Rooster)
REM 3 Feb 2030 MSG Chinese New Year (Dog)
REM 23 Jan 2031 MSG Chinese New Year (Pig)
REM 11 Feb 2032 MSG Chinese New Year (Rat)
REM 31 Jan 2033 MSG Chinese New Year (Ox)
REM 19 Feb 2034 MSG Chinese New Year (Tiger)
REM 8 Feb 2035 MSG Chinese New Year (Rabbit)
REM 28 Jan 2036 MSG Chinese New Year (Dragon)
REM 15 Feb 2037 MSG Chinese New Year (Snake)
REM 4 Feb 2038 MSG Chinese New Year (Horse)
REM 24 Jan 2039 MSG Chinese New Year (Goat)
REM 12 Feb 2040 MSG Chinese New Year (Monkey)
REM 1 Feb 2041 MSG Chinese New Year (Rooster)
REM 22 Jan 2042 MSG Chinese New Year (Dog)
REM 10 Feb 2043 MSG Chinese New Year (Pig)
REM 30 Jan 2044 MSG Chinese New Year (Rat)
REM 17 Feb 2045 MSG Chinese New Year (Ox)
REM 6 Feb 2046 MSG Chinese New Year (Tiger)
REM 26 Jan 2047 MSG Chinese New Year (Rabbit)
REM 14 Feb 2048 MSG Chinese New Year (Dragon)
REM 2 Feb 2049 MSG Chinese New Year (Snake)
REM 23 Jan 2050 MSG Chinese New Year (Horse)

View File

@@ -152,7 +152,6 @@ int DBufGets(DynamicBuffer *dbuf, FILE *fp)
/* Try reading the first few bytes right into the buffer --
we can usually save some unnecessary copying */
*(dbuf->buffer) = 0;
if (fgets(dbuf->buffer, dbuf->allocatedLen, fp) == NULL) {
return OK;
}

View File

@@ -129,7 +129,7 @@ static double phase (double, double *, double *, double *, double *, double *, d
/* */
/* jdate */
/* */
/* Convert a date and time to DSE day and fraction. */
/* Convert a date and time to Julian day and fraction. */
/* */
/***************************************************************/
static long jdate(int y, int mon, int day)

View File

@@ -145,7 +145,9 @@ int PushOmitContext(ParsePtr p)
context->partsave = malloc(NumPartialOmits * sizeof(int));
if (NumPartialOmits && !context->partsave) {
free(context->filename);
free(context->fullsave);
if (context->fullsave) {
free(context->fullsave);
}
free(context);
return E_NO_MEM;
}

View File

@@ -119,6 +119,21 @@ Token TokArray[] = {
static int TokStrCmp (Token const *t, char const *s);
static void
init_token(Token *t)
{
t->name = NULL;
t->type = T_Illegal;
t->val = 0;
}
static void
token_error(Token *t, int errcode)
{
t->type = T_Illegal;
t->val = -errcode;
}
/***************************************************************/
/* */
/* FindInitialToken */
@@ -132,7 +147,7 @@ char const *FindInitialToken(Token *tok, char const *s)
DynamicBuffer buf;
DBufInit(&buf);
tok->type = T_Illegal;
init_token(tok);
while (isempty(*s)) s++;
@@ -159,7 +174,7 @@ void FindToken(char const *s, Token *tok)
int top, bot, mid, r, max;
int l;
tok->type = T_Illegal;
init_token(tok);
if (! *s) {
tok->type = T_Empty;
return;
@@ -235,8 +250,7 @@ void FindNumericToken(char const *s, Token *t)
int ampm = 0;
int r;
t->type = T_Illegal;
t->val = 0;
init_token(t);
if (isdigit(*s)) {
PARSENUM(t->val, s);
@@ -262,9 +276,7 @@ void FindNumericToken(char const *s, Token *t)
t->type = T_DateTime;
t->val = MINUTES_PER_DAY * dse + tim;
} else {
t->type = T_Illegal;
/* Store error message negated as val! */
t->val = -r;
token_error(t, r);
}
return;
}
@@ -283,15 +295,13 @@ void FindNumericToken(char const *s, Token *t)
s++;
hour = t->val;
if (!isdigit(*s)) {
t->type = T_Illegal;
t->val = -E_BAD_TIME;
token_error(t, E_BAD_TIME);
return;
}
PARSENUM(min, s);
if (min > 59) {
/* Illegal time */
t->type = T_Illegal;
t->val = -E_BAD_TIME;
token_error(t, E_BAD_TIME);
return;
}
/* Check for p[m] or a[m] */
@@ -303,14 +313,12 @@ void FindNumericToken(char const *s, Token *t)
}
}
if (*s) {
t->type = T_Illegal;
t->val = -E_BAD_TIME;
token_error(t, E_BAD_TIME);
return;
}
if (ampm) {
if (hour < 1 || hour > 12) {
t->type = T_Illegal;
t->val = -E_BAD_TIME;
token_error(t, E_BAD_TIME);
return;
}
if (ampm == 'a') {
@@ -335,8 +343,7 @@ void FindNumericToken(char const *s, Token *t)
/* If we hit a non-digit, error! */
if (*s) {
t->type = T_Illegal;
t->val = -E_BAD_NUMBER;
token_error(t, E_BAD_NUMBER);
return;
}
@@ -353,8 +360,7 @@ void FindNumericToken(char const *s, Token *t)
PARSENUM(t->val, s);
if (*s) {
/* Illegal token if followed by non-numeric char */
t->type = T_Illegal;
t->val = -E_BAD_NUMBER;
token_error(t, E_BAD_NUMBER);
return;
}
t->type = T_Rep;
@@ -366,8 +372,7 @@ void FindNumericToken(char const *s, Token *t)
PARSENUM(t->val, s);
if (*s) {
/* Illegal token if followed by non-numeric char */
t->type = T_Illegal;
t->val = -E_BAD_NUMBER;
token_error(t, E_BAD_NUMBER);
return;
}
t->type = T_Delta;
@@ -379,8 +384,7 @@ void FindNumericToken(char const *s, Token *t)
PARSENUM(t->val, s);
if (*s) {
/* Illegal token if followed by non-numeric char */
t->type = T_Illegal;
t->val = -E_BAD_NUMBER;
token_error(t, E_BAD_NUMBER);
return;
}
t->type = T_Back;
@@ -393,8 +397,7 @@ void FindNumericToken(char const *s, Token *t)
PARSENUM(t->val, s);
if (*s) {
/* Illegal token if followed by non-numeric char */
t->type = T_Illegal;
t->val = -E_BAD_NUMBER;
token_error(t, E_BAD_NUMBER);
return;
}
t->type = T_BackAdj;