From 0601c3bf0f4dda2617ff90a3d419a4e0e387c0b1 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Thu, 26 Jul 2012 12:12:38 +0200 Subject: [PATCH] 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 "". --- src/muscle-tab.c | 18 +++++++++--------- src/scan-code.l | 2 -- src/system.h | 22 ++++++++++++++++++++++ 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/muscle-tab.c b/src/muscle-tab.c index a498b15b..5c624982 100644 --- a/src/muscle-tab.c +++ b/src/muscle-tab.c @@ -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"); diff --git a/src/scan-code.l b/src/scan-code.l index 785f386d..bc2cd580 100644 --- a/src/scan-code.l +++ b/src/scan-code.l @@ -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, diff --git a/src/system.h b/src/system.h index 06224596..06fd0f0a 100644 --- a/src/system.h +++ b/src/system.h @@ -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) + + + /*-----------------------------------------. -- 2.45.2