summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/flex-scanner.h3
-rw-r--r--src/output.c27
-rw-r--r--src/scan-code.l3
-rw-r--r--src/system.h59
4 files changed, 76 insertions, 16 deletions
diff --git a/src/flex-scanner.h b/src/flex-scanner.h
index 238ca881..08c0e62c 100644
--- a/src/flex-scanner.h
+++ b/src/flex-scanner.h
@@ -106,6 +106,9 @@ static struct obstack obstack_for_string;
# define STRING_GROW() \
obstack_grow (&obstack_for_string, yytext, yyleng)
+# define STRING_SGROW(String) \
+ obstack_sgrow (&obstack_for_string, String)
+
# define STRING_FINISH() \
(last_string = obstack_finish0 (&obstack_for_string))
diff --git a/src/output.c b/src/output.c
index 4b1bb0d8..07234f2a 100644
--- a/src/output.c
+++ b/src/output.c
@@ -104,20 +104,45 @@ GENERATE_MUSCLE_INSERT_TABLE (muscle_insert_symbol_number_table, symbol_number)
GENERATE_MUSCLE_INSERT_TABLE (muscle_insert_item_number_table, item_number)
GENERATE_MUSCLE_INSERT_TABLE (muscle_insert_state_number_table, state_number)
+
/*----------------------------------------------------------------.
| Print to OUT a representation of CP quoted and escaped for M4. |
+| |
+| Keep sync'ed with obstack_escape. |
`----------------------------------------------------------------*/
static void
output_escaped (FILE *out, const char *cp)
{
- for (; *cp; cp++)
+ for (; *cp; ++cp)
switch (*cp)
{
case '$': fputs ("$][", out); break;
case '@': fputs ("@@", out); break;
case '[': fputs ("@{", out); break;
case ']': fputs ("@}", out); break;
+
+ case 'b':
+ if (STRPREFIX_LIT ("b4_", cp))
+ {
+ fputs ("b4@'_", out);
+ cp += strlen ("b4_") - 1;
+ break;
+ }
+ else
+ goto append;
+
+ case 'm':
+ if (STRPREFIX_LIT ("m4_", cp))
+ {
+ fputs ("m4@'_", out);
+ cp += strlen ("m4_") - 1;
+ break;
+ }
+ else
+ goto append;
+
+ append:
default: fputc (*cp, out); break;
}
}
diff --git a/src/scan-code.l b/src/scan-code.l
index fced37d2..e3e765c8 100644
--- a/src/scan-code.l
+++ b/src/scan-code.l
@@ -197,6 +197,9 @@ ref -?[0-9]+|{id}|"["{id}"]"|"$"
<*>
{
+ "b4_" STRING_SGROW ("b4@'_");
+ "m4_" STRING_SGROW ("m4@'_");
+
/* Escape M4 quoting characters in C code. */
[$@\[\]] obstack_escape (&obstack_for_string, yytext);
diff --git a/src/system.h b/src/system.h
index bbdf9fd0..630ef646 100644
--- a/src/system.h
+++ b/src/system.h
@@ -204,24 +204,53 @@ max_int (int a, int b)
} while (0)
-/* Output Str escaped for our postprocessing (i.e., escape M4 special
+/* Output CP escaped for our postprocessing (i.e., escape M4 special
characters).
- For instance "[foo]" -> "@{foo@}", "$$" -> "$][$][". */
+ For instance "[foo]" -> "@{foo@}", "$$" -> "$][$][".
-# define obstack_escape(Obs, Str) \
- do { \
- char const *p__; \
- for (p__ = Str; *p__; p__++) \
- switch (*p__) \
- { \
- case '$': obstack_sgrow (Obs, "$]["); break; \
- case '@': obstack_sgrow (Obs, "@@" ); break; \
- case '[': obstack_sgrow (Obs, "@{" ); break; \
- case ']': obstack_sgrow (Obs, "@}" ); break; \
- default: obstack_1grow (Obs, *p__ ); break; \
- } \
- } while (0)
+ All the user's input passed to m4 is processed by this function or
+ by output_escaped, except user actions. Because of the specific
+ handling of @$, @1, etc., user actions are processed (and escaped)
+ by scan-code.l.
+
+ Keep output_escaped and obstack_escape sync'ed.
+ */
+
+static inline void
+obstack_escape (struct obstack* obs, const char *cp)
+{
+ for (; *cp; ++cp)
+ switch (*cp)
+ {
+ case '$': obstack_sgrow (obs, "$]["); break;
+ case '@': obstack_sgrow (obs, "@@" ); break;
+ case '[': obstack_sgrow (obs, "@{" ); break;
+ case ']': obstack_sgrow (obs, "@}" ); break;
+ case 'b':
+ if (STRPREFIX_LIT ("b4_", cp))
+ {
+ obstack_sgrow (obs, "b4@'_");
+ cp += strlen ("b4_") - 1;
+ break;
+ }
+ else
+ goto append;
+
+ case 'm':
+ if (STRPREFIX_LIT ("m4_", cp))
+ {
+ obstack_sgrow (obs, "m4@'_");
+ cp += strlen ("m4_") - 1;
+ break;
+ }
+ else
+ goto append;
+
+ append:
+ default: obstack_1grow (obs, *cp); break;
+ }
+}
/* Output Str both quoted for M4 (i.e., embed in [[...]]), and escaped