diff --git a/man/remind.1.in b/man/remind.1.in index 4f4e780d..ba412cf8 100644 --- a/man/remind.1.in +++ b/man/remind.1.in @@ -5076,7 +5076,18 @@ function, the command fails with an error message and does nothing. If you define a user-defined function and then later on redefine it, \fBRemind\fR will issue a warning. If you do not want this warning, then use \fBFUNSET\fR to remove the existing definition before you -redefine the function. +redefine the function. Alternatively, you can use a "-" token before +the function name to suppress "redefined function" warnings, as in the +following example: +.PP +.nf + FSET - f(x) 2*x + # You must have space before and after the "-" + # This will NOT work: + # FSET -f(x) 2*x +.fi +.PP +to define a function and suppress any "redefined function" warning. .PP .SH PRECISE SCHEDULING .PP diff --git a/src/userfns.c b/src/userfns.c index 5d444153..74dac5c4 100644 --- a/src/userfns.c +++ b/src/userfns.c @@ -181,12 +181,31 @@ int DoFset(ParsePtr p) Var *locals = NULL; Var local_array[MAX_FUNC_ARGS]; int orig_namelen; + int suppress_redefined_function_warning = 0; + int ch; DynamicBuffer buf; DBufInit(&buf); + + ch = ParseNonSpaceChar(p, &r, 1); + if (r) { + return r; + } + if (ch == '-') { + r = ParseToken(p, &buf); + if (strcmp(DBufValue(&buf), "-")) { + DBufFree(&buf); + return E_PARSE_ERR; + } + suppress_redefined_function_warning = 1; + DBufFree(&buf); + } + /* Get the function name */ - if ( (r=ParseIdentifier(p, &buf)) ) return r; + if ( (r=ParseIdentifier(p, &buf)) ) { + return r; + } if (*DBufValue(&buf) == '$') { DBufFree(&buf); return E_BAD_ID; @@ -222,8 +241,10 @@ int DoFset(ParsePtr p) return OK; } /* Warn about redefinition */ - Wprint(tr("Function `%s' redefined: previously defined at %s(%s)"), - existing->name, existing->filename, line_range(existing->lineno_start, existing->lineno)); + if (!suppress_redefined_function_warning) { + Wprint(tr("Function `%s' redefined: previously defined at %s(%s)"), + existing->name, existing->filename, line_range(existing->lineno_start, existing->lineno)); + } } /* Should be followed by '(' */ diff --git a/tests/test.cmp b/tests/test.cmp index 10092838..04ba2010 100644 --- a/tests/test.cmp +++ b/tests/test.cmp @@ -800,8 +800,7 @@ Leaving UserFN _ofunc(1991-02-28) => 0 ../tests/test.rem(224): Trig = Thursday, 28 February, 1991 # omitfunc ignores local/global omits -fset _ofunc(x) 0 -../tests/test.rem(227): Function `_ofunc' redefined: previously defined at ../tests/test.rem(222) +fset - _ofunc(x) 0 OMIT 1 March OMIT 2 March 1991 REM 1 March OMIT Sun OMITFUNC _ofunc AFTER MSG Should trigger 1 March diff --git a/tests/test.rem b/tests/test.rem index 98480318..91d22dbd 100644 --- a/tests/test.rem +++ b/tests/test.rem @@ -224,7 +224,7 @@ REM 1 March OMITFUNC _ofunc AFTER MSG OmitFunc Test REM 8 March OMITFUNC _ofunc -1 MSG OmitFunc Test 2 # omitfunc ignores local/global omits -fset _ofunc(x) 0 +fset - _ofunc(x) 0 OMIT 1 March OMIT 2 March 1991 REM 1 March OMIT Sun OMITFUNC _ofunc AFTER MSG Should trigger 1 March