bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 7/8] obstack_quote: escape and quote for M4


From: Akim Demaille
Subject: [PATCH 7/8] obstack_quote: escape and quote for M4
Date: Thu, 26 Jul 2012 12:44:21 +0200

* src/system.h (obstack_quote): New.
* src/muscle-tab.c: Use it instead of obstack_escape where applicable.
---
 src/muscle-tab.c | 18 +++++++++---------
 src/system.h     | 22 ++++++++++++++++++++++
 2 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/src/muscle-tab.c b/src/muscle-tab.c
index a498b15..5c62498 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/system.h b/src/system.h
index 0622459..cbfa876 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, output "[]" instead of "[[]]" as it make M4
+   programming easier (m4_ifval can be used).
+
+   For instance "[foo]" -> "address@hidden@}]]", "$$" -> "[[$][$][]]". */
+
+# define obstack_quote(Obs, Str)                \
+  do {                                          \
+    char const* obstack_quote_p = Str;          \
+    if (obstack_quote_p[0])                     \
+      {                                         \
+        obstack_sgrow (Obs, "[[");              \
+        obstack_escape (Obs, obstack_quote_p);  \
+        obstack_sgrow (Obs, "]]");              \
+      }                                         \
+    else                                        \
+      obstack_sgrow (Obs, "[]");                \
+  } while (0)
+
+
+
 
 
 /*-----------------------------------------.
-- 
1.7.11.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]