aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/variables.c
diff options
context:
space:
mode:
authorGravatar David Keijser <keijser@gmail.com>2011-05-30 19:15:01 +0200
committerGravatar David Keijser <keijser@gmail.com>2011-05-30 19:15:01 +0200
commit1110023039fa7d13e2ddab29d6a7db50ab61f2ae (patch)
tree2d9b6800c40e8cb7f4ad02253e03ee3fb1f318f7 /src/variables.c
parentda8e6d70e09c9c92c55b110ada1d3bcc63889a72 (diff)
hide some implementation details of variables
Diffstat (limited to 'src/variables.c')
-rw-r--r--src/variables.c29
1 files changed, 29 insertions, 0 deletions
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;