summaryrefslogtreecommitdiff
path: root/Src/math.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2017-03-01 10:01:01 +0000
committerPeter Stephenson <pws@zsh.org>2017-03-01 10:01:01 +0000
commit47c05f6b66ebd071a60a76158d7f51d4b49c25a2 (patch)
tree90e0ba26983d2ce22f5ecd317aa621bbf07b7f6e /Src/math.c
parent24497ad19624ae7de173c4276134365f67698299 (diff)
downloadzsh-47c05f6b66ebd071a60a76158d7f51d4b49c25a2.tar.gz
zsh-47c05f6b66ebd071a60a76158d7f51d4b49c25a2.zip
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.
Diffstat (limited to 'Src/math.c')
-rw-r--r--Src/math.c32
1 files changed, 22 insertions, 10 deletions
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 {