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 {

Reply via email to