summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@users.sourceforge.net>2012-12-24 21:16:06 +0100
committerTomas Bzatek <tbzatek@users.sourceforge.net>2012-12-24 21:16:06 +0100
commitdb6c3c5a0ef1cca1e951e21ea2633615d43233eb (patch)
treecf34418fb9c9315523588b12ea63785f8a8a23ad /src
parentc5e75352f27a02501b3a1a9189f10a581c12e7fb (diff)
downloadcataract-db6c3c5a0ef1cca1e951e21ea2633615d43233eb.tar.xz
block-parser: Relaxed endif()/else() syntax for custom block functions
Specifying all arguments in endif() or else() for custom block functions reduces code readability and debugging comfort. Let's be less strict and don't require them. A simple test for function name should be enough, moreover nesting is not limited by this change at all.
Diffstat (limited to 'src')
-rw-r--r--src/block-parser.c34
1 files changed, 30 insertions, 4 deletions
diff --git a/src/block-parser.c b/src/block-parser.c
index 8aa882a..ff40ed0 100644
--- a/src/block-parser.c
+++ b/src/block-parser.c
@@ -245,6 +245,32 @@ push_string (BlockParser *parser, const gchar *piece)
}
}
+static gboolean
+check_conditional_tree_for_token (const gchar *token, BlockData *data)
+{
+ gchar *func1, *func2;
+ gboolean ret;
+
+ if (data == NULL || ! data->is_conditional)
+ return FALSE;
+
+ ret = FALSE;
+
+ if (! data->is_conditional_function) {
+ ret = g_strcmp0 (data->conditional_key, token) == 0;
+ }
+
+ if (data->is_conditional_function) {
+ func1 = parse_function (token, NULL, NULL);
+ func2 = parse_function (data->conditional_key, NULL, NULL);
+ ret = (func1 != NULL && func2 != NULL && g_str_equal (func1, func2));
+ g_free (func1);
+ g_free (func2);
+ }
+
+ return ret;
+}
+
/*
* 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
@@ -331,8 +357,8 @@ block_parser_read_and_parse (BlockParser *parser, FILE *stream)
if (parser->conditionals && token_has_prefix (token, "endif")) {
s = extract_token_arg (token);
data = g_queue_peek_head (parser->active_tree);
- if (data == NULL || !data->is_conditional || strcmp (data->conditional_key, s) != 0) {
- log_error ("block_parser_read_and_parse: something is wrong with the parser table: expected '%s' but got '%s'\n", s, data->conditional_key);
+ if (! check_conditional_tree_for_token (s, data)) {
+ log_error ("block_parser_read_and_parse: something is wrong with the parser table: expected '%s' but got '%s'\n", data->conditional_key, s);
}
else {
g_queue_pop_head (parser->active_tree);
@@ -347,8 +373,8 @@ block_parser_read_and_parse (BlockParser *parser, FILE *stream)
if (parser->conditionals && token_has_prefix (token, "else")) {
s = extract_token_arg (token);
data = g_queue_peek_head (parser->active_tree);
- if (data == NULL || !data->is_conditional || strcmp (data->conditional_key, s) != 0) {
- log_error ("block_parser_read_and_parse: something is wrong with the parser table: expected '%s' but got '%s'\n", s, data->conditional_key);
+ if (! check_conditional_tree_for_token (s, data)) {
+ log_error ("block_parser_read_and_parse: something is wrong with the parser table: expected '%s' but got '%s'\n", data->conditional_key, s);
}
else {
data->should_ignore = ! data->should_ignore;