aboutsummaryrefslogtreecommitdiffhomepage
path: root/uzbl.c
diff options
context:
space:
mode:
authorGravatar Barrucadu <mike@barrucadu.co.uk>2009-04-29 19:14:40 +0100
committerGravatar Barrucadu <mike@barrucadu.co.uk>2009-04-29 19:14:40 +0100
commit2668b7723dff9460bb2b4ca842025c8ad6dae753 (patch)
treeaf7fbb1e97d3901a58c3ea9dba15fcb18756aae9 /uzbl.c
parent353aefa427b0153fe1db25781771bf1c52fab4d6 (diff)
parente0e74bb34d1ce7ff52f28fccb4f0c7bdf6740e92 (diff)
Merge branch 'dieter/experimental' into experimental
Conflicts: examples/scripts/load_url_from_bookmarks.sh examples/scripts/load_url_from_history.sh
Diffstat (limited to 'uzbl.c')
-rw-r--r--uzbl.c137
1 files changed, 65 insertions, 72 deletions
diff --git a/uzbl.c b/uzbl.c
index cf46f25..9cc2ca1 100644
--- a/uzbl.c
+++ b/uzbl.c
@@ -77,18 +77,14 @@ static gchar* modkey = NULL;
static guint modmask = 0;
static gchar* home_page = NULL;
-typedef struct {
- const char *binding;
- const char *action;
-} Binding;
-
/* settings from config: group bindings_internal */
-static Binding internal_bindings[256];
-static int num_internal_bindings = 0;
+static GHashTable *internal_bindings;
/* settings from config: group bindings_external */
-static Binding external_bindings[256];
-static int num_external_bindings = 0;
+static GHashTable *external_bindings;
+
+/* command list */
+static GHashTable *commands;
/* commandline arguments (set initial values for the state variables) */
static GOptionEntry entries[] =
@@ -102,7 +98,7 @@ static GOptionEntry entries[] =
/* for internal list of commands */
typedef struct
{
- const char *command;
+ gpointer command;
void (*func_1_param)(WebKitWebView*);
void (*func_2_params)(WebKitWebView*, const gchar *);
} Command;
@@ -258,10 +254,11 @@ log_history_cb () {
g_string_free (args, TRUE);
}
}
-
+
/* -- command to callback/function map for things we cannot attach to any signals */
// TODO: reload, home, quit
-static Command commands[] =
+
+static Command cmdlist[] =
{
{ "back", &go_back_cb, NULL },
{ "forward", &go_forward_cb, NULL },
@@ -273,9 +270,22 @@ static Command commands[] =
{ "toggle_status", &toggle_status_cb, NULL },
{ "home" , &go_home, NULL },
{ "exit" , &close_uzbl, NULL },
+ { NULL, NULL, NULL }
//{ "get uri", &webkit_web_view_get_uri},
};
+static void
+commands_hash(void)
+{
+ unsigned int i = 0;
+ commands = g_hash_table_new(g_str_hash, g_str_equal);
+
+ while(cmdlist[i].command != NULL){
+ g_hash_table_insert(commands, cmdlist[i].command, &cmdlist[i]);
+ i++;
+ }
+}
+
/* -- CORE FUNCTIONS -- */
static bool
@@ -350,42 +360,32 @@ run_command(const char *command, const char *args) {
static void
parse_command(const char *cmd) {
- unsigned int i;
- Command *c = NULL;
- char buffer[512];
- strcpy (buffer, cmd);
- const gchar * command_name = strtok (buffer, " ");
- const gchar * 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);
+ Command *c = NULL;
+ char buffer[512];
+ strcpy (buffer, cmd);
+ char * command_name = strtok (buffer, " ");
+ gchar * command_param = strtok (NULL, " ,");
+
+ if((c = g_hash_table_lookup(commands, command_name)) != 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_socket() {
if (socket_dir) {
@@ -487,7 +487,7 @@ static gboolean
key_press_cb (WebKitWebView* page, GdkEventKey* event)
{
(void) page;
- int i;
+ gpointer act;
gboolean result=FALSE; //TRUE to stop other handlers from being invoked for the event. FALSE to propagate the event further.
if (event->type != GDK_KEY_PRESS || event->keyval == GDK_Page_Up || event->keyval == GDK_Page_Down
|| event->keyval == GDK_Up || event->keyval == GDK_Down || event->keyval == GDK_Left || event->keyval == GDK_Right)
@@ -501,25 +501,19 @@ key_press_cb (WebKitWebView* page, GdkEventKey* event)
}
//INTERNAL BINDINGS
- for (i = 0; i < num_internal_bindings; i++) {
- if (strcmp(event->string, internal_bindings[i].binding) == 0) {
- if (!insert_mode || (event->state == modmask)) {
- parse_command (internal_bindings[i].action);
- result = TRUE;
- }
- }
- }
+ if((act = g_hash_table_lookup(internal_bindings, event->string)) != NULL)
+ if (!insert_mode || (event->state == modmask)) {
+ parse_command (act);
+ result = TRUE;
+ }
//EXTERNAL BINDINGS
- for (i = 0; i < num_external_bindings; i++) {
- if (strcmp(event->string, external_bindings[i].binding) == 0) {
- if (!insert_mode || (event->state == modmask)) {
- run_command(external_bindings[i].action, NULL);
- result = TRUE;
- }
- }
- }
-
+ if((act = g_hash_table_lookup(external_bindings, event->string)) != NULL)
+ if (!insert_mode || (event->state == modmask)) {
+ parse_command (act);
+ result = TRUE;
+ }
+
if (!result)
result = (insert_mode ? FALSE : TRUE);
@@ -569,14 +563,8 @@ GtkWidget* create_window () {
static void
add_binding (char *binding, char *action, bool internal) {
- Binding bind = {binding, action};
- if (internal) {
- internal_bindings[num_internal_bindings] = bind;
- num_internal_bindings ++;
- } else {
- external_bindings[num_external_bindings] = bind;
- num_external_bindings ++;
- }
+ g_hash_table_insert(internal ? internal_bindings : external_bindings,
+ binding, action);
}
static void
@@ -713,8 +701,13 @@ main (int argc, char* argv[]) {
g_option_context_add_main_entries (context, entries, NULL);
g_option_context_add_group (context, gtk_get_option_group (TRUE));
g_option_context_parse (context, &argc, &argv, &error);
+ /* initialize has tables */
+ internal_bindings = g_hash_table_new(g_str_hash, g_str_equal);
+ external_bindings = g_hash_table_new(g_str_hash, g_str_equal);
settings_init ();
+ commands_hash ();
+
if (always_insert_mode)
insert_mode = TRUE;