mirror of
https://github.com/vivier/EMILE.git
synced 2025-01-02 21:30:29 +00:00
First release
This commit is contained in:
parent
23de41a929
commit
efaf856a44
36
libconfig/Makefile
Normal file
36
libconfig/Makefile
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#
|
||||||
|
# (c) 2005-2007 Laurent Vivier <Laurent@lvivier.info>
|
||||||
|
#
|
||||||
|
|
||||||
|
TOP = $(shell pwd)
|
||||||
|
VPATH=$(TOP)
|
||||||
|
|
||||||
|
AS=$(CROSS_COMPILE)as
|
||||||
|
CC=$(CROSS_COMPILE)gcc
|
||||||
|
LD=$(CROSS_COMPILE)ld
|
||||||
|
AR=$(CROSS_COMPILE)ar
|
||||||
|
|
||||||
|
TARGET = native
|
||||||
|
CFLAGS += -nostdlib -nodefaultlibs -Wall -Werror -Wno-multichar
|
||||||
|
ifeq ($(TARGET), m68k-linux)
|
||||||
|
68000FLAGS = -m68000 -Wa,-m68000
|
||||||
|
CFLAGS += -fpic -O2 -Os
|
||||||
|
else
|
||||||
|
CFLAGS += -g
|
||||||
|
endif
|
||||||
|
CPPFLAGS = -I$(TOP)/../libstream
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
HEADERS = libconfig.h
|
||||||
|
|
||||||
|
all:
|
||||||
|
test -d $(TARGET) || mkdir $(TARGET)
|
||||||
|
$(MAKE) -C $(TARGET) -f $(TOP)/Makefile $(LIBRARY) TOP=$(TOP)
|
||||||
|
|
||||||
|
include $(TOP)/../Rules.mk
|
40
libconfig/config_get_indexed_property.c
Normal file
40
libconfig/config_get_indexed_property.c
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* (c) 2004-2007 Laurent Vivier <Laurent@lvivier.info>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "libconfig.h"
|
||||||
|
|
||||||
|
int config_get_indexed_property(char *configuration, char *index_name, char *index_property, char *name, char *property)
|
||||||
|
{
|
||||||
|
int found = (index_property == NULL); /* means not indexed */
|
||||||
|
int index = 0;
|
||||||
|
char current_name[256];
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
index = config_get_next_property(configuration, index,
|
||||||
|
current_name, property);
|
||||||
|
if (index == -1)
|
||||||
|
return -1;
|
||||||
|
if (found)
|
||||||
|
{
|
||||||
|
if ((index_name != NULL) &&
|
||||||
|
(strcmp(index_name, current_name) == 0))
|
||||||
|
return -1;
|
||||||
|
if (strcmp(name, current_name) == 0)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( (strcmp(index_name, current_name) == 0) &&
|
||||||
|
(strcmp(index_property, property) == 0) )
|
||||||
|
found = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
72
libconfig/config_get_next_property.c
Normal file
72
libconfig/config_get_next_property.c
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* (c) 2004-2007 Laurent Vivier <Laurent@lvivier.info>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "libconfig.h"
|
||||||
|
|
||||||
|
static inline char *read_line(char *s)
|
||||||
|
{
|
||||||
|
int read = 0;
|
||||||
|
while (*s && (*s != '\n'))
|
||||||
|
{
|
||||||
|
read++;
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
if (*s == 0)
|
||||||
|
return s;
|
||||||
|
return s + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *config_read_word(char *line, char **next)
|
||||||
|
{
|
||||||
|
char *word;
|
||||||
|
|
||||||
|
while ( (*line == ' ') || (*line == '\t') || (*line == '\n') )
|
||||||
|
line++;
|
||||||
|
|
||||||
|
word = line;
|
||||||
|
|
||||||
|
while ( *line && (*line != ' ') && (*line != '\t') && (*line != '\n') )
|
||||||
|
line++;
|
||||||
|
|
||||||
|
*next = line;
|
||||||
|
|
||||||
|
return word;
|
||||||
|
}
|
||||||
|
|
||||||
|
int config_get_next_property(char *configuration, int index, char *name, char *property)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
strncpy(name, current_name, next_word - current_name);
|
||||||
|
name[next_word - current_name] = 0;
|
||||||
|
|
||||||
|
current_property = config_read_word(next_word, &next_word);
|
||||||
|
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 - (char*)configuration;
|
||||||
|
}
|
14
libconfig/config_get_property.c
Normal file
14
libconfig/config_get_property.c
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* (c) 2004-2007 Laurent Vivier <Laurent@lvivier.info>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "libconfig.h"
|
||||||
|
|
||||||
|
int config_get_property(char *configuration, char *name, char *property)
|
||||||
|
{
|
||||||
|
return config_get_indexed_property(configuration, NULL, NULL, name, property);
|
||||||
|
}
|
52
libconfig/config_remove_indexed_property.c
Normal file
52
libconfig/config_remove_indexed_property.c
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* (c) 2005 Laurent Vivier <Laurent@lvivier.info>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "libconfig.h"
|
||||||
|
|
||||||
|
void config_remove_indexed_property(char *configuration, char *index_name,
|
||||||
|
char *index_property, char *name)
|
||||||
|
{
|
||||||
|
int found = (index_property == NULL); /* means not indexed */
|
||||||
|
int index = 0;
|
||||||
|
int last_index;
|
||||||
|
int current = 0;
|
||||||
|
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;
|
||||||
|
if (found)
|
||||||
|
{
|
||||||
|
if (strcmp(name, current_name) != 0)
|
||||||
|
{
|
||||||
|
int len;
|
||||||
|
len = strlen(configuration + index);
|
||||||
|
memcpy(configuration + last_index,
|
||||||
|
configuration + index, len);
|
||||||
|
if (configuration[index + len - 1] == '\n')
|
||||||
|
len--;
|
||||||
|
configuration[index + len] = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ( (strcmp(index_name, current_name) == 0) &&
|
||||||
|
(strcmp(index_property, current_property) == 0) )
|
||||||
|
found = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (configuration[current-1] == '\n')
|
||||||
|
current--;
|
||||||
|
configuration[current++] = 0;
|
||||||
|
}
|
15
libconfig/config_remove_property.c
Normal file
15
libconfig/config_remove_property.c
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* (c) 2005 Laurent Vivier <Laurent@lvivier.info>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "libconfig.h"
|
||||||
|
|
||||||
|
void config_remove_property(char *configuration, char *name)
|
||||||
|
{
|
||||||
|
config_remove_indexed_property(configuration, name, NULL, NULL);
|
||||||
|
}
|
58
libconfig/config_set_indexed_property.c
Normal file
58
libconfig/config_set_indexed_property.c
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* (c) 2005 Laurent Vivier <Laurent@lvivier.info>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "libconfig.h"
|
||||||
|
|
||||||
|
void config_set_indexed_property(char *configuration, char *index_name,
|
||||||
|
char *index_property, char *name,
|
||||||
|
char *property)
|
||||||
|
{
|
||||||
|
int found = (index_property == NULL); /* means not indexed */
|
||||||
|
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;
|
||||||
|
if (found)
|
||||||
|
{
|
||||||
|
if (strcmp(name, current_name) != 0)
|
||||||
|
{
|
||||||
|
int len, len_new, len_old;
|
||||||
|
|
||||||
|
len = strlen(configuration + index);
|
||||||
|
len_old = index - last_index;
|
||||||
|
len_new = strlen(name) + 1 +
|
||||||
|
strlen(property) + 1;
|
||||||
|
|
||||||
|
memcpy(configuration + last_index + len_new,
|
||||||
|
configuration + index, len);
|
||||||
|
|
||||||
|
sprintf(configuration + last_index,
|
||||||
|
"%s %s", name, property);
|
||||||
|
configuration[index + len_new] = '\n';
|
||||||
|
if (configuration[index + len - 1] == '\n')
|
||||||
|
len--;
|
||||||
|
configuration[index + len] = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ( (strcmp(index_name, current_name) == 0) &&
|
||||||
|
(strcmp(index_property, property) == 0) )
|
||||||
|
found = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
15
libconfig/config_set_property.c
Normal file
15
libconfig/config_set_property.c
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* (c) 2005 Laurent Vivier <Laurent@lvivier.info>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "libconfig.h"
|
||||||
|
|
||||||
|
void config_set_property(char *configuration, char *name, char *property)
|
||||||
|
{
|
||||||
|
config_set_indexed_property(configuration, NULL, NULL, name, property);
|
||||||
|
}
|
14
libconfig/libconfig.h
Normal file
14
libconfig/libconfig.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* (c) 2007 Laurent Vivier <Laurent@lvivier.info>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern char *config_read_word(char *line, char **next);
|
||||||
|
extern int config_get_next_property(char *configuration, int index, char *name, char *property);
|
||||||
|
extern int config_get_indexed_property(char *configuration, char *index_name, char *index_property, char *name, char *property);
|
||||||
|
extern int config_get_property(char *configuration, char *name, char *property);
|
||||||
|
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);
|
Loading…
Reference in New Issue
Block a user