mirror of
https://github.com/vivier/EMILE.git
synced 2024-12-23 01:29:34 +00:00
Add new functions for EM06
This commit is contained in:
parent
a10615bd87
commit
ed8593760b
54
libemile/emile_second_get_next_property.c
Normal file
54
libemile/emile_second_get_next_property.c
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "libemile.h"
|
||||||
|
|
||||||
|
static char *read_line(char *s)
|
||||||
|
{
|
||||||
|
int read = 0;
|
||||||
|
while (*s && (*s != '\n'))
|
||||||
|
{
|
||||||
|
read++;
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
return s + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *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 emile_second_get_next_property(char *configuration, int index, char *name, char *property)
|
||||||
|
{
|
||||||
|
char *next_word, *next_line;
|
||||||
|
char *current_name, *current_property;
|
||||||
|
|
||||||
|
next_line = configuration + index;
|
||||||
|
if (*next_line == 0)
|
||||||
|
return -1;
|
||||||
|
next_word = next_line;
|
||||||
|
next_line = read_line(next_line);
|
||||||
|
|
||||||
|
current_name = read_word(next_word, &next_word);
|
||||||
|
strncpy(name, current_name, next_word - current_name);
|
||||||
|
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;
|
||||||
|
|
||||||
|
return next_line - configuration;
|
||||||
|
}
|
18
libemile/emile_second_get_property.c
Normal file
18
libemile/emile_second_get_property.c
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "libemile.h"
|
||||||
|
|
||||||
|
int emile_second_get_property(char *configuration, char *name, char *property)
|
||||||
|
{
|
||||||
|
int index = 0;
|
||||||
|
char current_name[256];
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
index = emile_second_get_next_property(configuration, index, current_name, property);
|
||||||
|
if (index == -1)
|
||||||
|
break;
|
||||||
|
if (strcmp(name, current_name) == 0)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
29
libemile/emile_second_set_property.c
Normal file
29
libemile/emile_second_set_property.c
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "libemile.h"
|
||||||
|
void emile_second_set_property(char *configuration, char *name, char *property)
|
||||||
|
{
|
||||||
|
int index = 0;
|
||||||
|
int current = 0;
|
||||||
|
char current_name[256];
|
||||||
|
char current_property[256];
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
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));
|
||||||
|
current += strlen(current_name);
|
||||||
|
configuration[current++] = ' ';
|
||||||
|
memcpy(configuration + current, current_property, strlen(current_property));
|
||||||
|
current += strlen(current_property);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (configuration[current - 1] != '\n')
|
||||||
|
configuration[current - 1] = '\n';
|
||||||
|
sprintf(configuration + current, "%s %s", name, property);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user