From b98579699db53d8d72a3128405d4d70ff36b8266 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Tue, 11 Jun 2024 19:58:09 +0500 Subject: [PATCH] Improve #def --- src/process.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/process.c b/src/process.c index 77d72cd..d9cad8c 100644 --- a/src/process.c +++ b/src/process.c @@ -26,9 +26,10 @@ bool replace(tSyntaxElement* tree, tProcessingData* pd) { return false; } -void process_mod(tSyntaxElement* tree, tProcessingData* pdata) { +bool process_mod(tSyntaxElement* tree, tProcessingData* pdata) { tProcessingData* pd = pdata; + bool b = false; while (1) { @@ -38,7 +39,8 @@ void process_mod(tSyntaxElement* tree, tProcessingData* pdata) { if (tree->type == TOKEN) { switch (pd->type) { case REPLACE: - replace(tree,pd); + if (replace(tree,pd)) + b = true; break; case FUNCTION: break; @@ -51,6 +53,8 @@ void process_mod(tSyntaxElement* tree, tProcessingData* pdata) { else break; } + + return b; } @@ -129,11 +133,12 @@ bool process_find(tSyntaxElement* tree, tProcessingData** p_pdata) { } -void process(tSyntaxElement* tree, tProcessingData* pdata) { +bool process(tSyntaxElement* tree, tProcessingData* pdata) { tProcessingData* pd = pdata; bool deffound = false; + bool didreplace = false; tProcessingData* firstpd = NULL; @@ -147,22 +152,29 @@ void process(tSyntaxElement* tree, tProcessingData* pdata) { deffound = process_find(tree, &pd); if (tree->next != NULL) { - process(tree->next, pd); + if (process(tree->next, pd)) + didreplace = true; } if (!deffound) { if (se_istraversable(tree)) - process(tree->content.syntax, pd); + if (process(tree->content.syntax, pd)) + didreplace = true; - process_mod(tree, pd); + if (process_mod(tree, pd)) + didreplace = true; } if (pd != pdata) free(pd); - if (firstpd != pd && firstpd != NULL) + if (firstpd != pd && firstpd != NULL) { free(firstpd); - + if (didreplace) + process(tree, NULL); + } + + return didreplace; }