In fact, it's a fairly simple patch. See attached for my stab at it. (Also, there's a more straightforward test input file.) I did the two-arg divert(), since that seems more natural than coming up with a new/separate builtin for this.
I think this fills a hole in the core m4 feature set---right now, as I understand it, the only way to send text to a diversion is at the point when the text is actually being written out. With this, you can send text to a diversion in the same way that errprint() sends text to stderr: immediately upon evaluation of the builtin. Without regard to the invoking context. --Daniel -- NAME = Daniel Richard G. ## Remember, skunks _\|/_ meef? EMAIL1 = [EMAIL PROTECTED] ## don't smell bad--- (/o|o\) / EMAIL2 = [EMAIL PROTECTED] ## it's the people who < (^),> WWW = http://www.******.org/ ## annoy them that do! / \ -- (****** = site not yet online)
Index: modules/m4.c =================================================================== RCS file: /sources/m4/m4/modules/m4.c,v retrieving revision 1.106 diff -u -r1.106 m4.c --- modules/m4.c 3 Apr 2007 21:06:16 -0000 1.106 +++ modules/m4.c 21 May 2007 06:18:07 -0000 @@ -70,7 +70,7 @@ BUILTIN (decr, false, true, true, 1, 1 ) \ BUILTIN (define, true, true, false, 1, 2 ) \ BUILTIN (defn, false, true, false, 1, -1 ) \ - BUILTIN (divert, false, false, false, 0, 1 ) \ + BUILTIN (divert, false, false, false, 0, 2 ) \ BUILTIN (divnum, false, false, false, 0, 0 ) \ BUILTIN (dnl, false, false, false, 0, 0 ) \ BUILTIN (dumpdef, false, false, false, 0, -1 ) \ @@ -587,11 +587,24 @@ M4BUILTIN_HANDLER (divert) { int i = 0; + int prevdiv; + const char *text; if (argc >= 2 && !m4_numeric_arg (context, argc, argv, 1, &i)) return; + prevdiv = m4_get_current_diversion (context); + m4_make_diversion (context, i); + + if (argc == 2) + return; + + text = M4ARG (2); + + m4_shipout_text (context, NULL, text, strlen (text)); + + m4_make_diversion (context, prevdiv); } /* Expand to the current diversion number. */
define(`p', `<P>$1</P>')dnl dnl Mark 1 foo1 divert(10)<bar1>divert(0) qux1 Mark 2 p(`foo2 divert(10)<bar2>divert(0) qux2') Mark 3 p(foo3 divert(10)<bar3>divert(0) qux3) Mark 4 p(foo4 divert(10, <bar4>) qux4) Mark 5 p(foo5 divert(10, `p(bar5)') qux5) End of input
_______________________________________________ M4-discuss mailing list M4-discuss@gnu.org http://lists.gnu.org/mailman/listinfo/m4-discuss