2007-08-25 21:31:10 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* (c) 2004-2007 Laurent Vivier <Laurent@lvivier.info>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "libconfig.h"
|
|
|
|
|
2008-04-16 13:36:26 +00:00
|
|
|
static inline char* eat_blank(char *s)
|
|
|
|
{
|
|
|
|
again:
|
|
|
|
while ( (*s == ' ') || (*s == '\t') || (*s == '\n') )
|
|
|
|
s++;
|
|
|
|
if (*s == '#')
|
|
|
|
{
|
|
|
|
while (*s != '\n')
|
|
|
|
s++;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2007-08-25 21:31:10 +00:00
|
|
|
static inline char *read_line(char *s)
|
|
|
|
{
|
2008-04-16 13:36:26 +00:00
|
|
|
s = eat_blank(s);
|
|
|
|
|
2007-08-25 21:31:10 +00:00
|
|
|
while (*s && (*s != '\n'))
|
|
|
|
s++;
|
|
|
|
if (*s == 0)
|
|
|
|
return s;
|
|
|
|
return s + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *config_read_word(char *line, char **next)
|
|
|
|
{
|
|
|
|
char *word;
|
|
|
|
|
2008-04-16 13:36:26 +00:00
|
|
|
line = eat_blank(line);
|
2007-08-25 21:31:10 +00:00
|
|
|
|
|
|
|
word = line;
|
|
|
|
|
|
|
|
while ( *line && (*line != ' ') && (*line != '\t') && (*line != '\n') )
|
|
|
|
line++;
|
|
|
|
|
|
|
|
*next = line;
|
|
|
|
|
|
|
|
return word;
|
|
|
|
}
|
|
|
|
|
2007-09-08 23:09:14 +00:00
|
|
|
int config_get_next_property(int8_t *configuration, int index, char *name, char *property)
|
2007-08-25 21:31:10 +00:00
|
|
|
{
|
|
|
|
char *next_word, *next_line;
|
|
|
|
char *current_name, *current_property;
|
|
|
|
|
|
|
|
next_line = (char*)configuration + index;
|
|
|
|
if (*next_line == 0)
|
|
|
|
return -1;
|
|
|
|
next_word = next_line;
|
|
|
|
next_line = read_line(next_line);
|
|
|
|
|
|
|
|
current_name = config_read_word(next_word, &next_word);
|
2007-08-26 09:18:36 +00:00
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
strncpy(name, current_name, next_word - current_name);
|
|
|
|
name[next_word - current_name] = 0;
|
|
|
|
}
|
2007-08-25 21:31:10 +00:00
|
|
|
|
|
|
|
current_property = config_read_word(next_word, &next_word);
|
2007-08-26 09:18:36 +00:00
|
|
|
if (property)
|
2007-08-25 21:31:10 +00:00
|
|
|
{
|
2007-08-26 09:18:36 +00:00
|
|
|
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;
|
|
|
|
}
|
2007-08-25 21:31:10 +00:00
|
|
|
else
|
2007-08-26 09:18:36 +00:00
|
|
|
*property = 0;
|
2007-08-25 21:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return next_line - (char*)configuration;
|
|
|
|
}
|