EMILE/libconfig/config_remove_indexed_property.c

37 lines
758 B
C
Raw Normal View History

2007-08-25 21:31:10 +00:00
/*
*
* (c) 2005 Laurent Vivier <Laurent@lvivier.info>
*
*/
#include <stdio.h>
#include <string.h>
#include "libconfig.h"
2007-08-31 20:42:27 +00:00
int config_remove_indexed_property(char *configuration, char *index_name,
2007-08-25 21:31:10 +00:00
char *index_property, char *name)
{
int last_index;
2007-08-26 09:17:42 +00:00
int index;
int len = 0;
2007-08-25 21:31:10 +00:00
2007-08-26 09:17:42 +00:00
last_index = config_find_indexed_property(configuration, index_name,
index_property, name, NULL);
if (last_index == -1)
2007-08-31 20:42:27 +00:00
return -1;
2007-08-26 09:17:42 +00:00
index = config_get_next_property(configuration,
last_index, NULL, NULL);
if (index != -1)
2007-08-25 21:31:10 +00:00
{
2007-08-26 09:17:42 +00:00
len = strlen(configuration + index);
2007-08-26 19:16:40 +00:00
memmove(configuration + last_index, configuration + index, len);
2007-08-25 21:31:10 +00:00
}
2007-08-26 09:17:42 +00:00
if (configuration[index + len - 1] == '\n')
len--;
configuration[index + len] = 0;
2007-08-31 20:42:27 +00:00
return last_index;
2007-08-25 21:31:10 +00:00
}