From 29c15cf845d41ff4aa3cf2cb4d30a83c14485070 Mon Sep 17 00:00:00 2001 From: keis Date: Fri, 17 Dec 2010 23:23:57 +0100 Subject: add sync_spawn_exec command this command will execute the lines written by the program as uzbl-commands --- src/uzbl-core.c | 23 ++++++++++++++++++++--- src/uzbl-core.h | 3 +++ 2 files changed, 23 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/uzbl-core.c b/src/uzbl-core.c index 2a88e76..03741de 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -585,6 +585,7 @@ struct {const char *key; CommandInfo value;} cmdlist[] = { "toggle_status", {toggle_status_cb, 0} }, { "spawn", {spawn_async, 0} }, { "sync_spawn", {spawn_sync, 0} }, // needed for cookie handler + { "sync_spawn_exec", {spawn_sync_exec, 0} }, // needed for load_cookies.sh :( { "sh", {spawn_sh_async, 0} }, { "sync_sh", {spawn_sh_sync, 0} }, // needed for cookie handler { "exit", {close_uzbl, 0} }, @@ -1313,7 +1314,7 @@ split_quoted(const gchar* src, const gboolean unquote) { } void -spawn(GArray *argv, gboolean sync) { +spawn(GArray *argv, gboolean sync, gboolean exec) { gchar *path = NULL; //TODO: allow more control over argument order so that users can have some arguments before the default ones from run_command, and some after @@ -1324,6 +1325,16 @@ spawn(GArray *argv, gboolean sync) { run_command(path, 0, ((const gchar **) (argv->data + sizeof(gchar*))), 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; + gchar *tail; + while (tail = strchr (head, '\n')) { + *tail = '\0'; + parse_cmd_line(head, NULL); + head = tail + 1; + } + } g_free(path); } } @@ -1331,13 +1342,19 @@ spawn(GArray *argv, gboolean sync) { void spawn_async(WebKitWebView *web_view, GArray *argv, GString *result) { (void)web_view; (void)result; - spawn(argv, FALSE); + spawn(argv, FALSE, FALSE); } void spawn_sync(WebKitWebView *web_view, GArray *argv, GString *result) { (void)web_view; (void)result; - spawn(argv, TRUE); + spawn(argv, TRUE, FALSE); +} + +void +spawn_sync_exec(WebKitWebView *web_view, GArray *argv, GString *result) { + (void)web_view; (void)result; + spawn(argv, TRUE, TRUE); } void diff --git a/src/uzbl-core.h b/src/uzbl-core.h index f7cc993..98ae342 100644 --- a/src/uzbl-core.h +++ b/src/uzbl-core.h @@ -275,6 +275,9 @@ spawn_sync(WebKitWebView *web_view, GArray *argv, GString *result); void spawn_sh_sync(WebKitWebView *web_view, GArray *argv, GString *result); +void +spawn_sync_exec(WebKitWebView *web_view, GArray *argv, GString *result); + void parse_command(const char *cmd, const char *param, GString *result); -- cgit v1.2.3