summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorMark Lumsden <lum@cvs.openbsd.org>2019-07-19 16:00:09 +0000
committerMark Lumsden <lum@cvs.openbsd.org>2019-07-19 16:00:09 +0000
commit6c458a4a0e04b74ff9c7949cbe22437633a60a0a (patch)
treead0153ed64111239dd05a4fecc93b3a12ae6a650 /usr.bin
parent7523509ffb478ceed42273a0f83b5b2f489215b7 (diff)
Previously I left the ')' on the end of a list to indicate the end.
Just to get things working. Best get rid of that nonsense sooner rather than later.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/mg/interpreter.c38
1 files changed, 24 insertions, 14 deletions
diff --git a/usr.bin/mg/interpreter.c b/usr.bin/mg/interpreter.c
index 82e79f7b83a..b5309361077 100644
--- a/usr.bin/mg/interpreter.c
+++ b/usr.bin/mg/interpreter.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: interpreter.c,v 1.2 2019/07/18 10:50:24 lum Exp $ */
+/* $OpenBSD: interpreter.c,v 1.3 2019/07/19 16:00:08 lum Exp $ */
/*
* This file is in the public domain.
*
@@ -81,7 +81,7 @@ multiarg(char *funstr)
char excbuf[BUFSIZE], argbuf[BUFSIZE], *contbuf, tmpbuf[BUFSIZE];
char *cmdp, *argp, *fendp, *endp, *p, *t, *s = " ";
int singlecmd = 0, spc, numparams, numspc;
- int inlist, foundlst = 0, last, sizof;
+ int inlist, foundlst = 0, eolst, rpar, sizof, fin;
contbuf = NULL;
endp = strrchr(funstr, ')');
@@ -144,25 +144,29 @@ multiarg(char *funstr)
return (dobeep_msg("strlcpy error"));
argp = argbuf;
numspc = spc = 1; /* initially fake a space so we find first argument */
- inlist = last = 0;
+ inlist = eolst = fin = rpar = 0;
- for (p = argp; *p != '\0'; p++) {
+ for (p = argp; fin == 0; p++) {
#ifdef MGLOG
- mglog_execbuf("", excbuf, argbuf, argp, last, inlist, cmdp,
+ mglog_execbuf("", excbuf, argbuf, argp, eolst, inlist, cmdp,
p, contbuf);
#endif
if (foundlst) {
foundlst = 0;
p--; /* otherwise 1st arg is missed from list. */
}
- if (*p == ' ' || *p == '\t' || *p == ')') {
+ if (*p == ')') {
+ rpar = 1;
+ *p = '\0';
+ }
+ if (*p == ' ' || *p == '\t' || *p == '\0') {
if (spc == 1)
continue;
if (spc == 0 && (numspc % numparams == 0)) {
- if (*p == ')')
- last = 1;
+ if (*p == '\0')
+ eolst = 1;
else
- last = 0;
+ eolst = 0;
*p = '\0'; /* terminate arg string */
endp = p + 1;
excbuf[0] = '\0';
@@ -196,10 +200,10 @@ multiarg(char *funstr)
excline(excbuf);
#ifdef MGLOG
mglog_execbuf(" ", excbuf, argbuf, argp,
- last, inlist, cmdp, p, contbuf);
+ eolst, inlist, cmdp, p, contbuf);
#endif
*p = ' '; /* so 'for' loop can continue */
- if (last) {
+ if (eolst) {
if (contbuf != NULL) {
(void)strlcpy(argbuf, contbuf,
sizeof(argbuf));
@@ -207,11 +211,15 @@ multiarg(char *funstr)
p = argp = argbuf;
foundlst = 1;
inlist = 0;
+ if (rpar)
+ fin = 1;
continue;
}
spc = 1;
inlist = 0;
}
+ if (eolst && rpar)
+ fin = 1;
}
numspc++;
spc = 1;
@@ -260,7 +268,7 @@ foundlist(char *defstr)
{
struct varentry *vt, *v1 = NULL;
const char e[1] = "e", t[1] = "t";
- char *p, *vnamep, *vendp = NULL, *valp;
+ char *p, *vnamep, *vendp = NULL, *valp, *o;
int spc;
@@ -307,7 +315,7 @@ foundlist(char *defstr)
return(dobeep_msg("strndup error"));
v1->count = 0;
vendp = NULL;
-
+
/* initially fake a space so we find first value */
spc = 1;
/* now loop through values in list value string while counting them */
@@ -317,7 +325,9 @@ foundlist(char *defstr)
vendp = p;
spc = 1;
} else if (*p == ')') {
- vendp = ++p; /* currently need ')' */
+ o = p - 1;
+ if (*o != ' ' && *o != '\t')
+ vendp = p;
break;
} else {
if (spc == 1)