From 13b712d7d492da45303f20502adcf6a8c5a7afa2 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Thu, 26 Jul 2012 11:19:18 +0200 Subject: [PATCH] obstack_escape: escape M4 characters * src/muscle-tab.h (MUSCLE_OBSTACK_SGROW): This is not related to muscles, so move to, and rename as... * src/system.h (obstack_escape): this. Adjust dependencies. --- src/muscle-tab.c | 10 +++++----- src/muscle-tab.h | 21 +++------------------ src/output.c | 2 +- src/system.h | 21 +++++++++++++++++++++ 4 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/muscle-tab.c b/src/muscle-tab.c index 199049b5..ce6ac252 100644 --- a/src/muscle-tab.c +++ b/src/muscle-tab.c @@ -178,8 +178,8 @@ muscle_syncline_grow (char const *key, location loc) { char *extension = NULL; obstack_fgrow1 (&muscle_obstack, "]b4_syncline(%d, [[", loc.start.line); - MUSCLE_OBSTACK_SGROW (&muscle_obstack, - quotearg_style (c_quoting_style, loc.start.file)); + obstack_escape (&muscle_obstack, + quotearg_style (c_quoting_style, loc.start.file)); obstack_sgrow (&muscle_obstack, "]])["); obstack_1grow (&muscle_obstack, 0); extension = obstack_finish (&muscle_obstack); @@ -206,9 +206,9 @@ void muscle_pair_list_grow (const char *muscle, { char *pair; obstack_sgrow (&muscle_obstack, "[[["); - MUSCLE_OBSTACK_SGROW (&muscle_obstack, a1); + obstack_escape (&muscle_obstack, a1); obstack_sgrow (&muscle_obstack, "]], [["); - MUSCLE_OBSTACK_SGROW (&muscle_obstack, a2); + obstack_escape (&muscle_obstack, a2); obstack_sgrow (&muscle_obstack, "]]]"); obstack_1grow (&muscle_obstack, 0); pair = obstack_finish (&muscle_obstack); @@ -263,7 +263,7 @@ void muscle_boundary_grow (char const *key, boundary bound) { char *extension; - MUSCLE_OBSTACK_SGROW (&muscle_obstack, bound.file); + obstack_escape (&muscle_obstack, bound.file); obstack_1grow (&muscle_obstack, ':'); obstack_fgrow1 (&muscle_obstack, "%d", bound.line); obstack_1grow (&muscle_obstack, '.'); diff --git a/src/muscle-tab.h b/src/muscle-tab.h index 6c658be6..b8438218 100644 --- a/src/muscle-tab.h +++ b/src/muscle-tab.h @@ -64,30 +64,15 @@ extern struct obstack muscle_obstack; #define MUSCLE_INSERT_STRING(Key, Value) \ do { \ - MUSCLE_OBSTACK_SGROW (&muscle_obstack, Value); \ + obstack_escape (&muscle_obstack, Value); \ obstack_1grow (&muscle_obstack, 0); \ muscle_insert (Key, obstack_finish (&muscle_obstack)); \ } while (0) -#define MUSCLE_OBSTACK_SGROW(Obstack, Value) \ - do { \ - char const *p; \ - for (p = Value; *p; p++) \ - switch (*p) \ - { \ - case '$': obstack_sgrow (Obstack, "$]["); break; \ - case '@': obstack_sgrow (Obstack, "@@" ); break; \ - case '[': obstack_sgrow (Obstack, "@{" ); break; \ - case ']': obstack_sgrow (Obstack, "@}" ); break; \ - default: obstack_1grow (Obstack, *p); break; \ - } \ - } while (0) - #define MUSCLE_INSERT_C_STRING(Key, Value) \ do { \ - MUSCLE_OBSTACK_SGROW (&muscle_obstack, \ - quotearg_style (c_quoting_style, \ - Value)); \ + obstack_escape (&muscle_obstack, \ + quotearg_style (c_quoting_style, Value)); \ obstack_1grow (&muscle_obstack, 0); \ muscle_insert (Key, obstack_finish (&muscle_obstack)); \ } while (0) diff --git a/src/output.c b/src/output.c index 29e9ba84..e157460d 100644 --- a/src/output.c +++ b/src/output.c @@ -175,7 +175,7 @@ prepare_symbols (void) if (i) obstack_1grow (&format_obstack, ' '); - MUSCLE_OBSTACK_SGROW (&format_obstack, cp); + obstack_escape (&format_obstack, cp); free (cp); obstack_1grow (&format_obstack, ','); j += width; diff --git a/src/system.h b/src/system.h index 944907ec..06224596 100644 --- a/src/system.h +++ b/src/system.h @@ -192,6 +192,27 @@ typedef size_t uintptr_t; } while (0) +/* Output Str escaped for our postprocessing (i.e., escape M4 special + characters). + + 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) + + + /*-----------------------------------------. | Extensions to use for the output files. | -- 2.45.2