From 1110023039fa7d13e2ddab29d6a7db50ab61f2ae Mon Sep 17 00:00:00 2001 From: David Keijser Date: Mon, 30 May 2011 19:15:01 +0200 Subject: hide some implementation details of variables --- src/commands.c | 1 + src/uzbl-core.c | 15 +++------------ src/variables.c | 29 +++++++++++++++++++++++++++++ src/variables.h | 16 +--------------- 4 files changed, 34 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/commands.c b/src/commands.c index c4a4d34..c4f63af 100644 --- a/src/commands.c +++ b/src/commands.c @@ -5,6 +5,7 @@ #include "menu.h" #include "callbacks.h" #include "variables.h" +#include "type.h" /* -- command to callback/function map for things we cannot attach to any signals */ CommandInfo cmdlist[] = diff --git a/src/uzbl-core.c b/src/uzbl-core.c index 91a9cd0..6f82d2e 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -38,6 +38,7 @@ #include "menu.h" #include "io.h" #include "variables.h" +#include "type.h" UzblCore uzbl; @@ -90,7 +91,6 @@ get_exp_type(const gchar *s) { */ gchar* expand(const char* s, guint recurse) { - uzbl_cmdprop* c; enum exp_type etype; char* end_simple_var = "\t^°!\"§$%&/()=?'`'+~*'#-:,;@<>| \\{}[]¹²³¼½"; char* ret = NULL; @@ -147,17 +147,8 @@ expand(const char* s, guint recurse) { if(etype == EXP_SIMPLE_VAR || etype == EXP_BRACED_VAR) { - if( (c = g_hash_table_lookup(uzbl.behave.proto_var, ret)) ) { - if(c->type == TYPE_STR && *c->ptr.s != NULL) { - g_string_append(buf, (gchar *)*c->ptr.s); - } - else if(c->type == TYPE_INT) { - g_string_append_printf(buf, "%d", *c->ptr.i); - } - else if(c->type == TYPE_FLOAT) { - g_string_append_printf(buf, "%f", *c->ptr.f); - } - } + + expand_variable(buf, ret); if(etype == EXP_SIMPLE_VAR) s = vend; diff --git a/src/variables.c b/src/variables.c index e22d079..a3621dd 100644 --- a/src/variables.c +++ b/src/variables.c @@ -4,6 +4,7 @@ #include "events.h" #include "io.h" #include "util.h" +#include "type.h" /* abbreviations to help keep the table's width humane */ #define PTR_V_STR(var, d, fun) { .ptr.s = &(var), .type = TYPE_STR, .dump = d, .writeable = 1, .func = fun } @@ -13,6 +14,18 @@ #define PTR_C_INT(var, fun) { .ptr.i = (int*)&(var), .type = TYPE_INT, .dump = 0, .writeable = 0, .func = fun } #define PTR_C_FLOAT(var, fun) { .ptr.f = &(var), .type = TYPE_FLOAT, .dump = 0, .writeable = 0, .func = fun } +typedef struct { + enum ptr_type type; + union { + int *i; + float *f; + gchar **s; + } ptr; + int dump; + int writeable; + /*@null@*/ void (*func)(void); +} uzbl_cmdprop; + const struct var_name_to_ptr_t { const char *name; uzbl_cmdprop cp; @@ -138,6 +151,22 @@ send_set_var_event(const char *name, const uzbl_cmdprop *c) { } } +void +expand_variable(GString *buf, const gchar *name) { + uzbl_cmdprop* c; + if((c = g_hash_table_lookup(uzbl.behave.proto_var, name))) { + if(c->type == TYPE_STR && *c->ptr.s != NULL) { + g_string_append(buf, (gchar *)*c->ptr.s); + } + else if(c->type == TYPE_INT) { + g_string_append_printf(buf, "%d", *c->ptr.i); + } + else if(c->type == TYPE_FLOAT) { + g_string_append_printf(buf, "%f", *c->ptr.f); + } + } +} + gboolean set_var_value(const gchar *name, gchar *val) { uzbl_cmdprop *c = NULL; diff --git a/src/variables.h b/src/variables.h index c289c44..035c500 100644 --- a/src/variables.h +++ b/src/variables.h @@ -7,23 +7,9 @@ #include #include -#include "type.h" - -/* Uzbl variables */ - -typedef struct { - enum ptr_type type; - union { - int *i; - float *f; - gchar **s; - } ptr; - int dump; - int writeable; - /*@null@*/ void (*func)(void); -} uzbl_cmdprop; gboolean set_var_value(const gchar *name, gchar *val); +void expand_variable(GString *buf, const gchar *name); void variables_hash(); void dump_config(); void dump_config_as_events(); -- cgit v1.2.3