From 9c3f0f19949fecad403af0da954d8810513ecb4f Mon Sep 17 00:00:00 2001 From: Dianne Skoll Date: Sat, 25 May 2024 09:22:41 -0400 Subject: [PATCH] Allow "-ifoo" on the command-line, which is the same as "-ifoo=0" --- src/init.c | 22 ++++++++++++++++++++-- tests/test-rem | 9 +++++++++ tests/test.cmp | 8 ++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/init.c b/src/init.c index 91033ac8..e1d1d46e 100644 --- a/src/init.c +++ b/src/init.c @@ -936,10 +936,28 @@ static void InitializeVar(char const *str) str++; } varname[r] = 0; - if (!*str) { - fprintf(ErrFp, ErrMsg[M_I_OPTION], ErrMsg[E_MISS_EQ]); + if (!*varname) { + fprintf(ErrFp, ErrMsg[M_I_OPTION], ErrMsg[E_MISS_VAR]); return; } + if (!*str) { + /* Setting a system var does require =expr on the commandline */ + if (*varname == '$') { + fprintf(ErrFp, ErrMsg[M_I_OPTION], ErrMsg[E_MISS_EQ]); + return; + } + val.type = INT_TYPE; + val.v.val = 0; + r = SetVar(varname, &val); + if (!r) { + r = PreserveVar(varname); + } + if (r) { + fprintf(ErrFp, ErrMsg[M_I_OPTION], ErrMsg[r]); + } + return; + } + if (!*varname) { fprintf(ErrFp, ErrMsg[M_I_OPTION], ErrMsg[E_MISS_VAR]); return; diff --git a/tests/test-rem b/tests/test-rem index e82bf17e..e990933b 100644 --- a/tests/test-rem +++ b/tests/test-rem @@ -541,6 +541,15 @@ EOF (echo 'BANNER %'; echo 'REM 29 MSG No bug') | ../src/remind -dt - 29 Feb 2024 >> ../tests/test.out 2>&1 +../src/remind -ifoo - <<'EOF' >> ../tests/test.out 2>&1 +BANNER % +DUMP +EOF + +../src/remind '-i$AddBlankLines' - <<'EOF' >> ../tests/test.out 2>&1 +BANNER % +DUMP +EOF # Remove references to SysInclude, which is build-specific grep -F -v '$SysInclude' < ../tests/test.out > ../tests/test.out.1 && mv -f ../tests/test.out.1 ../tests/test.out cmp -s ../tests/test.out ../tests/test.cmp diff --git a/tests/test.cmp b/tests/test.cmp index 62f2a9ca..922bf01d 100644 --- a/tests/test.cmp +++ b/tests/test.cmp @@ -12001,3 +12001,11 @@ No reminders. -(2): Trig = Thursday, 29 February, 2024 No bug +Variable Value + +foo 0 +No reminders. +Remind: '-i' option: Missing '=' sign +Variable Value + +No reminders.