Implement EXPR ON and EXPR OFF

This commit is contained in:
Dianne Skoll
2024-06-02 12:39:00 -04:00
parent 07fca94a7f
commit b49c0f52bd
8 changed files with 52 additions and 3 deletions

View File

@@ -1669,6 +1669,7 @@ static void GenerateCalEntries(int col)
case T_Pop: r=PopOmitContext(&p); break;
case T_Push: r=PushOmitContext(&p); break;
case T_Preserve: r=DoPreserve(&p); break;
case T_Expr: r = DoExpr(&p); break;
case T_RemType: if (tok.val == RUN_TYPE) {
r=DoRun(&p);
break;

View File

@@ -123,6 +123,7 @@
#define E_DURATION_NO_AT 103
#define E_EXPECTING_WEEKDAY 104
#define E_REPEATED_ARG 105
#define E_EXPR_DISABLED 106
#ifdef MK_GLOBALS
#undef EXTERN
@@ -246,7 +247,8 @@ EXTERN char *ErrMsg[]
/* E_TIME_TWICE */ "Time specified twice",
/* E_DURATION_NO_AT */ "Cannot specify DURATION without specifying AT",
/* E_EXPECTING_WEEKDAY */ "Expecting weekday name",
/* E_REPEATED_ARG */ "Duplicate argument name"
/* E_REPEATED_ARG */ "Duplicate argument name",
/* E_EXPR_DISABLED */ "Expression evaluation is disabled"
}
#endif /* MK_GLOBALS */
;

View File

@@ -687,6 +687,10 @@ evaluate_expr_node(expr_node *node, Value *locals, Value *ans, int *nonconst)
{
int r;
if (ExpressionEvaluationDisabled) {
return E_EXPR_DISABLED;
}
if (!node) {
return E_SWERR;
}
@@ -2227,6 +2231,12 @@ expr_node *
parse_expression(char const **e, int *r, Var *locals)
{
char const *orig = *e;
if (ExpressionEvaluationDisabled) {
*r = E_EXPR_DISABLED;
return NULL;
}
expr_node *node = parse_expression_aux(e, r, locals);
if (DebugFlag & DB_PARSE_EXPR) {
fprintf(ErrFp, "Parsed expression: ");

View File

@@ -73,6 +73,7 @@ EXTERN INIT( int InfiniteDelta, 0);
EXTERN INIT( int DefaultTDelta, 0);
EXTERN INIT( int DeltaOverride, 0);
EXTERN INIT( int RunDisabled, 0);
EXTERN INIT( int ExpressionEvaluationDisabled, 0);
EXTERN INIT( int IgnoreOnce, 0);
EXTERN INIT( int SortByTime, 0);
EXTERN INIT( int SortByDate, 0);

View File

@@ -298,6 +298,7 @@ static void DoReminders(void)
case T_Pop: r=PopOmitContext(&p); break;
case T_Preserve: r=DoPreserve(&p); break;
case T_Push: r=PushOmitContext(&p); break;
case T_Expr: r = DoExpr(&p); break;
case T_RemType: if (tok.val == RUN_TYPE) {
r=DoRun(&p);
} else {
@@ -1185,7 +1186,6 @@ int DoBanner(ParsePtr p)
/* */
/* Enable or disable the RUN command under program control */
/* */
/* */
/***************************************************************/
int DoRun(ParsePtr p)
{
@@ -1212,6 +1212,38 @@ int DoRun(ParsePtr p)
return VerifyEoln(p);
}
/***************************************************************/
/* */
/* DoExpr */
/* */
/* Enable or disable expression evaluation */
/* */
/***************************************************************/
int DoExpr(ParsePtr p)
{
int r;
DynamicBuffer buf;
DBufInit(&buf);
if ( (r=ParseToken(p, &buf)) ) return r;
/* Only allow EXPR ON in top-level script */
if (! StrCmpi(DBufValue(&buf), "ON")) {
if (TopLevel()) ExpressionEvaluationDisabled = 0;
}
/* But allow EXPR OFF anywhere */
else if (! StrCmpi(DBufValue(&buf), "OFF"))
ExpressionEvaluationDisabled = 1;
else {
DBufFree(&buf);
return E_PARSE_ERR;
}
DBufFree(&buf);
return VerifyEoln(p);
}
/***************************************************************/
/* */
/* DoFlush */

View File

@@ -105,6 +105,7 @@ int VerifyEoln (ParsePtr p);
int DoDebug (ParsePtr p);
int DoBanner (ParsePtr p);
int DoRun (ParsePtr p);
int DoExpr (ParsePtr p);
int DoErrMsg (ParsePtr p);
int ClearGlobalOmits (void);
int DoClear (ParsePtr p);

View File

@@ -56,6 +56,7 @@ Token TokArray[] = {
{ "endif", 5, T_EndIf, 0 },
{ "errmsg", 6, T_ErrMsg, 0 },
{ "exit", 4, T_Exit, 0 },
{ "expr", 4, T_Expr, 0 },
{ "february", 3, T_Month, 1 },
{ "first", 5, T_Ordinal, 0 },
{ "flush", 5, T_Flush, 0 },

View File

@@ -234,7 +234,8 @@ enum TokTypes
T_MaybeUncomputable,
T_Ordinal,
T_In,
T_LastBack
T_LastBack,
T_Expr
};
/* The structure of a token */