mirror of
https://github.com/vivier/EMILE.git
synced 2025-04-08 04:39:14 +00:00
correct management of end of line at end of configuration
This commit is contained in:
parent
2fba2c0ea9
commit
2fa2fff513
@ -17,6 +17,8 @@ static char *read_line(char *s)
|
||||
read++;
|
||||
s++;
|
||||
}
|
||||
if (*s == 0)
|
||||
return s;
|
||||
return s + 1;
|
||||
}
|
||||
|
||||
@ -53,8 +55,19 @@ int emile_second_get_next_property(char *configuration, int index, char *name, c
|
||||
name[next_word - current_name] = 0;
|
||||
|
||||
current_property = read_word(next_word, &next_word);
|
||||
strncpy(property, current_property, next_line - current_property);
|
||||
property[next_line - current_property] = 0;
|
||||
if (next_line - current_property != 0)
|
||||
{
|
||||
strncpy(property, current_property, next_line - current_property);
|
||||
|
||||
/* remove '\n' if needed */
|
||||
|
||||
if (*(next_line - 1) == '\n')
|
||||
property[next_line - current_property - 1] = 0;
|
||||
else
|
||||
property[next_line - current_property] = 0;
|
||||
}
|
||||
else
|
||||
*property = 0;
|
||||
|
||||
return next_line - configuration;
|
||||
}
|
||||
|
@ -16,11 +16,9 @@ void emile_second_remove_property(char *configuration, char *name)
|
||||
char current_name[256];
|
||||
char current_property[256];
|
||||
|
||||
while (1)
|
||||
while (configuration[index])
|
||||
{
|
||||
index = emile_second_get_next_property(configuration, index, current_name, current_property);
|
||||
if (index == -1)
|
||||
break;
|
||||
if (strcmp(name, current_name) != 0)
|
||||
{
|
||||
memcpy(configuration + current, current_name, strlen(current_name));
|
||||
@ -28,8 +26,11 @@ void emile_second_remove_property(char *configuration, char *name)
|
||||
configuration[current++] = ' ';
|
||||
memcpy(configuration + current, current_property, strlen(current_property));
|
||||
current += strlen(current_property);
|
||||
if (configuration[index])
|
||||
configuration[current++] = '\n';
|
||||
}
|
||||
}
|
||||
if (configuration[current - 1] == '\n')
|
||||
configuration[current - 1] = 0;
|
||||
if (configuration[current-1] == '\n')
|
||||
current--;
|
||||
configuration[current++] = 0;
|
||||
}
|
||||
|
@ -15,11 +15,9 @@ void emile_second_set_property(char *configuration, char *name, char *property)
|
||||
char current_name[256];
|
||||
char current_property[256];
|
||||
|
||||
while (1)
|
||||
while (configuration[index])
|
||||
{
|
||||
index = emile_second_get_next_property(configuration, index, current_name, current_property);
|
||||
if (index == -1)
|
||||
break;
|
||||
if (strcmp(name, current_name) != 0)
|
||||
{
|
||||
memcpy(configuration + current, current_name, strlen(current_name));
|
||||
@ -27,9 +25,14 @@ void emile_second_set_property(char *configuration, char *name, char *property)
|
||||
configuration[current++] = ' ';
|
||||
memcpy(configuration + current, current_property, strlen(current_property));
|
||||
current += strlen(current_property);
|
||||
if (configuration[index])
|
||||
configuration[current++] = '\n';
|
||||
else
|
||||
{
|
||||
configuration[current++] = '\n';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (configuration[current - 1] != '\n')
|
||||
configuration[current - 1] = '\n';
|
||||
sprintf(configuration + current, "%s %s", name, property);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user