diff options
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | README | 10 | ||||
-rw-r--r-- | docs/CONTRIBUTING | 4 | ||||
-rw-r--r-- | examples/configs/sampleconfig | 10 | ||||
-rw-r--r-- | examples/configs/sampleconfig-dev | 10 | ||||
-rw-r--r-- | examples/scripts/hint.js | 26 | ||||
-rw-r--r-- | uzbl.c | 246 | ||||
-rw-r--r-- | uzbl.h | 19 |
8 files changed, 223 insertions, 103 deletions
@@ -14,7 +14,6 @@ Contributors: Evgeny Grablyk - libsoup settings Damien Leon - misc Peter Suschlik - backwards searching - (salinasv) - move some variables to heap Originaly based on http://trac.webkit.org/browser/trunk/WebKitTools/GtkLauncher/main.c Which is copyrighted: @@ -129,9 +129,6 @@ This tells uzbl to execute an action immediately. The simplest example of this KEYCMD <string> This sets the interactive command buffer to `<string>`. 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 <string> -Like KEYCMD, but also emulates a press of return which causes binds with an asterisk or underscore to execute. (See sample config) ### ACTIONS @@ -150,9 +147,11 @@ actions follows: * `zoom_in` * `zoom_out` * `uri <address>` -* `script <body>` +* `js <body>` - execute the javascript in `<body>` - remember that the commands, and thus actions, must not contain line breaks +* `script <file>` + - execute the javascript in `<file>` * `toggle_status` * `spawn <executable> <additonal args>` - runs a command; see EXTERNAL SCRIPTS for details @@ -164,7 +163,8 @@ actions follows: * `exit` * `search <string>` * `search_reverse <string>` -* `insert_mode` +* `toggle_insert_mode <optional state>` + - 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 diff --git a/docs/CONTRIBUTING b/docs/CONTRIBUTING index 9a2ff35..f351da9 100644 --- a/docs/CONTRIBUTING +++ b/docs/CONTRIBUTING @@ -25,10 +25,6 @@ If you're new to Git/github, have no fear: * [Github guides (highly recommended)](http://github.com/guides/home) * [Guides: Fork a project and submit your modifications](http://github.com/guides/fork-a-project-and-submit-your-modifications) -Our convention is to develop in the *experimental* branch, and keep only stable, tested stuff in *master*. -So ideally, all contributors develop in their experimental, that gets merged into the mainline experimental, and after QA it gets merged into the main master. - - ### VALGRIND PROFILING $ add this to Makefile header: CFLAGS=-g $ recompile diff --git a/examples/configs/sampleconfig b/examples/configs/sampleconfig index dfe99d6..b19b850 100644 --- a/examples/configs/sampleconfig +++ b/examples/configs/sampleconfig @@ -77,8 +77,8 @@ bind gh = uri http://www.uzbl.org bind o _ = uri %s bind :wiki _ = uri http://wiki.archlinux.org/index.php/Special:Search?search=%s&go=Go bind gg _ = uri http://www.google.com/search?q=%s -bind i = insert_mode -#TODO: no 'toggle' command? +bind i = toggle_insert_mode +bind I = toggle_insert_mode 0 # disable insert mode (1 to enable) bind B = spawn /usr/share/uzbl/examples/scripts/insert_bookmark.sh bind U = spawn /usr/share/uzbl/examples/scripts/load_url_from_history.sh bind u = spawn /usr/share/uzbl/examples/scripts/load_url_from_bookmarks.sh @@ -92,7 +92,7 @@ bind p = sh "echo act uri `xclip -selection primary -o` > $4" # go to the page in clipboard bind P = sh "echo act uri `xclip -selection clipboard -o` > $4" bind ZZ = exit -bind S = script alert("hi"); +bind S = js alert("hi"); # example showing how to use sh # it sends a command to the fifo, whose path is told via a positional param # if fifo_dir is not set, it'll echo to a file named (null) somewhere >:) remember to delete it @@ -101,9 +101,9 @@ bind S = script alert("hi"); bind XS = sh 'echo "act script alert (\'This is sent by the shell via a fifo\')" > "$4"' # Keyboard based link following: work in progress! No C DOM bindings yet, no click() event for hyperlinks so no referrer set..Quite basic but does the job for now... #hit F to toggle the Hints (now in form of link numbering) -bind F= script for (var i=0; i < document.links.length; i++) {var uzblid = 'uzbl_link_hint_';var li = document.links[i];var pre = document.getElementById(uzblid+i);if (pre) {li.removeChild(pre);} else {var hint = document.createElement('div');hint.setAttribute('id',uzblid+i);hint.innerHTML = i;hint.style.display='inline';hint.style.lineHeight='90%';hint.style.backgroundColor='red';hint.style.color='white';hint.style.fontSize='small-xx';hint.style.fontWeight='light';hint.style.margin='0px';hint.style.padding='2px';hint.style.position='absolute';hint.style.textDecoration='none';hint.style.left=li.style.left;hint.style.top=li.style.top;li.insertAdjacentElement('afterBegin',hint);}} +bind F= script /usr/share/uzbl/examples/scripts/hint.js #hit f followed by linknumber and ENTER to follow that link -bind f_ = script window.location = document.links[%s].href; +bind f_ = js window.location = document.links[%s].href; # "home" page if you will set uri = uzbl.org diff --git a/examples/configs/sampleconfig-dev b/examples/configs/sampleconfig-dev index 3f9b5fa..a8a1672 100644 --- a/examples/configs/sampleconfig-dev +++ b/examples/configs/sampleconfig-dev @@ -78,8 +78,8 @@ bind gh = uri http://www.uzbl.org bind o _ = uri %s bind :wiki _ = uri http://wiki.archlinux.org/index.php/Special:Search?search=%s&go=Go bind gg _ = uri http://www.google.com/search?q=%s -bind i = insert_mode -#TODO: no 'toggle' command? +bind i = toggle_insert_mode +bind I = toggle_insert_mode 0 # disable insert mode (1 to enable) # Enclose the executable in quotes if it has spaces. Any additional parameters you use will # appear AFTER the default parameters bind B = spawn ./examples/scripts/insert_bookmark.sh @@ -95,7 +95,7 @@ bind p = sh "echo act uri `xclip -selection primary -o` > $4" # go to the page in clipboard bind P = sh "echo act uri `xclip -selection clipboard -o` > $4" bind ZZ = exit -bind S = script alert("hi"); +bind S = js alert("hi"); # example showing how to use sh # it sends a command to the fifo, whose path is told via a positional param # if fifo_dir is not set, it'll echo to a file named (null) somewhere >:) remember to delete it @@ -107,9 +107,9 @@ bind XS = sh 'echo "act script alert (\\"This is sent by the shell via # Keyboard based link following: work in progress! No C DOM bindings yet, no click() event for hyperlinks so no referrer set..Quite basic but does the job for now... #hit F to toggle the Hints (now in form of link numbering) -bind F= script for (var i=0; i < document.links.length; i++) {var uzblid = 'uzbl_link_hint_';var li = document.links[i];var pre = document.getElementById(uzblid+i);if (pre) {li.removeChild(pre);} else {var hint = document.createElement('div');hint.setAttribute('id',uzblid+i);hint.innerHTML = i;hint.style.display='inline';hint.style.lineHeight='90%';hint.style.backgroundColor='red';hint.style.color='white';hint.style.fontSize='small-xx';hint.style.fontWeight='light';hint.style.margin='0px';hint.style.padding='2px';hint.style.position='absolute';hint.style.textDecoration='none';hint.style.left=li.style.left;hint.style.top=li.style.top;li.insertAdjacentElement('afterBegin',hint);}} +bind F= script ./examples/scripts/hint.js #hit f followed by linknumber and ENTER to follow that link -bind f_ = script window.location = document.links[%s].href; +bind f_ = js window.location = document.links[%s].href; # "home" page if you will set uri = uzbl.org diff --git a/examples/scripts/hint.js b/examples/scripts/hint.js new file mode 100644 index 0000000..ec7f1e2 --- /dev/null +++ b/examples/scripts/hint.js @@ -0,0 +1,26 @@ +for (var i=0; i < document.links.length; i++) { + var uzblid = 'uzbl_link_hint_'; + var li = document.links[i]; + var pre = document.getElementById(uzblid+i); + + if (pre) { + li.removeChild(pre); + } else { + var hint = document.createElement('div'); + hint.setAttribute('id',uzblid+i); + hint.innerHTML = i; + hint.style.display='inline'; + hint.style.lineHeight='90%'; + hint.style.backgroundColor='red'; + hint.style.color='white'; + hint.style.fontSize='small-xx'; + hint.style.fontWeight='light'; + hint.style.margin='0px'; + hint.style.padding='2px'; + hint.style.position='absolute'; + hint.style.textDecoration='none'; + hint.style.left=li.style.left; + hint.style.top=li.style.top; + li.insertAdjacentElement('afterBegin',hint); + } +} @@ -154,14 +154,57 @@ argv_idx(const GArray *a, const guint idx) { return g_array_index(a, gchar*, idx static char * str_replace (const char* search, const char* replace, const char* string) { - gchar **buf; - char *ret; + return g_strjoinv (replace, g_strsplit (string, search, -1)); +} + +static gchar** +read_file_by_line (gchar *path) { + GIOChannel *chan = NULL; + gchar *readbuf = NULL; + gsize len; + gchar *lines[512]; + int i; + + chan = g_io_channel_new_file(path, "r", NULL); + + if (chan) { + while (g_io_channel_read_line(chan, &readbuf, &len, NULL, NULL) + == G_IO_STATUS_NORMAL) { + lines[i] = g_strdup (readbuf); + g_free (readbuf); + i ++; + } + + g_io_channel_unref (chan); + } else { + fprintf(stderr, "File '%s' not be read.\n", path); + } + + lines[i] = NULL; + return lines; +} - buf = g_strsplit (string, search, -1); - ret = g_strjoinv (replace, buf); - g_strfreev(buf); +static +gchar* parseenv (const char* string) { + extern char** environ; + gchar* newstring = g_strdup (string); + int i = 0; - return ret; + while (environ[i] != NULL) { + gchar** env = g_strsplit (environ[i], "=", 0); + gchar* envname = malloc (strlen (env[0]) + 1); + + strcat (envname, "$"); + strcat (envname, env[0]); + + newstring = str_replace(envname, env[1], newstring); + + g_free (envname); + //g_strfreev (env); - This still breaks uzbl, but shouldn't. The mystery thickens... + i ++; + } + + return newstring; } static sigfunc* @@ -185,7 +228,6 @@ clean_up(void) { if (uzbl.behave.socket_dir) unlink (uzbl.comm.socket_path); - g_free(uzbl.state.executable_path); g_string_free(uzbl.state.keycmd, TRUE); g_hash_table_destroy(uzbl.bindings); g_hash_table_destroy(uzbl.behave.commands); @@ -228,7 +270,7 @@ create_web_view_cb (WebKitWebView *web_view, WebKitWebFrame *frame, gpointer us (void) web_view; (void) frame; (void) user_data; - if (uzbl.state.selected_url != NULL) { + if (uzbl.state.selected_url[0]!=0) { if (uzbl.state.verbose) printf("\nNew web view -> %s\n",uzbl.state.selected_url); new_window_load_uri(uzbl.state.selected_url); @@ -315,10 +357,9 @@ link_hover_cb (WebKitWebView* page, const gchar* title, const gchar* link, gpoin (void) title; (void) data; //Set selected_url state variable - g_free(uzbl.state.selected_url); - uzbl.state.selected_url = NULL; + uzbl.state.selected_url[0] = '\0'; if (link) { - uzbl.state.selected_url = g_strdup(link); + strcpy (uzbl.state.selected_url, link); } update_title(); } @@ -410,7 +451,6 @@ VIEWFUNC(go_forward) /* -- command to callback/function map for things we cannot attach to any signals */ // TODO: reload - static struct {char *name; Command command[2];} cmdlist[] = { /* key function no_split */ { "back", {view_go_back, 0} }, @@ -425,14 +465,15 @@ static struct {char *name; Command command[2];} cmdlist[] = { "zoom_in", {view_zoom_in, 0}, }, //Can crash (when max zoom reached?). { "zoom_out", {view_zoom_out, 0}, }, { "uri", {load_uri, NOSPLIT} }, - { "script", {run_js, NOSPLIT} }, + { "js", {run_js, NOSPLIT} }, + { "script", {run_external_js, 0} }, { "toggle_status", {toggle_status_cb, 0} }, { "spawn", {spawn, 0} }, { "sh", {spawn_sh, 0} }, { "exit", {close_uzbl, 0} }, { "search", {search_forward_text, NOSPLIT} }, { "search_reverse", {search_reverse_text, NOSPLIT} }, - { "insert_mode", {set_insert_mode, 0} }, + { "insert_mode", {toggle_insert_mode, 0} }, { "runcmd", {runcmd, NOSPLIT} } }; @@ -472,15 +513,24 @@ new_action(const gchar *name, const gchar *param) { static bool file_exists (const char * filename) { - return (access(filename, F_OK) == 0); + return (access(filename, F_OK) == 0); } static void -set_insert_mode(WebKitWebView *page, GArray *argv) { +toggle_insert_mode(WebKitWebView *page, GArray *argv) { (void)page; (void)argv; - uzbl.behave.insert_mode = TRUE; + if (argv_idx(argv, 0)) { + if (strcmp (argv_idx(argv, 0), "0") == 0) { + uzbl.behave.insert_mode = FALSE; + } else { + uzbl.behave.insert_mode = TRUE; + } + } else { + uzbl.behave.insert_mode = ! uzbl.behave.insert_mode; + } + update_title(); } @@ -490,7 +540,7 @@ load_uri (WebKitWebView *web_view, GArray *argv) { GString* newuri = g_string_new (argv_idx(argv, 0)); if (g_strrstr (argv_idx(argv, 0), "://") == NULL) g_string_prepend (newuri, "http://"); - /* if we do handle cookies, ask our handler for them */ + /* if we do handle cookies, ask our handler for them */ webkit_web_view_load_uri (web_view, newuri->str); g_string_free (newuri, TRUE); } @@ -503,6 +553,39 @@ run_js (WebKitWebView * web_view, GArray *argv) { } static void +run_external_js (WebKitWebView * web_view, GArray *argv) { + if (argv_idx(argv, 0)) { + gchar** lines = read_file_by_line (argv_idx (argv, 0)); + gchar* js = NULL; + int i; + + if (lines[0] != NULL) { + for (i = 0; lines[i] != NULL; i ++) { + if (js == NULL) { + js = g_strdup (lines[i]); + } else { + gchar* newjs = g_strconcat (js, lines[i], NULL); + js = newjs; + } + //g_free (lines[i]); - Another mysterious breakage + } + + if (uzbl.state.verbose) + printf ("External JavaScript file %s loaded\n", argv_idx(argv, 0)); + + if (argv_idx (argv, 1)) { + gchar* newjs = str_replace("%s", argv_idx (argv, 1), js); + js = newjs; + } + webkit_web_view_execute_script (web_view, js); + g_free (js); + } else { + fprintf(stderr, "JavaScript file '%s' not be read.\n", argv_idx(argv, 0)); + } + } +} + +static void search_text (WebKitWebView *page, GArray *argv, const gboolean forward) { if (argv_idx(argv, 0) && (*argv_idx(argv, 0) != '\0')) uzbl.state.searchtx = g_strdup(argv_idx(argv, 0)); @@ -510,12 +593,19 @@ search_text (WebKitWebView *page, GArray *argv, const gboolean forward) { if (uzbl.state.searchtx != NULL) { if (uzbl.state.verbose) printf ("Searching: %s\n", uzbl.state.searchtx); - webkit_web_view_unmark_text_matches (page); - webkit_web_view_mark_text_matches (page, uzbl.state.searchtx, FALSE, 0); + + if (g_strcmp0 (uzbl.state.searchtx, uzbl.state.searchold) != 0) { + webkit_web_view_unmark_text_matches (page); + webkit_web_view_mark_text_matches (page, uzbl.state.searchtx, FALSE, 0); + + if (uzbl.state.searchold != NULL) + g_free (uzbl.state.searchold); + + uzbl.state.searchold = g_strdup (uzbl.state.searchtx); + } + webkit_web_view_set_highlight_text_matches (page, TRUE); webkit_web_view_search_text (page, uzbl.state.searchtx, FALSE, forward, TRUE); - g_free(uzbl.state.searchtx); - uzbl.state.searchtx = NULL; } } @@ -647,11 +737,9 @@ expand_template(const char *template) { sym = (int)g_scanner_cur_value(uzbl.scan).v_symbol; switch(sym) { case SYM_URI: - buf = uzbl.state.uri? - g_markup_printf_escaped("%s", uzbl.state.uri) : - g_strdup(""); - g_string_append(ret, buf); - free(buf); + g_string_append(ret, + uzbl.state.uri? + g_markup_printf_escaped("%s", uzbl.state.uri):""); break; case SYM_LOADPRGS: buf = itos(uzbl.gui.sbar.load_progress); @@ -664,18 +752,14 @@ expand_template(const char *template) { g_free(buf); break; case SYM_TITLE: - buf = uzbl.gui.main_title? - g_markup_printf_escaped("%s", uzbl.gui.main_title) : - g_strdup(""); - g_string_append(ret, buf); - free(buf); + g_string_append(ret, + uzbl.gui.main_title? + g_markup_printf_escaped("%s", uzbl.gui.main_title):""); break; case SYM_SELECTED_URI: - buf = uzbl.state.selected_url? - g_markup_printf_escaped("%s", uzbl.state.selected_url) : - g_strdup(""); - g_string_append(ret, buf); - free(buf); + g_string_append(ret, + uzbl.state.selected_url? + g_markup_printf_escaped("%s", uzbl.state.selected_url):""); break; case SYM_NAME: buf = itos(uzbl.xwin); @@ -684,11 +768,9 @@ expand_template(const char *template) { free(buf); break; case SYM_KEYCMD: - buf = uzbl.state.keycmd->str? - g_markup_printf_escaped("%s", uzbl.state.keycmd->str) : - g_strdup(""); - g_string_append(ret, buf); - free(buf); + g_string_append(ret, + uzbl.state.keycmd->str ? + g_markup_printf_escaped("%s", uzbl.state.keycmd->str):""); break; case SYM_MODE: g_string_append(ret, @@ -859,7 +941,7 @@ static void spawn(WebKitWebView *web_view, GArray *argv) { (void)web_view; //TODO: allow more control over argument order so that users can have some arguments before the default ones from run_command, and some after - if (argv_idx(argv, 0)) run_command(argv_idx(argv, 0), 0, argv->data + sizeof(gchar*), FALSE, NULL); + if (argv_idx(argv, 0)) run_command(argv_idx(argv, 0), 0, (const gchar **) argv->data + sizeof(gchar*), FALSE, NULL); } static void @@ -878,7 +960,7 @@ spawn_sh(WebKitWebView *web_view, GArray *argv) { for (i = 1; i < g_strv_length(cmd); i++) g_array_prepend_val(argv, cmd[i]); - if (cmd) run_command(cmd[0], g_strv_length(cmd) + 1, argv->data, FALSE, NULL); + if (cmd) run_command(cmd[0], g_strv_length(cmd) + 1, (const gchar **) argv->data, FALSE, NULL); g_free (spacer); g_strfreev (cmd); } @@ -1001,7 +1083,6 @@ static gboolean set_var_value(gchar *name, gchar *val) { void **p = NULL; char *endp = NULL; - char *buf=NULL; if( (p = g_hash_table_lookup(uzbl.comm.proto_var, name)) ) { if(var_is("status_message", name) @@ -1035,13 +1116,11 @@ set_var_value(gchar *name, gchar *val) { } else if(var_is("fifo_dir", name)) { if(*p) free(*p); - buf = init_fifo(val); - *p = buf?buf:g_strdup(""); + *p = init_fifo(g_strdup(val)); } else if(var_is("socket_dir", name)) { if(*p) free(*p); - buf = init_socket(val); - *p = buf?buf:g_strdup(""); + *p = init_socket(g_strdup(val)); } else if(var_is("modkey", name)) { if(*p) free(*p); @@ -1055,8 +1134,7 @@ set_var_value(gchar *name, gchar *val) { } else if(var_is("useragent", name)) { if(*p) free(*p); - buf = set_useragent(val); - *p = buf?buf:g_strdup(""); + *p = set_useragent(g_strdup(val)); } else if(var_is("shell_cmd", name)) { if(*p) free(*p); @@ -1084,6 +1162,8 @@ set_var_value(gchar *name, gchar *val) { SOUP_SESSION_MAX_CONNS_PER_HOST, uzbl.net.max_conns_host, NULL); } else if (var_is("http_debug", name)) { + //soup_session_remove_feature + // (uzbl.net.soup_session, uzbl.net.soup_logger); soup_session_remove_feature (uzbl.net.soup_session, SOUP_SESSION_FEATURE(uzbl.net.soup_logger)); /* do we leak if this doesn't get freed? why does it occasionally crash if freed? */ @@ -1123,8 +1203,10 @@ parse_cmd_line(const char *ctl_line) { 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) { - set_var_value(tokens[1], tokens[2]); + gchar* value = parseenv (tokens[2]); + set_var_value(tokens[1], value); g_strfreev(tokens); + g_free(value); } else printf("Error in command: %s\n", tokens[0]); @@ -1143,8 +1225,10 @@ parse_cmd_line(const char *ctl_line) { else 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) { - add_binding(tokens[1], tokens[2]); + gchar* value = parseenv (tokens[2]); + add_binding(tokens[1], value); g_strfreev(tokens); + g_free(value); } else printf("Error in command: %s\n", tokens[0]); @@ -1167,8 +1251,6 @@ parse_cmd_line(const char *ctl_line) { 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(); g_strfreev(tokens); } @@ -1240,6 +1322,7 @@ init_fifo(gchar *dir) { /* return dir or, on error, free dir and return NULL */ } if (*dir == ' ') { /* space unsets the variable */ + g_free(dir); return NULL; } @@ -1265,16 +1348,22 @@ init_fifo(gchar *dir) { /* return dir or, on error, free dir and return NULL */ /* if we got this far, there was an error; cleanup */ if (error) g_error_free (error); g_free(path); + g_free(dir); return NULL; } static gboolean control_stdin(GIOChannel *gio, GIOCondition condition) { - (void) condition; gchar *ctl_line = NULL; + gsize ctl_line_len = 0; GIOStatus ret; - ret = g_io_channel_read_line(gio, &ctl_line, NULL, NULL, NULL); + if (condition & G_IO_HUP) { + ret = g_io_channel_shutdown (gio, FALSE, NULL); + return FALSE; + } + + ret = g_io_channel_read_line(gio, &ctl_line, &ctl_line_len, NULL, NULL); if ( (ret == G_IO_STATUS_ERROR) || (ret == G_IO_STATUS_EOF) ) return FALSE; @@ -1555,6 +1644,7 @@ create_browser () { GUI *g = &uzbl.gui; GtkWidget* scrolled_window = gtk_scrolled_window_new (NULL, NULL); + //main_window_ref = g_object_ref(scrolled_window); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_NEVER, GTK_POLICY_NEVER); //todo: some sort of display of position/total length. like what emacs does g->web_view = WEBKIT_WEB_VIEW (webkit_web_view_new ()); @@ -1581,6 +1671,9 @@ create_mainbar () { g->mainbar = gtk_hbox_new (FALSE, 0); + /* keep a reference to the bar so we can re-pack it at runtime*/ + //sbar_ref = g_object_ref(g->mainbar); + g->mainbar_label = gtk_label_new (""); gtk_label_set_selectable((GtkLabel *)g->mainbar_label, TRUE); gtk_label_set_ellipsize(GTK_LABEL(g->mainbar_label), PANGO_ELLIPSIZE_END); @@ -1633,9 +1726,11 @@ add_binding (const gchar *key, const gchar *act) { //Debug: if (uzbl.state.verbose) printf ("Binding %-10s : %s\n", key, act); - action = new_action(parts[0], parts[1]); - g_hash_table_replace(uzbl.bindings, g_strdup(key), action); + + if(g_hash_table_lookup(uzbl.bindings, key)) + g_hash_table_remove(uzbl.bindings, key); + g_hash_table_insert(uzbl.bindings, g_strdup(key), action); g_strfreev(parts); } @@ -1645,15 +1740,16 @@ get_xdg_var (XDG_Var xdg) { const gchar* actual_value = getenv (xdg.environmental); const gchar* home = getenv ("HOME"); - gchar* return_value = str_replace ("~", home, actual_value); + gchar* return_value = str_replace ("~", home, g_strdup (actual_value)); if (! actual_value || strcmp (actual_value, "") == 0) { if (xdg.default_value) { - return_value = str_replace ("~", home, xdg.default_value); + return_value = str_replace ("~", home, g_strdup (xdg.default_value)); } else { return_value = NULL; } } + return return_value; } @@ -1663,21 +1759,17 @@ find_xdg_file (int xdg_type, char* filename) { xdg_type = 1 => data xdg_type = 2 => cache*/ - gchar* temporary_file = malloc (1024); + gchar* temporary_file = (char *)malloc (1024); gchar* temporary_string = NULL; char* saveptr; - char* buf; - buf = get_xdg_var (XDG[xdg_type]); - strcpy (temporary_file, buf); + strcpy (temporary_file, get_xdg_var (XDG[xdg_type])); + strcat (temporary_file, filename); - free(buf); if (! file_exists (temporary_file) && xdg_type != 2) { - buf = get_xdg_var (XDG[3 + xdg_type]); - temporary_string = (char *) strtok_r (buf, ":", &saveptr); - free(buf); - + temporary_string = (char *) strtok_r (get_xdg_var (XDG[3 + xdg_type]), ":", &saveptr); + while (temporary_string && ! file_exists (temporary_file)) { strcpy (temporary_file, temporary_string); strcat (temporary_file, filename); @@ -1700,7 +1792,7 @@ settings_init () { uzbl.behave.reset_command_mode = 1; if (!s->config_file) { - s->config_file = find_xdg_file (0, "/uzbl/config"); + s->config_file = g_strdup (find_xdg_file (0, "/uzbl/config")); } if (s->config_file) { @@ -1763,7 +1855,7 @@ static void handle_cookies (SoupSession *session, SoupMessage *msg, gpointer use sharg_append(a, action); sharg_append(a, soup_uri->host); sharg_append(a, soup_uri->path); - run_command(uzbl.behave.cookie_handler, 0, a->data, TRUE, &stdout); /* TODO: use handler */ + run_command(uzbl.behave.cookie_handler, 0, (const gchar **) a->data, TRUE, &stdout); /* TODO: use handler */ //run_handler(uzbl.behave.cookie_handler); /* TODO: global stdout pointer, spawn_sync */ if(stdout) { soup_message_headers_replace (msg->request_headers, "Cookie", stdout); @@ -1786,7 +1878,7 @@ save_cookies (SoupMessage *msg, gpointer user_data){ sharg_append(a, soup_uri->host); sharg_append(a, soup_uri->path); sharg_append(a, cookie); - run_command(uzbl.behave.cookie_handler, 0, a->data, FALSE, NULL); + run_command(uzbl.behave.cookie_handler, 0, (const gchar **) a->data, FALSE, NULL); g_free (cookie); g_free (action); g_array_free(a, TRUE); @@ -1794,22 +1886,18 @@ save_cookies (SoupMessage *msg, gpointer user_data){ g_slist_free(ck); } - int main (int argc, char* argv[]) { gtk_init (&argc, &argv); if (!g_thread_supported ()) g_thread_init (NULL); - uzbl.state.executable_path = g_strdup(argv[0]); - uzbl.state.selected_url = NULL; - uzbl.state.searchtx = NULL; + strcpy(uzbl.state.executable_path,argv[0]); GOptionContext* context = g_option_context_new ("- some stuff here maybe someday"); 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, NULL); - g_option_context_free(context); /* initialize hash table */ uzbl.bindings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, free_action); @@ -1829,7 +1917,6 @@ main (int argc, char* argv[]) { commands_hash (); make_var_to_name_hash(); - uzbl.gui.vbox = gtk_vbox_new (FALSE, 0); uzbl.gui.scrolled_win = create_browser(); @@ -1842,6 +1929,7 @@ main (int argc, char* argv[]) { uzbl.gui.main_window = create_window (); gtk_container_add (GTK_CONTAINER (uzbl.gui.main_window), uzbl.gui.vbox); + //load_uri (uzbl.gui.web_view, uzbl.state.uri); //TODO: is this needed? gtk_widget_grab_focus (GTK_WIDGET (uzbl.gui.web_view)); gtk_widget_show_all (uzbl.gui.main_window); @@ -105,10 +105,12 @@ typedef struct { gchar *uri; gchar *config_file; char *instance_name; - gchar *selected_url; - gchar *executable_path; + gchar config_file_path[500]; + gchar selected_url[500]; + char executable_path[500]; GString* keycmd; - gchar *searchtx; + gchar* searchtx; + gchar* searchold; struct utsname unameinfo; /* system info */ gboolean verbose; } State; @@ -205,6 +207,12 @@ itos(int val); static char * str_replace (const char* search, const char* replace, const char* string); +static gchar** +read_file_by_line (gchar *path); + +static +gchar* parseenv (const char* string); + static void clean_up(void); @@ -263,7 +271,7 @@ static bool file_exists (const char * filename); static void -set_insert_mode(WebKitWebView *page, GArray *argv); +toggle_insert_mode(WebKitWebView *page, GArray *argv); static void load_uri (WebKitWebView * web_view, GArray *argv); @@ -365,6 +373,9 @@ search_reverse_text (WebKitWebView *page, GArray *argv); static void run_js (WebKitWebView * web_view, GArray *argv); +static void +run_external_js (WebKitWebView * web_view, GArray *argv); + static void handle_cookies (SoupSession *session, SoupMessage *msg, gpointer user_data); |