From 02fcb53e3a986a85fa8c0248a306132c8996acd8 Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Sat, 4 Jun 2011 18:18:32 +0200 Subject: replace-table: Link to defines table instead of copying on creation This allows actual defines to be used without explicit update. Also brings the benefit of placing empty string when define is not defined. --- src/block-parser.c | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) (limited to 'src/block-parser.c') diff --git a/src/block-parser.c b/src/block-parser.c index cfe9047..8bf7181 100644 --- a/src/block-parser.c +++ b/src/block-parser.c @@ -219,25 +219,6 @@ push_string (BlockParser *parser, const gchar *piece) } } -static gchar * -extract_arg (const gchar *str) -{ - const gchar *start; - const gchar *end; - - start = strstr (str, "("); - if (start == NULL) - return NULL; - start++; - - end = strstr (str, ")"); - if (end == NULL) - return NULL; - end++; - - return g_strndup (start, end - start - 1); -} - /* * 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 @@ -284,7 +265,7 @@ block_parser_read_and_parse (BlockParser *parser, FILE *stream) if (parser->conditionals && (g_str_has_prefix (token, "ifdef(") || g_str_has_prefix (token, "ifndef("))) { data = g_new0 (BlockData, 1); data->is_conditional = TRUE; - data->conditional_key = extract_arg (token); + data->conditional_key = extract_token_arg (token); data->should_ignore = ((g_str_has_prefix (token, "ifdef(") && g_hash_table_lookup (parser->conditionals, data->conditional_key) == NULL) || (g_str_has_prefix (token, "ifndef(") && g_hash_table_lookup (parser->conditionals, data->conditional_key) != NULL)); if (data->should_ignore && parser->ignore_level == 0) @@ -297,7 +278,7 @@ block_parser_read_and_parse (BlockParser *parser, FILE *stream) } if (parser->conditionals && g_str_has_prefix (token, "endif(")) { - s = extract_arg (token); + 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); @@ -313,7 +294,7 @@ block_parser_read_and_parse (BlockParser *parser, FILE *stream) } if (parser->conditionals && g_str_has_prefix (token, "else(")) { - s = extract_arg (token); + 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); -- cgit v1.2.3