From a05d36f970a5c4723d2be3945076bce9347143ec Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Mon, 19 Sep 2016 23:23:30 +0200 Subject: block-parser: Clear processed data for further use This change will allow certain blocks to be present multiple times and processed independently within a single page. --- src/block-parser.c | 20 ++++++++++++++++++++ src/block-parser.h | 6 ++++++ src/generators.c | 14 +++++++++++--- 3 files changed, 37 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/block-parser.c b/src/block-parser.c index 48c7671..f4ed78b 100644 --- a/src/block-parser.c +++ b/src/block-parser.c @@ -220,6 +220,26 @@ block_parser_set_as_used (BlockParser *parser, const gchar *key) } } +/* + * block_parser_clear_key_data: clear stored data block for the key + * + */ +void +block_parser_clear_key_data (BlockParser *parser, const gchar *key) +{ + BlockData *data = NULL; + + g_assert (parser != NULL); + + data = g_hash_table_lookup (parser->table, key); + if (data != NULL) { + g_free (data->data); + data->data = NULL; + data->used = FALSE; + data->finished = FALSE; + } +} + /* -------------------------------------------------------------------------------------------------------- */ diff --git a/src/block-parser.h b/src/block-parser.h index 5d8b69c..c5a1d9e 100644 --- a/src/block-parser.h +++ b/src/block-parser.h @@ -77,6 +77,12 @@ gboolean block_parser_has_unused_data (BlockParser *parser, const gchar *key); */ void block_parser_set_as_used (BlockParser *parser, const gchar *key); +/* + * block_parser_clear_key_data: clear stored data block for the key + * + */ +void block_parser_clear_key_data (BlockParser *parser, const gchar *key); + /* * block_parser_process: parse input data * - if there's a multiline block, string before the opening placeholder and diff --git a/src/generators.c b/src/generators.c index b9df04c..4648f49 100644 --- a/src/generators.c +++ b/src/generators.c @@ -1199,8 +1199,11 @@ write_html_page (TGallerySetup *setup, replace_table_process (&s1, global_replace_table); replace_table_add_key (global_replace_table, "IMG_LIST", s1); g_free (s1); - /* We don't use data from this key directly, let's mark it as used since we've built the structure we needed. */ - block_parser_set_as_used (block_parser, "IMG_LIST"); + /* Clear processed nested keys for further use */ + block_parser_clear_key_data (block_parser, "IMG_LIST"); + block_parser_clear_key_data (block_parser, "LIST_PICTURE"); + block_parser_clear_key_data (block_parser, "LIST_SEPARATOR"); + block_parser_clear_key_data (block_parser, "LIST_INTERSPACE"); } if (block_parser_has_unused_data (block_parser, "NAV_BAR")) { @@ -1210,7 +1213,12 @@ write_html_page (TGallerySetup *setup, replace_table_process (&s1, global_replace_table); replace_table_add_key (global_replace_table, "NAV_BAR", s1); g_free (s1); - block_parser_set_as_used (block_parser, "NAV_BAR"); + block_parser_clear_key_data (block_parser, "NAV_BAR"); + block_parser_clear_key_data (block_parser, "NAV_BAR_FIRST"); + block_parser_clear_key_data (block_parser, "NAV_BAR_ELEM"); + block_parser_clear_key_data (block_parser, "NAV_BAR_LAST"); + block_parser_clear_key_data (block_parser, "NAV_BAR_CURRENT"); + block_parser_clear_key_data (block_parser, "NAV_BAR_CURRENT_ROOT"); } /* Replace all known tags */ -- cgit v1.2.3