diff --git a/man/remind.1 b/man/remind.1 index 8b2369e2..a5b14a42 100644 --- a/man/remind.1 +++ b/man/remind.1 @@ -2358,6 +2358,11 @@ $TimeSep and $DateTimeSep when formatting its output. For example: .PP .RE .TP +.B any(arg1 [,arg2, ..., argN]); +Returns 1 if the first argument \fIarg1\fR is equal to any of the +subsequent arguments \fIarg2\fR through \fIargN\fR; returns 0 otherwise. +Also returns 0 if called with only one argument. +.TP .B args(s_fname) Returns the number of arguments expected by the user-defined function \fIfname\fR, or \-1 if no such user-defined function exists. Note that diff --git a/src/funcs.c b/src/funcs.c index 50e5997f..7a3a96d5 100644 --- a/src/funcs.c +++ b/src/funcs.c @@ -58,6 +58,7 @@ static int FADusk (func_info *); static int FAbs (func_info *); static int FAccess (func_info *); static int FAmpm (func_info *); +static int FAny (func_info *); static int FArgs (func_info *); static int FAsc (func_info *); static int FBaseyr (func_info *); @@ -209,6 +210,7 @@ BuiltinFunc Func[] = { { "adawn", 0, 1, 0, FADawn}, { "adusk", 0, 1, 0, FADusk}, { "ampm", 1, 3, 1, FAmpm }, + { "any", 1, NO_MAX, 1, FAny }, { "args", 1, 1, 0, FArgs }, { "asc", 1, 1, 1, FAsc }, { "baseyr", 0, 0, 1, FBaseyr }, @@ -1033,6 +1035,36 @@ static int FPlural(func_info *info) } } +/***************************************************************/ +/* */ +/* FAny */ +/* Return 1 if the first arg equals any subsequent arg, 0 */ +/* otherwise. */ +/* */ +/***************************************************************/ +static int FAny(func_info *info) +{ + int i; + RetVal.type = INT_TYPE; + RETVAL = 0; + for (i=1; i -2147483648 abs(-2147483648) => Number too high ../tests/test.rem(594): Number too high +# The "any" function +set a any(1) +any(1) => 0 +set a any("foo") +any("foo") => 0 +set a any(1:00) +any(01:00) => 0 +set a any(1, 2) +any(1, 2) => 0 +set a any("foo", 2) +any("foo", 2) => 0 +set a any(1:00, 2) +any(01:00, 2) => 0 +set a any(1, 2, 1, 3) +any(1, 2, 1, 3) => 1 +set a any("foo", 2, 3, "foo") +any("foo", 2, 3, "foo") => 1 +set a any(1:00, 2, "foo", 2:00, 1:00, 9:00) +any(01:00, 2, "foo", 02:00, 01:00, 09:00) => 1 + # Shellescape set a shellescape(" !\"#$%%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~") shellescape(" !"#$%%&'()*+,-./0123456789:;<=>?@ABCDEF"...) => "\ \!\"\#\$\%\%\&\'\(\)\*+,-./0123456789\"... msg [a] -../tests/test.rem(599): Trig = Saturday, 16 February, 1991 +../tests/test.rem(610): Trig = Saturday, 16 February, 1991 a => "\ \!\"\#\$\%\%\&\'\(\)\*+,-./0123456789\"... \ \!\"\#\$\\\&\'\(\)\*+,-./0123456789\:\;\<=\>\?@ABCDEFGHIJKLMNOPQRSTUVWXYZ\[\\\]\^_\`abcdefghijklmnopqrstuvwxyz\{\|\}\~ diff --git a/tests/test.rem b/tests/test.rem index abb7751a..360a1e97 100644 --- a/tests/test.rem +++ b/tests/test.rem @@ -593,6 +593,17 @@ set a $IntMin * (-1) set a (-1) * $IntMin set a abs($IntMin) +# The "any" function +set a any(1) +set a any("foo") +set a any(1:00) +set a any(1, 2) +set a any("foo", 2) +set a any(1:00, 2) +set a any(1, 2, 1, 3) +set a any("foo", 2, 3, "foo") +set a any(1:00, 2, "foo", 2:00, 1:00, 9:00) + # Shellescape set a shellescape(" !\"#$%%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~")