Removed trailing whitespace from uzbl_tabbed.py
[uzbl-mobile] / uzbl.c
diff --git a/uzbl.c b/uzbl.c
index 0852acb..e2148fd 100644 (file)
--- a/uzbl.c
+++ b/uzbl.c
@@ -53,6 +53,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <signal.h>
+#include <assert.h>
 #include <poll.h>
 #include <sys/uio.h>
 #include <sys/ioctl.h>
@@ -86,9 +87,7 @@ GOptionEntry entries[] =
 enum ptr_type {TYPE_INT, TYPE_STR, TYPE_FLOAT};
 
 /* associate command names to their properties */
-typedef const struct {
-    /* TODO: Make this ambiguous void **ptr into a union { char *char_p; int *int_p; float *float_p; } val;
-             the PTR() macro is kind of preventing this change at the moment. */
+typedef struct {
     enum ptr_type type;
     union {
         int *i;
@@ -223,10 +222,12 @@ const struct {
 /* construct a hash from the var_name_to_ptr array for quick access */
 void
 make_var_to_name_hash() {
-    struct var_name_to_ptr_t *n2v_p = &var_name_to_ptr;
+    const struct var_name_to_ptr_t *n2v_p = var_name_to_ptr;
     uzbl.comm.proto_var = g_hash_table_new(g_str_hash, g_str_equal);
     while(n2v_p->name) {
-        g_hash_table_insert(uzbl.comm.proto_var, n2v_p->name, (gpointer) &n2v_p->cp);
+        g_hash_table_insert(uzbl.comm.proto_var,
+                (gpointer) n2v_p->name,
+                (gpointer) &n2v_p->cp);
         n2v_p++;
     }
 }
@@ -304,6 +305,9 @@ expand(const char *s, guint recurse) {
                         vend = strstr(s, "]@");
                         if(!vend) vend = strchr(s, '\0');
                         break;
+                    /*@notreached@*/
+                    case EXP_ERR:
+                        break;
                 }
                 assert(vend);
 
@@ -314,7 +318,8 @@ expand(const char *s, guint recurse) {
                     if( (c = g_hash_table_lookup(uzbl.comm.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) {
+                        }
+                        else if(c->type == TYPE_INT) {
                             g_string_append_printf(buf, "%d", *c->ptr.i);
                         }
                         else if(c->type == TYPE_FLOAT) {
@@ -651,7 +656,7 @@ cmd_set_geometry() {
        the above setting and we don't want to end up with
        wrong geometry information
     */
-    retreive_geometry();
+    retrieve_geometry();
 }
 
 void
@@ -834,7 +839,8 @@ struct {const char *key; CommandInfo value;} cmdlist[] =
     { "keycmd_nl",          {keycmd_nl, TRUE}              },
     { "keycmd_bs",          {keycmd_bs, 0}                 },
     { "chain",              {chain, 0}                     },
-    { "print",              {print, TRUE}                  }
+    { "print",              {print, TRUE}                  },
+    { "update_gui",         {update_gui, TRUE}           }
 };
 
 void
@@ -844,7 +850,7 @@ commands_hash(void)
     uzbl.behave.commands = g_hash_table_new(g_str_hash, g_str_equal);
 
     for (i = 0; i < LENGTH(cmdlist); i++)
-        g_hash_table_insert(uzbl.behave.commands, cmdlist[i].key, &cmdlist[i].value);
+        g_hash_table_insert(uzbl.behave.commands, (gpointer) cmdlist[i].key, &cmdlist[i].value);
 }
 
 /* -- CORE FUNCTIONS -- */
@@ -889,6 +895,13 @@ set_var(WebKitWebView *page, GArray *argv, GString *result) {
 }
 
 void
+update_gui(WebKitWebView *page, GArray *argv, GString *result) {
+    (void) page; (void) argv; (void) result;
+
+    update_title();
+}
+
+void
 print(WebKitWebView *page, GArray *argv, GString *result) {
     (void) page; (void) result;
     gchar* buf;
@@ -1834,6 +1847,10 @@ cmd_useragent() {
 
 void
 move_statusbar() {
+    if (!uzbl.gui.scrolled_win &&
+            !uzbl.gui.mainbar)
+        return;
+
     gtk_widget_ref(uzbl.gui.scrolled_win);
     gtk_widget_ref(uzbl.gui.mainbar);
     gtk_container_remove(GTK_CONTAINER(uzbl.gui.vbox), uzbl.gui.scrolled_win);
@@ -1858,6 +1875,7 @@ set_var_value(const gchar *name, gchar *val) {
     uzbl_cmdprop *c = NULL;
     char *endp = NULL;
     char *buf = NULL;
+    char *invalid_chars = "^°!\"§$%&/()=?'`'+~*'#-.:,;@<>| \\{}[]¹²³¼½";
 
     if( (c = g_hash_table_lookup(uzbl.comm.proto_var, name)) ) {
         if(!c->writeable) return FALSE;
@@ -1879,6 +1897,25 @@ set_var_value(const gchar *name, gchar *val) {
 
         /* invoke a command specific function */
         if(c->func) c->func();
+    } else {
+        /* check wether name violates our naming scheme */
+        if(strpbrk(name, invalid_chars)) {
+            if (uzbl.state.verbose)
+                printf("Invalid variable name\n");
+            return FALSE;
+        }
+
+        /* custom vars */
+        c = malloc(sizeof(uzbl_cmdprop));
+        c->type = TYPE_STR;
+        c->dump = 0;
+        c->func = NULL;
+        c->writeable = 1;
+        buf = expand(val, 0);
+        c->ptr.s = malloc(sizeof(char *));
+        *c->ptr.s = buf;
+        g_hash_table_insert(uzbl.comm.proto_var,
+                g_strdup(name), (gpointer) c);
     }
     return TRUE;
 }
@@ -2191,7 +2228,7 @@ configure_event_cb(GtkWidget* window, GdkEventConfigure* event) {
     (void) window;
     (void) event;
 
-    retreive_geometry();
+    retrieve_geometry();
     return FALSE;
 }
 
@@ -2762,7 +2799,7 @@ dump_config() {
 }
 
 void
-retreive_geometry() {
+retrieve_geometry() {
     int w, h, x, y;
     GString *buf = g_string_new("");
 
@@ -2892,10 +2929,13 @@ main (int argc, char* argv[]) {
     uzbl.gui.bar_h = gtk_range_get_adjustment((GtkRange*) uzbl.gui.scbar_h);
     gtk_widget_set_scroll_adjustments ((GtkWidget*) uzbl.gui.web_view, uzbl.gui.bar_h, uzbl.gui.bar_v);
 
-    if(uzbl.gui.geometry)
-        cmd_set_geometry();
-    else
-        retreive_geometry();
+    /* Check uzbl is in window mode before getting/setting geometry */
+    if (uzbl.gui.main_window) {
+        if(uzbl.gui.geometry)
+            cmd_set_geometry();
+        else
+            retrieve_geometry();
+    }
 
     gchar *uri_override = (uzbl.state.uri ? g_strdup(uzbl.state.uri) : NULL);
     if (argc > 1 && !uzbl.state.uri)