aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Barrucadu <mike@barrucadu.co.uk>2009-05-18 22:01:30 +0100
committerGravatar Barrucadu <mike@barrucadu.co.uk>2009-05-18 22:01:30 +0100
commit992230601106aadf0146cb022cd240136ae2f261 (patch)
tree97ddf5a50943ddc5deb28e4beaea56dbb9ee68e0
parent7e301b27e4e61e0c1bd1bc40f1008608969033e6 (diff)
parent30131ffa360fc398e8b6393159f992f1adf89af1 (diff)
Merge branch 'dieter/experimental' into experimental
Conflicts: uzbl.c uzbl.h
-rw-r--r--AUTHORS1
-rw-r--r--README3
-rw-r--r--docs/CONTRIBUTING4
-rw-r--r--uzbl.c125
-rw-r--r--uzbl.h7
5 files changed, 83 insertions, 57 deletions
diff --git a/AUTHORS b/AUTHORS
index f77735f..66bd93e 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -14,6 +14,7 @@ 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:
diff --git a/README b/README
index b46c236..bf4b35c 100644
--- a/README
+++ b/README
@@ -129,6 +129,9 @@ 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
diff --git a/docs/CONTRIBUTING b/docs/CONTRIBUTING
index f351da9..9a2ff35 100644
--- a/docs/CONTRIBUTING
+++ b/docs/CONTRIBUTING
@@ -25,6 +25,10 @@ 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/uzbl.c b/uzbl.c
index d4fd90b..da81060 100644
--- a/uzbl.c
+++ b/uzbl.c
@@ -149,7 +149,14 @@ itos(int val) {
static char *
str_replace (const char* search, const char* replace, const char* string) {
- return g_strjoinv (replace, g_strsplit (string, search, -1));
+ gchar **buf;
+ char *ret;
+
+ buf = g_strsplit (string, search, -1);
+ ret = g_strjoinv (replace, buf);
+ g_strfreev(buf);
+
+ return ret;
}
static gchar**
@@ -223,6 +230,7 @@ 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);
@@ -265,7 +273,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[0]!=0) {
+ if (uzbl.state.selected_url != NULL) {
if (uzbl.state.verbose)
printf("\nNew web view -> %s\n",uzbl.state.selected_url);
new_window_load_uri(uzbl.state.selected_url);
@@ -354,9 +362,10 @@ link_hover_cb (WebKitWebView* page, const gchar* title, const gchar* link, gpoin
(void) title;
(void) data;
//Set selected_url state variable
- uzbl.state.selected_url[0] = '\0';
+ g_free(uzbl.state.selected_url);
+ uzbl.state.selected_url = NULL;
if (link) {
- strcpy (uzbl.state.selected_url, link);
+ uzbl.state.selected_url = g_strdup(link);
}
update_title();
}
@@ -504,7 +513,7 @@ 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);
}
void
@@ -531,7 +540,7 @@ load_uri (WebKitWebView * web_view, const gchar *param) {
GString* newuri = g_string_new (param);
if (g_strrstr (param, "://") == 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);
}
@@ -579,9 +588,9 @@ run_external_js (WebKitWebView * web_view, const gchar *param) {
static void
search_text (WebKitWebView *page, const char *param, const gboolean forward) {
if ((param) && (param[0] != '\0')) {
- strcpy(uzbl.state.searchtx, param);
+ uzbl.state.searchtx = g_strdup(param);
}
- if (uzbl.state.searchtx[0] != '\0') {
+ if (uzbl.state.searchtx != NULL) {
if (uzbl.state.verbose)
printf ("Searching: %s\n", uzbl.state.searchtx);
@@ -597,6 +606,8 @@ search_text (WebKitWebView *page, const char *param, const gboolean forward) {
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;
}
}
@@ -728,9 +739,11 @@ expand_template(const char *template) {
sym = (int)g_scanner_cur_value(uzbl.scan).v_symbol;
switch(sym) {
case SYM_URI:
- g_string_append(ret,
- uzbl.state.uri?
- g_markup_printf_escaped("%s", uzbl.state.uri):"");
+ buf = uzbl.state.uri?
+ g_markup_printf_escaped("%s", uzbl.state.uri) :
+ g_strdup("");
+ g_string_append(ret, buf);
+ free(buf);
break;
case SYM_LOADPRGS:
buf = itos(uzbl.gui.sbar.load_progress);
@@ -743,14 +756,18 @@ expand_template(const char *template) {
g_free(buf);
break;
case SYM_TITLE:
- g_string_append(ret,
- uzbl.gui.main_title?
- g_markup_printf_escaped("%s", uzbl.gui.main_title):"");
+ buf = uzbl.gui.main_title?
+ g_markup_printf_escaped("%s", uzbl.gui.main_title) :
+ g_strdup("");
+ g_string_append(ret, buf);
+ free(buf);
break;
case SYM_SELECTED_URI:
- g_string_append(ret,
- uzbl.state.selected_url?
- g_markup_printf_escaped("%s", uzbl.state.selected_url):"");
+ buf = uzbl.state.selected_url?
+ g_markup_printf_escaped("%s", uzbl.state.selected_url) :
+ g_strdup("");
+ g_string_append(ret, buf);
+ free(buf);
break;
case SYM_NAME:
buf = itos(uzbl.xwin);
@@ -759,9 +776,11 @@ expand_template(const char *template) {
free(buf);
break;
case SYM_KEYCMD:
- g_string_append(ret,
- uzbl.state.keycmd->str ?
- g_markup_printf_escaped("%s", uzbl.state.keycmd->str):"");
+ buf = uzbl.state.keycmd->str?
+ g_markup_printf_escaped("%s", uzbl.state.keycmd->str) :
+ g_strdup("");
+ g_string_append(ret, buf);
+ free(buf);
break;
case SYM_MODE:
g_string_append(ret,
@@ -1004,6 +1023,7 @@ 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)
@@ -1032,11 +1052,13 @@ set_var_value(gchar *name, gchar *val) {
}
else if(var_is("fifo_dir", name)) {
if(*p) free(*p);
- *p = init_fifo(g_strdup(val));
+ buf = init_fifo(val);
+ *p = buf?buf:g_strdup("");
}
else if(var_is("socket_dir", name)) {
if(*p) free(*p);
- *p = init_socket(g_strdup(val));
+ buf = init_socket(val);
+ *p = buf?buf:g_strdup("");
}
else if(var_is("modkey", name)) {
if(*p) free(*p);
@@ -1050,7 +1072,8 @@ set_var_value(gchar *name, gchar *val) {
}
else if(var_is("useragent", name)) {
if(*p) free(*p);
- *p = set_useragent(g_strdup(val));
+ buf = set_useragent(val);
+ *p = buf?buf:g_strdup("");
}
else if(var_is("shell_cmd", name)) {
if(*p) free(*p);
@@ -1078,8 +1101,6 @@ 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? */
@@ -1167,6 +1188,8 @@ 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);
}
@@ -1238,7 +1261,6 @@ 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;
}
@@ -1264,22 +1286,16 @@ 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;
- 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);
+ ret = g_io_channel_read_line(gio, &ctl_line, NULL, NULL, NULL);
if ( (ret == G_IO_STATUS_ERROR) || (ret == G_IO_STATUS_EOF) )
return FALSE;
@@ -1560,7 +1576,6 @@ 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 ());
@@ -1586,9 +1601,6 @@ 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);
@@ -1619,11 +1631,9 @@ 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]);
- 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);
+ action = new_action(parts[0], parts[1]);
+ g_hash_table_replace(uzbl.bindings, g_strdup(key), action);
g_strfreev(parts);
}
@@ -1633,16 +1643,15 @@ get_xdg_var (XDG_Var xdg) {
const gchar* actual_value = getenv (xdg.environmental);
const gchar* home = getenv ("HOME");
- gchar* return_value = str_replace ("~", home, g_strdup (actual_value));
+ gchar* return_value = str_replace ("~", home, actual_value);
if (! actual_value || strcmp (actual_value, "") == 0) {
if (xdg.default_value) {
- return_value = str_replace ("~", home, g_strdup (xdg.default_value));
+ return_value = str_replace ("~", home, xdg.default_value);
} else {
return_value = NULL;
}
}
-
return return_value;
}
@@ -1652,17 +1661,21 @@ find_xdg_file (int xdg_type, char* filename) {
xdg_type = 1 => data
xdg_type = 2 => cache*/
- gchar* temporary_file = (char *)malloc (1024);
+ gchar* temporary_file = malloc (1024);
gchar* temporary_string = NULL;
char* saveptr;
+ char* buf;
- strcpy (temporary_file, get_xdg_var (XDG[xdg_type]));
-
+ buf = get_xdg_var (XDG[xdg_type]);
+ strcpy (temporary_file, buf);
strcat (temporary_file, filename);
+ free(buf);
if (! file_exists (temporary_file) && xdg_type != 2) {
- temporary_string = (char *) strtok_r (get_xdg_var (XDG[3 + xdg_type]), ":", &saveptr);
-
+ buf = get_xdg_var (XDG[3 + xdg_type]);
+ temporary_string = (char *) strtok_r (buf, ":", &saveptr);
+ free(buf);
+
while (temporary_string && ! file_exists (temporary_file)) {
strcpy (temporary_file, temporary_string);
strcat (temporary_file, filename);
@@ -1685,7 +1698,7 @@ settings_init () {
uzbl.behave.reset_command_mode = 1;
if (!s->config_file) {
- s->config_file = g_strdup (find_xdg_file (0, "/uzbl/config"));
+ s->config_file = find_xdg_file (0, "/uzbl/config");
}
if (s->config_file) {
@@ -1775,12 +1788,15 @@ main (int argc, char* argv[]) {
if (!g_thread_supported ())
g_thread_init (NULL);
- strcpy(uzbl.state.executable_path,argv[0]);
+ uzbl.state.executable_path = g_strdup(argv[0]);
+ uzbl.state.selected_url = NULL;
+ uzbl.state.searchtx = NULL;
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);
@@ -1812,7 +1828,6 @@ 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);
@@ -1840,6 +1855,10 @@ main (int argc, char* argv[]) {
create_stdin();
+ if(uzbl.state.uri)
+ load_uri (uzbl.gui.web_view, uzbl.state.uri);
+
+
gtk_main ();
clean_up();
diff --git a/uzbl.h b/uzbl.h
index 7ff6584..a40e8d6 100644
--- a/uzbl.h
+++ b/uzbl.h
@@ -104,11 +104,10 @@ typedef struct {
gchar *uri;
gchar *config_file;
char *instance_name;
- gchar config_file_path[500];
- gchar selected_url[500];
- char executable_path[500];
+ gchar *selected_url;
+ gchar *executable_path;
GString* keycmd;
- gchar searchtx[500];
+ gchar *searchtx;
gchar* searchold;
struct utsname unameinfo; /* system info */
gboolean verbose;