Fix remove_entry
This commit is contained in:
parent
72455cbb65
commit
afe0498f21
15
src/io.c
15
src/io.c
@ -258,23 +258,38 @@ int remove_entry(
|
|||||||
char* rw_ptr;
|
char* rw_ptr;
|
||||||
char* bfr;
|
char* bfr;
|
||||||
char* entry_ptr=entry;
|
char* entry_ptr=entry;
|
||||||
|
// whether to write the entry
|
||||||
int go=1;
|
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(ptr=param_str, rw_ptr=ptr; *ptr!='\0'; ptr++){
|
||||||
|
// 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++){
|
for(bfr=ptr,entry_ptr=entry; *bfr==*entry_ptr; bfr++, entry_ptr++){
|
||||||
// check if reached end of entry
|
// check if reached end of entry
|
||||||
if(*(bfr+1)=='=' && *(entry_ptr+1)=='\0'){
|
if(*(bfr+1)=='=' && *(entry_ptr+1)=='\0'){
|
||||||
|
// match: do not write entry
|
||||||
go=0;
|
go=0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// write entry
|
||||||
if(go==1){
|
if(go==1){
|
||||||
*rw_ptr=*ptr;
|
*rw_ptr=*ptr;
|
||||||
rw_ptr++;
|
rw_ptr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// next iterate will no longer be at the beginning of the entry
|
||||||
|
at_top=0;
|
||||||
|
|
||||||
//reset
|
//reset
|
||||||
if(*ptr==';'){
|
if(*ptr==';'){
|
||||||
go=1;
|
go=1;
|
||||||
|
at_top=1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*rw_ptr='\0';
|
*rw_ptr='\0';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user