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/variables.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/variables.c') 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; -- cgit v1.2.3