/* * Copyright © 2009 Benjamin Otte * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "ephy-history.h" static gboolean quiet = FALSE; static void ephy_query_history_print_results (GObject *history, GAsyncResult *res, gpointer loop) { GError *error = NULL; GSList *list; guint i; list = ephy_history_select_finish (EPHY_HISTORY (history), res, &error); if (list == NULL) g_main_loop_quit (loop); if (error) { g_print ("Error: %s\n", error->message); g_error_free (error); return; } if (!quiet) { for (; list; list = list->next) { GValueArray *array = list->data; for (i = 0; i < array->n_values; i++) { char *s = g_strdup_value_contents (&array->values[i]); g_print ("%s\t", s); } g_print ("\n"); } } } int main (int argc, char *argv[]) { static char *filename = NULL; static GOptionEntry options[] = { { "filename", 'f', 0, G_OPTION_ARG_FILENAME, &filename, "file to use as history instead of default", "FILENAME" }, { "quiet", 'q', 0, G_OPTION_ARG_NONE, &quiet, "don't print output", NULL }, { NULL } }; GOptionContext *ctx; GError *error = NULL; EphyHistory *history; GMainLoop *loop; GTimer *timer; g_thread_init (NULL); g_type_init (); ctx = g_option_context_new (""); g_option_context_add_main_entries (ctx, options, "options"); g_option_context_parse (ctx, &argc, &argv, &error); g_option_context_free (ctx); if (error) { g_printerr ("Error parsing command line arguments: %s\n", error->message); g_error_free (error); return 1; } if (argc < 2) { g_print ("usage: %s [OPTIONS] SQL\n", argv[0]); return 1; } history = ephy_history_new (filename); loop = g_main_loop_new (NULL, FALSE); timer = g_timer_new (); g_timer_start (timer); ephy_history_select_async (history, 50, 1000, ephy_query_history_print_results, loop, NULL, "%s", argv[1]); g_main_loop_run (loop); g_print ("Query took %gs\n", g_timer_elapsed (timer, NULL)); g_timer_destroy (timer); g_main_loop_unref (loop); g_object_unref (history); return 0; }