On Wed, Jun 08, 2022 at 09:44:19PM +0200, Marc Espie wrote: > Naddy told me about an app that wants a gnu-m4 extension that > requires >9 arguments to macros. > > I wrote a very quick patch that seems to do the work. There are probably > lots of kinks to work out, it's been very lightly tested. > (in particular, I haven't looked at stuff like $* and friends yet, maybe > they work, maybe they won't) > > But if anyone requires this type of functionality, I'd like them to chime > in. > > > Index: eval.c > =================================================================== > RCS file: /cvs/src/usr.bin/m4/eval.c,v > retrieving revision 1.78 > diff -u -p -r1.78 eval.c > --- eval.c 28 Jun 2019 05:35:34 -0000 1.78 > +++ eval.c 8 Jun 2022 13:03:29 -0000 > @@ -40,6 +40,7 @@ > */ > > #include <sys/types.h> > +#include <ctype.h> > #include <err.h> > #include <errno.h> > #include <limits.h> > @@ -542,6 +543,21 @@ expand_macro(const char *argv[], int arg > p++; > p--; /* last character of defn */ > while (p > t) { > + if (mimic_gnu && isdigit(*p)) { > + const char *pos = p; > + int mult = 1; > + argno = 0; > + while (isdigit(*pos) && pos > t) { > + argno += mult * (*pos - '0'); > + mult *= 10; > + pos--; > + } > + if (*pos == ARGFLAG && argno < argc -1) { > + pbstr(argv[argno + 1]); > + p = pos-1; > + continue; > + } > + } > if (*(p - 1) != ARGFLAG) > PUSHBACK(*p); > else { > >
That code appears to work just fine and we even have a trivial regress test. In the mean time, naddy@ tells me that the port in question moved away from using that specific gnu-m4 extension. On one side, that code is 100% self-contained and safe for non gnu-m4 compat mode. And it went through a full bulk build without any issue. On the other side, I don't know if some other stuff might rely on it eventually. Among other things it is quite possible someone wrote an autoconf macro somewhere that actually requires over 9 parameters. So the question is: do I shelve it, or commit it ? I don't really care all that much either way, I would just love to close the subject.