diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/block-parser.c | 10 | ||||
| -rw-r--r-- | src/replace-table.c | 20 | ||||
| -rw-r--r-- | src/replace-table.h | 6 |
3 files changed, 30 insertions, 6 deletions
diff --git a/src/block-parser.c b/src/block-parser.c index 8bf7181..0697d2a 100644 --- a/src/block-parser.c +++ b/src/block-parser.c @@ -262,12 +262,12 @@ block_parser_read_and_parse (BlockParser *parser, FILE *stream) g_free (s); /* match conditionals */ - if (parser->conditionals && (g_str_has_prefix (token, "ifdef(") || g_str_has_prefix (token, "ifndef("))) { + if (parser->conditionals && (token_has_prefix (token, "ifdef") || token_has_prefix (token, "ifndef"))) { data = g_new0 (BlockData, 1); data->is_conditional = TRUE; 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)); + data->should_ignore = ((token_has_prefix (token, "ifdef") && g_hash_table_lookup (parser->conditionals, data->conditional_key) == NULL) || + (token_has_prefix (token, "ifndef") && g_hash_table_lookup (parser->conditionals, data->conditional_key) != NULL)); if (data->should_ignore && parser->ignore_level == 0) parser->ignore_level = 1; else @@ -277,7 +277,7 @@ block_parser_read_and_parse (BlockParser *parser, FILE *stream) handled = TRUE; } - if (parser->conditionals && g_str_has_prefix (token, "endif(")) { + 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) { @@ -293,7 +293,7 @@ block_parser_read_and_parse (BlockParser *parser, FILE *stream) g_free (s); } - if (parser->conditionals && g_str_has_prefix (token, "else(")) { + 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) { diff --git a/src/replace-table.c b/src/replace-table.c index 2f80beb..3398bae 100644 --- a/src/replace-table.c +++ b/src/replace-table.c @@ -279,7 +279,7 @@ replace_table_process (gchar **buffer, ReplaceTable *table) replace_value = NULL; /* match defines */ - if (table->defines && g_str_has_prefix (token, "value(")) { + if (table->defines && token_has_prefix (token, "value")) { s = extract_token_arg (token); replace_value = g_strdup (g_hash_table_lookup (table->defines, s)); /* fall back to empty string if not defined */ @@ -450,3 +450,21 @@ extract_token_arg (const gchar *str) return g_strndup (start, end - start - 1); } +/* + * token_has_prefix: returns TRUE if 'prefix' matches the token syntax (i.e. "prefix (") with unlimited number of spaces before the opening bracket + * + */ +gboolean +token_has_prefix (const gchar *token, const gchar *prefix) +{ + const gchar *s; + + if (! g_str_has_prefix (token, prefix)) + return FALSE; + + s = token + strlen (prefix); + while (*s != '\0' && (*s == ' ' || *s == '\t')) + s++; + + return (*s == '('); +} diff --git a/src/replace-table.h b/src/replace-table.h index 0d81c92..81365cc 100644 --- a/src/replace-table.h +++ b/src/replace-table.h @@ -94,6 +94,12 @@ gchar * get_next_token (const gchar *s, gchar **start, gchar **end, gboolean *ta */ gchar * extract_token_arg (const gchar *str); +/* + * token_has_prefix: returns TRUE if 'prefix' matches the token syntax (i.e. "prefix (") with unlimited number of spaces before the opening bracket + * + */ +gboolean token_has_prefix (const gchar *token, const gchar *prefix); + G_END_DECLS |
