+// make sure to put '' around args, so that if there is whitespace we can still keep arguments together.
+static gboolean
+run_command(const char *command, const char *args) {
+ //command <uzbl conf> <uzbl pid> <uzbl win id> <uzbl fifo file> [args]
+ GString* to_execute = g_string_new ("");
+ gboolean result;
+ g_string_printf (to_execute, "%s '%s' '%i' '%i' '%s' %s", command, config_file, (int) getpid() , (int) xwin, "/tmp/uzbl_25165827", args);
+ result = g_spawn_command_line_async (to_execute->str, NULL);
+ printf("Called %s. Result: %s\n", to_execute->str, (result ? "FALSE" : "TRUE" ));
+ return result;
+}
+
+static void
+parse_command(const char *cmd) {
+ unsigned int i;
+ Command *c = NULL;
+ char buffer[200];
+ strcpy(buffer,cmd);
+ char * command_name = strtok (buffer, " ");
+ char * command_param = strtok (NULL, " ,");
+
+ Command *c_tmp = NULL;
+ for (i = 0; i < LENGTH (commands); i++) {
+ c_tmp = &commands[i];
+ if (strncmp (command_name, c_tmp->command, strlen (c_tmp->command)) == 0) {
+ c = c_tmp;
+ }
+ }
+ if (c != NULL) {
+ if (c->func_2_params != NULL) {
+ if (command_param != NULL) {
+ printf ("command executing: \"%s %s\"\n", command_name, command_param);
+ c->func_2_params (web_view, command_param);
+ } else {
+ if (c->func_1_param != NULL) {
+ printf ("command executing: \"%s\"\n", command_name);
+ c->func_1_param (web_view);
+ } else {
+ fprintf (stderr, "command needs a parameter. \"%s\" is not complete\n", command_name);
+ }
+ }
+ } else if (c->func_1_param != NULL) {
+ printf ("command executing: \"%s\"\n", command_name);
+ c->func_1_param (web_view);
+ }
+ } else {
+ fprintf (stderr, "command \"%s\" not understood. ignoring.\n", cmd);
+ }
+}
+
+static void
+*control_fifo() {
+ if (fifodir) {
+ sprintf (fifopath, "%s/uzbl_%d", fifodir, (int) xwin);
+ } else {
+ sprintf (fifopath, "/tmp/uzbl_%d", (int) xwin);
+ }
+
+ if (mkfifo (fifopath, 0666) == -1) {
+ printf ("Possible error creating fifo\n");
+ }
+
+ printf ("Control fifo opened in %s\n", fifopath);
+
+ while (true) {
+ FILE *fifo = fopen (fifopath, "r");
+ if (!fifo) {
+ printf ("Could not open %s for reading\n", fifopath);
+ return NULL;
+ }
+
+ char buffer[256];
+ memset (buffer, 0, sizeof (buffer));
+ while (!feof (fifo) && fgets (buffer, sizeof (buffer), fifo)) {
+ if (strcmp (buffer, "\n")) {
+ buffer[strlen (buffer) - 1] = '\0'; // Remove newline
+ parse_command (buffer);
+ }
+ }
+ }
+
+ return NULL;
+}
+