From b2134d0394f706d5f9582efe6a2d5b696e84cecc Mon Sep 17 00:00:00 2001 From: "Ira W. Snyder" Date: Fri, 18 Jan 2008 16:41:08 -0800 Subject: [PATCH] Add initial command-line interface This adds the first option to the command-line interface: version information. More will be needed in the future, but I'm not ready for interface design yet, so it will wait until later. --- tilda.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ tilda.h | 3 +++ 2 files changed, 53 insertions(+) diff --git a/tilda.c b/tilda.c index c712fc7..7656551 100644 --- a/tilda.c +++ b/tilda.c @@ -1,4 +1,5 @@ #include +#include #include "tilda.h" #include "tilda-window.h" @@ -113,6 +114,52 @@ tilda_del_window (gint number) } } +static void +tilda_parse_command_line (gint argc, gchar *argv[]) +{ + debug_enter (); + + gboolean version = FALSE; + + /* All of the various command-line options */ + const GOptionEntry cl_opts[] = { + { "version", 'V', 0, G_OPTION_ARG_NONE, &version, N_("Show version information"), NULL }, + { NULL }, + }; + + /* Set up the command-line parser */ + GError *error = NULL; + GOptionContext *context = g_option_context_new (NULL); + g_option_context_add_main_entries (context, cl_opts, NULL); + g_option_context_add_group (context, gtk_get_option_group (TRUE)); + g_option_context_parse (context, &argc, &argv, &error); + g_option_context_free (context); + + /* Check for unknown options, and give a nice message if there are some */ + if (error) + { + g_printerr (_("Error parsing command-line options: %s\n"), error->message); + g_printerr (_("The command \"tilda --help\" will show all possible options\n")); + g_error_free (error); + exit (EXIT_FAILURE); + } + + /* If we need to show the version, show it then exit normally */ + if (version) + { + g_print ("%s\n\n", TILDA_VERSION); + + g_print ("Copyright (c) 2005-2008 Tristan Sloughter (sloutri@iit.edu)\n"); + g_print ("Copyright (c) 2005-2008 Ira W. Snyder (tilda@irasnyder.com)\n\n"); + + g_print ("This program comes with ABSOLUTELY NO WARRANTY.\n"); + g_print ("This is free software, and you are welcome to redistribute it\n"); + g_print ("under certain conditions. See the file COPYING for details.\n"); + + exit (EXIT_SUCCESS); + } +} + int main (int argc, char *argv[]) { debug_enter (); @@ -126,6 +173,9 @@ int main (int argc, char *argv[]) textdomain (PACKAGE); #endif + /* Parse the command-line options */ + tilda_parse_command_line (argc, argv); + /* Initialize GTK+ (and the GObject system) */ gtk_init (&argc, &argv); diff --git a/tilda.h b/tilda.h index 96adfa1..3262d8c 100644 --- a/tilda.h +++ b/tilda.h @@ -23,6 +23,9 @@ #define N_(X) X #endif +// FIXME: remove when the project is autoconfed +#define TILDA_VERSION "0.10.0pre" + /* Project-global variables */ extern DBusGConnection *dbus_connection; -- 2.25.1