From 7d5ab1c4e3a5ce45d41804f1122f5b79e8256a0f Mon Sep 17 00:00:00 2001 From: Fabrice Le Fessant Date: Tue, 23 Apr 2024 11:04:05 +0200 Subject: [PATCH] xxx --- cobc/replace.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/cobc/replace.c b/cobc/replace.c index cab72b3d5..873b92831 100644 --- a/cobc/replace.c +++ b/cobc/replace.c @@ -87,7 +87,7 @@ function to keep the depth of the recursion. */ /* #define DEBUG_REPLACE_TRACE */ -/* #define DEBUG_REPLACE */ +/* #define DEBUG_REPLACE */ #ifdef DEBUG_REPLACE_TRACE #define DEBUG_REPLACE @@ -341,8 +341,6 @@ char * string_of_##kind##_list(const struct cb_##kind##_list *list) \ return text_list_string; \ } -/* string_of_token_list (...) */ -STRING_OF_LIST(token) /* string_of_text_list (...) */ STRING_OF_LIST(text) @@ -411,7 +409,7 @@ static void ppecho_switch_token_queue (WITH_DEPTH struct cb_replacement_state *repls, struct cb_token_queue *q) { -#ifdef DEBUG_REPLACE_TRACE +#if 0 fprintf (stderr, "%sppecho_switch_token_queue(%s, %s)\n", DEPTH, repls->name, string_of_token_list(p)); #endif @@ -513,7 +511,7 @@ check_replace (WITH_DEPTH struct cb_replacement_state* repls, /* remove the text from the current stream */ const char* text; const char* token; - token_queue_take (MORE_DEPTH repls->token_queue, &text, &token); + token_queue_take (repls->token_queue, &text, &token); /* pass it to the next stream */ ppecho_switch (MORE_DEPTH repls, text, token); @@ -544,7 +542,7 @@ check_replace (WITH_DEPTH struct cb_replacement_state* repls, /* MATCH */ /* remove the text from the current stream */ - token_queue_remove (MORE_DEPTH repls->token_queue, 1); + token_queue_remove (repls->token_queue, 1); /* perform a partial replacement on the text, and pass it to the next stream */ @@ -599,8 +597,8 @@ check_replace_all (WITH_DEPTH DEPTH, repls->name); fprintf (stderr, "%s new_text = %s,\n", DEPTH, string_of_text_list(new_text)); - fprintf (stderr, "%s texts = %s,\n", DEPTH, - string_of_token_list(texts)); +// fprintf (stderr, "%s texts = %s,\n", DEPTH, +// string_of_token_list(texts)); fprintf (stderr, "%s src = %s,\n", DEPTH, string_of_text_list(src)); fprintf (stderr, "%s)\n", DEPTH); @@ -751,7 +749,7 @@ is_word (WITH_DEPTH const char *s) { static void add_text_to_replace (WITH_DEPTH struct cb_replacement_state *repls, - int prequeue, const char* text, const char* token + int prequeue, const char* text, const char* token ) { /* CHECKME: this function takes >35% of the parsing cpu instructions, @@ -792,7 +790,7 @@ add_text_to_replace (WITH_DEPTH struct cb_replacement_state *repls, } else { - if (repls->token_queue == NULL + if ( token_queue_is_empty (repls->token_queue) && is_space_or_nl (text[0]) ) { ppecho_switch (MORE_DEPTH repls, text, token); } else { @@ -801,8 +799,9 @@ add_text_to_replace (WITH_DEPTH struct cb_replacement_state *repls, "%s add_text_to_replace () -> push_text()\n", DEPTH); #endif - token_queue_put(MORE_DEPTH repls->token_queue, - 1, /* TODO strdup check */ + token_queue_put(repls->token_queue, + /* use strdup if we are in the COPY phase */ + repls->ppecho == CB_PPECHO_REPLACE ? 1 : 0, text, token); do_replace (MORE_DEPTH repls);