Fix remove_entry

This commit is contained in:
Ian Jauslin 2025-06-05 14:55:34 +02:00
parent 72455cbb65
commit afe0498f21

View File

@ -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';