From 6760049bbc890ee6dd2f56ff270bfa730996cd58 Mon Sep 17 00:00:00 2001 From: Robert Manea Date: Tue, 26 May 2009 23:13:19 +0200 Subject: fix stupid comment --- uzbl.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/uzbl.c b/uzbl.c index 9b07593..ae00462 100644 --- a/uzbl.c +++ b/uzbl.c @@ -1451,7 +1451,6 @@ parse_cmd_line(const char *ctl_line) { Behaviour *b = &uzbl.behave; if(b->mode == M_HTML) { - if(!strncmp(b->html_endmarker, ctl_line, strlen(b->html_endmarker))) { set_timeout(0); set_var_value("mode", "0"); @@ -1459,7 +1458,6 @@ parse_cmd_line(const char *ctl_line) { return; } else { - /* set an alarm to kill us after the timeout */ set_timeout(b->html_timeout); g_string_append(b->html_buffer, ctl_line); } -- cgit v1.2.3 From 84f95f1b5a985790d03daff6ee97bd3b22205684 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Tue, 26 May 2009 23:22:12 +0200 Subject: more precise gtk dep --- docs/INSTALL | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/INSTALL b/docs/INSTALL index 440157a..3453e03 100644 --- a/docs/INSTALL +++ b/docs/INSTALL @@ -29,7 +29,7 @@ Dependencies * pkgconfig (for Make/gcc) * libwebkit 1.1.4 or higher * libsoup 2.24 or higher (dep for webkit/gtk+) -* gtk 2 something something +* gtk 2.14 or higher Optional/Recommended -------------------- -- cgit v1.2.3 From 6dcbd38b46b3d43af443f297348f406250fe9fce Mon Sep 17 00:00:00 2001 From: Robert Manea Date: Wed, 27 May 2009 10:22:51 +0200 Subject: added dump_config action --- uzbl.c | 44 +++++++++++++++++++++++++++++++++++++++----- uzbl.h | 12 ++++++++++++ 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/uzbl.c b/uzbl.c index 5748a2b..411c2f2 100644 --- a/uzbl.c +++ b/uzbl.c @@ -386,23 +386,27 @@ scroll (GtkAdjustment* bar, GArray *argv) { gtk_adjustment_set_value (bar, gtk_adjustment_get_value(bar)+amount); } -static void scroll_begin(WebKitWebView* page, GArray *argv) { +static void +scroll_begin(WebKitWebView* page, GArray *argv) { (void) page; (void) argv; gtk_adjustment_set_value (uzbl.gui.bar_v, gtk_adjustment_get_lower(uzbl.gui.bar_v)); } -static void scroll_end(WebKitWebView* page, GArray *argv) { +static void +scroll_end(WebKitWebView* page, GArray *argv) { (void) page; (void) argv; gtk_adjustment_set_value (uzbl.gui.bar_v, gtk_adjustment_get_upper(uzbl.gui.bar_v) - gtk_adjustment_get_page_size(uzbl.gui.bar_v)); } -static void scroll_vert(WebKitWebView* page, GArray *argv) { +static void +scroll_vert(WebKitWebView* page, GArray *argv) { (void) page; scroll(uzbl.gui.bar_v, argv); } -static void scroll_horz(WebKitWebView* page, GArray *argv) { +static void +scroll_horz(WebKitWebView* page, GArray *argv) { (void) page; scroll(uzbl.gui.bar_h, argv); } @@ -559,7 +563,8 @@ static struct {char *name; Command command[2];} cmdlist[] = { "dehilight", {dehilight, 0} }, { "toggle_insert_mode", {toggle_insert_mode, 0} }, { "runcmd", {runcmd, NOSPLIT} }, - { "set", {set_var, NOSPLIT} } + { "set", {set_var, NOSPLIT} }, + { "dump_config", {act_dump_config, 0} } }; static void @@ -611,6 +616,11 @@ set_var(WebKitWebView *page, GArray *argv) { g_free(ctl_line); } +static void +act_dump_config() { + dump_config(); +} + static void toggle_insert_mode(WebKitWebView *page, GArray *argv) { (void)page; @@ -2215,7 +2225,31 @@ set_up_inspector() { g_signal_connect (G_OBJECT (g->inspector), "notify::inspected-uri", G_CALLBACK (inspector_uri_changed_cb), NULL); } +static void +dump_var_hash(gpointer k, gpointer v, gpointer ud) { + (void) ud; + uzbl_cmdprop *c = v; + + if(c->type == TYPE_STR) + printf("set %s = %s\n", (char *)k, *c->ptr?(char *)*c->ptr:" "); + else if(c->type == TYPE_INT) + printf("set %s = %d\n", (char *)k, (int)*c->ptr); +} + +static void +dump_key_hash(gpointer k, gpointer v, gpointer ud) { + (void) ud; + Action *a = v; + + printf("bind %s = %s %s\n", (char *)k , + (char *)a->name, a->param?(char *)a->param:""); +} +static void +dump_config() { + g_hash_table_foreach(uzbl.comm.proto_var, dump_var_hash, NULL); + g_hash_table_foreach(uzbl.bindings, dump_key_hash, NULL); +} /** -- MAIN -- **/ int diff --git a/uzbl.h b/uzbl.h index cd5e3ef..287d9ef 100644 --- a/uzbl.h +++ b/uzbl.h @@ -416,12 +416,24 @@ save_cookies (SoupMessage *msg, static void set_var(WebKitWebView *page, GArray *argv); +static void +act_dump_config(); + static void render_html(); static void set_timeout(int seconds); +static void +dump_var_hash(gpointer k, gpointer v, gpointer ud); + +static void +dump_key_hash(gpointer k, gpointer v, gpointer ud); + +static void +dump_config(); + /* Command callbacks */ static void -- cgit v1.2.3 From 1c0197ef6ea14e57854a6dcd3de0bc331fb6e470 Mon Sep 17 00:00:00 2001 From: Robert Manea Date: Wed, 27 May 2009 10:49:03 +0200 Subject: added dump identifier to uzbl_cmdprop --- uzbl.c | 110 ++++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 57 insertions(+), 53 deletions(-) diff --git a/uzbl.c b/uzbl.c index 411c2f2..282be1b 100644 --- a/uzbl.c +++ b/uzbl.c @@ -81,72 +81,73 @@ GOptionEntry entries[] = typedef const struct { void **ptr; int type; + int dump; void (*func)(void); } uzbl_cmdprop; enum {TYPE_INT, TYPE_STR}; /* an abbreviation to help keep the table's width humane */ -#define PTR(var, t, fun) { .ptr = (void*)&(var), .type = TYPE_##t, .func = fun } +#define PTR(var, t, d, fun) { .ptr = (void*)&(var), .type = TYPE_##t, .dump = d,.func = fun } const struct { char *name; uzbl_cmdprop cp; } var_name_to_ptr[] = { -/* variable name pointer to variable in code type callback function */ +/* variable name pointer to variable in code type dump callback function */ /* --------------------------------------------------------------------------------------- */ - { "uri", PTR(uzbl.state.uri, STR, cmd_load_uri)}, - { "mode", PTR(uzbl.behave.mode, INT, NULL)}, - { "inject_html", PTR(uzbl.behave.inject_html, STR, cmd_inject_html)}, - { "base_url", PTR(uzbl.behave.base_url, STR, NULL)}, - { "html_endmarker", PTR(uzbl.behave.html_endmarker, STR, NULL)}, - { "html_mode_timeout", PTR(uzbl.behave.html_timeout, INT, NULL)}, - { "status_message", PTR(uzbl.gui.sbar.msg, STR, update_title)}, - { "show_status", PTR(uzbl.behave.show_status, INT, cmd_set_status)}, - { "status_top", PTR(uzbl.behave.status_top, INT, move_statusbar)}, - { "status_format", PTR(uzbl.behave.status_format, STR, update_title)}, - { "status_pbar_done", PTR(uzbl.gui.sbar.progress_s, STR, update_title)}, - { "status_pbar_pending", PTR(uzbl.gui.sbar.progress_u, STR, update_title)}, - { "status_pbar_width", PTR(uzbl.gui.sbar.progress_w, INT, update_title)}, - { "status_background", PTR(uzbl.behave.status_background, STR, update_title)}, - { "title_format_long", PTR(uzbl.behave.title_format_long, STR, update_title)}, - { "title_format_short", PTR(uzbl.behave.title_format_short, STR, update_title)}, - { "insert_mode", PTR(uzbl.behave.insert_mode, INT, NULL)}, - { "always_insert_mode", PTR(uzbl.behave.always_insert_mode, INT, cmd_always_insert_mode)}, - { "reset_command_mode", PTR(uzbl.behave.reset_command_mode, INT, NULL)}, - { "modkey", PTR(uzbl.behave.modkey, STR, cmd_modkey)}, - { "load_finish_handler", PTR(uzbl.behave.load_finish_handler, STR, NULL)}, - { "load_start_handler", PTR(uzbl.behave.load_start_handler, STR, NULL)}, - { "load_commit_handler", PTR(uzbl.behave.load_commit_handler, STR, NULL)}, - { "history_handler", PTR(uzbl.behave.history_handler, STR, NULL)}, - { "download_handler", PTR(uzbl.behave.download_handler, STR, NULL)}, - { "cookie_handler", PTR(uzbl.behave.cookie_handler, STR, cmd_cookie_handler)}, - { "fifo_dir", PTR(uzbl.behave.fifo_dir, STR, cmd_fifo_dir)}, - { "socket_dir", PTR(uzbl.behave.socket_dir, STR, cmd_socket_dir)}, - { "http_debug", PTR(uzbl.behave.http_debug, INT, cmd_http_debug)}, - { "shell_cmd", PTR(uzbl.behave.shell_cmd, STR, NULL)}, - { "proxy_url", PTR(uzbl.net.proxy_url, STR, set_proxy_url)}, - { "max_conns", PTR(uzbl.net.max_conns, INT, cmd_max_conns)}, - { "max_conns_host", PTR(uzbl.net.max_conns_host, INT, cmd_max_conns_host)}, - { "useragent", PTR(uzbl.net.useragent, STR, cmd_useragent)}, + { "uri", PTR(uzbl.state.uri, STR, 1, cmd_load_uri)}, + { "mode", PTR(uzbl.behave.mode, INT, 0, NULL)}, + { "inject_html", PTR(uzbl.behave.inject_html, STR, 0, cmd_inject_html)}, + { "base_url", PTR(uzbl.behave.base_url, STR, 1, NULL)}, + { "html_endmarker", PTR(uzbl.behave.html_endmarker, STR, 1, NULL)}, + { "html_mode_timeout", PTR(uzbl.behave.html_timeout, INT, 1, NULL)}, + { "status_message", PTR(uzbl.gui.sbar.msg, STR, 1, update_title)}, + { "show_status", PTR(uzbl.behave.show_status, INT, 1, cmd_set_status)}, + { "status_top", PTR(uzbl.behave.status_top, INT, 1, move_statusbar)}, + { "status_format", PTR(uzbl.behave.status_format, STR, 1, update_title)}, + { "status_pbar_done", PTR(uzbl.gui.sbar.progress_s, STR, 1, update_title)}, + { "status_pbar_pending", PTR(uzbl.gui.sbar.progress_u, STR, 1, update_title)}, + { "status_pbar_width", PTR(uzbl.gui.sbar.progress_w, INT, 1, update_title)}, + { "status_background", PTR(uzbl.behave.status_background, STR, 1, update_title)}, + { "title_format_long", PTR(uzbl.behave.title_format_long, STR, 1, update_title)}, + { "title_format_short", PTR(uzbl.behave.title_format_short, STR, 1, update_title)}, + { "insert_mode", PTR(uzbl.behave.insert_mode, INT, 1, NULL)}, + { "always_insert_mode", PTR(uzbl.behave.always_insert_mode, INT, 1, cmd_always_insert_mode)}, + { "reset_command_mode", PTR(uzbl.behave.reset_command_mode, INT, 1, NULL)}, + { "modkey", PTR(uzbl.behave.modkey, STR, 1, cmd_modkey)}, + { "load_finish_handler", PTR(uzbl.behave.load_finish_handler, STR, 1, NULL)}, + { "load_start_handler", PTR(uzbl.behave.load_start_handler, STR, 1, NULL)}, + { "load_commit_handler", PTR(uzbl.behave.load_commit_handler, STR, 1, NULL)}, + { "history_handler", PTR(uzbl.behave.history_handler, STR, 1, NULL)}, + { "download_handler", PTR(uzbl.behave.download_handler, STR, 1, NULL)}, + { "cookie_handler", PTR(uzbl.behave.cookie_handler, STR, 1, cmd_cookie_handler)}, + { "fifo_dir", PTR(uzbl.behave.fifo_dir, STR, 1, cmd_fifo_dir)}, + { "socket_dir", PTR(uzbl.behave.socket_dir, STR, 1, cmd_socket_dir)}, + { "http_debug", PTR(uzbl.behave.http_debug, INT, 1, cmd_http_debug)}, + { "shell_cmd", PTR(uzbl.behave.shell_cmd, STR, 1, NULL)}, + { "proxy_url", PTR(uzbl.net.proxy_url, STR, 1, set_proxy_url)}, + { "max_conns", PTR(uzbl.net.max_conns, INT, 1, cmd_max_conns)}, + { "max_conns_host", PTR(uzbl.net.max_conns_host, INT, 1, cmd_max_conns_host)}, + { "useragent", PTR(uzbl.net.useragent, STR, 1, cmd_useragent)}, /* exported WebKitWebSettings properties*/ - { "font_size", PTR(uzbl.behave.font_size, INT, cmd_font_size)}, - { "monospace_size", PTR(uzbl.behave.monospace_size, INT, cmd_font_size)}, - { "minimum_font_size", PTR(uzbl.behave.minimum_font_size, INT, cmd_minimum_font_size)}, - { "disable_plugins", PTR(uzbl.behave.disable_plugins, INT, cmd_disable_plugins)}, - { "disable_scripts", PTR(uzbl.behave.disable_scripts, INT, cmd_disable_scripts)}, - { "autoload_images", PTR(uzbl.behave.autoload_img, INT, cmd_autoload_img)}, - { "autoshrink_images", PTR(uzbl.behave.autoshrink_img, INT, cmd_autoshrink_img)}, - { "enable_spellcheck", PTR(uzbl.behave.enable_spellcheck, INT, cmd_enable_spellcheck)}, - { "enable_private", PTR(uzbl.behave.enable_private, INT, cmd_enable_private)}, - { "print_backgrounds", PTR(uzbl.behave.print_bg, INT, cmd_print_bg)}, - { "stylesheet_uri", PTR(uzbl.behave.style_uri, STR, cmd_style_uri)}, - { "resizable_text_areas",PTR(uzbl.behave.resizable_txt, INT, cmd_resizable_txt)}, - { "default_encoding", PTR(uzbl.behave.default_encoding, STR, cmd_default_encoding)}, - { "enforce_96_dpi", PTR(uzbl.behave.enforce_96dpi, INT, cmd_enforce_96dpi)}, - { "caret_browsing", PTR(uzbl.behave.caret_browsing, INT, cmd_caret_browsing)}, - - { NULL, {.ptr = NULL, .type = TYPE_INT, .func = NULL}} + { "font_size", PTR(uzbl.behave.font_size, INT, 1, cmd_font_size)}, + { "monospace_size", PTR(uzbl.behave.monospace_size, INT, 1, cmd_font_size)}, + { "minimum_font_size", PTR(uzbl.behave.minimum_font_size, INT, 1, cmd_minimum_font_size)}, + { "disable_plugins", PTR(uzbl.behave.disable_plugins, INT, 1, cmd_disable_plugins)}, + { "disable_scripts", PTR(uzbl.behave.disable_scripts, INT, 1, cmd_disable_scripts)}, + { "autoload_images", PTR(uzbl.behave.autoload_img, INT, 1, cmd_autoload_img)}, + { "autoshrink_images", PTR(uzbl.behave.autoshrink_img, INT, 1, cmd_autoshrink_img)}, + { "enable_spellcheck", PTR(uzbl.behave.enable_spellcheck, INT, 1, cmd_enable_spellcheck)}, + { "enable_private", PTR(uzbl.behave.enable_private, INT, 1, cmd_enable_private)}, + { "print_backgrounds", PTR(uzbl.behave.print_bg, INT, 1, cmd_print_bg)}, + { "stylesheet_uri", PTR(uzbl.behave.style_uri, STR, 1, cmd_style_uri)}, + { "resizable_text_areas",PTR(uzbl.behave.resizable_txt, INT, 1, cmd_resizable_txt)}, + { "default_encoding", PTR(uzbl.behave.default_encoding, STR, 1, cmd_default_encoding)}, + { "enforce_96_dpi", PTR(uzbl.behave.enforce_96dpi, INT, 1, cmd_enforce_96dpi)}, + { "caret_browsing", PTR(uzbl.behave.caret_browsing, INT, 1, cmd_caret_browsing)}, + + { NULL, {.ptr = NULL, .type = TYPE_INT, .dump = 0, .func = NULL}} }, *n2v_p = var_name_to_ptr; const struct { @@ -2230,6 +2231,9 @@ dump_var_hash(gpointer k, gpointer v, gpointer ud) { (void) ud; uzbl_cmdprop *c = v; + if(!c->dump) + return; + if(c->type == TYPE_STR) printf("set %s = %s\n", (char *)k, *c->ptr?(char *)*c->ptr:" "); else if(c->type == TYPE_INT) -- cgit v1.2.3 From eacd934e6456f354df9a1eaedee7e10964eea90c Mon Sep 17 00:00:00 2001 From: Robert Manea Date: Wed, 27 May 2009 13:14:51 +0200 Subject: added insert_indicator and command_indicator --- uzbl.c | 11 +++++++++-- uzbl.h | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/uzbl.c b/uzbl.c index 282be1b..0fc5911 100644 --- a/uzbl.c +++ b/uzbl.c @@ -88,7 +88,7 @@ typedef const struct { enum {TYPE_INT, TYPE_STR}; /* an abbreviation to help keep the table's width humane */ -#define PTR(var, t, d, fun) { .ptr = (void*)&(var), .type = TYPE_##t, .dump = d,.func = fun } +#define PTR(var, t, d, fun) { .ptr = (void*)&(var), .type = TYPE_##t, .dump = d, .func = fun } const struct { char *name; @@ -110,6 +110,8 @@ const struct { { "status_pbar_pending", PTR(uzbl.gui.sbar.progress_u, STR, 1, update_title)}, { "status_pbar_width", PTR(uzbl.gui.sbar.progress_w, INT, 1, update_title)}, { "status_background", PTR(uzbl.behave.status_background, STR, 1, update_title)}, + { "insert_indicator", PTR(uzbl.behave.insert_indicator, STR, 1, update_title)}, + { "command_indicator", PTR(uzbl.behave.cmd_indicator, STR, 1, update_title)}, { "title_format_long", PTR(uzbl.behave.title_format_long, STR, 1, update_title)}, { "title_format_short", PTR(uzbl.behave.title_format_short, STR, 1, update_title)}, { "insert_mode", PTR(uzbl.behave.insert_mode, INT, 1, NULL)}, @@ -904,7 +906,8 @@ expand_template(const char *template, gboolean escape_markup) { break; case SYM_MODE: g_string_append(ret, - uzbl.behave.insert_mode?"[I]":"[C]"); + uzbl.behave.insert_mode? + uzbl.behave.insert_indicator:uzbl.behave.cmd_indicator); break; case SYM_MSG: g_string_append(ret, @@ -2297,6 +2300,10 @@ main (int argc, char* argv[]) { uzbl.behave.html_timeout = 60; uzbl.behave.base_url = g_strdup("http://invalid"); + /* default mode indicators */ + uzbl.behave.insert_indicator = g_strdup("I"); + uzbl.behave.cmd_indicator = g_strdup("C"); + setup_regex(); setup_scanner(); commands_hash (); diff --git a/uzbl.h b/uzbl.h index 287d9ef..8618675 100644 --- a/uzbl.h +++ b/uzbl.h @@ -171,6 +171,8 @@ typedef struct { guint mode; gchar* base_url; gchar* html_endmarker; + gchar* insert_indicator; + gchar* cmd_indicator; GString* html_buffer; guint html_timeout; -- cgit v1.2.3 From 06badfff71f5f2bf3ab4945e6edbd8471517f557 Mon Sep 17 00:00:00 2001 From: Robert Manea Date: Wed, 27 May 2009 16:00:30 +0200 Subject: make check for html_end_marker safe --- uzbl.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/uzbl.c b/uzbl.c index 0fc5911..ba6655a 100644 --- a/uzbl.c +++ b/uzbl.c @@ -1471,9 +1471,13 @@ static void parse_cmd_line(const char *ctl_line) { gchar **tokens = NULL; Behaviour *b = &uzbl.behave; + size_t len=0; if(b->mode == M_HTML) { - if(!strncmp(b->html_endmarker, ctl_line, strlen(b->html_endmarker))) { + len = strlen(b->html_endmarker); + /* ctl_line has trailing '\n' so we check for strlen(ctl_line)-1 */ + if(len == strlen(ctl_line)-1 && + !strncmp(b->html_endmarker, ctl_line, len)) { set_timeout(0); set_var_value("mode", "0"); render_html(); -- cgit v1.2.3 From 075fe52dac7f032640669f7c454789ba6506f1b6 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Wed, 27 May 2009 21:40:20 +0200 Subject: put sample indicators in config --- examples/configs/sampleconfig-dev | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/configs/sampleconfig-dev b/examples/configs/sampleconfig-dev index 3deeac1..0dcc0d2 100644 --- a/examples/configs/sampleconfig-dev +++ b/examples/configs/sampleconfig-dev @@ -60,7 +60,7 @@ set shell_cmd = sh -c set show_status = 1 # you can optionally use this setting to override the background color of the statusbar from your GTK theme. set status_background = #303030 -set status_format = MODE [KEYCMD] LOAD_PROGRESSBAR URI NAME MSGSELECTED_URI +set status_format = [MODE] [KEYCMD] LOAD_PROGRESSBAR URI NAME MSGSELECTED_URI set status_top = 0 # define how your titlebar should look like. (short = statusbar is also shown, long = show everything you must see if statusbar is off) set title_format_short = TITLE - Uzbl browser @@ -69,7 +69,8 @@ set title_format_long = KEYCMD MODE TITLE - Uzbl browser > SELECTED_URI set status_pbar_done = * set status_pbar_pending = - set status_pbar_width = 12 - +set insert_indicator = I +set command_indicator = C set modkey = Mod1 # reset to command mode when new page is loaded set reset_command_mode = 1 -- cgit v1.2.3 From 7b2b1b142159f2c7ec0de334b303723dd2c6e70c Mon Sep 17 00:00:00 2001 From: DuClare Date: Thu, 28 May 2009 15:53:09 +0300 Subject: Add action 'keycmd_bs' for backspacing a char --- uzbl.c | 17 ++++++++++++----- uzbl.h | 3 +++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/uzbl.c b/uzbl.c index ba6655a..a8b97c4 100644 --- a/uzbl.c +++ b/uzbl.c @@ -567,7 +567,8 @@ static struct {char *name; Command command[2];} cmdlist[] = { "toggle_insert_mode", {toggle_insert_mode, 0} }, { "runcmd", {runcmd, NOSPLIT} }, { "set", {set_var, NOSPLIT} }, - { "dump_config", {act_dump_config, 0} } + { "dump_config", {act_dump_config, 0} }, + { "keycmd_bs", {keycmd_bs, 0} } }; static void @@ -746,6 +747,14 @@ new_window_load_uri (const gchar * uri) { g_string_free (to_execute, TRUE); } +static void +keycmd_bs (WebKitWebView *page, GArray *argv) { + (void)page; + (void)argv; + g_string_truncate(uzbl.state.keycmd, uzbl.state.keycmd->len - 1); + update_title(); +} + static void close_uzbl (WebKitWebView *page, GArray *argv) { (void)page; @@ -1856,10 +1865,8 @@ key_press_cb (GtkWidget* window, GdkEventKey* event) return TRUE; } - if ((event->keyval == GDK_BackSpace) && (uzbl.state.keycmd->len > 0)) { - g_string_truncate(uzbl.state.keycmd, uzbl.state.keycmd->len - 1); - update_title(); - } + if (event->keyval == GDK_BackSpace) + keycmd_bs(NULL, NULL); gboolean key_ret = FALSE; if ((event->keyval == GDK_Return) || (event->keyval == GDK_KP_Enter)) diff --git a/uzbl.h b/uzbl.h index 8618675..b7a5565 100644 --- a/uzbl.h +++ b/uzbl.h @@ -305,6 +305,9 @@ load_uri (WebKitWebView * web_view, GArray *argv); static void new_window_load_uri (const gchar * uri); +static void +keycmd_bs (WebKitWebView *page, GArray *argv); + static void close_uzbl (WebKitWebView *page, GArray *argv); -- cgit v1.2.3 From 51b0c647afd2c93e020fd414065805cd20e8a83f Mon Sep 17 00:00:00 2001 From: DuClare Date: Thu, 28 May 2009 16:02:40 +0300 Subject: Add actions keycmd and keycmd_nl --- uzbl.c | 20 ++++++++++++++++++++ uzbl.h | 6 ++++++ 2 files changed, 26 insertions(+) diff --git a/uzbl.c b/uzbl.c index a8b97c4..70b3ed7 100644 --- a/uzbl.c +++ b/uzbl.c @@ -568,6 +568,8 @@ static struct {char *name; Command command[2];} cmdlist[] = { "runcmd", {runcmd, NOSPLIT} }, { "set", {set_var, NOSPLIT} }, { "dump_config", {act_dump_config, 0} }, + { "keycmd", {keycmd, NOSPLIT} }, + { "keycmd_nl", {keycmd_nl, NOSPLIT} }, { "keycmd_bs", {keycmd_bs, 0} } }; @@ -747,6 +749,24 @@ new_window_load_uri (const gchar * uri) { g_string_free (to_execute, TRUE); } +static void +keycmd (WebKitWebView *page, GArray *argv) { + (void)page; + (void)argv; + g_string_assign(uzbl.state.keycmd, argv_idx(argv, 0)); + run_keycmd(FALSE); + update_title(); +} + +static void +keycmd_nl (WebKitWebView *page, GArray *argv) { + (void)page; + (void)argv; + g_string_assign(uzbl.state.keycmd, argv_idx(argv, 0)); + run_keycmd(TRUE); + update_title(); +} + static void keycmd_bs (WebKitWebView *page, GArray *argv) { (void)page; diff --git a/uzbl.h b/uzbl.h index b7a5565..0750e63 100644 --- a/uzbl.h +++ b/uzbl.h @@ -305,6 +305,12 @@ load_uri (WebKitWebView * web_view, GArray *argv); static void new_window_load_uri (const gchar * uri); +static void +keycmd (WebKitWebView *page, GArray *argv); + +static void +keycmd_nl (WebKitWebView *page, GArray *argv); + static void keycmd_bs (WebKitWebView *page, GArray *argv); -- cgit v1.2.3 From cf6f5f41dfb424213b6a8d06edadc0a4c384661d Mon Sep 17 00:00:00 2001 From: DuClare Date: Thu, 28 May 2009 16:05:28 +0300 Subject: Remove KEYCMD and KEYCMDN commands --- uzbl.c | 15 --------------- uzbl.h | 1 - 2 files changed, 16 deletions(-) diff --git a/uzbl.c b/uzbl.c index 70b3ed7..371b40f 100644 --- a/uzbl.c +++ b/uzbl.c @@ -1198,8 +1198,6 @@ setup_regex() { G_REGEX_UNGREEDY|G_REGEX_OPTIMIZE, 0, NULL); uzbl.comm.act_regex = g_regex_new("^[Aa][a-zA-Z]*\\s+([^ \\n]+)\\s*([^\\n]*)?$", G_REGEX_OPTIMIZE, 0, NULL); - uzbl.comm.keycmd_regex = g_regex_new("^[Kk][a-zA-Z]*\\s+([^\\n]+)$", - G_REGEX_OPTIMIZE, 0, NULL); } static gboolean @@ -1558,19 +1556,6 @@ parse_cmd_line(const char *ctl_line) { else printf("Error in command: %s\n", tokens[0]); } - /* KEYCMD command */ - else if(ctl_line[0] == 'K' || ctl_line[0] == 'k') { - tokens = g_regex_split(uzbl.comm.keycmd_regex, ctl_line, 0); - if(tokens[0][0] == 0) { - /* should incremental commands want each individual "keystroke" - sent in a loop or the whole string in one go like now? */ - g_string_assign(uzbl.state.keycmd, tokens[1]); - run_keycmd(FALSE); - if (g_strstr_len(ctl_line, 7, "n") || g_strstr_len(ctl_line, 7, "N")) - run_keycmd(TRUE); - update_title(); - } - } /* Comments */ else if( (ctl_line[0] == '#') || (ctl_line[0] == ' ') diff --git a/uzbl.h b/uzbl.h index 0750e63..fe63b3c 100644 --- a/uzbl.h +++ b/uzbl.h @@ -96,7 +96,6 @@ typedef struct { /* command parsing regexes */ GRegex *set_regex; GRegex *act_regex; - GRegex *keycmd_regex; GRegex *get_regex; GRegex *bind_regex; gchar *sync_stdout; -- cgit v1.2.3 From cbc4a4fcf731d6d215ce47fa67bfa7e0b9feddd8 Mon Sep 17 00:00:00 2001 From: DuClare Date: Thu, 28 May 2009 18:46:29 +0300 Subject: Add 'chain' action for binding multiple actions --- uzbl.c | 16 +++++++++++++++- uzbl.h | 3 +++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/uzbl.c b/uzbl.c index 371b40f..a064e99 100644 --- a/uzbl.c +++ b/uzbl.c @@ -570,7 +570,8 @@ static struct {char *name; Command command[2];} cmdlist[] = { "dump_config", {act_dump_config, 0} }, { "keycmd", {keycmd, NOSPLIT} }, { "keycmd_nl", {keycmd_nl, NOSPLIT} }, - { "keycmd_bs", {keycmd_bs, 0} } + { "keycmd_bs", {keycmd_bs, 0} }, + { "chain", {chain, 0} } }; static void @@ -749,6 +750,19 @@ new_window_load_uri (const gchar * uri) { g_string_free (to_execute, TRUE); } +static void +chain (WebKitWebView *page, GArray *argv) { + (void)page; + gchar *a = NULL; + gchar **parts = NULL; + guint i = 0; + while ((a = argv_idx(argv, i++))) { + parts = g_strsplit (a, " ", 2); + parse_command(parts[0], parts[1]); + g_strfreev (parts); + } +} + static void keycmd (WebKitWebView *page, GArray *argv) { (void)page; diff --git a/uzbl.h b/uzbl.h index fe63b3c..a36b3f7 100644 --- a/uzbl.h +++ b/uzbl.h @@ -304,6 +304,9 @@ load_uri (WebKitWebView * web_view, GArray *argv); static void new_window_load_uri (const gchar * uri); +static void +chain (WebKitWebView *page, GArray *argv); + static void keycmd (WebKitWebView *page, GArray *argv); -- cgit v1.2.3 From 476b4c97a260b5a2b05c7889f057172f11a44483 Mon Sep 17 00:00:00 2001 From: DuClare Date: Thu, 28 May 2009 22:49:54 +0300 Subject: Fix disable_scripts --- uzbl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uzbl.c b/uzbl.c index a064e99..6e9a17c 100644 --- a/uzbl.c +++ b/uzbl.c @@ -1315,7 +1315,7 @@ cmd_disable_plugins() { static void cmd_disable_scripts() { g_object_set (G_OBJECT(view_settings()), "enable-scripts", - !uzbl.behave.disable_plugins, NULL); + !uzbl.behave.disable_scripts, NULL); } static void -- cgit v1.2.3 From eeff23bea0328226f4644edaa925ea8ddee1be67 Mon Sep 17 00:00:00 2001 From: DuClare Date: Thu, 28 May 2009 22:57:02 +0300 Subject: Document keycmd* actions, undocument removed commands --- README | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/README b/README index 71cdcfa..250d928 100644 --- a/README +++ b/README @@ -128,12 +128,6 @@ Examples: ACT This tells uzbl to execute an action immediately. The simplest example of this would be `act exit`; you know what that'll do. - KEYCMD -This sets the interactive command buffer to ``. Keycmd is primarily useful for scripts that help you type a command while still letting you edit it before execution. -For example, if you have a binding like "o _" that opens an URL, then you could create a binding `O` that spawns a script which will set the command buffer to "o current-uri-here", letting you enter relative URLs easily. - - KEYCMDN -Like KEYCMD, but also emulates a press of return which causes binds with an asterisk or underscore to execute. (See sample config) ### ACTIONS @@ -175,6 +169,11 @@ actions follows: - if the optional state is 0, disable insert mode. If 1, enable insert mode. * `runcmd` - can be used for running a command such as SET or BIND +* `keycmd ` +* `keycmd_nl ` + - keycmd sets the interactive command buffer to ``. If the given string is a valid binding, it will execute. `Keycmd_nl` is like `keycmd`, but it also emulates a press of return, causing bindings with a parameter to execute. For example, `keycmd_nl o google.com` would load the said url if you have a binding like `bind o _ = uri %s`. +* `keycmd_bs` + - erase (backspace) one character from the command buffer ### VARIABLE REPLACEMENT -- cgit v1.2.3 From e70206ca43c1eb120681c7cfc67737ab36f4a867 Mon Sep 17 00:00:00 2001 From: DuClare Date: Thu, 28 May 2009 22:58:45 +0300 Subject: Document 'chain' --- README | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README b/README index 250d928..68a3b33 100644 --- a/README +++ b/README @@ -174,6 +174,9 @@ actions follows: - keycmd sets the interactive command buffer to ``. If the given string is a valid binding, it will execute. `Keycmd_nl` is like `keycmd`, but it also emulates a press of return, causing bindings with a parameter to execute. For example, `keycmd_nl o google.com` would load the said url if you have a binding like `bind o _ = uri %s`. * `keycmd_bs` - erase (backspace) one character from the command buffer +* `chain ..` + - use for chaining multiple actions + - remember to quote the actions; one action must come as one parameter ### VARIABLE REPLACEMENT -- cgit v1.2.3 From fa29506fdba7a2965886c7f199182fc08ee4ca57 Mon Sep 17 00:00:00 2001 From: Robert Manea Date: Fri, 29 May 2009 14:06:03 +0200 Subject: added possibilty to expand uzbl vars in commands --- uzbl.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/uzbl.c b/uzbl.c index 6e9a17c..74d2d6d 100644 --- a/uzbl.c +++ b/uzbl.c @@ -186,8 +186,49 @@ make_var_to_name_hash() { } } - /* --- UTILITY FUNCTIONS --- */ +static gchar * +expand_vars(char *s) { + + char ret[256], /* 256 chars per var name should be safe */ + *vend; + uzbl_cmdprop *c; + GString *buf = g_string_new(""); + + while(*s) { + /* found quotation char */ + if(*s == '\\') { + g_string_append_c(buf, *s); + g_string_append_c(buf, *(s+1)); + s += 2; + } + /* found variable */ + else if(*s == '@') { + s++; + if( (vend = strchr(s, ' ')) || + (vend = strchr(s, '\0')) ) { + strncpy(ret, s, vend-s); + ret[vend-s] = '\0'; + if( (c = g_hash_table_lookup(uzbl.comm.proto_var, ret)) ) { + if(c->type == TYPE_STR) + g_string_append(buf, (gchar *)*c->ptr); + else if(c->type == TYPE_INT) { + char *b = itos((int)*c->ptr); + g_string_append(buf, b); + g_free(b); + } + } + s = vend; + } + } + /* every other char */ + else { + g_string_append_c(buf, *s); + s++; + } + } + return g_string_free(buf, FALSE); +} char * itos(int val) { @@ -1472,15 +1513,19 @@ static gboolean set_var_value(gchar *name, gchar *val) { uzbl_cmdprop *c = NULL; char *endp = NULL; + char *buf = NULL; if( (c = g_hash_table_lookup(uzbl.comm.proto_var, name)) ) { /* check for the variable type */ if (c->type == TYPE_STR) { + buf = expand_vars(val); g_free(*c->ptr); - *c->ptr = g_strdup(val); + *c->ptr = buf; } else if(c->type == TYPE_INT) { int *ip = (int *)c->ptr; - *ip = (int)strtoul(val, &endp, 10); + buf = expand_vars(val); + *ip = (int)strtoul(buf, &endp, 10); + g_free(buf); } /* invoke a command specific function */ @@ -2388,6 +2433,8 @@ main (int argc, char* argv[]) { g_array_free (a, TRUE); } + //char *tstr = "Proxy is @proxy_url and now quoted \\@proxy_url status_top=@status_top \\\\\\"; + //expand_vars(tstr); gtk_main (); clean_up(); -- cgit v1.2.3 From 1dc2eb6e9a1a9791e6cf2e0ef9851431aabbf72b Mon Sep 17 00:00:00 2001 From: Robert Manea Date: Fri, 29 May 2009 14:13:59 +0200 Subject: fix expand_vars to not append the quoting char --- uzbl.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/uzbl.c b/uzbl.c index 74d2d6d..cfac3b2 100644 --- a/uzbl.c +++ b/uzbl.c @@ -198,7 +198,7 @@ expand_vars(char *s) { while(*s) { /* found quotation char */ if(*s == '\\') { - g_string_append_c(buf, *s); + //g_string_append_c(buf, *s); g_string_append_c(buf, *(s+1)); s += 2; } @@ -2433,8 +2433,6 @@ main (int argc, char* argv[]) { g_array_free (a, TRUE); } - //char *tstr = "Proxy is @proxy_url and now quoted \\@proxy_url status_top=@status_top \\\\\\"; - //expand_vars(tstr); gtk_main (); clean_up(); -- cgit v1.2.3 From dcc309c7de594c70cb7b8d7dc0851e5342a09996 Mon Sep 17 00:00:00 2001 From: Robert Manea Date: Fri, 29 May 2009 14:18:31 +0200 Subject: one more fix to expand_vars --- uzbl.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/uzbl.c b/uzbl.c index cfac3b2..ee5c6bb 100644 --- a/uzbl.c +++ b/uzbl.c @@ -198,15 +198,14 @@ expand_vars(char *s) { while(*s) { /* found quotation char */ if(*s == '\\') { - //g_string_append_c(buf, *s); - g_string_append_c(buf, *(s+1)); - s += 2; + g_string_append_c(buf, *++s); + s++; } /* found variable */ else if(*s == '@') { s++; if( (vend = strchr(s, ' ')) || - (vend = strchr(s, '\0')) ) { + (vend = strchr(s, '\0')) ) { strncpy(ret, s, vend-s); ret[vend-s] = '\0'; if( (c = g_hash_table_lookup(uzbl.comm.proto_var, ret)) ) { -- cgit v1.2.3 From 86d8f9b372c9c558527a2fc7b305f1a681e97d68 Mon Sep 17 00:00:00 2001 From: Vsevolod Kozlov Date: Fri, 29 May 2009 18:39:41 +0200 Subject: cleanup uzblctrl --- uzblctrl.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/uzblctrl.c b/uzblctrl.c index 55a3aac..9aaca0b 100644 --- a/uzblctrl.c +++ b/uzblctrl.c @@ -23,7 +23,7 @@ static gchar* command; static GOptionEntry entries[] = { - { "socket", 's', 0, G_OPTION_ARG_STRING, &sockpath, "Socket path of the client uzbl", NULL }, + { "socket", 's', 0, G_OPTION_ARG_STRING, &sockpath, "Path to the uzbl socket", NULL }, { "command", 'c', 0, G_OPTION_ARG_STRING, &command, "The uzbl command to execute", NULL }, { NULL, 0, 0, 0, NULL, NULL, NULL } }; @@ -31,7 +31,7 @@ static GOptionEntry entries[] = int main(int argc, char* argv[]) { GError *error = NULL; - GOptionContext* context = g_option_context_new ("- some stuff here maybe someday"); + GOptionContext* context = g_option_context_new ("- utility for controlling uzbl"); g_option_context_add_main_entries (context, entries, NULL); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_parse (context, &argc, &argv, &error); @@ -64,8 +64,7 @@ main(int argc, char* argv[]) { return 0; } else { - printf ("You need to specify the -s and -c parameters for uzblctrl to do anything of use.\n"); - printf ("Usage: uzblctrl -s /path/to/socket -c \"command\"\n"); + puts ("Usage: uzblctrl -s /path/to/socket -c \"command\""); return 1; } } -- cgit v1.2.3 From e2f75a1e547e43f26ba6b32adfa59b2534743288 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 29 May 2009 18:41:28 +0200 Subject: formatting + clarification --- uzblctrl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uzblctrl.c b/uzblctrl.c index 9aaca0b..7c369aa 100644 --- a/uzblctrl.c +++ b/uzblctrl.c @@ -23,7 +23,7 @@ static gchar* command; static GOptionEntry entries[] = { - { "socket", 's', 0, G_OPTION_ARG_STRING, &sockpath, "Path to the uzbl socket", NULL }, + { "socket", 's', 0, G_OPTION_ARG_STRING, &sockpath, "Path to the uzbl socket", NULL }, { "command", 'c', 0, G_OPTION_ARG_STRING, &command, "The uzbl command to execute", NULL }, { NULL, 0, 0, 0, NULL, NULL, NULL } }; @@ -31,7 +31,7 @@ static GOptionEntry entries[] = int main(int argc, char* argv[]) { GError *error = NULL; - GOptionContext* context = g_option_context_new ("- utility for controlling uzbl"); + GOptionContext* context = g_option_context_new ("- utility for controlling and interacting with uzbl through it's socket file"); //TODO: get stuff back from uzbl g_option_context_add_main_entries (context, entries, NULL); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_parse (context, &argc, &argv, &error); -- cgit v1.2.3 From 2fff3ed7bceb33212b39f6c421f46b6d8155b6d0 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 29 May 2009 18:46:14 +0200 Subject: Dieterbe, should be "its socket file" crap --- uzblctrl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uzblctrl.c b/uzblctrl.c index 7c369aa..f0fe732 100644 --- a/uzblctrl.c +++ b/uzblctrl.c @@ -31,7 +31,7 @@ static GOptionEntry entries[] = int main(int argc, char* argv[]) { GError *error = NULL; - GOptionContext* context = g_option_context_new ("- utility for controlling and interacting with uzbl through it's socket file"); //TODO: get stuff back from uzbl + GOptionContext* context = g_option_context_new ("- utility for controlling and interacting with uzbl through its socket file"); //TODO: get stuff back from uzbl g_option_context_add_main_entries (context, entries, NULL); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_parse (context, &argc, &argv, &error); -- cgit v1.2.3 From aaa98f8e81f7ff4f5f6cd4c692283b15518c60c7 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 29 May 2009 18:54:45 +0200 Subject: faq entry about socket vs fifo --- docs/FAQ | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/FAQ b/docs/FAQ index b5a6323..7286ec7 100644 --- a/docs/FAQ +++ b/docs/FAQ @@ -64,12 +64,19 @@ Note that we do *not* depend on any Gnome libraries such as gconf. _That_ would ### Do you support flash? javascript? Ajax? Recent html/css/.. standards? Yes, Webkit takes care of all of that. Not that we like all of these, but you can use them if you want. +### What's the difference between the socket file and the fifo? +They both have advantages and disadvantages: + + * fifo's are _very_ easy to work with. You can write just plaintext commands into them, but they are unidirectional (you can only communicate in one direction) + * Sockets are bidirectional but more complex. You cannot just write a plaintext string into them. In shellscripts you can use uzblctrl or netcat to work with sockets, when programming you need to use library functions. + +So, when writing scripts, using fifo's is usually the fastest method (because you do not need to fork another process), so fifo is preferred unless you need a response. + ### Does the world really need another browser? We did try a lot of browsers, and we do not suffer [NIH](http://en.wikipedia.org/wiki/Not_Invented_Here). We believe that the approach taken by way too many browsers is wrong. We do not want browsers that try to do everything, instead we prefer a system where different applications work together, which gives plenty of advantages. We also like open source. We take a lot of things from other projects and we also try to contribute to other projects. - ### What? You call all of this user-friendly? Yes. If you don't agree, don't use it :) -- cgit v1.2.3 From 9a050cc2e728e651d65d9211e1450f9bf35aa5b5 Mon Sep 17 00:00:00 2001 From: Robert Manea Date: Fri, 29 May 2009 19:03:51 +0200 Subject: added variable delimiters working like in the shell, foo@{var}baz --- uzbl.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/uzbl.c b/uzbl.c index ee5c6bb..e7f43ce 100644 --- a/uzbl.c +++ b/uzbl.c @@ -189,10 +189,10 @@ make_var_to_name_hash() { /* --- UTILITY FUNCTIONS --- */ static gchar * expand_vars(char *s) { - char ret[256], /* 256 chars per var name should be safe */ *vend; uzbl_cmdprop *c; + char upto = ' '; GString *buf = g_string_new(""); while(*s) { @@ -203,8 +203,11 @@ expand_vars(char *s) { } /* found variable */ else if(*s == '@') { + if(*(s+1) == '{') { + upto = '}'; s++; + } s++; - if( (vend = strchr(s, ' ')) || + if( (vend = strchr(s, upto)) || (vend = strchr(s, '\0')) ) { strncpy(ret, s, vend-s); ret[vend-s] = '\0'; @@ -217,7 +220,11 @@ expand_vars(char *s) { g_free(b); } } - s = vend; + if(upto == ' ') + s = vend; + else + s = vend+1; + upto = ' '; } } /* every other char */ @@ -1260,7 +1267,7 @@ get_var_value(gchar *name) { if( (c = g_hash_table_lookup(uzbl.comm.proto_var, name)) ) { if(c->type == TYPE_STR) - printf("VAR: %s VALUE: %s\n", name, (char *)*c->ptr); + printf("VAR: %s VALUE: (%s)\n", name, (char *)*c->ptr); else if(c->type == TYPE_INT) printf("VAR: %s VALUE: %d\n", name, (int)*c->ptr); } -- cgit v1.2.3 From 43b2dceaacc18a0230d657ffabb3894d9776711f Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 29 May 2009 19:13:50 +0200 Subject: duclare joins the club --- AUTHORS | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index 2212a87..21c95d8 100644 --- a/AUTHORS +++ b/AUTHORS @@ -3,11 +3,11 @@ Developers: Dieter Plaetinck (Dieter@be) Dusan Popovic (dusanx) Michael Walker (Barrucadu) - Přemysl Hrubý, (anydot) + Přemysl Hrubý (anydot) Robert Manea (robm) + Henri Kemppainen (DuClare) Contributors: - (DuClare) - Various improvements Zane Ashby (HashBox) - Rewrote FIFO interface. Fixed various bugs. (sentientswitch) - Cleaned up code. Added some commands. Jan Kolkmeier (jouz) - scrolling, link following -- cgit v1.2.3 From 8515e50930406aebf7a58550818bfe15abd1c546 Mon Sep 17 00:00:00 2001 From: DuClare Date: Fri, 29 May 2009 20:40:03 +0300 Subject: Fix run_handler to consider action chains --- uzbl.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 95 insertions(+), 18 deletions(-) diff --git a/uzbl.c b/uzbl.c index 6e9a17c..7d7caf1 100644 --- a/uzbl.c +++ b/uzbl.c @@ -1388,6 +1388,7 @@ cmd_caret_browsing() { static void cmd_cookie_handler() { gchar **split = g_strsplit(uzbl.behave.cookie_handler, " ", 2); + /* pitfall: doesn't handle chain actions; must the sync_ action manually */ if ((g_strcmp0(split[0], "sh") == 0) || (g_strcmp0(split[0], "spawn") == 0)) { g_free (uzbl.behave.cookie_handler); @@ -2007,29 +2008,105 @@ GtkWidget* create_window () { return window; } +static gchar** +inject_handler_args(const gchar *actname, const gchar *origargs, const gchar *newargs) { + /* + If actname is one that calls an external command, this function will inject + newargs in front of the user-provided args in that command line. They will + come become after the body of the script (in sh) or after the name of + the command to execute (in spawn). + i.e. sh becomes sh and + span becomes spawn . + + The return value consist of two strings: the action (sh, ...) and its args. + + If act is not one that calls an external command, then the given action merely + gets duplicated. + */ + GArray *rets = g_array_new(TRUE, FALSE, sizeof(gchar*)); + gchar *actdup = g_strdup(actname); + g_array_append_val(rets, actdup); + + if ((g_strcmp0(actname, "spawn") == 0) || + (g_strcmp0(actname, "sh") == 0) || + (g_strcmp0(actname, "sync_spawn") == 0) || + (g_strcmp0(actname, "sync_sh") == 0)) { + guint i; + GString *a = g_string_new(""); + gchar **spawnparts = split_quoted(origargs, FALSE); + g_string_append_printf(a, "%s", spawnparts[0]); /* sh body or script name */ + if (newargs) g_string_append_printf(a, " %s", newargs); /* handler args */ + + for (i = 1; i < g_strv_length(spawnparts); i++) /* user args */ + if (spawnparts[i]) g_string_append_printf(a, " %s", spawnparts[i]); + + g_array_append_val(rets, a->str); + g_string_free(a, FALSE); + g_strfreev(spawnparts); + } else { + gchar *origdup = g_strdup(origargs); + g_array_append_val(rets, origdup); + } + return (gchar**)g_array_free(rets, FALSE); +} + static void run_handler (const gchar *act, const gchar *args) { + /* Consider this code a temporary hack to make the handlers usable. + In practice, all this splicing, injection, and reconstruction is + inefficient, annoying and hard to manage. Potential pitfalls arise + when the handler specific args 1) are not quoted (the handler + callbacks should take care of this) 2) are quoted but interfere + with the users' own quotation. A more ideal solution is + to refactor parse_command so that it doesn't just take a string + and execute it; rather than that, we should have a function which + returns the argument vector parsed from the string. This vector + could be modified (e.g. insert additional args into it) before + passing it to the next function that actually executes it. Though + it still isn't perfect for chain actions.. will reconsider & re- + factor when I have the time. -duc */ + char **parts = g_strsplit(act, " ", 2); if (!parts) return; - else if ((g_strcmp0(parts[0], "spawn") == 0) - || (g_strcmp0(parts[0], "sh") == 0) - || (g_strcmp0(parts[0], "sync_spawn") == 0) - || (g_strcmp0(parts[0], "sync_sh") == 0)) { - guint i; - GString *a = g_string_new (""); - char **spawnparts; - spawnparts = split_quoted(parts[1], FALSE); - g_string_append_printf(a, "%s", spawnparts[0]); - if (args) g_string_append_printf(a, " %s", args); /* append handler args before user args */ + if (g_strcmp0(parts[0], "chain") == 0) { + GString *newargs = g_string_new(""); + gchar **chainparts = split_quoted(parts[1], FALSE); - for (i = 1; i < g_strv_length(spawnparts); i++) /* user args */ - g_string_append_printf(a, " %s", spawnparts[i]); - parse_command(parts[0], a->str); - g_string_free (a, TRUE); - g_strfreev (spawnparts); - } else - parse_command(parts[0], parts[1]); - g_strfreev (parts); + /* for every argument in the chain, inject the handler args + and make sure the new parts are wrapped in quotes */ + gchar **cp = chainparts; + gchar quot = '\''; + gchar *quotless = NULL; + gchar **spliced_quotless = NULL; // sigh -_-; + gchar **inpart = NULL; + + while (*cp) { + if ((**cp == '\'') || (**cp == '\"')) { /* strip old quotes */ + quot = **cp; + quotless = g_strndup(&(*cp)[1], strlen(*cp) - 2); + } else quotless = g_strdup(*cp); + + spliced_quotless = g_strsplit(quotless, " ", 2); + inpart = inject_handler_args(spliced_quotless[0], spliced_quotless[1], args); + g_strfreev(spliced_quotless); + + g_string_append_printf(newargs, " %c%s %s%c", quot, inpart[0], inpart[1], quot); + g_free(quotless); + g_strfreev(inpart); + cp++; + } + + parse_command(parts[0], &(newargs->str[1])); + g_string_free(newargs, TRUE); + g_strfreev(chainparts); + + } else { + gchar **inparts = inject_handler_args(parts[0], parts[1], args); + parse_command(inparts[0], inparts[1]); + g_free(inparts[0]); + g_free(inparts[1]); + } + g_strfreev(parts); } static void -- cgit v1.2.3 From 0c6a5ff58fa87ec65ea1b3054586da19d0dc96f2 Mon Sep 17 00:00:00 2001 From: DuClare Date: Fri, 29 May 2009 21:16:38 +0300 Subject: Add 'get' action, remove GET command. Const correctness fix. --- uzbl.c | 18 ++++++++---------- uzbl.h | 6 ++++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/uzbl.c b/uzbl.c index e5498f0..7855353 100644 --- a/uzbl.c +++ b/uzbl.c @@ -614,6 +614,7 @@ static struct {char *name; Command command[2];} cmdlist[] = { "toggle_insert_mode", {toggle_insert_mode, 0} }, { "runcmd", {runcmd, NOSPLIT} }, { "set", {set_var, NOSPLIT} }, + { "get", {get_var, NOSPLIT} }, { "dump_config", {act_dump_config, 0} }, { "keycmd", {keycmd, NOSPLIT} }, { "keycmd_nl", {keycmd_nl, NOSPLIT} }, @@ -670,6 +671,12 @@ set_var(WebKitWebView *page, GArray *argv) { g_free(ctl_line); } +static void +get_var(WebKitWebView *page, GArray *argv) { + (void) page; + get_var_value(argv_idx(argv, 0)); +} + static void act_dump_config() { dump_config(); @@ -1262,7 +1269,7 @@ setup_regex() { } static gboolean -get_var_value(gchar *name) { +get_var_value(const gchar *name) { uzbl_cmdprop *c; if( (c = g_hash_table_lookup(uzbl.comm.proto_var, name)) ) { @@ -1593,15 +1600,6 @@ parse_cmd_line(const char *ctl_line) { else printf("Error in command: %s\n", tokens[0]); } - /* GET command */ - else if(ctl_line[0] == 'g' || ctl_line[0] == 'G') { - tokens = g_regex_split(uzbl.comm.get_regex, ctl_line, 0); - if(tokens[0][0] == 0) { - get_var_value(tokens[1]); - } - else - printf("Error in command: %s\n", tokens[0]); - } /* BIND command */ else if(ctl_line[0] == 'b' || ctl_line[0] == 'B') { tokens = g_regex_split(uzbl.comm.bind_regex, ctl_line, 0); diff --git a/uzbl.h b/uzbl.h index a36b3f7..dd4ceb5 100644 --- a/uzbl.h +++ b/uzbl.h @@ -247,6 +247,9 @@ setup_signal(int signe, sigfunc *shandler); static gboolean set_var_value(gchar *name, gchar *val); +static gboolean +get_var_value(const gchar *name); + static gboolean new_window_cb (WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, WebKitWebNavigationAction *navigation_action, WebKitWebPolicyDecision *policy_decision, gpointer user_data); @@ -429,6 +432,9 @@ save_cookies (SoupMessage *msg, static void set_var(WebKitWebView *page, GArray *argv); +static void +get_var(WebKitWebView *page, GArray *argv); + static void act_dump_config(); -- cgit v1.2.3 From b33d152c8cca9ea50899a74e24316808d8e12607 Mon Sep 17 00:00:00 2001 From: DuClare Date: Fri, 29 May 2009 21:40:36 +0300 Subject: Don't call parse_cmd_line in set_var, rm SET cmd, rm unused regexes --- uzbl.c | 25 ++++--------------------- uzbl.h | 2 -- 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/uzbl.c b/uzbl.c index 7855353..205e9c0 100644 --- a/uzbl.c +++ b/uzbl.c @@ -664,11 +664,9 @@ file_exists (const char * filename) { static void set_var(WebKitWebView *page, GArray *argv) { (void) page; - gchar *ctl_line; - - ctl_line = g_strdup_printf("%s %s", "set", argv_idx(argv, 0)); - parse_cmd_line(ctl_line); - g_free(ctl_line); + gchar **split = g_strsplit(argv_idx(argv, 0), "=", 2); + set_var_value(g_strstrip(split[0]), (g_strchug(split[1]) ? split[1] : " ")); + g_strfreev(split); } static void @@ -1258,10 +1256,6 @@ parse_command(const char *cmd, const char *param) { /* command parser */ static void setup_regex() { - uzbl.comm.get_regex = g_regex_new("^[Gg][a-zA-Z]*\\s+([^ \\n]+)$", - G_REGEX_OPTIMIZE, 0, NULL); - uzbl.comm.set_regex = g_regex_new("^[Ss][a-zA-Z]*\\s+([^ ]+)\\s*=\\s*([^\\n].*)$", - G_REGEX_OPTIMIZE, 0, NULL); uzbl.comm.bind_regex = g_regex_new("^[Bb][a-zA-Z]*\\s+?(.*[^ ])\\s*?=\\s*([a-z][^\\n].+)$", G_REGEX_UNGREEDY|G_REGEX_OPTIMIZE, 0, NULL); uzbl.comm.act_regex = g_regex_new("^[Aa][a-zA-Z]*\\s+([^ \\n]+)\\s*([^\\n]*)?$", @@ -1589,19 +1583,8 @@ parse_cmd_line(const char *ctl_line) { } } else { - /* SET command */ - if(ctl_line[0] == 's' || ctl_line[0] == 'S') { - tokens = g_regex_split(uzbl.comm.set_regex, ctl_line, 0); - if(tokens[0][0] == 0) { - gchar* value = parseenv(g_strdup(tokens[2])); - set_var_value(tokens[1], value); - g_free(value); - } - else - printf("Error in command: %s\n", tokens[0]); - } /* BIND command */ - else if(ctl_line[0] == 'b' || ctl_line[0] == 'B') { + if(ctl_line[0] == 'b' || ctl_line[0] == 'B') { tokens = g_regex_split(uzbl.comm.bind_regex, ctl_line, 0); if(tokens[0][0] == 0) { gchar* value = parseenv(g_strdup(tokens[2])); diff --git a/uzbl.h b/uzbl.h index dd4ceb5..d2364de 100644 --- a/uzbl.h +++ b/uzbl.h @@ -94,9 +94,7 @@ typedef struct { /* stores (key)"variable name" -> (value)"pointer to this var*/ GHashTable *proto_var; /* command parsing regexes */ - GRegex *set_regex; GRegex *act_regex; - GRegex *get_regex; GRegex *bind_regex; gchar *sync_stdout; } Communication; -- cgit v1.2.3 From 12ce2ed00d4f0c9ed877cfda1ca3345212656cfe Mon Sep 17 00:00:00 2001 From: Mark Nevill Date: Fri, 29 May 2009 20:52:13 +0200 Subject: better support for CPP/LDFLAGS environment variables in build --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index d158a9b..3110b25 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -CPPFLAGS=$(shell pkg-config --cflags gtk+-2.0 webkit-1.0) -ggdb -Wall -W -DARCH="\"$(shell uname -m)\"" -DG_ERRORCHECK_MUTEXES -DCOMMIT="\"$(shell git log | head -n1 | sed "s/.* //")\"" -LDFLAGS=$(shell pkg-config --libs gtk+-2.0 webkit-1.0) +CPPFLAGS:=$(shell pkg-config --cflags gtk+-2.0 webkit-1.0) -ggdb -Wall -W -DARCH="\"$(shell uname -m)\"" -DG_ERRORCHECK_MUTEXES -DCOMMIT="\"$(shell git log | head -n1 | sed "s/.* //")\"" $(CPPFLAGS) +LDFLAGS:=$(shell pkg-config --libs gtk+-2.0 webkit-1.0) $(LDFLAGS) all: uzbl uzblctrl test: uzbl -- cgit v1.2.3 From c623fc168543ec335fee528c1bc32e93febd02bc Mon Sep 17 00:00:00 2001 From: Mark Nevill Date: Fri, 29 May 2009 21:02:36 +0200 Subject: Added support for altering install prefix --- Makefile | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 3110b25..fa20b6c 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,8 @@ CPPFLAGS:=$(shell pkg-config --cflags gtk+-2.0 webkit-1.0) -ggdb -Wall -W -DARCH LDFLAGS:=$(shell pkg-config --libs gtk+-2.0 webkit-1.0) $(LDFLAGS) all: uzbl uzblctrl +PREFIX?=$(DESTDIR)/usr + test: uzbl ./uzbl --uri http://www.uzbl.org @@ -16,18 +18,19 @@ clean: rm -f uzblctrl install: - install -d $(DESTDIR)/usr/bin - install -d $(DESTDIR)/usr/share/uzbl/docs - install -d $(DESTDIR)/usr/share/uzbl/examples - install -D -m755 uzbl $(DESTDIR)/usr/bin/uzbl - install -D -m755 uzblctrl $(DESTDIR)/usr/bin/uzblctrl - cp -ax docs $(DESTDIR)/usr/share/uzbl/ - cp -ax config.h $(DESTDIR)/usr/share/uzbl/docs/ - cp -ax examples $(DESTDIR)/usr/share/uzbl/ - install -D -m644 AUTHORS $(DESTDIR)/usr/share/uzbl/docs - install -D -m644 README $(DESTDIR)/usr/share/uzbl/docs + install -d $(PREFIX)/bin + install -d $(PREFIX)/share/uzbl/docs + install -d $(PREFIX)/share/uzbl/examples + install -D -m755 uzbl $(PREFIX)/bin/uzbl + install -D -m755 uzblctrl $(PREFIX)/bin/uzblctrl + cp -ax docs $(PREFIX)/share/uzbl/ + cp -ax config.h $(PREFIX)/share/uzbl/docs/ + cp -ax examples $(PREFIX)/share/uzbl/ + install -D -m644 AUTHORS $(PREFIX)/share/uzbl/docs + install -D -m644 README $(PREFIX)/share/uzbl/docs + uninstall: - rm -rf $(DESTDIR)/usr/bin/uzbl - rm -rf $(DESTDIR)/usr/bin/uzblctrl - rm -rf $(DESTDIR)/usr/share/uzbl + rm -rf $(PREFIX)/bin/uzbl + rm -rf $(PREFIX)/bin/uzblctrl + rm -rf $(PREFIX)/share/uzbl -- cgit v1.2.3 From 68f356bbc256a1001d514adc1e9cb26b0e6102d0 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 29 May 2009 21:03:18 +0200 Subject: authors update --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 21c95d8..24597f1 100644 --- a/AUTHORS +++ b/AUTHORS @@ -17,6 +17,7 @@ Contributors: (salinasv) - move some variables to heap Sylvester Johansson (scj) - form filler script & different take on link follower (mxf) - uzblcat + Mark Nevill - misc patches Originaly based on http://trac.webkit.org/browser/trunk/WebKitTools/GtkLauncher/main.c Which is copyrighted: -- cgit v1.2.3 From 1e66be3a8635040f7e7d3ab828507ba361523a71 Mon Sep 17 00:00:00 2001 From: DuClare Date: Fri, 29 May 2009 22:11:06 +0300 Subject: Rem BIND cmd, add 'bind' action. Use parseenv in set_var & bind --- uzbl.c | 31 ++++++++++++++++--------------- uzbl.h | 4 +++- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/uzbl.c b/uzbl.c index 205e9c0..2b0571d 100644 --- a/uzbl.c +++ b/uzbl.c @@ -615,6 +615,7 @@ static struct {char *name; Command command[2];} cmdlist[] = { "runcmd", {runcmd, NOSPLIT} }, { "set", {set_var, NOSPLIT} }, { "get", {get_var, NOSPLIT} }, + { "bind", {act_bind, NOSPLIT} }, { "dump_config", {act_dump_config, 0} }, { "keycmd", {keycmd, NOSPLIT} }, { "keycmd_nl", {keycmd_nl, NOSPLIT} }, @@ -665,7 +666,9 @@ static void set_var(WebKitWebView *page, GArray *argv) { (void) page; gchar **split = g_strsplit(argv_idx(argv, 0), "=", 2); - set_var_value(g_strstrip(split[0]), (g_strchug(split[1]) ? split[1] : " ")); + gchar *value = parseenv(g_strdup(split[1] ? g_strchug(split[1]) : " ")); + set_var_value(g_strstrip(split[0]), value); + g_free(value); g_strfreev(split); } @@ -675,6 +678,17 @@ get_var(WebKitWebView *page, GArray *argv) { get_var_value(argv_idx(argv, 0)); } +static void +act_bind(WebKitWebView *page, GArray *argv) { + (void) page; + gchar **split = g_strsplit(argv_idx(argv, 0), " = ", 2); + gchar *value = parseenv(g_strdup(split[1] ? g_strchug(split[1]) : " ")); + add_binding(g_strstrip(split[0]), value); + g_free(value); + g_strfreev(split); +} + + static void act_dump_config() { dump_config(); @@ -1256,8 +1270,6 @@ parse_command(const char *cmd, const char *param) { /* command parser */ static void setup_regex() { - uzbl.comm.bind_regex = g_regex_new("^[Bb][a-zA-Z]*\\s+?(.*[^ ])\\s*?=\\s*([a-z][^\\n].+)$", - G_REGEX_UNGREEDY|G_REGEX_OPTIMIZE, 0, NULL); uzbl.comm.act_regex = g_regex_new("^[Aa][a-zA-Z]*\\s+([^ \\n]+)\\s*([^\\n]*)?$", G_REGEX_OPTIMIZE, 0, NULL); } @@ -1583,19 +1595,8 @@ parse_cmd_line(const char *ctl_line) { } } else { - /* BIND command */ - if(ctl_line[0] == 'b' || ctl_line[0] == 'B') { - tokens = g_regex_split(uzbl.comm.bind_regex, ctl_line, 0); - if(tokens[0][0] == 0) { - gchar* value = parseenv(g_strdup(tokens[2])); - add_binding(tokens[1], value); - g_free(value); - } - else - printf("Error in command: %s\n", tokens[0]); - } /* ACT command */ - else if(ctl_line[0] == 'A' || ctl_line[0] == 'a') { + if(ctl_line[0] == 'A' || ctl_line[0] == 'a') { tokens = g_regex_split(uzbl.comm.act_regex, ctl_line, 0); if(tokens[0][0] == 0) { parse_command(tokens[1], tokens[2]); diff --git a/uzbl.h b/uzbl.h index d2364de..bedefe0 100644 --- a/uzbl.h +++ b/uzbl.h @@ -95,7 +95,6 @@ typedef struct { GHashTable *proto_var; /* command parsing regexes */ GRegex *act_regex; - GRegex *bind_regex; gchar *sync_stdout; } Communication; @@ -433,6 +432,9 @@ set_var(WebKitWebView *page, GArray *argv); static void get_var(WebKitWebView *page, GArray *argv); +static void +act_bind(WebKitWebView *page, GArray *argv); + static void act_dump_config(); -- cgit v1.2.3 From d1c6ba765827f985507283080bf67a2b012f2e17 Mon Sep 17 00:00:00 2001 From: DuClare Date: Fri, 29 May 2009 22:15:02 +0300 Subject: Remove action 'runcmd': commands are deprecated :) --- uzbl.c | 7 ------- uzbl.h | 3 --- 2 files changed, 10 deletions(-) diff --git a/uzbl.c b/uzbl.c index 2b0571d..51e89e6 100644 --- a/uzbl.c +++ b/uzbl.c @@ -612,7 +612,6 @@ static struct {char *name; Command command[2];} cmdlist[] = { "search_reverse", {search_reverse_text, NOSPLIT} }, { "dehilight", {dehilight, 0} }, { "toggle_insert_mode", {toggle_insert_mode, 0} }, - { "runcmd", {runcmd, NOSPLIT} }, { "set", {set_var, NOSPLIT} }, { "get", {get_var, NOSPLIT} }, { "bind", {act_bind, NOSPLIT} }, @@ -1554,12 +1553,6 @@ set_var_value(gchar *name, gchar *val) { return TRUE; } -static void -runcmd(WebKitWebView* page, GArray *argv) { - (void) page; - parse_cmd_line(argv_idx(argv, 0)); -} - static void render_html() { Behaviour *b = &uzbl.behave; diff --git a/uzbl.h b/uzbl.h index bedefe0..a78a79e 100644 --- a/uzbl.h +++ b/uzbl.h @@ -338,9 +338,6 @@ spawn_sh_sync(WebKitWebView *web_view, GArray *argv); static void parse_command(const char *cmd, const char *param); -static void -runcmd(WebKitWebView *page, GArray *argv); - static void parse_cmd_line(const char *ctl_line); -- cgit v1.2.3 From 0c5963cfe4f53dc453ab9d5b2246a1ae796d126f Mon Sep 17 00:00:00 2001 From: Robert Manea Date: Fri, 29 May 2009 21:26:51 +0200 Subject: use switch in xpand_var() --- uzbl.c | 66 +++++++++++++++++++++++++++++++----------------------------------- 1 file changed, 31 insertions(+), 35 deletions(-) diff --git a/uzbl.c b/uzbl.c index e7f43ce..baaa4c3 100644 --- a/uzbl.c +++ b/uzbl.c @@ -189,48 +189,44 @@ make_var_to_name_hash() { /* --- UTILITY FUNCTIONS --- */ static gchar * expand_vars(char *s) { - char ret[256], /* 256 chars per var name should be safe */ - *vend; uzbl_cmdprop *c; char upto = ' '; + char ret[256], *vend; GString *buf = g_string_new(""); while(*s) { - /* found quotation char */ - if(*s == '\\') { - g_string_append_c(buf, *++s); - s++; - } - /* found variable */ - else if(*s == '@') { - if(*(s+1) == '{') { - upto = '}'; s++; - } - s++; - if( (vend = strchr(s, upto)) || - (vend = strchr(s, '\0')) ) { - strncpy(ret, s, vend-s); - ret[vend-s] = '\0'; - if( (c = g_hash_table_lookup(uzbl.comm.proto_var, ret)) ) { - if(c->type == TYPE_STR) - g_string_append(buf, (gchar *)*c->ptr); - else if(c->type == TYPE_INT) { - char *b = itos((int)*c->ptr); - g_string_append(buf, b); - g_free(b); + switch(*s) { + case '\\': + g_string_append_c(buf, *++s); + s++; + break; + case '@': + if(*(s+1) == '{') { + upto = '}'; s++; + } + s++; + if( (vend = strchr(s, upto)) || + (vend = strchr(s, '\0')) ) { + strncpy(ret, s, vend-s); + ret[vend-s] = '\0'; + if( (c = g_hash_table_lookup(uzbl.comm.proto_var, ret)) ) { + if(c->type == TYPE_STR) + g_string_append(buf, (gchar *)*c->ptr); + else if(c->type == TYPE_INT) { + char *b = itos((int)*c->ptr); + g_string_append(buf, b); + g_free(b); + } } + if(upto == ' ') s = vend; + else s = vend+1; + upto = ' '; } - if(upto == ' ') - s = vend; - else - s = vend+1; - upto = ' '; - } - } - /* every other char */ - else { - g_string_append_c(buf, *s); - s++; + break; + default: + g_string_append_c(buf, *s); + s++; + break; } } return g_string_free(buf, FALSE); -- cgit v1.2.3 From 816fa0aaf162542eaedfcad4ec91a966bc349523 Mon Sep 17 00:00:00 2001 From: DuClare Date: Fri, 29 May 2009 23:16:21 +0300 Subject: Make parse_cmd_line parse as actions --- uzbl.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/uzbl.c b/uzbl.c index 51e89e6..fd2a887 100644 --- a/uzbl.c +++ b/uzbl.c @@ -1602,9 +1602,16 @@ parse_cmd_line(const char *ctl_line) { || (ctl_line[0] == ' ') || (ctl_line[0] == '\n')) ; /* ignore these lines */ - else - printf("Command not understood (%s)\n", ctl_line); - + else { + gchar *ctlstrip; + if (ctl_line[strlen(ctl_line) - 1] == '\n') + ctlstrip = g_strndup(ctl_line, strlen(ctl_line) - 1); + else ctlstrip = g_strdup(ctl_line); + tokens = g_strsplit(ctlstrip, " ", 2); + + parse_command(tokens[0], tokens[1]); + g_free(ctlstrip); + } if(tokens) g_strfreev(tokens); } -- cgit v1.2.3 From 9ede5b7d9622e4468b917ce552dc43871a3bfb98 Mon Sep 17 00:00:00 2001 From: DuClare Date: Fri, 29 May 2009 23:25:06 +0300 Subject: Remove ACT command, remove regexes as they're no longer used. --- uzbl.c | 54 ++++++++++++++++-------------------------------------- uzbl.h | 2 -- 2 files changed, 16 insertions(+), 40 deletions(-) diff --git a/uzbl.c b/uzbl.c index fd2a887..d854bd2 100644 --- a/uzbl.c +++ b/uzbl.c @@ -1266,13 +1266,6 @@ parse_command(const char *cmd, const char *param) { g_printerr ("command \"%s\" not understood. ignoring.\n", cmd); } -/* command parser */ -static void -setup_regex() { - uzbl.comm.act_regex = g_regex_new("^[Aa][a-zA-Z]*\\s+([^ \\n]+)\\s*([^\\n]*)?$", - G_REGEX_OPTIMIZE, 0, NULL); -} - static gboolean get_var_value(const gchar *name) { uzbl_cmdprop *c; @@ -1568,7 +1561,6 @@ render_html() { enum {M_CMD, M_HTML}; static void parse_cmd_line(const char *ctl_line) { - gchar **tokens = NULL; Behaviour *b = &uzbl.behave; size_t len=0; @@ -1587,36 +1579,23 @@ parse_cmd_line(const char *ctl_line) { g_string_append(b->html_buffer, ctl_line); } } - else { - /* ACT command */ - if(ctl_line[0] == 'A' || ctl_line[0] == 'a') { - tokens = g_regex_split(uzbl.comm.act_regex, ctl_line, 0); - if(tokens[0][0] == 0) { - parse_command(tokens[1], tokens[2]); - } - else - printf("Error in command: %s\n", tokens[0]); - } - /* Comments */ - else if( (ctl_line[0] == '#') - || (ctl_line[0] == ' ') - || (ctl_line[0] == '\n')) - ; /* ignore these lines */ - else { - gchar *ctlstrip; - if (ctl_line[strlen(ctl_line) - 1] == '\n') - ctlstrip = g_strndup(ctl_line, strlen(ctl_line) - 1); - else ctlstrip = g_strdup(ctl_line); - tokens = g_strsplit(ctlstrip, " ", 2); - - parse_command(tokens[0], tokens[1]); - g_free(ctlstrip); - } - if(tokens) - g_strfreev(tokens); + else if((ctl_line[0] == '#') /* Comments */ + || (ctl_line[0] == ' ') + || (ctl_line[0] == '\n')) + ; /* ignore these lines */ + else { /* parse a command */ + gchar *ctlstrip; + gchar **tokens = NULL; + + if (ctl_line[strlen(ctl_line) - 1] == '\n') /* strip trailing newline */ + ctlstrip = g_strndup(ctl_line, strlen(ctl_line) - 1); + else ctlstrip = g_strdup(ctl_line); + + tokens = g_strsplit(ctlstrip, " ", 2); + parse_command(tokens[0], tokens[1]); + g_free(ctlstrip); + g_strfreev(tokens); } - - return; } static gchar* @@ -2444,7 +2423,6 @@ main (int argc, char* argv[]) { uzbl.behave.insert_indicator = g_strdup("I"); uzbl.behave.cmd_indicator = g_strdup("C"); - setup_regex(); setup_scanner(); commands_hash (); make_var_to_name_hash(); diff --git a/uzbl.h b/uzbl.h index a78a79e..6ab31f6 100644 --- a/uzbl.h +++ b/uzbl.h @@ -93,8 +93,6 @@ typedef struct { gchar *socket_path; /* stores (key)"variable name" -> (value)"pointer to this var*/ GHashTable *proto_var; - /* command parsing regexes */ - GRegex *act_regex; gchar *sync_stdout; } Communication; -- cgit v1.2.3 From c4d404d2f09add3c5d70df8473ca4d5ed0d1a78f Mon Sep 17 00:00:00 2001 From: DuClare Date: Fri, 29 May 2009 23:46:20 +0300 Subject: Merge COMMAND SYNTAX and ACTIONS in README, document sync_* and fix some details --- README | 66 ++++++++++++++++++++++++++++-------------------------------------- 1 file changed, 28 insertions(+), 38 deletions(-) diff --git a/README b/README index 68a3b33..5529b8f 100644 --- a/README +++ b/README @@ -95,44 +95,31 @@ Uzbl will read commands via standard input, named fifo pipe (if `fifo_dir` is se For convenience, uzbl can also be instructed to read commands from a file on startup by using the `-c` option. Indeed, the config file is nothing more than a list of commands. Each command starts with the name of the command, which must be the first thing on a line; preceding whitespace is not allowed. -A command is terminated by a newline. Empty lines and lines that start with the hash sign are ignored by the parser. Command names are not case sensitive. +A command is terminated by a newline. Empty lines and lines that start with the hash sign are ignored by the parser. Command names are always written in lowercase. The following commands are recognized: - SET = -Set is used for changing variables. Every variable can be changed on the fly and for some variables, some additional logic is performed. -For example, setting the variable `uri` will make uzbl start loading it, and changing the format of the statusbar/windowtitle/user agent/.. will be effective immediately. -If you want to unset a string, use SET with one space after the equals sign. - - GET -Use this to print the value of a key. (and TODO, get the value through the socket) - - BIND = -Makes the character sequence `` invoke `` when typed interactively in uzbl. -There are a few tricks you can do: - -* `` ends with an underscore: the action will only be invoked after pressing return/enter. If the user enters text where `` has the underscore, `%s` in the `` string will be replaced by this text. (optional) -* `` ends with an asterisk: similar behavior as with an underscore, but also makes the binding incremental (i.e. the action will be invoked on every keystroke). -* `` ends on a different character: you need to type the full string, which will trigger the action immediately, without pressing enter/return. - -Examples: - - # uzbl will load the url when you type: 'o ' - bind o _ = uri %s - # a search action which is called on every character typed after the slash, letting you see the search narrow down while typing. - # Hitting return, enter or esc will terminate the search. - bind /* = search %s - # when you type `ZZ` and nothing else, the exit action will be triggered immediately. - bind ZZ = exit - - ACT -This tells uzbl to execute an action immediately. The simplest example of this would be `act exit`; you know what that'll do. - -(See sample config) - -### ACTIONS -Actions are invoked via bindings and by the ACT command. Most actions are self-explanatory, though a few need to be clarified. A list of -actions follows: +* `set = ` + - used for changing variables on the fly + - the changes are effective immediately; for example, setting the variable `uri` will make uzbl start loading, and changing `status_format` will make the status bar react immediately + - if you want to unset a string, use `set` with one space after the equals sign +* `get ` + - use this to print the value of a variable. (and TODO, get the value through the socket) +* `bind = ` + - sets the character sequence `` to invoke `` when typed interactively in uzbl + - there are a few tricks you can do: + * `` ends with an underscore: the command will only be invoked after pressing return/enter. If the user enters text where `` has the underscore, `%s` in the `` string will be replaced by this text. (optional) + * `` ends with an asterisk: similar behavior as with an underscore, but also makes the binding incremental (i.e. the command will be invoked on every keystroke). + * `` ends on a different character: you need to type the full string, which will trigger the command immediately, without pressing enter/return. + - examples: + + # uzbl will load the url when you type: 'o ' + bind o _ = uri %s + # a search command which is called on every character typed after the slash, letting you see the search narrow down while typing. + # Hitting return, enter or esc will terminate the search. + bind /* = search %s + # when you type `ZZ` and nothing else, the exit command will be triggered immediately. + bind ZZ = exit * `back` * `forward` @@ -150,7 +137,7 @@ actions follows: * `uri
` * `js ` - execute the javascript in `` - - remember that the commands, and thus actions, must not contain line breaks + - remember that the commands must not contain line breaks * `script ` - execute the javascript in `` * `toggle_status` @@ -161,14 +148,16 @@ actions follows: * `sh ` - runs a shell command by expanding `%s` in the `shell_cmd` variable with the specified command; primarily useful as a shortcut for `spawn sh -c ` - note that the arguments as specified in "EXTERNAL SCRIPTS" are appended at the end, so the argument numbers will be higher. +* `sync_spawn ` +* `sync_sh ` + - these are synchronous variants of `spawn` and `sh`, which means uzbl will wait for them to return + - you should only need to use these manually if you want to use a chain action in a handler that wants output from the command it runs * `exit` * `search ` * `search_reverse ` - search with no string will search for the next/previous occurrence of the string previously searched for * `toggle_insert_mode ` - if the optional state is 0, disable insert mode. If 1, enable insert mode. -* `runcmd` - - can be used for running a command such as SET or BIND * `keycmd ` * `keycmd_nl ` - keycmd sets the interactive command buffer to ``. If the given string is a valid binding, it will execute. `Keycmd_nl` is like `keycmd`, but it also emulates a press of return, causing bindings with a parameter to execute. For example, `keycmd_nl o google.com` would load the said url if you have a binding like `bind o _ = uri %s`. @@ -177,6 +166,7 @@ actions follows: * `chain ..` - use for chaining multiple actions - remember to quote the actions; one action must come as one parameter + - if you use `chain` with a handler script which must return some output (such as a cookie handler -- uzbl will wait for and use its output), use sync_spawn or sync_sh instead of spawn or sh in the command that should give the output ### VARIABLE REPLACEMENT -- cgit v1.2.3 From e80ef2dc33edb53bf6a1e36b9c1db8a64dfb025c Mon Sep 17 00:00:00 2001 From: DuClare Date: Fri, 29 May 2009 23:53:13 +0300 Subject: Update sampleconfigs. Commands and actions have been merged :) --- examples/configs/sampleconfig | 12 ++++++------ examples/configs/sampleconfig-dev | 13 ++++++------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/examples/configs/sampleconfig b/examples/configs/sampleconfig index 06f3f13..42edf75 100644 --- a/examples/configs/sampleconfig +++ b/examples/configs/sampleconfig @@ -2,13 +2,13 @@ # example uzbl config. in a real config, we should obey the xdg spec # all settings are optional. you can use uzbl without any config at all (but it won't do much) -# keyboard behavior is vimstyle by default (all actions -> 1 key). set +# keyboard behavior is vimstyle by default (all commands -> 1 key). set # always_insert_mode to always be in insert mode and disable going out of it. -# if you do this, make sure you've set a modkey so you can reach the actions +# if you do this, make sure you've set a modkey so you can reach the commands # from insert mode by combining them with the modkey # TODO: ability to attach misc things (spawn , script ,.. to internal events) -# You can use any action in place of spawn +# You can use any command in place of spawn set history_handler = spawn /usr/share/uzbl/examples/scripts/history.sh set download_handler = spawn /usr/share/uzbl/examples/scripts/download.sh set cookie_handler = spawn /usr/share/uzbl/examples/scripts/cookies.sh @@ -94,9 +94,9 @@ bind ytitle = spawn /usr/share/uzbl/examples/scripts/yank.sh 9 clipboard # does the same as yurl but without needing a script bind y2url = sh "echo -n $6 | xclip" # go the page from primary selection -bind p = sh "echo act uri `xclip -selection primary -o` > $4" +bind p = sh "echo uri `xclip -selection primary -o` > $4" # go to the page in clipboard -bind P = sh "echo act uri `xclip -selection clipboard -o` > $4" +bind P = sh "echo uri `xclip -selection clipboard -o` > $4" bind ZZ = exit bind S = js alert("hi"); # example showing how to use sh @@ -104,7 +104,7 @@ bind S = js alert("hi"); # if fifo_dir is not set, it'll echo to a file named (null) somewhere >:) remember to delete it # Parameters are separated by spaces and the script body must be one parameter, so enclose it in # quotes and escape any inner quotes using backslashes -bind XS = sh 'echo "act script alert (\'This is sent by the shell via a fifo\')" > "$4"' +bind XS = sh 'echo "js alert (\'This is sent by the shell via a fifo\')" > "$4"' # we ship some javascripts to do keyboard based link hinting/following. (webkit does not have C DOM bindings yet) diff --git a/examples/configs/sampleconfig-dev b/examples/configs/sampleconfig-dev index 3deeac1..002f550 100644 --- a/examples/configs/sampleconfig-dev +++ b/examples/configs/sampleconfig-dev @@ -2,13 +2,13 @@ # example uzbl config. in a real config, we should obey the xdg spec # all settings are optional. you can use uzbl without any config at all (but it won't do much) -# keyboard behavior is vimstyle by default (all actions -> 1 key). set +# keyboard behavior is vimstyle by default (all commands -> 1 key). set # always_insert_mode to always be in insert mode and disable going out of it. -# if you do this, make sure you've set a modkey so you can reach the actions +# if you do this, make sure you've set a modkey so you can reach the commands # from insert mode by combining them with the modkey # TODO: ability to attach misc things (spawn , script ,.. to internal events) -# Usually you want to spawn a script to handle things, but any action (such as sh) can be used +# Usually you want to spawn a script to handle things, but any command (such as sh) can be used set history_handler = spawn ./examples/scripts/history.sh set download_handler = spawn ./examples/scripts/download.sh set cookie_handler = spawn ./examples/scripts/cookies.sh @@ -130,9 +130,9 @@ bind ytitle = spawn ./examples/scripts/yank.sh 9 clipboard # does the same as yurl but without needing a script bind y2url = sh 'echo -n $6 | xclip' # go the page from primary selection -bind p = sh "echo act uri `xclip -selection primary -o` > $4" +bind p = sh "echo uri `xclip -selection primary -o` > $4" # go to the page in clipboard -bind P = sh "echo act uri `xclip -selection clipboard -o` > $4" +bind P = sh "echo uri `xclip -selection clipboard -o` > $4" bind ZZ = exit bind S = js alert("hi"); # example showing how to use sh @@ -142,8 +142,7 @@ bind S = js alert("hi"); # you must enclose it in quotes. Remember to escape (and double-escape) quotes and backslashes # in the body. Any additional parameters you use will appear AFTER the default parameters (cfg file # path, fifo & socket dirs, etc.) -bind XS = sh 'echo "act script alert (\\"This is sent by the shell via a fifo\\")" > "$4"' - +bind XS = sh 'echo "js alert (\\"This is sent by the shell via a fifo\\")" > "$4"' # this script allows you to configure (per domain) values to fill in form fields (eg login information) and to fill in these values automatically bind za = spawn ./examples/scripts/formfiller.sh -- cgit v1.2.3 From 079f3851fe7b4077ad56594936f8181225373224 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Fri, 29 May 2009 23:48:06 +0200 Subject: readme cleanup re: commands vs actions --- README | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/README b/README index 5529b8f..4f394bd 100644 --- a/README +++ b/README @@ -83,14 +83,6 @@ When uzbl forks a new instance (eg "open in new window") it will use the same co If you made changes to the configuration at runtime, these are not pased on to the child. ### COMMAND SYNTAX -Commands are used for: - -* creating keybindings -* altering variables -* getting the values of variables -* running actions -* setting the input buffer - Uzbl will read commands via standard input, named fifo pipe (if `fifo_dir` is set) and IPC socket (when `socket_dir` is set). For convenience, uzbl can also be instructed to read commands from a file on startup by using the `-c` option. Indeed, the config file is nothing more than a list of commands. @@ -151,7 +143,7 @@ The following commands are recognized: * `sync_spawn ` * `sync_sh ` - these are synchronous variants of `spawn` and `sh`, which means uzbl will wait for them to return - - you should only need to use these manually if you want to use a chain action in a handler that wants output from the command it runs + - you should only need to use these manually if you want to use a chain command in a handler that wants output from the command it runs * `exit` * `search ` * `search_reverse ` @@ -163,9 +155,9 @@ The following commands are recognized: - keycmd sets the interactive command buffer to ``. If the given string is a valid binding, it will execute. `Keycmd_nl` is like `keycmd`, but it also emulates a press of return, causing bindings with a parameter to execute. For example, `keycmd_nl o google.com` would load the said url if you have a binding like `bind o _ = uri %s`. * `keycmd_bs` - erase (backspace) one character from the command buffer -* `chain ..` - - use for chaining multiple actions - - remember to quote the actions; one action must come as one parameter +* `chain ..` + - use for chaining multiple commands + - remember to quote the commands; one command must come as one parameter - if you use `chain` with a handler script which must return some output (such as a cookie handler -- uzbl will wait for and use its output), use sync_spawn or sync_sh instead of spawn or sh in the command that should give the output -- cgit v1.2.3 From 26f103c5cdda0f4874fb41632808451b59ad9278 Mon Sep 17 00:00:00 2001 From: DuClare Date: Sat, 30 May 2009 00:48:49 +0300 Subject: Make --uri override the uri read from config. --- uzbl.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/uzbl.c b/uzbl.c index d854bd2..a6b699a 100644 --- a/uzbl.c +++ b/uzbl.c @@ -2392,6 +2392,9 @@ main (int argc, char* argv[]) { g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_parse (context, &argc, &argv, NULL); g_option_context_free(context); + + gchar *uri_override = (uzbl.state.uri ? g_strdup(uzbl.state.uri) : NULL); + /* initialize hash table */ uzbl.bindings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, free_action); @@ -2469,12 +2472,11 @@ main (int argc, char* argv[]) { create_stdin(); - if(uzbl.state.uri) { - GArray *a = g_array_new (TRUE, FALSE, sizeof(gchar*)); - g_array_append_val(a, uzbl.state.uri); - load_uri (uzbl.gui.web_view, a); - g_array_free (a, TRUE); - } + if (uri_override) { + set_var_value("uri", uri_override); + g_free(uri_override); + } else if (uzbl.state.uri) + cmd_load_uri(uzbl.gui.web_view, NULL); gtk_main (); clean_up(); -- cgit v1.2.3 From affa3d4e8fd344d08f8a20b8a1fa19570f6e917f Mon Sep 17 00:00:00 2001 From: DuClare Date: Sat, 30 May 2009 01:08:33 +0300 Subject: Add var 'verbose' --- uzbl.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/uzbl.c b/uzbl.c index a6b699a..78760b0 100644 --- a/uzbl.c +++ b/uzbl.c @@ -97,6 +97,7 @@ const struct { /* variable name pointer to variable in code type dump callback function */ /* --------------------------------------------------------------------------------------- */ { "uri", PTR(uzbl.state.uri, STR, 1, cmd_load_uri)}, + { "verbose", PTR(uzbl.state.verbose, INT, 1, NULL)}, { "mode", PTR(uzbl.behave.mode, INT, 0, NULL)}, { "inject_html", PTR(uzbl.behave.inject_html, STR, 0, cmd_inject_html)}, { "base_url", PTR(uzbl.behave.base_url, STR, 1, NULL)}, @@ -2394,6 +2395,7 @@ main (int argc, char* argv[]) { g_option_context_free(context); gchar *uri_override = (uzbl.state.uri ? g_strdup(uzbl.state.uri) : NULL); + gboolean verbose_override = uzbl.state.verbose; /* initialize hash table */ uzbl.bindings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, free_action); @@ -2472,6 +2474,9 @@ main (int argc, char* argv[]) { create_stdin(); + if (verbose_override > uzbl.state.verbose) + uzbl.state.verbose = verbose_override; + if (uri_override) { set_var_value("uri", uri_override); g_free(uri_override); -- cgit v1.2.3 From f219ef203be9b8b89a8ef13b7ebc78aa3ff01112 Mon Sep 17 00:00:00 2001 From: Robert Manea Date: Sat, 30 May 2009 13:22:08 +0200 Subject: added print command --- uzbl.c | 18 +++++++++++++++--- uzbl.h | 3 +++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/uzbl.c b/uzbl.c index e870872..db7d7e9 100644 --- a/uzbl.c +++ b/uzbl.c @@ -616,7 +616,8 @@ static struct {char *name; Command command[2];} cmdlist[] = { "keycmd", {keycmd, NOSPLIT} }, { "keycmd_nl", {keycmd_nl, NOSPLIT} }, { "keycmd_bs", {keycmd_bs, 0} }, - { "chain", {chain, 0} } + { "chain", {chain, 0} }, + { "print", {print, NOSPLIT} } }; static void @@ -674,6 +675,16 @@ get_var(WebKitWebView *page, GArray *argv) { get_var_value(argv_idx(argv, 0)); } +static void +print(WebKitWebView *page, GArray *argv) { + (void) page; + gchar* buf; + + buf = expand_vars(argv_idx(argv, 0)); + puts(buf); + g_free(buf); +} + static void act_bind(WebKitWebView *page, GArray *argv) { (void) page; @@ -1583,9 +1594,10 @@ parse_cmd_line(const char *ctl_line) { else { /* parse a command */ gchar *ctlstrip; gchar **tokens = NULL; + len = strlen(ctl_line); - if (ctl_line[strlen(ctl_line) - 1] == '\n') /* strip trailing newline */ - ctlstrip = g_strndup(ctl_line, strlen(ctl_line) - 1); + if (ctl_line[len - 1] == '\n') /* strip trailing newline */ + ctlstrip = g_strndup(ctl_line, len - 1); else ctlstrip = g_strdup(ctl_line); tokens = g_strsplit(ctlstrip, " ", 2); diff --git a/uzbl.h b/uzbl.h index 6ab31f6..121d6b5 100644 --- a/uzbl.h +++ b/uzbl.h @@ -245,6 +245,9 @@ set_var_value(gchar *name, gchar *val); static gboolean get_var_value(const gchar *name); +static void +print(WebKitWebView *page, GArray *argv); + static gboolean new_window_cb (WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, WebKitWebNavigationAction *navigation_action, WebKitWebPolicyDecision *policy_decision, gpointer user_data); -- cgit v1.2.3 From d6911ffa67b69deecfbab30b72e4aebf592754d3 Mon Sep 17 00:00:00 2001 From: Robert Manea Date: Sat, 30 May 2009 14:14:08 +0200 Subject: removed get command in favour of print --- uzbl.c | 21 +-------------------- uzbl.h | 6 ------ 2 files changed, 1 insertion(+), 26 deletions(-) diff --git a/uzbl.c b/uzbl.c index db7d7e9..9041f35 100644 --- a/uzbl.c +++ b/uzbl.c @@ -610,7 +610,7 @@ static struct {char *name; Command command[2];} cmdlist[] = { "dehilight", {dehilight, 0} }, { "toggle_insert_mode", {toggle_insert_mode, 0} }, { "set", {set_var, NOSPLIT} }, - { "get", {get_var, NOSPLIT} }, + //{ "get", {get_var, NOSPLIT} }, { "bind", {act_bind, NOSPLIT} }, { "dump_config", {act_dump_config, 0} }, { "keycmd", {keycmd, NOSPLIT} }, @@ -669,12 +669,6 @@ set_var(WebKitWebView *page, GArray *argv) { g_strfreev(split); } -static void -get_var(WebKitWebView *page, GArray *argv) { - (void) page; - get_var_value(argv_idx(argv, 0)); -} - static void print(WebKitWebView *page, GArray *argv) { (void) page; @@ -1274,19 +1268,6 @@ parse_command(const char *cmd, const char *param) { g_printerr ("command \"%s\" not understood. ignoring.\n", cmd); } -static gboolean -get_var_value(const gchar *name) { - uzbl_cmdprop *c; - - if( (c = g_hash_table_lookup(uzbl.comm.proto_var, name)) ) { - if(c->type == TYPE_STR) - printf("VAR: %s VALUE: (%s)\n", name, (char *)*c->ptr); - else if(c->type == TYPE_INT) - printf("VAR: %s VALUE: %d\n", name, (int)*c->ptr); - } - return TRUE; -} - static void set_proxy_url() { SoupURI *suri; diff --git a/uzbl.h b/uzbl.h index 121d6b5..846dad6 100644 --- a/uzbl.h +++ b/uzbl.h @@ -242,9 +242,6 @@ setup_signal(int signe, sigfunc *shandler); static gboolean set_var_value(gchar *name, gchar *val); -static gboolean -get_var_value(const gchar *name); - static void print(WebKitWebView *page, GArray *argv); @@ -427,9 +424,6 @@ save_cookies (SoupMessage *msg, static void set_var(WebKitWebView *page, GArray *argv); -static void -get_var(WebKitWebView *page, GArray *argv); - static void act_bind(WebKitWebView *page, GArray *argv); -- cgit v1.2.3 From 19861c22bc98358b379d4ebde0b07fd94f819e54 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sun, 31 May 2009 17:59:14 +0200 Subject: select more sense making paths for cookie data and config --- examples/scripts/cookies.sh | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/examples/scripts/cookies.sh b/examples/scripts/cookies.sh index cd449dc..ecb6d60 100755 --- a/examples/scripts/cookies.sh +++ b/examples/scripts/cookies.sh @@ -21,15 +21,16 @@ # http://kb.mozillazine.org/Cookies.txt # don't always append cookies, sometimes we need to overwrite -if [ -f /usr/share/uzbl/examples/configs/cookies ] -then - file=/usr/share/uzbl/examples/configs/cookies -else - file=./examples/configs/cookies #useful when developing -fi +[ -f /usr/share/uzbl/examples/configs/cookies ] && file=/usr/share/uzbl/examples/configs/cookies +[ -f $XDG_CONFIG_HOME/uzbl/cookies ] && file=$XDG_CONFIG_HOME/uzbl/cookies +[ -f ./examples/configs/cookies ] && file=./examples/configs/cookies #useful when developing +[ -z "$file" ] && exit 1 + +[ -d /usr/share/uzbl/examples/data ] && cookie_file=/usr/share/uzbl/examples/data/cookies.txt +[ -d $XDG_DATA_HOME/uzbl/ ] && cookie_file=$XDG_DATA_HOME/uzbl/cookies.txt +[ -d ./examples/data/ ] && cookie_file=./examples/data/cookies.txt #useful when developing +[ -z "$cookie_file" ] && exit 1 -#cookie_file=$XDG_DATA_HOME/uzbl/cookies.txt -cookie_file=./examples/data/cookies.txt which zenity &>/dev/null || exit 2 -- cgit v1.2.3 From 4fbcb2837c40036b2677470c07deaefc19996a86 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sun, 31 May 2009 18:34:44 +0200 Subject: notify user of stuff re: cookies + save_cookie function --- examples/scripts/cookies.sh | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/examples/scripts/cookies.sh b/examples/scripts/cookies.sh index ecb6d60..efac322 100755 --- a/examples/scripts/cookies.sh +++ b/examples/scripts/cookies.sh @@ -1,4 +1,7 @@ #!/bin/bash + +# THIS IS EXPERIMENTAL AND COULD BE INSECURE !!!!!! + # this is an example script of how you could manage your cookies.. # we use the cookies.txt format (See http://kb.mozillazine.org/Cookies.txt) # This is one textfile with entries like this: @@ -31,7 +34,13 @@ [ -d ./examples/data/ ] && cookie_file=./examples/data/cookies.txt #useful when developing [ -z "$cookie_file" ] && exit 1 - +# if this variable is set, we will use it to inform you when and which cookies we store, and when/which we send. +#notifier= +#notifier=notify-send +notify_wrapper () { + echo "$@" >> $HOME/cookielog +} +notifier=notify_wrapper which zenity &>/dev/null || exit 2 # Example cookie: @@ -53,6 +62,10 @@ field_name= field_value= field_exp='end_session' +function notify () { + [ -n "$notifier" ] && $notifier "$@" +} + # FOR NOW LETS KEEP IT SIMPLE AND JUST ALWAYS PUT AND ALWAYS GET function parse_cookie () { @@ -80,19 +93,32 @@ function parse_cookie () { # match cookies in cookies.txt againsh hostname and path function get_cookie () { path_esc=${path//\//\\/} - cookie=`awk "/^[^\t]*$host\t[^\t]*\t$path_esc/" $cookie_file 2>/dev/null | tail -n 1` + search="^[^\t]*$host\t[^\t]*\t$path_esc" + cookie=`awk "/$search/" $cookie_file 2>/dev/null | tail -n 1` if [ -z "$cookie" ] then + notify "Get_cookie: search: $search in $cookie_file -> no result" false else + notify "Get_cookie: search: $search in $cookie_file -> result: $cookie" read domain alow_read_other_subdomains path http_required expiration name value <<< "$cookie" cookie="$name=$value" - #echo "COOKIE $cookie" >> $HOME/cookielog true fi } -[ $action == PUT ] && parse_cookie && echo -e "$field_domain\tFALSE\t$field_path\tFALSE\t$field_exp\t$field_name\t$field_value" >> $cookie_file +function save_cookie () { + if parse_cookie + then + data="$field_domain\tFALSE\t$field_path\tFALSE\t$field_exp\t$field_name\t$field_value" + notify "save_cookie: adding $data to $cookie_file" + echo -e "$data" >> $cookie_file + else + notify "not saving a cookie. since we don't have policies yet, parse_cookie must have returned false. this is a bug" + fi +} + +[ $action == PUT ] && save_cookie [ $action == GET ] && get_cookie && echo "$cookie" exit -- cgit v1.2.3 From 5941ba2954f4d4694668f61189f940cb40fbfb51 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sun, 31 May 2009 23:18:55 +0200 Subject: cleanup. log script stdout with verbose flag --- uzbl.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/uzbl.c b/uzbl.c index d854bd2..25c3c38 100644 --- a/uzbl.c +++ b/uzbl.c @@ -1134,6 +1134,9 @@ run_command (const gchar *command, const guint npre, const gchar **args, g_string_append_printf(s, " -- result: %s", (result ? "true" : "false")); printf("%s\n", s->str); g_string_free(s, TRUE); + if(stdout) { + printf("Stdout: %s\n", *stdout); + } } if (err) { g_printerr("error on run_command: %s\n", err->message); @@ -2223,7 +2226,8 @@ settings_init () { static void handle_cookies (SoupSession *session, SoupMessage *msg, gpointer user_data){ (void) session; (void) user_data; - if (!uzbl.behave.cookie_handler) return; + if (!uzbl.behave.cookie_handler) + return; soup_message_add_header_handler(msg, "got-headers", "Set-Cookie", G_CALLBACK(save_cookies), NULL); GString *s = g_string_new (""); @@ -2233,7 +2237,6 @@ static void handle_cookies (SoupSession *session, SoupMessage *msg, gpointer use if(uzbl.comm.sync_stdout) soup_message_headers_replace (msg->request_headers, "Cookie", uzbl.comm.sync_stdout); - //printf("stdout: %s\n", uzbl.comm.sync_stdout); // debugging if (uzbl.comm.sync_stdout) uzbl.comm.sync_stdout = strfree(uzbl.comm.sync_stdout); g_string_free(s, TRUE); -- cgit v1.2.3 From ce4ce4ad0cdb53af39092607fadc0b94e609d2e3 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sun, 31 May 2009 23:29:09 +0200 Subject: adapt to new syntax --- examples/scripts/load_url_from_bookmarks.sh | 4 ++-- examples/scripts/load_url_from_history.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/scripts/load_url_from_bookmarks.sh b/examples/scripts/load_url_from_bookmarks.sh index 21ea33d..1ae39ff 100755 --- a/examples/scripts/load_url_from_bookmarks.sh +++ b/examples/scripts/load_url_from_bookmarks.sh @@ -18,5 +18,5 @@ else goto=`awk '{print $1}' $file | $DMENU $COLORS` fi -#[ -n "$goto" ] && echo "act uri $goto" > $4 -[ -n "$goto" ] && uzblctrl -s $5 -c "act uri $goto" +#[ -n "$goto" ] && echo "uri $goto" > $4 +[ -n "$goto" ] && uzblctrl -s $5 -c "uri $goto" diff --git a/examples/scripts/load_url_from_history.sh b/examples/scripts/load_url_from_history.sh index 649c6b7..37c2afc 100755 --- a/examples/scripts/load_url_from_history.sh +++ b/examples/scripts/load_url_from_history.sh @@ -17,5 +17,5 @@ else current=`tail -n 1 $history_file | awk '{print $3}'`; goto=`(echo $current; awk '{print $3}' $history_file | grep -v "^$current\$" | sort -u) | $DMENU $COLORS` fi -[ -n "$goto" ] && echo "act uri $goto" > $4 -#[ -n "$goto" ] && uzblctrl -s $5 -c "act uri $goto" +[ -n "$goto" ] && echo "uri $goto" > $4 +#[ -n "$goto" ] && uzblctrl -s $5 -c "uri $goto" -- cgit v1.2.3 From fb4d926b1349e36bc2d3870a266d360d02d5d335 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Mon, 1 Jun 2009 00:23:28 +0200 Subject: fix for better uzbl.comm.sync_stdout checking + fix for libsoup-CRITICAL **: soup_message_headers_append: assertion strpbrk (value, "\r\n") == NULL' failed. basic cookies seem to be working now --- uzbl.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/uzbl.c b/uzbl.c index 25c3c38..9588aca 100644 --- a/uzbl.c +++ b/uzbl.c @@ -2235,9 +2235,13 @@ static void handle_cookies (SoupSession *session, SoupMessage *msg, gpointer use g_string_printf(s, "GET '%s' '%s'", soup_uri->host, soup_uri->path); run_handler(uzbl.behave.cookie_handler, s->str); - if(uzbl.comm.sync_stdout) - soup_message_headers_replace (msg->request_headers, "Cookie", uzbl.comm.sync_stdout); - if (uzbl.comm.sync_stdout) uzbl.comm.sync_stdout = strfree(uzbl.comm.sync_stdout); + if(uzbl.comm.sync_stdout && strcmp (uzbl.comm.sync_stdout, "") != 0) { + char *p = strchr(uzbl.comm.sync_stdout, '\n' ); + if ( p != NULL ) *p = '\0'; + soup_message_headers_replace (msg->request_headers, "Cookie", (const char *) uzbl.comm.sync_stdout); + } + if (uzbl.comm.sync_stdout) + uzbl.comm.sync_stdout = strfree(uzbl.comm.sync_stdout); g_string_free(s, TRUE); } -- cgit v1.2.3