aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/uzbl-core.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/uzbl-core.c')
-rw-r--r--src/uzbl-core.c64
1 files changed, 23 insertions, 41 deletions
diff --git a/src/uzbl-core.c b/src/uzbl-core.c
index a33d51d..b7b8b00 100644
--- a/src/uzbl-core.c
+++ b/src/uzbl-core.c
@@ -460,8 +460,9 @@ get_click_context() {
if(!uzbl.state.last_button)
return -1;
- ht = webkit_web_view_get_hit_test_result(g->web_view, uzbl.state.last_button);
- g_object_get(ht, "context", &context, NULL);
+ ht = webkit_web_view_get_hit_test_result (g->web_view, uzbl.state.last_button);
+ g_object_get (ht, "context", &context, NULL);
+ g_object_unref (ht);
return (gint)context;
}
@@ -675,7 +676,7 @@ add_to_menu(GArray *argv, guint context) {
g->menu_items = g_ptr_array_new();
if(split[1])
- item_cmd = g_strdup(split[1]);
+ item_cmd = split[1];
if(split[0]) {
m = malloc(sizeof(MenuItem));
@@ -685,8 +686,6 @@ add_to_menu(GArray *argv, guint context) {
m->issep = FALSE;
g_ptr_array_add(g->menu_items, m);
}
- else
- g_free(item_cmd);
g_strfreev(split);
}
@@ -1216,30 +1215,19 @@ sharg_append(GArray *a, const gchar *str) {
g_array_append_val(a, s);
}
-// make sure that the args string you pass can properly be interpreted (eg properly escaped against whitespace, quotes etc)
+/* make sure that the args string you pass can properly be interpreted (eg
+ * properly escaped against whitespace, quotes etc) */
gboolean
-run_command (const gchar *command, const guint npre, const gchar **args,
- const gboolean sync, char **output_stdout) {
- //command <uzbl conf> <uzbl pid> <uzbl win id> <uzbl fifo file> <uzbl socket file> [args]
+run_command (const gchar *command, const gchar **args, const gboolean sync,
+ char **output_stdout) {
GError *err = NULL;
GArray *a = g_array_new (TRUE, FALSE, sizeof(gchar*));
- gchar *pid = itos(getpid());
- gchar *xwin = itos(uzbl.xwin);
guint i;
sharg_append(a, command);
- for (i = 0; i < npre; i++) /* add n args before the default vars */
- sharg_append(a, args[i]);
- sharg_append(a, uzbl.state.config_file);
- sharg_append(a, pid);
- sharg_append(a, xwin);
- sharg_append(a, uzbl.comm.fifo_path);
- sharg_append(a, uzbl.comm.socket_path);
- sharg_append(a, uzbl.state.uri);
- sharg_append(a, uzbl.gui.main_title);
-
- for (i = npre; i < g_strv_length((gchar**)args); i++)
+
+ for (i = 0; i < g_strv_length((gchar**)args); i++)
sharg_append(a, args[i]);
gboolean result;
@@ -1270,8 +1258,6 @@ run_command (const gchar *command, const guint npre, const gchar **args,
g_printerr("error on run_command: %s\n", err->message);
g_error_free (err);
}
- g_free (pid);
- g_free (xwin);
g_array_free (a, TRUE);
return result;
}
@@ -1316,15 +1302,13 @@ split_quoted(const gchar* src, const gboolean unquote) {
void
spawn(GArray *argv, gboolean sync, gboolean exec) {
gchar *path = NULL;
+ gchar *arg_car = argv_idx(argv, 0);
+ const gchar **arg_cdr = &g_array_index(argv, const gchar *, 1);
- //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) &&
- ((path = find_existing_file(argv_idx(argv, 0)))) ) {
+ if (arg_car && (path = find_existing_file(arg_car))) {
if (uzbl.comm.sync_stdout)
uzbl.comm.sync_stdout = strfree(uzbl.comm.sync_stdout);
- run_command(path, 0,
- ((const gchar **) (argv->data + sizeof(gchar*))),
- sync, sync?&uzbl.comm.sync_stdout:NULL);
+ run_command(path, arg_cdr, sync, sync?&uzbl.comm.sync_stdout:NULL);
// run each line of output from the program as a command
if (sync && exec && uzbl.comm.sync_stdout) {
gchar *head = uzbl.comm.sync_stdout;
@@ -1363,11 +1347,11 @@ spawn_sh(GArray *argv, gboolean sync) {
g_printerr ("spawn_sh: shell_cmd is not set!\n");
return;
}
-
guint i;
- gchar *spacer = g_strdup("");
- g_array_insert_val(argv, 1, spacer);
+
gchar **cmd = split_quoted(uzbl.behave.shell_cmd, TRUE);
+ gchar *cmdname = g_strdup(cmd[0]);
+ g_array_insert_val(argv, 1, cmdname);
for (i = 1; i < g_strv_length(cmd); i++)
g_array_prepend_val(argv, cmd[i]);
@@ -1376,11 +1360,10 @@ spawn_sh(GArray *argv, gboolean sync) {
if (uzbl.comm.sync_stdout)
uzbl.comm.sync_stdout = strfree(uzbl.comm.sync_stdout);
- run_command(cmd[0], g_strv_length(cmd) + 1,
- (const gchar **) argv->data,
- sync, sync?&uzbl.comm.sync_stdout:NULL);
+ run_command(cmd[0], (const gchar **) argv->data,
+ sync, sync?&uzbl.comm.sync_stdout:NULL);
}
- g_free (spacer);
+ g_free (cmdname);
g_strfreev (cmd);
}
@@ -1432,14 +1415,13 @@ parse_command(const char *cmd, const char *param, GString *result) {
strcmp("request", cmd)) {
g_string_printf(tmp, "%s %s", cmd, param?param:"");
send_event(COMMAND_EXECUTED, tmp->str, NULL);
- g_string_free(tmp, TRUE);
}
}
else {
- gchar *tmp = g_strdup_printf("%s %s", cmd, param?param:"");
- send_event(COMMAND_ERROR, tmp, NULL);
- g_free(tmp);
+ g_string_printf (tmp, "%s %s", cmd, param?param:"");
+ send_event(COMMAND_ERROR, tmp->str, NULL);
}
+ g_string_free(tmp, TRUE);
}