[ob3] config stuff

smoynes at nexus.carleton.ca smoynes at nexus.carleton.ca
Sat Mar 22 13:23:00 EST 2003


Here's a patch for the config system.

It allows the plugins to specify the config parameters they take and
basic information about the type of data. They can register parameter
names and specify if they are strings or integers. If they are
strings, they can either be free form, or given a list of valid
strings using config_def_add_value().
There's currently plenty of issues with memory handling, but I guess
we can fix that up when we decide how to handle reloading the config
file and plugins.
-- 
Scott Moynes http://www.icculus.org/openbox/
"Computer science is as much about computers
as astronomy is about telescopes." -- Dijkstra
-------------- next part --------------
? config-def.diff
? openbox-2_3
? swigpatch.diff
? woodblocks-first-patch.diff
? c/.deps
? c/Makefile
? c/Makefile.in
? data/styles/Makefile
? data/styles/Makefile.in
? engines/ob/Makefile
? engines/ob/Makefile.in
? engines/openbox/semantic.cache
? engines/pwm/.deps
? engines/pwm/.libs
? engines/pwm/Makefile
? engines/pwm/Makefile.in
? engines/pwm/pwm.la
? engines/pwm/pwm.lo
? intl/Makefile
? kernel/menu.c
? kernel/menu.h
? kernel/menunotes
? kernel/ob3
? kernel/semantic.cache
? m4/Makefile
? m4/Makefile.in
? otk/Makefile.in
? otk/otk.py
? otk/otk_wrap.cc
? plugins/resistance.lo
? python/Makefile
? python/Makefile.in
? python/hooks/Makefile
? python/hooks/Makefile.in
? python/ob/Makefile
? python/ob/Makefile.in
? render/semantic.cache
? scripts/Makefile.in
? src/Makefile.in
? src/ob.py
? src/openbox_wrap.cc
? util/.deps
? util/Makefile
? util/Makefile.in
? util/epist/.deps
? util/epist/Makefile
? util/epist/Makefile.in
Index: bootstrap
===================================================================
RCS file: /cvs/cvsroot/openbox/bootstrap,v
retrieving revision 1.13
diff -p -u -r1.13 bootstrap
--- bootstrap	2003/03/16 21:11:38	1.13
+++ bootstrap	2003/03/22 18:14:19
@@ -6,9 +6,9 @@ sh() {
 
 sh autopoint --force # for GNU gettext
 sh libtoolize --copy --force --automake
-sh aclocal -I m4
+sh aclocal -I m4 -I /usr/local/share/aclocal
 #sh autoheader
-sh autoconf
+sh autoconf 
 sh automake --foreign --include-deps --add-missing --copy
 
 echo
Index: kernel/config.c
===================================================================
RCS file: /cvs/cvsroot/openbox/kernel/config.c,v
retrieving revision 1.1
diff -p -u -r1.1 config.c
--- kernel/config.c	2003/03/22 14:41:19	1.1
+++ kernel/config.c	2003/03/22 18:14:19
@@ -4,7 +4,15 @@
 #  include <stdio.h>
 #endif
 
-static GSList *config = NULL;
+void config_free_entry(gpointer entry);
+void config_set_entry(char *name, ConfigValueType type, ConfigValue value);
+void print_config(GQuark q, gpointer data, gpointer fonk){
+    ConfigDefEntry *e = (ConfigDefEntry *)data;
+    g_message("config: %s %d\n", e->name, e->hasList);
+}
+
+static GData *config = NULL;
+static GData *config_def = NULL;
 
 /* provided by cparse.l */
 void cparse_go(FILE *);
@@ -12,6 +20,18 @@ void cparse_go(FILE *);
 
 void config_startup()
 {
+    /* test definition */
+    ConfigDefEntry *def;
+
+    config_def_new(&def, "test", Config_String);
+    config_def_set(def);
+
+    config_def_new(&def, "testlist", Config_String);
+    config_def_add_value(def, "one");
+    config_def_add_value(def, "two");
+    config_def_set(def);
+
+    g_datalist_foreach(&config_def, print_config, NULL);
 }
 
 void config_shutdown()
@@ -32,6 +52,97 @@ void config_parse()
 
 gboolean config_set(char *name, ConfigValueType type, ConfigValue value)
 {
+    ConfigDefEntry *def;
+     
     g_message("Setting %s\n", name);
+
+    g_datalist_foreach(&config_def, print_config, NULL);
+    def = (ConfigDefEntry *) g_datalist_get_data(&config_def, g_strdown(name));
+
+    if (def == NULL)
+    {
+        g_message("Invalid config option '%s'\n", name);
+    }
+    else
+    {
+        if (def->hasList)
+        {
+            gboolean found = FALSE;
+            GSList *i = def->values;
+
+            do
+            {
+                if (g_strcasecmp((char *)i->data, value.string) == 0)
+                {
+                    found = TRUE;
+                    break;
+                }
+            }while( (i = g_slist_next(i)) );
+            
+
+            if (found)
+                config_set_entry(name, type, value);
+            else
+                g_message("Invalid value '%s' for config option '%s'",
+                          value.string, name);
+        }
+
+        config_set_entry(name, type, value);
+    }
+    return TRUE;
+}
+
+void config_set_entry(char *name, ConfigValueType type, ConfigValue value)
+{
+    ConfigEntry *entry = NULL;
+
+    
+    entry = g_malloc(sizeof(ConfigEntry));
+    entry->name = g_strdup(name);
+    entry->type = type;
+    if (type == Config_String)
+        entry->value.string = g_strdup(value.string);
+    else
+        entry->value = value;
+
+    g_datalist_set_data_full(&config, name, entry, config_free_entry);
+}
+
+void config_free_entry(gpointer p)
+{
+    ConfigEntry *entry = (ConfigEntry *)p;
+    g_free(entry->name);
+    entry->name = NULL;
+    if(entry->type == Config_String)
+        g_free(entry->value.string);
+    entry->value.string = NULL;
+    g_free(entry);
+    entry = NULL;
+}
+
+void config_def_new(ConfigDefEntry **entry, char *name, ConfigValueType type)
+{
+    *entry = g_malloc(sizeof(ConfigDefEntry));
+    (*entry)->name = name;
+    (*entry)->hasList = FALSE;
+    (*entry)->type = type;
+    (*entry)->values = NULL;
+}
+
+gboolean config_def_add_value(ConfigDefEntry *entry, char *value)
+{
+    if (entry->type != Config_String) {
+        g_message("Error: Tried adding value to non-string config definition\n");
+        return FALSE;
+    }
+
+    entry->hasList = TRUE;
+    entry->values = g_slist_append(entry->values, value);
+    return TRUE;
+}
+
+gboolean config_def_set(ConfigDefEntry *entry)
+{
+    g_datalist_set_data(&config_def, g_strdown(entry->name), entry);
     return TRUE;
 }
Index: kernel/config.h
===================================================================
RCS file: /cvs/cvsroot/openbox/kernel/config.h,v
retrieving revision 1.1
diff -p -u -r1.1 config.h
--- kernel/config.h	2003/03/22 14:41:19	1.1
+++ kernel/config.h	2003/03/22 18:14:19
@@ -19,10 +19,23 @@ typedef struct {
     ConfigValue value;
 } ConfigEntry;
 
+typedef struct {
+    char *name;
+    ConfigValueType type;
+    /* if it is a string type optionally provide a list of valid strings */
+    gboolean hasList;
+    GSList *values;
+} ConfigDefEntry;
+
 void config_startup();
 void config_shutdown();
 
 gboolean config_set(char *name, ConfigValueType type, ConfigValue value);
+
+/* XXX: aiee. what to do about memory? */
+void config_def_new(ConfigDefEntry **entry, char *name, ConfigValueType type);
+gboolean config_def_add_value(ConfigDefEntry *entry, char *value);
+gboolean config_def_set(ConfigDefEntry *entry);
 
 void config_parse();
 


More information about the openbox mailing list