aboutsummaryrefslogtreecommitdiffhomepage
path: root/uzbl.c
diff options
context:
space:
mode:
Diffstat (limited to 'uzbl.c')
-rw-r--r--uzbl.c164
1 files changed, 134 insertions, 30 deletions
diff --git a/uzbl.c b/uzbl.c
index f691445..da81060 100644
--- a/uzbl.c
+++ b/uzbl.c
@@ -159,6 +159,56 @@ str_replace (const char* search, const char* replace, const char* string) {
return ret;
}
+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;
+}
+
+static
+gchar* parseenv (const char* string) {
+ extern char** environ;
+ gchar* newstring = g_strdup (string);
+ int i = 0;
+
+ 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*
setup_signal(int signr, sigfunc *shandler) {
struct sigaction nh, oh;
@@ -403,27 +453,28 @@ VIEWFUNC(go_forward)
static struct {char *name; Command command;} cmdlist[] =
{
- { "back", view_go_back },
- { "forward", view_go_forward },
- { "scroll_vert", scroll_vert },
- { "scroll_horz", scroll_horz },
- { "scroll_begin", scroll_begin },
- { "scroll_end", scroll_end },
- { "reload", view_reload, },
- { "reload_ign_cache", view_reload_bypass_cache},
- { "stop", view_stop_loading, },
- { "zoom_in", view_zoom_in, }, //Can crash (when max zoom reached?).
- { "zoom_out", view_zoom_out, },
- { "uri", load_uri },
- { "script", run_js },
- { "toggle_status", toggle_status_cb },
- { "spawn", spawn },
- { "sh", spawn_sh },
- { "exit", close_uzbl },
- { "search", search_forward_text },
- { "search_reverse", search_reverse_text },
- { "insert_mode", set_insert_mode },
- { "runcmd", runcmd }
+ { "back", view_go_back },
+ { "forward", view_go_forward },
+ { "scroll_vert", scroll_vert },
+ { "scroll_horz", scroll_horz },
+ { "scroll_begin", scroll_begin },
+ { "scroll_end", scroll_end },
+ { "reload", view_reload, },
+ { "reload_ign_cache", view_reload_bypass_cache},
+ { "stop", view_stop_loading, },
+ { "zoom_in", view_zoom_in, }, //Can crash (when max zoom reached?).
+ { "zoom_out", view_zoom_out, },
+ { "uri", load_uri },
+ { "js", run_js },
+ { "script", run_external_js },
+ { "toggle_status", toggle_status_cb },
+ { "spawn", spawn },
+ { "sh", spawn_sh },
+ { "exit", close_uzbl },
+ { "search", search_forward_text },
+ { "search_reverse", search_reverse_text },
+ { "toggle_insert_mode", toggle_insert_mode },
+ { "runcmd", runcmd }
};
static void
@@ -465,12 +516,21 @@ file_exists (const char * filename) {
return (access(filename, F_OK) == 0);
}
-static void
-set_insert_mode(WebKitWebView *page, const gchar *param) {
+void
+toggle_insert_mode(WebKitWebView *page, const gchar *param) {
(void)page;
(void)param;
- uzbl.behave.insert_mode = TRUE;
+ if (param != NULL) {
+ if (strcmp (param, "0") == 0) {
+ uzbl.behave.insert_mode = FALSE;
+ } else {
+ uzbl.behave.insert_mode = TRUE;
+ }
+ } else {
+ uzbl.behave.insert_mode = ! uzbl.behave.insert_mode;
+ }
+
update_title();
}
@@ -493,6 +553,39 @@ run_js (WebKitWebView * web_view, const gchar *param) {
}
static void
+run_external_js (WebKitWebView * web_view, const gchar *param) {
+ if (param) {
+ gchar** splitted = g_strsplit (param, " ", 2);
+ gchar** lines = read_file_by_line (splitted[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;
+ }
+ }
+
+ if (uzbl.state.verbose)
+ printf ("External JavaScript file %s loaded\n", splitted[0]);
+
+ if (splitted[1]) {
+ gchar* newjs = str_replace("%s", splitted[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", splitted[0]);
+ }
+ }
+}
+
+static void
search_text (WebKitWebView *page, const char *param, const gboolean forward) {
if ((param) && (param[0] != '\0')) {
uzbl.state.searchtx = g_strdup(param);
@@ -500,8 +593,17 @@ search_text (WebKitWebView *page, const char *param, 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);
@@ -1038,8 +1140,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]);
@@ -1058,8 +1162,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]);
@@ -1676,7 +1782,6 @@ save_cookies (SoupMessage *msg, gpointer user_data){
g_slist_free(ck);
}
-
int
main (int argc, char* argv[]) {
gtk_init (&argc, &argv);
@@ -1711,7 +1816,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();