From bb9f1669f66de38cf4eb64cd52eb54d93460aadf Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Sun, 28 Nov 2021 17:13:23 +0100 Subject: [PATCH] Enable math characters also in tokens like i(z/z) by temporarily putting " around the token. Improve error message on missing vector --- src/frontend/parse.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/src/frontend/parse.c b/src/frontend/parse.c index 31e675c7a..867950aa2 100644 --- a/src/frontend/parse.c +++ b/src/frontend/parse.c @@ -102,7 +102,7 @@ struct pnode* ft_getpnames_quotes(wordlist* wl, bool check) { struct pnode* names = NULL, * tmpnode = NULL; char* sz = wl_flatten(wl); - if ((strstr(sz, "v(") || strstr(sz, "V(")) && !cp_getvar("noquotesinoutput", CP_BOOL, NULL, 0)) + if ((strstr(sz, "v(") || strstr(sz, "V(") || strstr(sz, "i(") || strstr(sz, "I(")) && !cp_getvar("noquotesinoutput", CP_BOOL, NULL, 0)) { char* tmpstr; char* nsz = tmpstr = stripWhiteSpacesInsideParens(sz); @@ -165,6 +165,36 @@ struct pnode* ft_getpnames_quotes(wordlist* wl, bool check) tfree(partoken1); tfree(partoken2); } + else if ((tmpstr[0] == 'i' || tmpstr[0] == 'I') && tmpstr[1] == '(' && tmpstr[2] != '\"' && + (nsz == tmpstr || isspace_c(tmpstr[-1]) || is_arith_char(tmpstr[-1]) || tmpstr[-1] == '.')) { + char* tmpstr2, *tmpstr3; + tmpstr3 = tmpstr; + tmpstr += 2; + /* get the complete zzz of i(zzz) */ + tmpstr2 = gettok_char(&tmpstr, ')', FALSE, FALSE); + /* missing final ) ?*/ + if (!tmpstr2) { + fprintf(stderr, "Error: closing ) is missing in %s,\n ignored\n", tmpstr3); + tmpstr = ++tmpstr3; + continue; + } + /* check if this is i(zzz) or v(xx,yy) */ + sadd(&ds1, "i("); + + bool hac = has_arith_char(tmpstr2); + if (is_all_digits(tmpstr2)) { + sadd(&ds1, tmpstr2); + } + else if (isdigit_c(*tmpstr2) || hac) { + cadd(&ds1, '\"'); + sadd(&ds1, tmpstr2); + cadd(&ds1, '\"'); + } + else + sadd(&ds1, tmpstr2); + + tfree(tmpstr2); + } cadd(&ds1, *tmpstr); tmpstr++; } @@ -175,7 +205,7 @@ struct pnode* ft_getpnames_quotes(wordlist* wl, bool check) tfree(nsz); /* restore the old node name after parsing */ for (tmpnode = names; tmpnode; tmpnode = tmpnode->pn_next) { - if (strstr(tmpnode->pn_name, "v(\"")) { + if (strstr(tmpnode->pn_name, "v(\"") || strstr(tmpnode->pn_name, "i(\"")) { char newstr[100]; char* tmp = tmpnode->pn_name; int ii = 0; @@ -454,8 +484,10 @@ struct pnode *PP_mkfnode(const char *func, struct pnode *arg) d = vec_get(buf); if (d == NULL) { /* Well, too bad. */ - fprintf(cp_err, "Error: no such function as %s.\n", + fprintf(cp_err, "\nError: no such function as %s,\n", func); + fprintf(cp_err, " or %s is not available.\n", + buf); return (struct pnode *) NULL; } /* (void) strcpy(buf, d->v_name); XXX */