summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@users.sourceforge.net>2013-02-10 18:03:39 +0100
committerTomas Bzatek <tbzatek@users.sourceforge.net>2013-02-10 18:03:39 +0100
commit84d9c637087ba1f2fd5dcaa7a74d61aa15848832 (patch)
tree6bf0b1fe8744f1a4c3f79bcbfe109db3f684a477
parent0cb2950ba336d6c291a1dc086ad2f3138f37e132 (diff)
downloadcataract-84d9c637087ba1f2fd5dcaa7a74d61aa15848832.tar.xz
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.
-rw-r--r--src/block-parser.c24
1 files 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)) {