]> git.saurik.com Git - bison.git/blobdiff - src/system.h
obstack_escape: escape M4 characters
[bison.git] / src / system.h
index 944907ec7365664b41d1970ebdccdc43f908446f..06224596b283af564c85167142886184a65f5091 100644 (file)
@@ -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.  |