diff options
author | Ori Bernstein <ori@eigenstate.org> | 2020-04-26 09:32:42 -0700 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2020-04-26 09:32:42 -0700 |
commit | c6f7989176b9da3b977f397ac4f20bc2f86dec1b (patch) | |
tree | b75c585b86f8c11d9f8e5a9f83a153401f7cd91e /sys/src/cmd/cpp/macro.c | |
parent | 8ebe958ddf4b81df3ecf9b26c4333b2dca1cc987 (diff) |
copy all the tokens from the tokenrows with a paste.
if we do 'CAT(foo bar, baz quux)', the resulting token row
should have 3 tokens: 'foo', 'barbaz', 'quux'.
tested by jonasa, rebuilding /sys/src, perl, netsurf, and nuklear.
Diffstat (limited to 'sys/src/cmd/cpp/macro.c')
-rw-r--r-- | sys/src/cmd/cpp/macro.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/sys/src/cmd/cpp/macro.c b/sys/src/cmd/cpp/macro.c index 67af0bd0c..89516a77e 100644 --- a/sys/src/cmd/cpp/macro.c +++ b/sys/src/cmd/cpp/macro.c @@ -350,7 +350,7 @@ ispaste(Tokenrow *rtr, Token **ap, Token **an, int *ntok) void substargs(Nlist *np, Tokenrow *rtr, Tokenrow **atr) { - Tokenrow ttr; + Tokenrow ttr, rp, rn; Token *tp, *ap, *an, *pp, *pn; int ntok, argno, hs; @@ -369,19 +369,25 @@ substargs(Nlist *np, Tokenrow *rtr, Tokenrow **atr) insertrow(rtr, ntok, stringify(atr[argno])); } else if (ispaste(rtr, &ap, &an, &ntok)) { /* first token, just do the next one */ pp = ap; + memset(&rp, 0, sizeof(rp)); pn = an; + memset(&rn, 0, sizeof(rp)); if (ap && (argno = lookuparg(np, ap)) >= 0){ pp = nil; - if(atr[argno]->tp != atr[argno]->lp) - pp = atr[argno]->lp - 1; + rp = *atr[argno]; + if(rp.tp != rp.lp) + pp = --rp.lp; } if (an && (argno = lookuparg(np, an)) >= 0) { pn = nil; - if(atr[argno]->tp != atr[argno]->lp) - pn = atr[argno]->lp - 1; + rn = *atr[argno]; + if(rn.tp != rn.lp) + pn = rn.bp++; } glue(&ttr, pp, pn); + insertrow(rtr, 0, &rp); insertrow(rtr, ntok, &ttr); + insertrow(rtr, 0, &rn); free(ttr.bp); } else if (rtr->tp->type==NAME) { if((argno = lookuparg(np, rtr->tp)) >= 0) { |