gnuastro-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnuastro-commits] master 392fa8c0: Makefile plugins: text-prev function


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 392fa8c0: Makefile plugins: text-prev functions when target not in list
Date: Tue, 16 Apr 2024 16:03:27 -0400 (EDT)

branch: master
commit 392fa8c080ea06594e842632f472043a8b460adf
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    Makefile plugins: text-prev functions when target not in list
    
    Until now, when the 'ast-text-prev*' functions were given a target that
    didn't exist in the input list, they would return the last batch of the
    full list! This is wrong: when not in the input, the Make culture expects
    an empty string.
    
    With this commit, a check has been added to only continue with printing the
    batch when the given target was actually found in the input list.
---
 lib/makeplugin.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/makeplugin.c b/lib/makeplugin.c
index f4e116cb..f0e37f93 100644
--- a/lib/makeplugin.c
+++ b/lib/makeplugin.c
@@ -271,8 +271,8 @@ static char *
 makeplugin_text_prev_batch_work(char *target, size_t num_in_batch,
                                 char *list)
 {
-  int is_first_batch=1;
   size_t anum=0, starti, endi, outlen;
+  int is_first_batch=1, target_found=0;
   char *startend[4]={NULL, NULL, NULL, NULL};
   char *cp, *token, *saveptr=NULL, *out=NULL, *delimiters=" ";
 
@@ -322,7 +322,7 @@ makeplugin_text_prev_batch_work(char *target, size_t 
num_in_batch,
       */
 
       /* If the target is reached, break out of the loop. */
-      if( !strcmp(target, token) ) break;
+      if( !strcmp(target, token) ) { target_found=1; break; }
 
       /* Go to the next token. */
       ++anum; /* Count of all tokens. */
@@ -330,9 +330,9 @@ makeplugin_text_prev_batch_work(char *target, size_t 
num_in_batch,
     }
   while(token);
 
-  /* We need to return a non-empty output only when a previous batch
-     exists.*/
-  if(startend[0])
+  /* We need to return a non-empty output only when the target was found
+     and a previous batch exists. */
+  if(target_found && startend[0])
     {
       /* Find the positions of the start and end of the output string
          within the (copied) input string and from that measure the length



reply via email to

[Prev in Thread] Current Thread [Next in Thread]