start the config system, add the config file parser

This commit is contained in:
Dana Jansens 2003-03-22 14:41:19 +00:00
parent 4502cad550
commit 56dc0446cd
6 changed files with 1840 additions and 2 deletions

View file

@ -27,11 +27,11 @@ openbox3_LDADD=@LIBINTL@ ../render/librender.a
openbox3_LDFLAGS=-export-dynamic
openbox3_SOURCES=client.c event.c extensions.c focus.c frame.c openbox.c \
prop.c screen.c stacking.c xerror.c themerc.c timer.c dispatch.c \
engine.c plugin.c action.c grab.c
engine.c plugin.c action.c grab.c cparse.l config.c
noinst_HEADERS=client.h event.h extensions.h focus.h frame.h geom.h gettext.h \
openbox.h prop.h screen.h stacking.h xerror.h themerc.h dispatch.h \
timer.h engine.h plugin.h action.h grab.h
timer.h engine.h plugin.h action.h grab.h config.h
MAINTAINERCLEANFILES= Makefile.in

37
openbox/config.c Normal file
View file

@ -0,0 +1,37 @@
#include "config.h"
#ifdef HAVE_STDIO_H
# include <stdio.h>
#endif
static GSList *config = NULL;
/* provided by cparse.l */
void cparse_go(FILE *);
void config_startup()
{
}
void config_shutdown()
{
}
void config_parse()
{
FILE *file;
char *path;
path = g_build_filename(g_get_home_dir(), ".openbox", "rc3", NULL);
if ((file = fopen(path, "r")) != NULL) {
cparse_go(file);
fclose(file);
}
}
gboolean config_set(char *name, ConfigValueType type, ConfigValue value)
{
g_message("Setting %s\n", name);
return TRUE;
}

29
openbox/config.h Normal file
View file

@ -0,0 +1,29 @@
#ifndef __config_h
#define __config_h
#include <glib.h>
typedef enum {
Config_String,
Config_Integer
} ConfigValueType;
typedef union {
char *string;
int integer;
} ConfigValue;
typedef struct {
char *name;
ConfigValueType type;
ConfigValue value;
} ConfigEntry;
void config_startup();
void config_shutdown();
gboolean config_set(char *name, ConfigValueType type, ConfigValue value);
void config_parse();
#endif

1672
openbox/cparse.c Normal file

File diff suppressed because it is too large Load diff

95
openbox/cparse.l Normal file
View file

@ -0,0 +1,95 @@
%{
#include <glib.h>
#include "config.h"
static int yylineno = 1;
static gboolean haserror = FALSE;
static ConfigEntry entry = { NULL, -1 };
static void stringvalue();
static void numbervalue();
static void identifier();
static void newline();
static int yywrap();
%}
number [0-9]+
string \"[^"\n]*\"
identifier [a-zA-Z][a-zA-Z0-9_]*
white [ \t]*
assign {white}={white}
%%
{string}/{white}\n stringvalue();
{number}/{white}\n numbervalue();
^{identifier}/{assign} identifier();
\n newline();
=
[ \t]
. haserror = TRUE;
%%
static void stringvalue()
{
if (!haserror && entry.name != NULL && (signed)entry.type < 0) {
entry.type = Config_String;
entry.value.string = g_strdup(yytext+1); /* drop the left quote */
if (entry.value.string[yyleng-2] != '"')
printf("warning: improperly terminated string on line %d\n",
yylineno);
else
entry.value.string[yyleng-2] = '\0';
} else
haserror = TRUE;
}
static void numbervalue()
{
if (!haserror && entry.name != NULL && (signed)entry.type < 0) {
entry.type = Config_Integer;
entry.value.integer = atoi(yytext);
} else
haserror = TRUE;
}
static void identifier()
{
g_print("identifier: %s\n", yytext);
entry.name = g_strdup(yytext);
entry.type = -1;
}
static void newline()
{
if (!haserror && entry.name != NULL && (signed)entry.type >= 0) {
if (!config_set(entry.name, entry.type, entry.value))
g_warning("Invalid option in config file: '%s'\n", entry.name);
} else {
printf("Parser error in config file on line %d\n", yylineno);
}
g_free(entry.name);
entry.name = NULL;
if (entry.type == Config_String)
g_free(entry.value.string);
entry.type = -1;
haserror = FALSE;
++yylineno;
}
static int yywrap()
{
g_free(entry.name);
entry.name = NULL;
if (entry.type == Config_String)
g_free(entry.value.string);
return 1;
}
void cparse_go(FILE *file)
{
yyin = file;
yylex();
}

View file

@ -8,6 +8,7 @@
#include "focus.h"
#include "extensions.h"
#include "gettext.h"
#include "config.h"
#include "grab.h"
#include "engine.h"
#include "themerc.h"
@ -143,6 +144,7 @@ int main(int argc, char **argv)
if (screen_annex()) { /* it will be ours! */
timer_startup();
config_startup();
render_startup();
font_startup();
themerc_startup();
@ -154,6 +156,8 @@ int main(int argc, char **argv)
grab_startup();
plugin_startup();
config_parse();
/* XXX load all plugins!! */
plugin_open("focus");
plugin_open("keyboard");
@ -180,6 +184,7 @@ int main(int argc, char **argv)
engine_shutdown();
themerc_shutdown();
render_shutdown();
config_shutdown();
timer_shutdown();
}