aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/uzbl-core.c
diff options
context:
space:
mode:
authorGravatar Brendan Taylor <whateley@gmail.com>2011-06-05 14:03:42 -0600
committerGravatar Brendan Taylor <whateley@gmail.com>2011-06-05 14:03:42 -0600
commitb9cb02d42b1e9b33b973efa98772a3559bf630f9 (patch)
tree398731a564dd358d037595c59b1e1da4cc33aeff /src/uzbl-core.c
parent4b890ec08c066be56f79c53e420f20d179d595e9 (diff)
parent1110023039fa7d13e2ddab29d6a7db50ab61f2ae (diff)
Merge remote-tracking branch 'keis/split-core' into experimental
Diffstat (limited to 'src/uzbl-core.c')
-rw-r--r--src/uzbl-core.c711
1 files changed, 17 insertions, 694 deletions
diff --git a/src/uzbl-core.c b/src/uzbl-core.c
index 6dd7a30..3cf2407 100644
--- a/src/uzbl-core.c
+++ b/src/uzbl-core.c
@@ -37,6 +37,8 @@
#include "util.h"
#include "menu.h"
#include "io.h"
+#include "variables.h"
+#include "type.h"
UzblCore uzbl;
@@ -67,110 +69,6 @@ GOptionEntry entries[] = {
{ NULL, 0, 0, 0, NULL, NULL, NULL }
};
-/* abbreviations to help keep the table's width humane */
-#define PTR_V_STR(var, d, fun) { .ptr.s = &(var), .type = TYPE_STR, .dump = d, .writeable = 1, .func = fun }
-#define PTR_V_INT(var, d, fun) { .ptr.i = (int*)&(var), .type = TYPE_INT, .dump = d, .writeable = 1, .func = fun }
-#define PTR_V_FLOAT(var, d, fun) { .ptr.f = &(var), .type = TYPE_FLOAT, .dump = d, .writeable = 1, .func = fun }
-#define PTR_C_STR(var, fun) { .ptr.s = &(var), .type = TYPE_STR, .dump = 0, .writeable = 0, .func = fun }
-#define PTR_C_INT(var, fun) { .ptr.i = (int*)&(var), .type = TYPE_INT, .dump = 0, .writeable = 0, .func = fun }
-#define PTR_C_FLOAT(var, fun) { .ptr.f = &(var), .type = TYPE_FLOAT, .dump = 0, .writeable = 0, .func = fun }
-
-const struct var_name_to_ptr_t {
- const char *name;
- uzbl_cmdprop cp;
-} var_name_to_ptr[] = {
-/* variable name pointer to variable in code dump callback function */
-/* ---------------------------------------------------------------------------------------------- */
- { "uri", PTR_V_STR(uzbl.state.uri, 1, cmd_load_uri)},
- { "verbose", PTR_V_INT(uzbl.state.verbose, 1, NULL)},
- { "print_events", PTR_V_INT(uzbl.state.events_stdout, 1, NULL)},
- { "inject_html", PTR_V_STR(uzbl.behave.inject_html, 0, cmd_inject_html)},
- { "geometry", PTR_V_STR(uzbl.gui.geometry, 1, cmd_set_geometry)},
- { "show_status", PTR_V_INT(uzbl.behave.show_status, 1, cmd_set_status)},
- { "status_top", PTR_V_INT(uzbl.behave.status_top, 1, move_statusbar)},
- { "status_format", PTR_V_STR(uzbl.behave.status_format, 1, NULL)},
- { "status_format_right", PTR_V_STR(uzbl.behave.status_format_right, 1, NULL)},
- { "status_background", PTR_V_STR(uzbl.behave.status_background, 1, set_status_background)},
- { "title_format_long", PTR_V_STR(uzbl.behave.title_format_long, 1, NULL)},
- { "title_format_short", PTR_V_STR(uzbl.behave.title_format_short, 1, NULL)},
- { "icon", PTR_V_STR(uzbl.gui.icon, 1, set_icon)},
- { "forward_keys", PTR_V_INT(uzbl.behave.forward_keys, 1, NULL)},
- { "authentication_handler", PTR_V_STR(uzbl.behave.authentication_handler, 1, set_authentication_handler)},
- { "scheme_handler", PTR_V_STR(uzbl.behave.scheme_handler, 1, NULL)},
- { "download_handler", PTR_V_STR(uzbl.behave.download_handler, 1, NULL)},
- { "fifo_dir", PTR_V_STR(uzbl.behave.fifo_dir, 1, cmd_fifo_dir)},
- { "socket_dir", PTR_V_STR(uzbl.behave.socket_dir, 1, cmd_socket_dir)},
- { "http_debug", PTR_V_INT(uzbl.behave.http_debug, 1, cmd_http_debug)},
- { "shell_cmd", PTR_V_STR(uzbl.behave.shell_cmd, 1, NULL)},
- { "proxy_url", PTR_V_STR(uzbl.net.proxy_url, 1, set_proxy_url)},
- { "max_conns", PTR_V_INT(uzbl.net.max_conns, 1, cmd_max_conns)},
- { "max_conns_host", PTR_V_INT(uzbl.net.max_conns_host, 1, cmd_max_conns_host)},
- { "useragent", PTR_V_STR(uzbl.net.useragent, 1, cmd_useragent)},
- { "accept_languages", PTR_V_STR(uzbl.net.accept_languages, 1, set_accept_languages)},
- { "javascript_windows", PTR_V_INT(uzbl.behave.javascript_windows, 1, cmd_javascript_windows)},
- /* requires webkit >=1.1.14 */
- { "view_source", PTR_V_INT(uzbl.behave.view_source, 0, cmd_view_source)},
-
- /* exported WebKitWebSettings properties */
- { "zoom_level", PTR_V_FLOAT(uzbl.behave.zoom_level, 1, cmd_zoom_level)},
- { "zoom_type", PTR_V_INT(uzbl.behave.zoom_type, 1, cmd_set_zoom_type)},
- { "font_size", PTR_V_INT(uzbl.behave.font_size, 1, cmd_font_size)},
- { "default_font_family", PTR_V_STR(uzbl.behave.default_font_family, 1, cmd_default_font_family)},
- { "monospace_font_family", PTR_V_STR(uzbl.behave.monospace_font_family, 1, cmd_monospace_font_family)},
- { "cursive_font_family", PTR_V_STR(uzbl.behave.cursive_font_family, 1, cmd_cursive_font_family)},
- { "sans_serif_font_family", PTR_V_STR(uzbl.behave.sans_serif_font_family, 1, cmd_sans_serif_font_family)},
- { "serif_font_family", PTR_V_STR(uzbl.behave.serif_font_family, 1, cmd_serif_font_family)},
- { "fantasy_font_family", PTR_V_STR(uzbl.behave.fantasy_font_family, 1, cmd_fantasy_font_family)},
- { "monospace_size", PTR_V_INT(uzbl.behave.monospace_size, 1, cmd_font_size)},
- { "minimum_font_size", PTR_V_INT(uzbl.behave.minimum_font_size, 1, cmd_minimum_font_size)},
- { "enable_pagecache", PTR_V_INT(uzbl.behave.enable_pagecache, 1, cmd_enable_pagecache)},
- { "disable_plugins", PTR_V_INT(uzbl.behave.disable_plugins, 1, cmd_disable_plugins)},
- { "disable_scripts", PTR_V_INT(uzbl.behave.disable_scripts, 1, cmd_disable_scripts)},
- { "autoload_images", PTR_V_INT(uzbl.behave.autoload_img, 1, cmd_autoload_img)},
- { "autoshrink_images", PTR_V_INT(uzbl.behave.autoshrink_img, 1, cmd_autoshrink_img)},
- { "enable_spellcheck", PTR_V_INT(uzbl.behave.enable_spellcheck, 1, cmd_enable_spellcheck)},
- { "enable_private", PTR_V_INT(uzbl.behave.enable_private, 1, cmd_enable_private)},
- { "print_backgrounds", PTR_V_INT(uzbl.behave.print_bg, 1, cmd_print_bg)},
- { "stylesheet_uri", PTR_V_STR(uzbl.behave.style_uri, 1, cmd_style_uri)},
- { "resizable_text_areas", PTR_V_INT(uzbl.behave.resizable_txt, 1, cmd_resizable_txt)},
- { "default_encoding", PTR_V_STR(uzbl.behave.default_encoding, 1, cmd_default_encoding)},
- { "current_encoding", PTR_V_STR(uzbl.behave.current_encoding, 1, set_current_encoding)},
- { "enforce_96_dpi", PTR_V_INT(uzbl.behave.enforce_96dpi, 1, cmd_enforce_96dpi)},
- { "caret_browsing", PTR_V_INT(uzbl.behave.caret_browsing, 1, cmd_caret_browsing)},
-
-#if !GTK_CHECK_VERSION(3,0,0)
- { "scrollbars_visible", PTR_V_INT(uzbl.gui.scrollbars_visible, 1, cmd_scrollbars_visibility)},
-#endif
-
- /* constants (not dumpable or writeable) */
- { "WEBKIT_MAJOR", PTR_C_INT(uzbl.info.webkit_major, NULL)},
- { "WEBKIT_MINOR", PTR_C_INT(uzbl.info.webkit_minor, NULL)},
- { "WEBKIT_MICRO", PTR_C_INT(uzbl.info.webkit_micro, NULL)},
- { "ARCH_UZBL", PTR_C_STR(uzbl.info.arch, NULL)},
- { "COMMIT", PTR_C_STR(uzbl.info.commit, NULL)},
- { "TITLE", PTR_C_STR(uzbl.gui.main_title, NULL)},
- { "SELECTED_URI", PTR_C_STR(uzbl.state.selected_url, NULL)},
- { "NAME", PTR_C_STR(uzbl.state.instance_name, NULL)},
- { "PID", PTR_C_STR(uzbl.info.pid_str, NULL)},
- { "_", PTR_C_STR(uzbl.state.last_result, NULL)},
-
- { NULL, {.ptr.s = NULL, .type = TYPE_INT, .dump = 0, .writeable = 0, .func = NULL}}
-};
-
-/* construct a hash from the var_name_to_ptr array for quick access */
-void
-create_var_to_name_hash() {
- 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,
- (gpointer) n2v_p->name,
- (gpointer) &n2v_p->cp);
- n2v_p++;
- }
-}
-
-
/* --- UTILITY FUNCTIONS --- */
enum exp_type {
EXP_ERR, EXP_SIMPLE_VAR, EXP_BRACED_VAR, EXP_EXPR, EXP_JS, EXP_ESCAPE
@@ -193,7 +91,6 @@ get_exp_type(const gchar *s) {
*/
gchar*
expand(const char* s, guint recurse) {
- uzbl_cmdprop* c;
enum exp_type etype;
char* end_simple_var = "\t^°!\"§$%&/()=?'`'+~*'#-:,;@<>| \\{}[]¹²³¼½";
char* ret = NULL;
@@ -250,17 +147,8 @@ expand(const char* s, guint recurse) {
if(etype == EXP_SIMPLE_VAR ||
etype == EXP_BRACED_VAR) {
- if( (c = g_hash_table_lookup(uzbl.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) {
- g_string_append_printf(buf, "%d", *c->ptr.i);
- }
- else if(c->type == TYPE_FLOAT) {
- g_string_append_printf(buf, "%f", *c->ptr.f);
- }
- }
+
+ expand_variable(buf, ret);
if(etype == EXP_SIMPLE_VAR)
s = vend;
@@ -454,194 +342,8 @@ scroll(GtkAdjustment* bar, gchar *amount_str) {
gtk_adjustment_set_value (bar, value);
}
-/*
- * scroll vertical 20
- * scroll vertical 20%
- * scroll vertical -40
- * scroll vertical begin
- * scroll vertical end
- * scroll horizontal 10
- * scroll horizontal -500
- * scroll horizontal begin
- * scroll horizontal end
- */
-void
-scroll_cmd(WebKitWebView* page, GArray *argv, GString *result) {
- (void) page; (void) result;
- gchar *direction = g_array_index(argv, gchar*, 0);
- gchar *argv1 = g_array_index(argv, gchar*, 1);
- GtkAdjustment *bar = NULL;
-
- if (g_strcmp0(direction, "horizontal") == 0)
- bar = uzbl.gui.bar_h;
- else if (g_strcmp0(direction, "vertical") == 0)
- bar = uzbl.gui.bar_v;
- else {
- if(uzbl.state.verbose)
- puts("Unrecognized scroll format");
- return;
- }
-
- if (g_strcmp0(argv1, "begin") == 0)
- gtk_adjustment_set_value(bar, gtk_adjustment_get_lower(bar));
- else if (g_strcmp0(argv1, "end") == 0)
- gtk_adjustment_set_value (bar, gtk_adjustment_get_upper(bar) -
- gtk_adjustment_get_page_size(bar));
- else
- scroll(bar, argv1);
-}
-
-
-/* VIEW funcs (little webkit wrappers) */
-#define VIEWFUNC(name) void view_##name(WebKitWebView *page, GArray *argv, GString *result){(void)argv; (void)result; webkit_web_view_##name(page);}
-VIEWFUNC(reload)
-VIEWFUNC(reload_bypass_cache)
-VIEWFUNC(stop_loading)
-VIEWFUNC(zoom_in)
-VIEWFUNC(zoom_out)
-VIEWFUNC(go_back)
-VIEWFUNC(go_forward)
-#undef VIEWFUNC
-
-/* -- command to callback/function map for things we cannot attach to any signals */
-CommandInfo cmdlist[] =
-{ /* key function no_split */
- { "back", view_go_back, 0 },
- { "forward", view_go_forward, 0 },
- { "scroll", scroll_cmd, 0 },
- { "reload", view_reload, 0 },
- { "reload_ign_cache", view_reload_bypass_cache, 0 },
- { "stop", view_stop_loading, 0 },
- { "zoom_in", view_zoom_in, 0 }, //Can crash (when max zoom reached?).
- { "zoom_out", view_zoom_out, 0 },
- { "toggle_zoom_type", toggle_zoom_type, 0 },
- { "uri", load_uri, TRUE },
- { "js", run_js, TRUE },
- { "script", run_external_js, 0 },
- { "toggle_status", toggle_status_cb, 0 },
- { "spawn", spawn_async, 0 },
- { "sync_spawn", spawn_sync, 0 },
- { "sync_spawn_exec", spawn_sync_exec, 0 }, // needed for load_cookies.sh :(
- { "sh", spawn_sh_async, 0 },
- { "sync_sh", spawn_sh_sync, 0 },
- { "exit", close_uzbl, 0 },
- { "search", search_forward_text, TRUE },
- { "search_reverse", search_reverse_text, TRUE },
- { "search_clear", search_clear, TRUE },
- { "dehilight", dehilight, 0 },
- { "set", set_var, TRUE },
- { "dump_config", act_dump_config, 0 },
- { "dump_config_as_events", act_dump_config_as_events, 0 },
- { "chain", chain, 0 },
- { "print", print, TRUE },
- { "event", event, TRUE },
- { "request", event, TRUE },
- { "menu_add", menu_add, TRUE },
- { "menu_link_add", menu_add_link, TRUE },
- { "menu_image_add", menu_add_image, TRUE },
- { "menu_editable_add", menu_add_edit, TRUE },
- { "menu_separator", menu_add_separator, TRUE },
- { "menu_link_separator", menu_add_separator_link, TRUE },
- { "menu_image_separator", menu_add_separator_image, TRUE },
- { "menu_editable_separator", menu_add_separator_edit, TRUE },
- { "menu_remove", menu_remove, TRUE },
- { "menu_link_remove", menu_remove_link, TRUE },
- { "menu_image_remove", menu_remove_image, TRUE },
- { "menu_editable_remove", menu_remove_edit, TRUE },
- { "hardcopy", hardcopy, TRUE },
- { "include", include, TRUE },
- { "show_inspector", show_inspector, 0 },
- { "add_cookie", add_cookie, 0 },
- { "delete_cookie", delete_cookie, 0 },
- { "clear_cookies", clear_cookies, 0 },
- { "download", download, 0 }
-};
-
-void
-commands_hash(void) {
- unsigned int i;
- 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, (gpointer) cmdlist[i].key, &cmdlist[i]);
-}
-
-
-void
-builtins() {
- unsigned int i;
- unsigned int len = LENGTH(cmdlist);
- GString* command_list = g_string_new("");
-
- for (i = 0; i < len; i++) {
- g_string_append(command_list, cmdlist[i].key);
- g_string_append_c(command_list, ' ');
- }
-
- send_event(BUILTINS, NULL, TYPE_STR, command_list->str, NULL);
- g_string_free(command_list, TRUE);
-}
-
/* -- CORE FUNCTIONS -- */
-void
-set_var(WebKitWebView *page, GArray *argv, GString *result) {
- (void) page; (void) result;
-
- if(!argv_idx(argv, 0))
- return;
-
- gchar **split = g_strsplit(argv_idx(argv, 0), "=", 2);
- if (split[0] != NULL) {
- gchar *value = split[1] ? g_strchug(split[1]) : " ";
- set_var_value(g_strstrip(split[0]), value);
- }
- g_strfreev(split);
-}
-
-
-void
-event(WebKitWebView *page, GArray *argv, GString *result) {
- (void) page; (void) result;
- GString *event_name;
- gchar **split = NULL;
-
- if(!argv_idx(argv, 0))
- return;
-
- split = g_strsplit(argv_idx(argv, 0), " ", 2);
- if(split[0])
- event_name = g_string_ascii_up(g_string_new(split[0]));
- else
- return;
-
- send_event(0, event_name->str, TYPE_FORMATTEDSTR, split[1] ? split[1] : "", NULL);
-
- g_string_free(event_name, TRUE);
- g_strfreev(split);
-}
-
-void
-print(WebKitWebView *page, GArray *argv, GString *result) {
- (void) page; (void) result;
- gchar* buf;
-
- if(!result)
- return;
-
- buf = expand(argv_idx(argv, 0), 0);
- g_string_assign(result, buf);
- g_free(buf);
-}
-
-void
-hardcopy(WebKitWebView *page, GArray *argv, GString *result) {
- (void) argv;
- (void) result;
-
- webkit_web_frame_print(webkit_web_view_get_main_frame(page));
-}
-
/* just a wrapper so parse_cmd_line can be used with for_each_line_in_file */
static void
parse_cmd_line_cb(const char *line, void *user_data) {
@@ -650,135 +352,12 @@ parse_cmd_line_cb(const char *line, void *user_data) {
}
void
-include(WebKitWebView *page, GArray *argv, GString *result) {
- (void) page;
- (void) result;
- gchar *path = argv_idx(argv, 0);
-
- if(!path)
- return;
-
- if((path = find_existing_file(path))) {
- if(!for_each_line_in_file(path, parse_cmd_line_cb, NULL)) {
- gchar *tmp = g_strdup_printf("File %s can not be read.", path);
- send_event(COMMAND_ERROR, NULL, TYPE_STR, tmp, NULL);
- g_free(tmp);
- }
-
- send_event(FILE_INCLUDED, NULL, TYPE_STR, path, NULL);
- g_free(path);
- }
-}
-
-void
-show_inspector(WebKitWebView *page, GArray *argv, GString *result) {
- (void) page; (void) argv; (void) result;
-
- webkit_web_inspector_show(uzbl.gui.inspector);
-}
-
-void
-add_cookie(WebKitWebView *page, GArray *argv, GString *result) {
- (void) page; (void) result;
- gchar *host, *path, *name, *value;
- gboolean secure = 0;
- SoupDate *expires = NULL;
-
- if(argv->len != 6)
- return;
-
- // Parse with same syntax as ADD_COOKIE event
- host = argv_idx (argv, 0);
- path = argv_idx (argv, 1);
- name = argv_idx (argv, 2);
- value = argv_idx (argv, 3);
- secure = strcmp (argv_idx (argv, 4), "https") == 0;
- if (strlen (argv_idx (argv, 5)) != 0)
- expires = soup_date_new_from_time_t (
- strtoul (argv_idx (argv, 5), NULL, 10));
-
- // Create new cookie
- SoupCookie * cookie = soup_cookie_new (name, value, host, path, -1);
- soup_cookie_set_secure (cookie, secure);
- if (expires)
- soup_cookie_set_expires (cookie, expires);
-
- // Add cookie to jar
- uzbl.net.soup_cookie_jar->in_manual_add = 1;
- soup_cookie_jar_add_cookie (SOUP_COOKIE_JAR (uzbl.net.soup_cookie_jar), cookie);
- uzbl.net.soup_cookie_jar->in_manual_add = 0;
-}
-
-void
-delete_cookie(WebKitWebView *page, GArray *argv, GString *result) {
- (void) page; (void) result;
-
- if(argv->len < 4)
- return;
-
- SoupCookie * cookie = soup_cookie_new (
- argv_idx (argv, 2),
- argv_idx (argv, 3),
- argv_idx (argv, 0),
- argv_idx (argv, 1),
- 0);
-
- uzbl.net.soup_cookie_jar->in_manual_add = 1;
- soup_cookie_jar_delete_cookie (SOUP_COOKIE_JAR (uzbl.net.soup_cookie_jar), cookie);
- uzbl.net.soup_cookie_jar->in_manual_add = 0;
-}
-
-
-void
-clear_cookies(WebKitWebView *page, GArray *argv, GString *result) {
- (void) page; (void) argv; (void) result;
-
- // Replace the current cookie jar with a new empty jar
- soup_session_remove_feature (uzbl.net.soup_session,
- SOUP_SESSION_FEATURE (uzbl.net.soup_cookie_jar));
- g_object_unref (G_OBJECT (uzbl.net.soup_cookie_jar));
- uzbl.net.soup_cookie_jar = uzbl_cookie_jar_new ();
- soup_session_add_feature(uzbl.net.soup_session,
- SOUP_SESSION_FEATURE (uzbl.net.soup_cookie_jar));
-}
-
-void
-download(WebKitWebView *web_view, GArray *argv, GString *result) {
- (void) result;
-
- const gchar *uri = argv_idx(argv, 0);
- const gchar *destination = NULL;
- if(argv->len > 1)
- destination = argv_idx(argv, 1);
-
- WebKitNetworkRequest *req = webkit_network_request_new(uri);
- WebKitDownload *download = webkit_download_new(req);
-
- download_cb(web_view, download, (gpointer)destination);
-
- if(webkit_download_get_destination_uri(download))
- webkit_download_start(download);
- else
- g_object_unref(download);
-
- g_object_unref(req);
-}
-
-void
-act_dump_config() {
- dump_config();
-}
-
-void
-act_dump_config_as_events() {
- dump_config_as_events();
-}
-
-void
-load_uri(WebKitWebView *web_view, GArray *argv, GString *result) {
- (void) web_view; (void) result;
- gchar * uri = argv_idx(argv, 0);
- set_var_value("uri", uri ? uri : "");
+run_command_file(const gchar *path) {
+ if(!for_each_line_in_file(path, parse_cmd_line_cb, NULL)) {
+ gchar *tmp = g_strdup_printf("File %s can not be read.", path);
+ send_event(COMMAND_ERROR, NULL, TYPE_STR, tmp, NULL);
+ g_free(tmp);
+ }
}
/* Javascript*/
@@ -862,51 +441,16 @@ eval_js(WebKitWebView * web_view, const gchar *script, GString *result, const ch
}
void
-run_js (WebKitWebView * web_view, GArray *argv, GString *result) {
- if (argv_idx(argv, 0))
- eval_js(web_view, argv_idx(argv, 0), result, "(command)");
-}
-
-void
-run_external_js (WebKitWebView * web_view, GArray *argv, GString *result) {
- (void) result;
- gchar *path = NULL;
-
- if (argv_idx(argv, 0) &&
- ((path = find_existing_file(argv_idx(argv, 0)))) ) {
- gchar *file_contents = NULL;
-
- GIOChannel *chan = g_io_channel_new_file(path, "r", NULL);
- if (chan) {
- gsize len;
- g_io_channel_read_to_end(chan, &file_contents, &len, NULL);
- g_io_channel_unref (chan);
- }
-
- if (uzbl.state.verbose)
- printf ("External JavaScript file %s loaded\n", argv_idx(argv, 0));
-
- gchar *js = str_replace("%s", argv_idx (argv, 1) ? argv_idx (argv, 1) : "", file_contents);
- g_free (file_contents);
-
- eval_js (web_view, js, result, path);
- g_free (js);
- g_free(path);
- }
-}
-
-void
-search_text (WebKitWebView *page, GArray *argv, const gboolean forward) {
- if (argv_idx(argv, 0) && (*argv_idx(argv, 0) != '\0')) {
- if (g_strcmp0 (uzbl.state.searchtx, argv_idx(argv, 0)) != 0) {
+search_text (WebKitWebView *page, const gchar *key, const gboolean forward) {
+ if (key && (*key != '\0')) {
+ if (g_strcmp0 (uzbl.state.searchtx, key) != 0) {
webkit_web_view_unmark_text_matches (page);
- webkit_web_view_mark_text_matches (page, argv_idx(argv, 0), FALSE, 0);
+ webkit_web_view_mark_text_matches (page, key, FALSE, 0);
g_free (uzbl.state.searchtx);
- uzbl.state.searchtx = g_strdup(argv_idx(argv, 0));
+ uzbl.state.searchtx = g_strdup (key);
}
}
-
if (uzbl.state.searchtx) {
if (uzbl.state.verbose)
printf ("Searching: %s\n", uzbl.state.searchtx);
@@ -916,61 +460,6 @@ search_text (WebKitWebView *page, GArray *argv, const gboolean forward) {
}
void
-search_clear(WebKitWebView *page, GArray *argv, GString *result) {
- (void) argv;
- (void) result;
-
- webkit_web_view_unmark_text_matches (page);
- g_free(uzbl.state.searchtx);
- uzbl.state.searchtx = NULL;
-}
-
-void
-search_forward_text (WebKitWebView *page, GArray *argv, GString *result) {
- (void) result;
- search_text(page, argv, TRUE);
-}
-
-void
-search_reverse_text(WebKitWebView *page, GArray *argv, GString *result) {
- (void) result;
- search_text(page, argv, FALSE);
-}
-
-void
-dehilight(WebKitWebView *page, GArray *argv, GString *result) {
- (void) argv; (void) result;
- webkit_web_view_set_highlight_text_matches (page, FALSE);
-}
-
-void
-chain(WebKitWebView *page, GArray *argv, GString *result) {
- (void) page;
- guint i = 0;
- const gchar *cmd;
- GString *r = g_string_new ("");
- while ((cmd = argv_idx(argv, i++))) {
- GArray *a = g_array_new (TRUE, FALSE, sizeof(gchar*));
- const CommandInfo *c = parse_command_parts(cmd, a);
- if (c)
- run_parsed_command(c, a, r);
- g_array_free (a, TRUE);
- }
- if(result)
- g_string_assign (result, r->str);
-
- g_string_free(r, TRUE);
-}
-
-void
-close_uzbl (WebKitWebView *page, GArray *argv, GString *result) {
- (void)page;
- (void)argv;
- (void)result;
- gtk_main_quit ();
-}
-
-void
sharg_append(GArray *a, const gchar *str) {
const gchar *s = (str ? str : "");
g_array_append_val(a, s);
@@ -1089,29 +578,6 @@ spawn(GArray *argv, GString *result, gboolean exec) {
}
void
-spawn_async(WebKitWebView *web_view, GArray *argv, GString *result) {
- (void)web_view; (void)result;
- spawn(argv, NULL, FALSE);
-}
-
-void
-spawn_sync(WebKitWebView *web_view, GArray *argv, GString *result) {
- (void)web_view;
- spawn(argv, result, FALSE);
-}
-
-void
-spawn_sync_exec(WebKitWebView *web_view, GArray *argv, GString *result) {
- (void)web_view;
- if(!result) {
- GString *force_result = g_string_new("");
- spawn(argv, force_result, TRUE);
- g_string_free (force_result, TRUE);
- } else
- spawn(argv, result, TRUE);
-}
-
-void
spawn_sh(GArray *argv, GString *result) {
if (!uzbl.behave.shell_cmd) {
g_printerr ("spawn_sh: shell_cmd is not set!\n");
@@ -1142,18 +608,6 @@ spawn_sh(GArray *argv, GString *result) {
}
void
-spawn_sh_async(WebKitWebView *web_view, GArray *argv, GString *result) {
- (void)web_view; (void)result;
- spawn_sh(argv, NULL);
-}
-
-void
-spawn_sh_sync(WebKitWebView *web_view, GArray *argv, GString *result) {
- (void)web_view; (void)result;
- spawn_sh(argv, result);
-}
-
-void
run_parsed_command(const CommandInfo *c, GArray *a, GString *result) {
/* send the COMMAND_EXECUTED event, except for set and event/request commands */
if(strcmp("set", c->key) &&
@@ -1254,7 +708,6 @@ parse_command(const char *cmd, const char *params, GString *result) {
}
}
-
void
move_statusbar() {
if (!uzbl.gui.scrolled_win && !uzbl.gui.mainbar)
@@ -1287,97 +740,6 @@ valid_name(const gchar* name) {
}
void
-send_set_var_event(const char *name, const uzbl_cmdprop *c) {
- /* check for the variable type */
- switch(c->type) {
- case TYPE_STR:
- send_event (VARIABLE_SET, NULL,
- TYPE_NAME, name,
- TYPE_NAME, "str",
- TYPE_STR, *c->ptr.s ? *c->ptr.s : " ",
- NULL);
- break;
- case TYPE_INT:
- send_event (VARIABLE_SET, NULL,
- TYPE_NAME, name,
- TYPE_NAME, "int",
- TYPE_INT, *c->ptr.i,
- NULL);
- break;
- case TYPE_FLOAT:
- send_event (VARIABLE_SET, NULL,
- TYPE_NAME, name,
- TYPE_NAME, "float",
- TYPE_FLOAT, *c->ptr.f,
- NULL);
- break;
- default:
- g_assert_not_reached();
- }
-}
-
-gboolean
-set_var_value(const gchar *name, gchar *val) {
- uzbl_cmdprop *c = NULL;
- char *endp = NULL;
- char *buf = NULL;
-
- g_assert(val != NULL);
-
- if( (c = g_hash_table_lookup(uzbl.comm.proto_var, name)) ) {
- if(!c->writeable) return FALSE;
-
- switch(c->type) {
- case TYPE_STR:
- buf = g_strdup(val);
- g_free(*c->ptr.s);
- *c->ptr.s = buf;
- break;
- case TYPE_INT:
- *c->ptr.i = (int)strtoul(val, &endp, 10);
- break;
- case TYPE_FLOAT:
- *c->ptr.f = strtod(val, &endp);
- break;
- default:
- g_assert_not_reached();
- }
-
- send_set_var_event(name, c);
-
- /* invoke a command specific function */
- if(c->func) c->func();
- } else {
- /* check wether name violates our naming scheme */
- if(!valid_name(name)) {
- if (uzbl.state.verbose)
- printf("Invalid variable name: %s\n", name);
- return FALSE;
- }
-
- /* custom vars */
- c = g_malloc(sizeof(uzbl_cmdprop));
- c->type = TYPE_STR;
- c->dump = 0;
- c->func = NULL;
- c->writeable = 1;
- buf = g_strdup(val);
- c->ptr.s = g_malloc(sizeof(char *));
- *c->ptr.s = buf;
- g_hash_table_insert(uzbl.comm.proto_var,
- g_strdup(name), (gpointer) c);
-
- send_event (VARIABLE_SET, NULL,
- TYPE_NAME, name,
- TYPE_NAME, "str",
- TYPE_STR, buf,
- NULL);
- }
- update_title();
- return TRUE;
-}
-
-void
parse_cmd_line(const char *ctl_line, GString *result) {
gchar *work_string = g_strdup(ctl_line);
@@ -1584,11 +946,7 @@ settings_init () {
/* Load config file, if any */
if (s->config_file) {
- if (!for_each_line_in_file(s->config_file, parse_cmd_line_cb, NULL)) {
- gchar *tmp = g_strdup_printf("File %s can not be read.", s->config_file);
- send_event(COMMAND_ERROR, NULL, TYPE_STR, tmp, NULL);
- g_free(tmp);
- }
+ run_command_file(s->config_file);
g_setenv("UZBL_CONFIG", s->config_file, TRUE);
} else if (uzbl.state.verbose)
printf ("No configuration file loaded.\n");
@@ -1655,41 +1013,6 @@ void handle_authentication (SoupSession *session, SoupMessage *msg, SoupAuth *au
}
void
-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.s ? *c->ptr.s : " ");
- else if(c->type == TYPE_INT)
- printf("set %s = %d\n", (char *)k, *c->ptr.i);
- else if(c->type == TYPE_FLOAT)
- printf("set %s = %f\n", (char *)k, *c->ptr.f);
-}
-
-void
-dump_config() {
- g_hash_table_foreach(uzbl.comm.proto_var, dump_var_hash, NULL);
-}
-
-void
-dump_var_hash_as_event(gpointer k, gpointer v, gpointer ud) {
- (void) ud;
- uzbl_cmdprop *c = v;
-
- if(c->dump)
- send_set_var_event(k, c);
-}
-
-void
-dump_config_as_events() {
- g_hash_table_foreach(uzbl.comm.proto_var, dump_var_hash_as_event, NULL);
-}
-
-void
retrieve_geometry() {
int w, h, x, y;
GString *buf = g_string_new("");
@@ -1760,7 +1083,7 @@ initialize(int argc, char** argv) {
commands_hash();
- create_var_to_name_hash();
+ variables_hash();
/* GUI */
gtk_init(&argc, &argv);