From ddadb157cfa3e1658f120341b4085ec5421ff73f Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Sun, 7 Apr 2013 12:01:40 +0200 Subject: Strip unused template tags by default If there's a tag defined but not used on replace table processing, this option determines whether it should be written in the generated file or ignored completely. Turned on by default, this will save a few bytes. Use commandline option '--debug-dont-strip-unused-tags' to turn it off, e.g. when debugging template files. --- src/replace-table.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/replace-table.c') diff --git a/src/replace-table.c b/src/replace-table.c index 9c1b254..a36a83c 100644 --- a/src/replace-table.c +++ b/src/replace-table.c @@ -34,6 +34,7 @@ struct ReplaceTable { GHashTable *table; GHashTable *defines; GHashTable *functions; + gboolean strip_unused_tags; }; typedef struct { @@ -50,6 +51,7 @@ replace_table_new () table = g_new0 (ReplaceTable, 1); table->table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); table->functions = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + table->strip_unused_tags = TRUE; /* default */ return table; } @@ -65,6 +67,18 @@ replace_table_free (ReplaceTable *table) } +/* + * replace_table_set_strip_unused_tags: set whether all unused/unknown tags should be stripped (default = TRUE) + * + */ +void +replace_table_set_strip_unused_tags (ReplaceTable *table, gboolean value) +{ + g_return_if_fail (table != NULL); + + table->strip_unused_tags = value; +} + /* * replace_table_add_key: add tag/value pair to replace * @@ -345,7 +359,7 @@ replace_table_process (gchar **buffer, ReplaceTable *table) } /* push the tag if not matched above */ - if (! handled) + if (! handled && ! table->strip_unused_tags) g_string_append_len (dst, start, end - start + 1); g_free (token); -- cgit v1.2.3