From bcd4616f16471e71660577af6309bc29598df1e2 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Tue, 21 Apr 2009 22:47:59 +0200 Subject: [PATCH] simple commandline argument parsing support --- Makefile | 2 +- uzbl.c | 29 ++++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 0772e72..881ddc0 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ all: gcc `pkg-config --libs --cflags gtk+-2.0` `pkg-config --libs --cflags webkit-1.0` -Wall uzbl.c -o uzbl test: - ./uzbl http://www.archlinux.org + ./uzbl --uri http://www.archlinux.org diff --git a/uzbl.c b/uzbl.c index 4a34476..c66dd53 100644 --- a/uzbl.c +++ b/uzbl.c @@ -37,6 +37,21 @@ static gchar* main_title; static gint load_progress; static guint status_context_id; + + +static gchar* uri = NULL; +static gboolean verbose = FALSE; + +static GOptionEntry entries[] = +{ + { "uri", 'u', 0, G_OPTION_ARG_STRING, &uri, "Uri to load", NULL }, + { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Be verbose", NULL }, + { NULL } +}; + + + + static void activate_uri_entry_cb (GtkWidget* entry, gpointer data) { @@ -45,8 +60,7 @@ activate_uri_entry_cb (GtkWidget* entry, gpointer data) webkit_web_view_load_uri (web_view, uri); } -static void -update_title (GtkWindow* window) +static void update_title (GtkWindow* window) { GString* string = g_string_new (main_title); g_string_append (string, " - Uzbl browser"); @@ -125,8 +139,7 @@ create_browser () return scrolled_window; } -static GtkWidget* -create_statusbar () +static GtkWidget* create_statusbar () { main_statusbar = GTK_STATUSBAR (gtk_statusbar_new ()); status_context_id = gtk_statusbar_get_context_id (main_statusbar, "Link Hover"); @@ -156,8 +169,14 @@ int main (int argc, char* argv[]) main_window = create_window (); gtk_container_add (GTK_CONTAINER (main_window), vbox); + GError *error = NULL; + + GOptionContext* context = g_option_context_new ("- some stuff here maybe someday"); + 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); + - gchar* uri = (gchar*) (argc > 1 ? argv[1] : "http://www.google.com/"); webkit_web_view_load_uri (web_view, uri); gtk_widget_grab_focus (GTK_WIDGET (web_view)); -- 1.7.9.5