+void
+keywords_load(void)
+{
+ GError *err = NULL;
+ GIOChannel *channel = NULL;
+ gchar *path = NULL;
+ gchar *buf = NULL;
+ gchar **tokens = NULL;
+
+ keywords = g_hash_table_new(g_str_hash, g_str_equal);
+
+ path = g_build_filename(g_get_user_config_dir(), __NAME__, "keywordsearch",
+ NULL);
+ channel = g_io_channel_new_file(path, "r", &err);
+ if (channel != NULL)
+ {
+ while (g_io_channel_read_line(channel, &buf, NULL, NULL, NULL)
+ == G_IO_STATUS_NORMAL)
+ {
+ g_strstrip(buf);
+ if (buf[0] != '#')
+ {
+ tokens = g_strsplit(buf, " ", 2);
+ if (tokens[0] != NULL && tokens[1] != NULL)
+ g_hash_table_insert(keywords, tokens[0], tokens[1]);
+ else
+ g_strfreev(tokens);
+ }
+ g_free(buf);
+ }
+ }
+ g_io_channel_shutdown(channel, FALSE, NULL);
+ g_free(path);
+}
+
+gboolean
+keywords_try_search(WebKitWebView *web_view, const gchar *t)
+{
+ gboolean ret = FALSE;
+ gchar **tokens = NULL;
+ gchar *val = NULL;
+ gchar *uri = NULL;
+
+ tokens = g_strsplit(t, " ", 2);
+ if (tokens[0] != NULL && tokens[1] != NULL)
+ {
+ val = g_hash_table_lookup(keywords, tokens[0]);
+ if (val != NULL)
+ {
+ uri = g_strdup_printf((gchar *)val, tokens[1]);
+ if (show_all_requests)
+ fprintf(stderr, "====> %s\n", uri);
+ webkit_web_view_load_uri(web_view, uri);
+ g_free(uri);
+ ret = TRUE;
+ }
+ }
+ g_strfreev(tokens);
+
+ return ret;
+}
+