]> git.saurik.com Git - bison.git/commitdiff
obstack_escape: escape M4 characters
authorAkim Demaille <akim@lrde.epita.fr>
Thu, 26 Jul 2012 09:19:18 +0000 (11:19 +0200)
committerAkim Demaille <akim@lrde.epita.fr>
Thu, 26 Jul 2012 10:30:02 +0000 (12:30 +0200)
* 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
src/muscle-tab.h
src/output.c
src/system.h

index 199049b5bd2276488c606916acfe0de603653bc4..ce6ac2523f933520707fbfe1b12b466c37477124 100644 (file)
@@ -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);
 {
   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);
   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, "[[[");
 {
   char *pair;
   obstack_sgrow (&muscle_obstack, "[[[");
-  MUSCLE_OBSTACK_SGROW (&muscle_obstack, a1);
+  obstack_escape (&muscle_obstack, a1);
   obstack_sgrow (&muscle_obstack, "]], [[");
   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);
   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_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, '.');
   obstack_1grow (&muscle_obstack, ':');
   obstack_fgrow1 (&muscle_obstack, "%d", bound.line);
   obstack_1grow (&muscle_obstack, '.');
index 6c658be6cc3f132433a2013f2ba5b6139a597dec..b84382187fbee866f47e38f64ffc48ee05b4008f 100644 (file)
@@ -64,30 +64,15 @@ extern struct obstack muscle_obstack;
 
 #define MUSCLE_INSERT_STRING(Key, Value)                        \
   do {                                                          \
 
 #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)
 
     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 {                                                          \
 #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)
     obstack_1grow (&muscle_obstack, 0);                         \
     muscle_insert (Key, obstack_finish (&muscle_obstack));      \
   } while (0)
index 29e9ba841c16c1933ae4d5903ddb31512aa93fc8..e157460d0863be63828f601f7ba9968733776ab9 100644 (file)
@@ -175,7 +175,7 @@ prepare_symbols (void)
 
        if (i)
          obstack_1grow (&format_obstack, ' ');
 
        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;
         free (cp);
        obstack_1grow (&format_obstack, ',');
        j += width;
index 944907ec7365664b41d1970ebdccdc43f908446f..06224596b283af564c85167142886184a65f5091 100644 (file)
@@ -192,6 +192,27 @@ typedef size_t uintptr_t;
   } while (0)
 
 
   } 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.  |
 
 /*-----------------------------------------.
 | Extensions to use for the output files.  |