[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Changes to m4/m4/output.c,v
From: |
Eric Blake |
Subject: |
Changes to m4/m4/output.c,v |
Date: |
Mon, 28 May 2007 21:48:44 +0000 |
CVSROOT: /sources/m4
Module name: m4
Changes by: Eric Blake <ericb> 07/05/28 21:48:42
Index: m4/output.c
===================================================================
RCS file: /sources/m4/m4/m4/output.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -b -r1.43 -r1.44
--- m4/output.c 28 May 2007 20:10:01 -0000 1.43
+++ m4/output.c 28 May 2007 21:48:41 -0000 1.44
@@ -418,8 +418,8 @@
/* Output one TEXT having LENGTH characters, when it is known that it goes
to a diversion file or an in-memory diversion buffer. */
-static void
-output_text (m4 *context, const char *text, size_t length)
+void
+m4_output_text (m4 *context, const char *text, size_t length)
{
size_t count;
@@ -441,20 +441,23 @@
}
/* Add some text into an obstack OBS, taken from TEXT, having LENGTH
- characters. If OBS is NULL, rather output the text to an external file
- or an in-memory diversion buffer. If OBS is NULL, and there is no
- output file, the text is discarded.
-
- If we are generating sync lines, the output have to be examined, because
- we need to know how much output each input line generates. In general,
- sync lines are output whenever a single input lines generates several
- output lines, or when several input lines does not generate any output. */
+ characters. If OBS is NULL, output the text to an external file or
+ an in-memory diversion buffer instead. If OBS is NULL, and there
+ is no output file, the text is discarded. LINE is the line where
+ the token starts (not necessarily m4_get_output_line, in the case
+ of multiline tokens).
+
+ If we are generating sync lines, the output has to be examined,
+ because we need to know how much output each input line generates.
+ In general, sync lines are output whenever a single input line
+ generates several output lines, or when several input lines do not
+ generate any output. */
void
m4_shipout_text (m4 *context, m4_obstack *obs,
- const char *text, size_t length)
+ const char *text, size_t length, int line)
{
static bool start_of_output_line = true;
- char line[20];
+ char linebuf[20];
const char *cursor;
/* If output goes to an obstack, merely add TEXT to it. */
@@ -492,18 +495,21 @@
/* Optimize longer texts. */
default:
- output_text (context, text, length);
+ m4_output_text (context, text, length);
}
else
- for (; length-- > 0; text++)
{
+ /* Check for syncline only at the start of a token. Multiline
+ tokens, and tokens that are out of sync but in the middle of
+ the line, must wait until the next raw newline triggers a
+ syncline. */
if (start_of_output_line)
{
start_of_output_line = false;
m4_set_output_line (context, m4_get_output_line (context) + 1);
#ifdef DEBUG_OUTPUT
- fprintf (stderr, "DEBUG: cur %lu, cur out %lu\n",
+ fprintf (stderr, "DEBUG: line %d, cur %lu, cur out %lu\n", line,
(unsigned long int) m4_get_current_line (context),
(unsigned long int) m4_get_output_line (context));
#endif
@@ -512,11 +518,11 @@
If output_line was previously given a negative
value (invalidated), then output `#line NUM "FILE"'. */
- if (m4_get_output_line (context) != m4_get_current_line (context))
+ if (m4_get_output_line (context) != line)
{
- sprintf (line, "#line %lu",
+ sprintf (linebuf, "#line %lu",
(unsigned long int) m4_get_current_line (context));
- for (cursor = line; *cursor; cursor++)
+ for (cursor = linebuf; *cursor; cursor++)
OUTPUT_CHARACTER (*cursor);
if (m4_get_output_line (context) < 1
&& m4_get_current_file (context)[0] != '\0')
@@ -531,13 +537,29 @@
OUTPUT_CHARACTER ('"');
}
OUTPUT_CHARACTER ('\n');
- m4_set_output_line (context, m4_get_current_line (context));
+ m4_set_output_line (context, line);
}
}
+
+ /* Output the token, and track embedded newlines. */
+ for (; length-- > 0; text++)
+ {
+ if (start_of_output_line)
+ {
+ start_of_output_line = false;
+ m4_set_output_line (context, m4_get_output_line (context) + 1);
+
+#ifdef DEBUG_OUTPUT
+ fprintf (stderr, "DEBUG: line %d, cur %lu, cur out %lu\n", line,
+ (unsigned long int) m4_get_current_line (context),
+ (unsigned long int) m4_get_output_line (context));
+#endif
+ }
OUTPUT_CHARACTER (*text);
if (*text == '\n')
start_of_output_line = true;
}
+ }
}
/* Format an int VAL, and stuff it into an obstack OBS. Used for
@@ -697,7 +719,7 @@
m4_error (context, EXIT_FAILURE, errno, _("reading inserted file"));
if (length == 0)
break;
- output_text (context, buffer, length);
+ m4_output_text (context, buffer, length);
}
}
@@ -714,7 +736,7 @@
if (output_diversion)
{
if (diversion->size)
- output_text (context, diversion->u.buffer, diversion->used);
+ m4_output_text (context, diversion->u.buffer, diversion->used);
else
{
assert (diversion->used);