obstack_quote: escape and quote for M4

* src/system.h (obstack_quote): New.
* src/muscle-tab.c: Use it instead of obstack_escape where applicable.
* src/scan-code.l: Since obstack_quote supports NULL, leave type_name
as NULL instead of defaulting to "".
This commit is contained in:
Akim Demaille
2012-07-26 12:12:38 +02:00
parent eea7239a23
commit 0601c3bf0f
3 changed files with 31 additions and 11 deletions

View File

@@ -177,10 +177,10 @@ static void
muscle_syncline_grow (char const *key, location loc)
{
char *extension = NULL;
obstack_fgrow1 (&muscle_obstack, "]b4_syncline(%d, [[", loc.start.line);
obstack_escape (&muscle_obstack,
quotearg_style (c_quoting_style, loc.start.file));
obstack_sgrow (&muscle_obstack, "]])[");
obstack_fgrow1 (&muscle_obstack, "]b4_syncline(%d, ", loc.start.line);
obstack_quote (&muscle_obstack,
quotearg_style (c_quoting_style, loc.start.file));
obstack_sgrow (&muscle_obstack, ")[");
obstack_1grow (&muscle_obstack, 0);
extension = obstack_finish (&muscle_obstack);
muscle_grow (key, extension, "");
@@ -205,11 +205,11 @@ void muscle_pair_list_grow (const char *muscle,
const char *a1, const char *a2)
{
char *pair;
obstack_sgrow (&muscle_obstack, "[[[");
obstack_escape (&muscle_obstack, a1);
obstack_sgrow (&muscle_obstack, "]], [[");
obstack_escape (&muscle_obstack, a2);
obstack_sgrow (&muscle_obstack, "]]]");
obstack_sgrow (&muscle_obstack, "[");
obstack_quote (&muscle_obstack, a1);
obstack_sgrow (&muscle_obstack, ", ");
obstack_quote (&muscle_obstack, a2);
obstack_sgrow (&muscle_obstack, "]");
obstack_1grow (&muscle_obstack, 0);
pair = obstack_finish (&muscle_obstack);
muscle_grow (muscle, pair, ",\n");

View File

@@ -762,7 +762,6 @@ handle_action_dollar (symbol_list *rule, char *text, location dollar_loc)
}
else
untyped_var_seen = true;
type_name = "";
}
obstack_fgrow1 (&obstack_for_string,
@@ -783,7 +782,6 @@ handle_action_dollar (symbol_list *rule, char *text, location dollar_loc)
cp, quote (effective_rule->content.sym->tag));
else
untyped_var_seen = true;
type_name = "";
}
obstack_fgrow3 (&obstack_for_string,

View File

@@ -212,6 +212,28 @@ typedef size_t uintptr_t;
} while (0)
/* Output Str both quoted for M4 (i.e., embed in [[...]]), and escaped
for our postprocessing (i.e., escape M4 special characters). If
Str is empty (or NULL), output "[]" instead of "[[]]" as it make M4
programming easier (m4_ifval can be used).
For instance "[foo]" -> "[[@{foo@}]]", "$$" -> "[[$][$][]]". */
# define obstack_quote(Obs, Str) \
do { \
char const* obstack_quote_p = Str; \
if (obstack_quote_p && obstack_quote_p[0]) \
{ \
obstack_sgrow (Obs, "[["); \
obstack_escape (Obs, obstack_quote_p); \
obstack_sgrow (Obs, "]]"); \
} \
else \
obstack_sgrow (Obs, "[]"); \
} while (0)
/*-----------------------------------------.