aboutsummaryrefslogtreecommitdiffhomepage
path: root/uzbl.c
diff options
context:
space:
mode:
authorGravatar Dieter Plaetinck <dieter@plaetinck.be>2009-04-25 23:43:42 +0200
committerGravatar Dieter Plaetinck <dieter@plaetinck.be>2009-04-25 23:43:42 +0200
commiteb0c7ca3297e16a13ede258b20d7eae57730b3a8 (patch)
tree1426280e920ff5ad14c8ef22df41670743ffa0ed /uzbl.c
parentaad63593edbc4805fbeed5d7820662e9df753deb (diff)
attempt for commands which support params. unfortunately this doesnt work yet
Diffstat (limited to 'uzbl.c')
-rw-r--r--uzbl.c49
1 files changed, 32 insertions, 17 deletions
diff --git a/uzbl.c b/uzbl.c
index e6916f2..79df06d 100644
--- a/uzbl.c
+++ b/uzbl.c
@@ -68,6 +68,8 @@ typedef struct
{
const char *command;
void (*func)(WebKitWebView*);
+ const gboolean param_allow;
+ const gboolean param_optional;
} Command;
@@ -153,12 +155,13 @@ log_history_cb () {
// TODO: reload, home, quit
static Command commands[] =
{
- { "back", &go_back_cb },
- { "forward", &go_forward_cb },
- { "refresh", &webkit_web_view_reload }, //Buggy
- { "stop", &webkit_web_view_stop_loading },
- { "zoom_in", &webkit_web_view_zoom_in }, //Can crash (when max zoom reached?).
- { "zoom_out", &webkit_web_view_zoom_out }
+ { "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 }
//{ "get uri", &webkit_web_view_get_uri},
};
@@ -170,25 +173,37 @@ parse_command(const char *command) {
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
+
Command *c;
for (i = 0; i < LENGTH(commands); i++) {
- c = &commands[i];
- if (!strncmp (command, c->command, strlen (c->command))) {
+ c = &commands[i];
+ if (!strncmp (command_name, c->command, strlen (c->command))) {
func = c->func;
done = true;
}
}
- printf("command received: \"%s\"\n", command);
-
- if (done) {
- func (web_view);
- } else {
- if (!strncmp ("http://", command, 7)) {
- printf ("Loading URI \"%s\"\n", command);
- strcpy(uri, command);
- webkit_web_view_load_uri (web_view, uri);
+ 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);
+ } else {
+ if(c->param_optional) {
+ printf("command executing: \"%s\"\n", command_name);
+ func (web_view);
+ } else {
+ 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 {
+ fprintf(stderr, "command \"%s\" not understood. ignoring.\n", command);
}
}