aboutsummaryrefslogtreecommitdiffhomepage
path: root/uzbl.c
diff options
context:
space:
mode:
authorGravatar Barrucadu <mike@barrucadu.co.uk>2009-04-26 09:39:16 +0100
committerGravatar Barrucadu <mike@barrucadu.co.uk>2009-04-26 09:39:16 +0100
commit8e6ee828a1af6fe74b4bc472493c3dbd186449c2 (patch)
treefdd9c9c23b8928a81338b9c3b68963868ffc8520 /uzbl.c
parentbed8c529b5d9bfa94e8cb0c5a2de08f7f8e74134 (diff)
parent301c206143319ce7f00ffdfeb873cf51507b25b4 (diff)
Merge branch 'dieter/experimental' into experimental. Fixed a few coding style mistakes.
Diffstat (limited to 'uzbl.c')
-rw-r--r--uzbl.c120
1 files changed, 56 insertions, 64 deletions
diff --git a/uzbl.c b/uzbl.c
index bbfe75e..fe45d57 100644
--- a/uzbl.c
+++ b/uzbl.c
@@ -74,9 +74,8 @@ static GOptionEntry entries[] =
typedef struct
{
const char *command;
- void (*func)(WebKitWebView*);
- const gboolean param_allow;
- const gboolean param_optional;
+ void (*func_1_param)(WebKitWebView*);
+ void (*func_2_params)(WebKitWebView*, char *);
} Command;
typedef struct
@@ -178,13 +177,13 @@ log_history_cb () {
// TODO: reload, home, quit
static Command commands[] =
{
- { "back", &go_back_cb, false, false },
- { "forward", &go_forward_cb, false, false },
- { "refresh", &webkit_web_view_reload, false, false }, //Buggy
- { "stop", &webkit_web_view_stop_loading, false, false },
- { "zoom_in", &webkit_web_view_zoom_in, false, false }, //Can crash (when max zoom reached?).
- { "zoom_out", &webkit_web_view_zoom_out, false, false } ,
- { "go", &webkit_web_view_load_uri, true, false }
+ { "back", &go_back_cb, NULL },
+ { "forward", &go_forward_cb, NULL },
+ { "refresh", &webkit_web_view_reload, NULL }, //Buggy
+ { "stop", &webkit_web_view_stop_loading, NULL },
+ { "zoom_in", &webkit_web_view_zoom_in, NULL }, //Can crash (when max zoom reached?).
+ { "zoom_out", &webkit_web_view_zoom_out, NULL } ,
+ { "uri", NULL, &webkit_web_view_load_uri }
//{ "get uri", &webkit_web_view_get_uri},
};
@@ -192,88 +191,81 @@ static Command commands[] =
static void
parse_command(const char *command) {
- int i = 0;
- bool done = false;
- void (*func)(WebKitWebView*);
-
- char * command_name = strtok (command," ");
- char * command_param = strtok (NULL, " ,"); //dunno how this works, but it seems to work
-
+ int i;
Command *c;
+ char * command_name = strtok (command, " ");
+ char * command_param = strtok (NULL, " ,"); //dunno how this works, but it seems to work
+
+ Command *c_tmp;
for (i = 0; i < LENGTH(commands); i++) {
- c = &commands[i];
- if (!strncmp (command_name, c->command, strlen (c->command))) {
- func = c->func;
- done = true;
+ c_tmp = &commands[i];
+ if (strncmp (command_name, c_tmp->command, strlen (c_tmp->command)) == 0) {
+ c = c_tmp;
}
}
-
- if (done) {
- if (c->param_allow) {
- if(command_param != NULL) {
- printf("command executing: \"%s %s\"\n", command_name, command_param);
- //func (web_view, command_param);
+ 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->param_optional) {
- printf("command executing: \"%s\"\n", command_name);
- func (web_view);
+ 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);
+ fprintf (stderr, "command needs a parameter. \"%s\" is not complete\n", command_name);
}
}
- } else {
- printf("command executing: \"%s\"\n", command_name);
- func (web_view);
+ } 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", command);
+ fprintf (stderr, "command \"%s\" not understood. ignoring.\n", command);
}
}
static void
*control_fifo() {
- if (fifodir) {
- sprintf (fifopath, "%s/uzbl_%d", fifodir, (int) xwin);
- } else {
- sprintf (fifopath, "/tmp/uzbl_%d", (int) xwin);
- }
+ 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");
- }
+ if (mkfifo (fifopath, 0666) == -1) {
+ printf ("Possible error creating fifo\n");
+ }
- printf ("Control fifo opened in %s\n", fifopath);
+ 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;
- }
+ 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);
- }
+ 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;
+ return NULL;
}
static void
setup_threading () {
- pthread_t control_thread;
- pthread_create(&control_thread, NULL, control_fifo, NULL);
+ pthread_t control_thread;
+ pthread_create(&control_thread, NULL, control_fifo, NULL);
}
-
-
-
static void
update_title (GtkWindow* window) {
GString* string = g_string_new (main_title);