From 47c05f6b66ebd071a60a76158d7f51d4b49c25a2 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 1 Mar 2017 10:01:01 +0000 Subject: 40622 with typos fixed: functions -Ms. This adds the capability for mathematical functions based on shell functions to have a string argument. Module functions have had this for a long time. --- Src/math.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'Src/math.c') diff --git a/Src/math.c b/Src/math.c index 37981cf22..f19c0ed61 100644 --- a/Src/math.c +++ b/Src/math.c @@ -974,7 +974,7 @@ callmathfunc(char *o) a[strlen(a) - 1] = '\0'; if ((f = getmathfunc(n, 1))) { - if (f->flags & MFF_STR) { + if ((f->flags & (MFF_STR|MFF_USERFUNC)) == MFF_STR) { return f->sfunc(n, a, f->funcid); } else { int argc = 0; @@ -987,22 +987,34 @@ callmathfunc(char *o) addlinknode(l, n); } - while (iblank(*a)) - a++; + if (f->flags & MFF_STR) { + if (!*a) { + addlinknode(l, dupstring("")); + argc++; + } + } else { + while (iblank(*a)) + a++; + } while (*a) { if (*a) { argc++; if (f->flags & MFF_USERFUNC) { /* need to pass strings */ char *str; - marg = mathevall(a, MPREC_ARG, &a); - if (marg.type & MN_FLOAT) { - /* convfloat is off the heap */ - str = convfloat(marg.u.d, 0, 0, NULL); + if (f->flags & MFF_STR) { + str = dupstring(a); + a = ""; } else { - char buf[BDIGBUFSIZE]; - convbase(buf, marg.u.l, 10); - str = dupstring(buf); + marg = mathevall(a, MPREC_ARG, &a); + if (marg.type & MN_FLOAT) { + /* convfloat is off the heap */ + str = convfloat(marg.u.d, 0, 0, NULL); + } else { + char buf[BDIGBUFSIZE]; + convbase(buf, marg.u.l, 10); + str = dupstring(buf); + } } addlinknode(l, str); } else { -- cgit 1.4.1