mirror of
https://github.com/vivier/EMILE.git
synced 2025-02-06 23:30:37 +00:00
use libconfig
This commit is contained in:
parent
cfb0c28b54
commit
d7ef366023
@ -9,6 +9,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "libemile.h"
|
||||
#include "libconfig.h"
|
||||
|
||||
int emile_second_get_param(int fd, char *kernel, char *parameters, char *initrd)
|
||||
{
|
||||
@ -34,13 +35,13 @@ int emile_second_get_param(int fd, char *kernel, char *parameters, char *initrd)
|
||||
return -1;
|
||||
|
||||
if (kernel != NULL)
|
||||
emile_second_get_property(configuration, "kernel", kernel);
|
||||
config_get_property(configuration, "kernel", kernel);
|
||||
|
||||
if (parameters != NULL)
|
||||
emile_second_get_property(configuration, "parameters", parameters);
|
||||
config_get_property(configuration, "parameters", parameters);
|
||||
|
||||
if (initrd != NULL)
|
||||
emile_second_get_property(configuration, "initrd", initrd);
|
||||
config_get_property(configuration, "initrd", initrd);
|
||||
|
||||
free(configuration);
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "libemile.h"
|
||||
#include "libconfig.h"
|
||||
|
||||
int emile_second_set_param(int fd, char *kernel, char *parameters, char *initrd)
|
||||
{
|
||||
@ -25,28 +26,28 @@ int emile_second_set_param(int fd, char *kernel, char *parameters, char *initrd)
|
||||
if (kernel != NULL)
|
||||
{
|
||||
if (*kernel)
|
||||
emile_second_set_property(configuration, "kernel", kernel);
|
||||
config_set_property(configuration, "kernel", kernel);
|
||||
else
|
||||
emile_second_remove_property(configuration, "kernel");
|
||||
config_remove_property(configuration, "kernel");
|
||||
}
|
||||
|
||||
if (parameters != NULL)
|
||||
{
|
||||
if (*parameters)
|
||||
emile_second_set_property(configuration, "parameters", parameters);
|
||||
config_set_property(configuration, "parameters", parameters);
|
||||
else
|
||||
emile_second_remove_property(configuration, "parameters");
|
||||
config_remove_property(configuration, "parameters");
|
||||
}
|
||||
|
||||
if (initrd != NULL)
|
||||
{
|
||||
if (*initrd)
|
||||
emile_second_set_property(configuration, "initrd", initrd);
|
||||
config_set_property(configuration, "initrd", initrd);
|
||||
else
|
||||
emile_second_remove_property(configuration, "initrd");
|
||||
config_remove_property(configuration, "initrd");
|
||||
}
|
||||
|
||||
emile_second_set_property(configuration, "vga", "default");
|
||||
config_set_property(configuration, "vga", "default");
|
||||
|
||||
ret = lseek(fd, offset, SEEK_SET);
|
||||
if (ret == -1)
|
||||
|
@ -12,7 +12,7 @@ VPATH = $(TOP)
|
||||
CPPFLAGS = -DVERSION="\"$(VERSION)\"" -I$(TOP) -Wa,-I$(TOP) \
|
||||
$(OPT_CPPFLAGS) -DUSE_CLI \
|
||||
-I$(TOP)/../libmacos -Wa,-I$(TOP)/../libmacos \
|
||||
-I$(TOP)/../libstream -I$(TOP)/../libui
|
||||
-I$(TOP)/../libstream -I$(TOP)/../libui -I$(TOP)/../libconfig
|
||||
|
||||
# -O2 is needed to be able to inline functions from libmacos
|
||||
CFLAGS = $(OPT_CFLAGS) -nostdlib -nodefaultlibs -Wall -Werror -Wno-multichar -fpic -O2
|
||||
@ -24,7 +24,8 @@ LIBS = $(OPT_LIBS) -L$(TOP)/../libiso9660/m68k-linux \
|
||||
-L$(TOP)/../libfloppy -lfloppy -L$(TOP)/../libscsi -lscsi \
|
||||
-L$(TOP)/../libblock -lblock \
|
||||
-L$(TOP)/../libcontainer -lcontainer -lunix \
|
||||
-L$(TOP)/../libui -lui
|
||||
-L$(TOP)/../libui -lui \
|
||||
-L$(TOP)/../libconfig/m68k-linux -lconfig -lunix
|
||||
|
||||
LS = ls
|
||||
AWK = awk
|
||||
|
121
second/config.c
121
second/config.c
@ -12,6 +12,7 @@
|
||||
#include <string.h>
|
||||
#include <libstream.h>
|
||||
#include <libui.h>
|
||||
#include <libconfig.h>
|
||||
#include "config.h"
|
||||
#if defined(USE_CLI) && defined(__LINUX__)
|
||||
#include "console.h"
|
||||
@ -27,101 +28,6 @@
|
||||
#define COMMAND_LINE_LENGTH 256
|
||||
#define DEFAULT_TIMEOUT 5
|
||||
|
||||
static char *read_line(char *s)
|
||||
{
|
||||
int read = 0;
|
||||
while (*s && (*s != '\n'))
|
||||
{
|
||||
read++;
|
||||
s++;
|
||||
}
|
||||
if (*s == 0)
|
||||
return 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;
|
||||
}
|
||||
|
||||
static int get_next_property(int8_t *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 = 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);
|
||||
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;
|
||||
}
|
||||
|
||||
static int get_indexed_property(int8_t *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 = get_next_property(configuration, index,
|
||||
current_name, property);
|
||||
if (index == -1)
|
||||
return -1;
|
||||
if (found)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
static int get_property(int8_t *configuration, char *name, char *property)
|
||||
{
|
||||
return get_indexed_property(configuration, NULL, NULL, name, property);
|
||||
}
|
||||
|
||||
static int8_t *open_config(emile_l2_header_t *info)
|
||||
{
|
||||
stream_t *stream;
|
||||
@ -130,7 +36,8 @@ static int8_t *open_config(emile_l2_header_t *info)
|
||||
char property[COMMAND_LINE_LENGTH];
|
||||
int ret;
|
||||
|
||||
if (get_property(info->configuration, "configuration", property) == 0)
|
||||
if (config_get_property(info->configuration,
|
||||
"configuration", property) == 0)
|
||||
{
|
||||
stream = stream_open(property);
|
||||
if (stream == NULL)
|
||||
@ -221,7 +128,7 @@ int read_config_vga(emile_l2_header_t* info)
|
||||
int ret;
|
||||
|
||||
configuration = open_config(info);
|
||||
ret = get_property(configuration, "vga", property);
|
||||
ret = config_get_property(configuration, "vga", property);
|
||||
close_config(configuration);
|
||||
|
||||
return ret;
|
||||
@ -234,7 +141,7 @@ int read_config_modem(emile_l2_header_t* info, int *bitrate, int *parity, int *d
|
||||
int ret;
|
||||
|
||||
configuration = open_config(info);
|
||||
ret = get_property(configuration, "modem", property);
|
||||
ret = config_get_property(configuration, "modem", property);
|
||||
if (ret == -1)
|
||||
{
|
||||
close_config(configuration);
|
||||
@ -253,7 +160,7 @@ int read_config_printer(emile_l2_header_t* info, int *bitrate, int *parity, int
|
||||
int ret;
|
||||
|
||||
configuration = open_config(info);
|
||||
ret = get_property(configuration, "printer", property);
|
||||
ret = config_get_property(configuration, "printer", property);
|
||||
if (ret == -1)
|
||||
{
|
||||
close_config(configuration);
|
||||
@ -302,18 +209,18 @@ int read_config(emile_l2_header_t* info,
|
||||
|
||||
configuration = open_config(info);
|
||||
|
||||
if (get_property(configuration, "gestaltID", property) == 0)
|
||||
if (config_get_property(configuration, "gestaltID", property) == 0)
|
||||
{
|
||||
machine_id = strtol(property, NULL, 0);
|
||||
printf("User forces gestalt ID to %ld\n", machine_id);
|
||||
}
|
||||
|
||||
choice = 0;
|
||||
if (get_property(configuration, "default", property) == 0)
|
||||
if (config_get_property(configuration, "default", property) == 0)
|
||||
choice = strtol(property, NULL, 0);
|
||||
|
||||
timeout = DEFAULT_TIMEOUT;
|
||||
if (get_property(configuration, "timeout", property) == 0)
|
||||
if (config_get_property(configuration, "timeout", property) == 0)
|
||||
timeout = strtol(property, NULL, 0);
|
||||
|
||||
for (index = 0; index < MAX_KERNELS; index++)
|
||||
@ -322,7 +229,7 @@ int read_config(emile_l2_header_t* info,
|
||||
|
||||
title[index] = NULL;
|
||||
|
||||
if (get_property(configuration, "title", property) == 0)
|
||||
if (config_get_property(configuration, "title", property) == 0)
|
||||
{
|
||||
title[index] = strdup(property);
|
||||
if (title[index] == NULL)
|
||||
@ -334,7 +241,8 @@ int read_config(emile_l2_header_t* info,
|
||||
prop = 0;
|
||||
for(i = 0; known_properties[i] != NULL; i++)
|
||||
{
|
||||
if (get_indexed_property(configuration, "title", title[index],
|
||||
if (config_get_indexed_property(configuration,
|
||||
"title", title[index],
|
||||
known_properties[i], property) == 0)
|
||||
{
|
||||
properties[index][prop] = malloc(strlen(known_properties[i]) +
|
||||
@ -351,6 +259,9 @@ int read_config(emile_l2_header_t* info,
|
||||
}
|
||||
prop_nb[index] = prop;
|
||||
|
||||
if (prop == 0)
|
||||
break;
|
||||
|
||||
if (title[index] == NULL) /* if no title, only one entry */
|
||||
{
|
||||
title[index] = strdup("Linux");
|
||||
@ -450,7 +361,7 @@ int read_config(emile_l2_header_t* info,
|
||||
{
|
||||
char *id, *next;
|
||||
|
||||
id = read_word(properties[choice][i], &next);
|
||||
id = config_read_word(properties[choice][i], &next);
|
||||
*next = 0;
|
||||
next++;
|
||||
|
||||
|
@ -25,13 +25,16 @@ DISTFILES =$(HEADERS) $(SOURCES) Makefile
|
||||
|
||||
CPPFLAGS = $(CROSS_COMPILE_CPPFLAGS) -DSIGNATURE="\"$(SIGNATURE)\"" -DPREFIX=\"$(PREFIX)\" \
|
||||
-I../libemile -I../libiso9660 -I../libgzip -I../libstream \
|
||||
-I../libcontainer -I../libmacos -DFATFREE -DNO_GZCOMPRESS
|
||||
-I../libcontainer -I../libmacos -DFATFREE -DNO_GZCOMPRESS \
|
||||
-I../libconfig
|
||||
|
||||
CFLAGS = -Wall -Werror -g
|
||||
LDLIBS = $(CROSS_COMPILE_LDFLAGS) -L../libemile -lemile -L../libiso9660/native -liso9660 -L../libgzip/native -lgzip
|
||||
LDLIBS = $(CROSS_COMPILE_LDFLAGS) -L../libemile -lemile -L../libiso9660/native -liso9660 -L../libgzip/native -lgzip -L../libconfig/native -lconfig
|
||||
|
||||
all: $(PROGRAMS)
|
||||
|
||||
emile-install: emile-install.o emile_config.o
|
||||
|
||||
emile: emile.o emile_scanbus.o emile_config.o
|
||||
|
||||
emile-map-set: emile-map-set.o emile_scanbus.o
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <getopt.h>
|
||||
|
||||
#include "libemile.h"
|
||||
#include "libconfig.h"
|
||||
|
||||
static char parity[] = { 'n', 'o', 'e' };
|
||||
enum {
|
||||
@ -126,22 +127,22 @@ static int display_output(char* image)
|
||||
|
||||
close(fd);
|
||||
|
||||
if (emile_second_get_property(configuration, "vga", property) == 0)
|
||||
if (config_get_property(configuration, "vga", property) == 0)
|
||||
printf("Output to display enabled (%s)\n", property);
|
||||
else
|
||||
printf("Output to display disabled\n");
|
||||
|
||||
if (emile_second_get_property(configuration, "modem", property) == 0)
|
||||
if (config_get_property(configuration, "modem", property) == 0)
|
||||
printf("Output to serial port 0 (modem) enabled (%s)\n", property);
|
||||
else
|
||||
printf("Output to serial port 0 (modem) disabled\n");
|
||||
|
||||
if (emile_second_get_property(configuration, "printer", property) == 0)
|
||||
if (config_get_property(configuration, "printer", property) == 0)
|
||||
printf("Output to serial port 1 (printer) enabled (%s)\n", property);
|
||||
else
|
||||
printf("Output to serial port 1 (printer) disabled\n");
|
||||
|
||||
if (emile_second_get_property(configuration, "gestaltID", property) == 0)
|
||||
if (config_get_property(configuration, "gestaltID", property) == 0)
|
||||
printf("Force Gestalt ID to %ld\n", strtol(property, NULL, 0));
|
||||
else
|
||||
printf("Gestalt ID is not modified\n");
|
||||
@ -199,31 +200,31 @@ static int set_output(char* image,
|
||||
}
|
||||
|
||||
if (disable_mask & STDOUT_VGA)
|
||||
emile_second_remove_property(configuration, "vga");
|
||||
config_remove_property(configuration, "vga");
|
||||
if (disable_mask & STDOUT_MODEM)
|
||||
emile_second_remove_property(configuration, "modem");
|
||||
config_remove_property(configuration, "modem");
|
||||
if (disable_mask & STDOUT_PRINTER)
|
||||
emile_second_remove_property(configuration, "printer");
|
||||
config_remove_property(configuration, "printer");
|
||||
|
||||
if (enable_mask & STDOUT_VGA)
|
||||
emile_second_set_property(configuration, "vga", "default");
|
||||
config_set_property(configuration, "vga", "default");
|
||||
if (enable_mask & STDOUT_MODEM)
|
||||
{
|
||||
sprintf(property, "%d%c%d+%d", bitrate0, parity[parity0], datasize0, stopbits0);
|
||||
emile_second_set_property(configuration, "modem", property);
|
||||
config_set_property(configuration, "modem", property);
|
||||
}
|
||||
if (enable_mask & STDOUT_PRINTER)
|
||||
{
|
||||
sprintf(property, "%d%c%d+%d", bitrate1, parity[parity1], datasize1, stopbits1);
|
||||
emile_second_set_property(configuration, "printer", property);
|
||||
config_set_property(configuration, "printer", property);
|
||||
}
|
||||
|
||||
if (gestaltid == 0)
|
||||
emile_second_remove_property(configuration, "gestaltID");
|
||||
config_remove_property(configuration, "gestaltID");
|
||||
else if (gestaltid != -1)
|
||||
{
|
||||
sprintf(property, "0x%x", gestaltid);
|
||||
emile_second_set_property(configuration, "gestaltID", property);
|
||||
config_set_property(configuration, "gestaltID", property);
|
||||
}
|
||||
|
||||
ret = lseek(fd, offset, SEEK_SET);
|
||||
|
Loading…
x
Reference in New Issue
Block a user