From afe0498f21ac8b09c7b31ae1d0814fd7006201cf Mon Sep 17 00:00:00 2001 From: Ian Jauslin Date: Thu, 5 Jun 2025 14:55:34 +0200 Subject: [PATCH] Fix remove_entry --- src/io.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/io.c b/src/io.c index 098734f..0acb358 100644 --- a/src/io.c +++ b/src/io.c @@ -258,23 +258,38 @@ int remove_entry( char* rw_ptr; char* bfr; char* entry_ptr=entry; + // whether to write the entry int go=1; + // whether the pointer is at the beginning of the entry + int at_top=1; for(ptr=param_str, rw_ptr=ptr; *ptr!='\0'; ptr++){ - for(bfr=ptr,entry_ptr=entry; *bfr==*entry_ptr; bfr++, entry_ptr++){ - // check if reached end of entry - if(*(bfr+1)=='=' && *(entry_ptr+1)=='\0'){ - go=0; - break; + // only match entries if one is at the beginning of an entry + if(at_top==1){ + // check that the entry under ptr matches entry + for(bfr=ptr,entry_ptr=entry; *bfr==*entry_ptr; bfr++, entry_ptr++){ + // check if reached end of entry + if(*(bfr+1)=='=' && *(entry_ptr+1)=='\0'){ + // match: do not write entry + go=0; + break; + } } } + + // write entry if(go==1){ *rw_ptr=*ptr; rw_ptr++; } + + // next iterate will no longer be at the beginning of the entry + at_top=0; + //reset if(*ptr==';'){ go=1; + at_top=1; } } *rw_ptr='\0';