[Top][All Lists]
[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
- [PATCH 0/8] {maint} Properly escape type names, Akim Demaille, 2012/07/26
- [PATCH 2/8] remove dead macro, Akim Demaille, 2012/07/26
- [PATCH 5/8] muscles: make private functions static, Akim Demaille, 2012/07/26
- [PATCH 3/8] obstack_escape: escape M4 characters, Akim Demaille, 2012/07/26
- [PATCH 1/8] maint: style changes, Akim Demaille, 2012/07/26
- [PATCH 4/8] muscles: rename private functions/macros, Akim Demaille, 2012/07/26
- [PATCH 6/8] muscles: shuffle responsabilities, Akim Demaille, 2012/07/26
- [PATCH 7/8] obstack_quote: escape and quote for M4,
Akim Demaille <=
- [PATCH 8/8] be sure to properly escape type names, Akim Demaille, 2012/07/26