mirror of
https://github.com/vivier/EMILE.git
synced 2025-02-25 23:29:10 +00:00
add find functions
This commit is contained in:
parent
d8941fa5c0
commit
f19444a5f1
@ -25,7 +25,8 @@ LIBRARY = libconfig.a
|
||||
SOURCES = config_get_indexed_property.c config_get_next_property.c \
|
||||
config_get_property.c config_remove_property.c \
|
||||
config_set_property.c config_set_indexed_property.c \
|
||||
config_remove_indexed_property.c
|
||||
config_remove_indexed_property.c config_find_indexed_property.c \
|
||||
config_find_entry.c
|
||||
|
||||
HEADERS = libconfig.h
|
||||
|
||||
|
32
libconfig/config_find_entry.c
Normal file
32
libconfig/config_find_entry.c
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
*
|
||||
* (c) 2004-2007 Laurent Vivier <Laurent@lvivier.info>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "libconfig.h"
|
||||
|
||||
int config_find_entry(char *configuration, char *name, char *property)
|
||||
{
|
||||
int index = 0;
|
||||
int last_index;
|
||||
char current_name[256];
|
||||
char current_property[256];
|
||||
|
||||
while (configuration[index])
|
||||
{
|
||||
last_index = index;
|
||||
index = config_get_next_property(configuration, index,
|
||||
current_name, current_property);
|
||||
if (index == -1)
|
||||
return -1;
|
||||
if ( (strcmp(name, current_name) == 0) &&
|
||||
(strcmp(property, current_property) == 0) )
|
||||
return index;
|
||||
|
||||
}
|
||||
return -1;
|
||||
}
|
37
libconfig/config_find_indexed_property.c
Normal file
37
libconfig/config_find_indexed_property.c
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
*
|
||||
* (c) 2004-2007 Laurent Vivier <Laurent@lvivier.info>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "libconfig.h"
|
||||
|
||||
int config_find_indexed_property(char *configuration, char *index_name, char *index_property, char *name, char *property)
|
||||
{
|
||||
int index;
|
||||
int last_index;
|
||||
char current_name[256];
|
||||
|
||||
index = config_find_entry(configuration, index_name, index_property);
|
||||
if (index == -1)
|
||||
return -1;
|
||||
while (configuration[index])
|
||||
{
|
||||
last_index = index;
|
||||
index = config_get_next_property(configuration, index,
|
||||
current_name, property);
|
||||
if (index == -1)
|
||||
return -1;
|
||||
|
||||
if (strcmp(name, current_name) == 0)
|
||||
return last_index;
|
||||
|
||||
if ((index_name != NULL) &&
|
||||
(strcmp(index_name, current_name) == 0))
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
@ -12,3 +12,5 @@ extern void config_remove_property(char *configuration, char *name);
|
||||
extern void config_set_property(char *configuration, char *name, char *property);
|
||||
extern void config_set_indexed_property(char *configuration, char *index_name, char *index_property, char *name, char *property);
|
||||
extern void config_remove_indexed_property(char *configuration, char *index_name, char *index_property, char *name);
|
||||
extern int config_find_indexed_property(char *configuration, char *index_name, char *index_property, char *name, char *property);
|
||||
extern int config_find_entry(char *configuration, char *name, char *property);
|
||||
|
Loading…
x
Reference in New Issue
Block a user