From 84d9c637087ba1f2fd5dcaa7a74d61aa15848832 Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Sun, 10 Feb 2013 18:03:39 +0100 Subject: block-parser: Don't process conditionals when retrieving block data This allows us to retrieve unmodified block data that could be used for conditional processing later. --- src/block-parser.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/block-parser.c b/src/block-parser.c index ff40ed0..ab679df 100644 --- a/src/block-parser.c +++ b/src/block-parser.c @@ -271,6 +271,22 @@ check_conditional_tree_for_token (const gchar *token, BlockData *data) return ret; } +/* returns TRUE when the parser is in block retrieval state (i.e. between BEGIN_xxx and END_xxx tags) */ +static gboolean +in_block_retrieval (BlockParser *parser) +{ + BlockData *data; + + if (parser->active_tree == NULL) + return FALSE; + + data = g_queue_peek_head (parser->active_tree); + if (data != NULL && ! data->is_conditional) + return TRUE; + + return FALSE; +} + /* * block_parser_read_and_parse: reads input from the file and returns parsed line * - if there's a multiline block, string before the opening placeholder and @@ -317,8 +333,8 @@ block_parser_read_and_parse (BlockParser *parser, FILE *stream) g_free (s); /* match conditionals */ - if ((parser->conditionals && (token_has_prefix (token, "ifdef") || token_has_prefix (token, "ifndef"))) || - token_has_prefix (token, "if")) + if (!in_block_retrieval (parser) && ((parser->conditionals && (token_has_prefix (token, "ifdef") || token_has_prefix (token, "ifndef"))) || + token_has_prefix (token, "if"))) { data = g_new0 (BlockData, 1); data->is_conditional = TRUE; @@ -354,7 +370,7 @@ block_parser_read_and_parse (BlockParser *parser, FILE *stream) handled = TRUE; } - if (parser->conditionals && token_has_prefix (token, "endif")) { + if (parser->conditionals && !in_block_retrieval (parser) && token_has_prefix (token, "endif")) { s = extract_token_arg (token); data = g_queue_peek_head (parser->active_tree); if (! check_conditional_tree_for_token (s, data)) { @@ -370,7 +386,7 @@ block_parser_read_and_parse (BlockParser *parser, FILE *stream) g_free (s); } - if (parser->conditionals && token_has_prefix (token, "else")) { + if (parser->conditionals && !in_block_retrieval (parser) && token_has_prefix (token, "else")) { s = extract_token_arg (token); data = g_queue_peek_head (parser->active_tree); if (! check_conditional_tree_for_token (s, data)) { -- cgit v1.2.3