+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;
+}
+
+static void
+setup_threading () {
+ pthread_t control_thread;
+ pthread_create(&control_thread, NULL, control_fifo, NULL);
+}
+
+static void
+update_title (GtkWindow* window) {
+ GString* string_long = g_string_new ("");
+ GString* string_short = g_string_new ("");
+ if (!always_insert_mode)
+ g_string_append (string_long, (insert_mode ? "[I] " : "[C] "));
+ g_string_append (string_long, main_title);
+ g_string_append (string_short, main_title);
+ g_string_append (string_long, " - Uzbl browser");
+ g_string_append (string_short, " - Uzbl browser");
+ if (load_progress < 100)
+ g_string_append_printf (string_long, " (%d%%)", load_progress);
+
+ if (selected_url[0]!=0) {
+ g_string_append_printf (string_long, " -> (%s)", selected_url);
+ }
+
+ gchar* title_long = g_string_free (string_long, FALSE);
+ gchar* title_short = g_string_free (string_short, FALSE);
+
+ if (show_status) {
+ gtk_window_set_title (window, title_short);
+ gtk_label_set_text(GTK_LABEL(mainbar_label), title_long);
+ } else {
+ gtk_window_set_title (window, title_long);
+ }
+
+ g_free (title_long);
+ g_free (title_short);
+}
+
+static gboolean
+key_press_cb (WebKitWebView* page, GdkEventKey* event)