Hello Tristan

Glib has had functions for parsing command-lines for quite some time
now. As such, there is no reason to use libpopt anymore.

ChangeLog Entry
---------------

2006-04-08  Vincent Geddes <[EMAIL PROTECTED]>

        * src/main.c: 
        o Use glib instead of libpopt for command-line parsing.
        o Added '--version' option.
        o Do not try to open non-existent files supplied
          on command-line.  

        * configure.in: Remove libpopt dependency.



Cheers

Vincent Geddes

Index: configure.in
===================================================================
RCS file: /cvs/gnome/glade3/configure.in,v
retrieving revision 1.53
diff -u -p -r1.53 configure.in
--- configure.in	4 Apr 2006 14:47:14 -0000	1.53
+++ configure.in	9 Apr 2006 11:11:05 -0000
@@ -53,10 +53,6 @@ PKG_CHECK_MODULES(GLADE, gtk+-2.0 >= 2.8
 AC_SUBST(GLADE_LIBS)
 AC_SUBST(GLADE_CFLAGS)
 
-AC_CHECK_LIB(popt, poptStrippedArgv,, AC_MSG_ERROR([popt 1.5 or newer is required to build
-glade-3. You can download the latest version from ftp://people.redhat.com/sopwith/popt/]))
-
-
 glade_version="${VERSION}"
 glade_datadir='${datadir}/${PACKAGE}'
 glade_libdir='${libdir}/${PACKAGE}'
@@ -78,14 +74,6 @@ AC_SUBST(glade_localedir)
 case $host_os in
 *mingw* | pw32* | cygwin*)
   win32=yes
-  AC_ARG_ENABLE(popt_dll,
-                [  --disable-popt-dll         disable use of libpopt.dll (use static version instead)],
-                popt_dll=$enableval, popt_dll=yes)
-  if test "x$popt_dll" = "xyes"; then
-    AC_DEFINE(USE_POPT_DLL, 1, [Define to 1 if libpopt.dll is to be used.])
-  else
-    AC_DEFINE(POPT_STATIC, 1, [Define to 1 if static version of libpopt is to be used.])
-  fi
   ;;
 esac
 AM_CONDITIONAL(WITH_WIN32, test x"$win32" = "xyes")
Index: src/main.c
===================================================================
RCS file: /cvs/gnome/glade3/src/main.c,v
retrieving revision 1.43
diff -u -p -r1.43 main.c
--- src/main.c	6 Dec 2005 20:46:48 -0000	1.43
+++ src/main.c	9 Apr 2006 11:11:06 -0000
@@ -18,21 +18,19 @@
  *
  * Authors:
  *   Chema Celorio <[EMAIL PROTECTED]>
+ *   Vincent Geddes <[EMAIL PROTECTED]>
  */
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
 
+#include <glib.h>
 #include <glib/gi18n.h>
 
 #include <locale.h>
 #include <gmodule.h>
 
-#ifdef HAVE_LIBPOPT
-#include <popt.h>
-#endif
-
 #ifdef G_OS_WIN32
 #include <stdlib.h> /* __argc & __argv on the windows build */
 #endif
@@ -42,72 +40,36 @@
 #include "glade-debug.h"
 
 
-static gchar *widget_name = NULL;
+/* Application arguments */
+static gboolean version = FALSE;
+static gchar **files = NULL;
 
-#ifdef HAVE_LIBPOPT
-static struct poptOption options[] = {
-	{ "dump", '\0', POPT_ARG_STRING, &widget_name, 0,
-	  N_("dump the properties of a widget. --dump [gtk type] "
-	     "where type can be GtkWindow, GtkLabel etc."), NULL },
-	{ "verbose", 'v', POPT_ARG_NONE, NULL, 0,
-	  N_("be verbose."), NULL },
-#ifndef USE_POPT_DLL
-	POPT_AUTOHELP
-#else
-	/* poptHelpOptions can not be resolved during linking on Win32,
-	   get it at runtime. */
-	{ NULL, '\0', POPT_ARG_INCLUDE_TABLE, 0, 0,
-	  N_("Help options:"), NULL },
-#endif
-	POPT_TABLEEND
-};
-
-static GList *
-parse_command_line (poptContext pctx)
+static GOptionEntry option_entries[] = 
 {
-	gint opt;
-	const gchar **args;
-	GList *files = NULL;
-	gint i;
-
-	/* parse options */
-	while ((opt = poptGetNextOpt (pctx)) > 0 || opt == POPT_ERROR_BADOPT)
-		/* do nothing */ ;
-
-	/* load the args that aren't options as files */
-	args = poptGetArgs (pctx);
-
-	for (i = 0; args && args[i]; i++)
-		files = g_list_prepend (files, g_strdup (args[i]));
-
-	files = g_list_reverse (files);
+  { "version", '\0', 0, G_OPTION_ARG_NONE, &version, "output version information and exit", NULL },
+  { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &files, "", "" },
+  { NULL }
+};
 
-	return files;
-}
-#endif
+/* Debugging arguments */
+static gchar *widget_name = NULL;
+static gboolean verbose = FALSE;
 
-static gint
-glade_init (void)
+static GOptionEntry debug_option_entries[] = 
 {
-	if (!g_module_supported ())
-	{
-		g_warning (_("gmodule support not found. gmodule support is required "
-			     "for glade to work"));
-		return FALSE;
-	}
-
-	return TRUE;
-}
+  { "dump", 'd', 0, G_OPTION_ARG_STRING, &widget_name, "dump the properties of a widget", "GTKWIDGET" },
+  { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "be verbose", NULL },
+  { NULL }
+};
 
 int
 main (int argc, char *argv[])
 {
 	GladeProjectWindow *project_window;
-	GList *files = NULL, *l;
-#ifdef HAVE_LIBPOPT
-	poptContext popt_context;
-#endif
-
+	GOptionContext *option_context;
+	GOptionGroup *option_group;
+	GError *error = NULL;
+	
 #ifdef ENABLE_NLS
 	setlocale (LC_ALL, "");
 	bindtextdomain (GETTEXT_PACKAGE, glade_locale_dir);
@@ -115,28 +77,61 @@ main (int argc, char *argv[])
 	textdomain (GETTEXT_PACKAGE);
 #endif
 
-	g_set_application_name (_("Glade-3 GUI Builder"));
+	/* Set up option groups */
+	option_context = g_option_context_new ("[FILE...]");
 
-#ifdef HAVE_LIBPOPT
-# ifdef USE_POPT_DLL
-	options[G_N_ELEMENTS (options) - 2].arg = poptHelpOptions;
-# endif
-	options[1].arg = &glade_verbose;
-	popt_context = poptGetContext ("Glade3", argc, (const char **) argv, options, 0);
-	files = parse_command_line (popt_context);
-	poptFreeContext (popt_context);
-#endif
+	option_group = g_option_group_new ("glade",
+					   N_("Glade GUI Builder"),
+					   N_("Glade GUI Builder options"),
+					   NULL, NULL);
+	g_option_group_add_entries (option_group, option_entries);
+	g_option_context_set_main_group (option_context, option_group);
+
+	option_group = g_option_group_new ("debug",
+					   "Glade debug options",
+					   "Show debug options",
+					   NULL, NULL);
+	g_option_group_add_entries (option_group, debug_option_entries);
+	g_option_context_add_group (option_context, option_group);
 
-	gtk_init (&argc, &argv);
+	/* Add Gtk option group */
+	g_option_context_add_group (option_context, gtk_get_option_group (TRUE));
 
-	glade_setup_log_handlers ();
+	/* Parse command line */
+	if (!g_option_context_parse (option_context, &argc, &argv, &error))
+	{
+		g_option_context_free (option_context);
+	
+		g_print ("%s\n", error->message);
+		g_error_free (error);
+		exit (1);
+	}
+	
 
-	if (!glade_init ())
-		return -1;
+	if (version == TRUE)
+	{
+		/* Print version information and exit */
+		g_print ("%s\n", PACKAGE_STRING);
+		return 0;
+	}
+	
 
+	g_set_application_name (_("Glade-3 GUI Builder"));
+	
+	glade_setup_log_handlers ();
+	
+	/* Check for gmodule support */
+	if (!g_module_supported ())
+	{
+		g_warning (_("gmodule support not found. gmodule support is required "
+			     "for glade to work"));
+		return -1;
+	}
+	
 	project_window = glade_project_window_new ();
 	glade_default_app_set (GLADE_APP (project_window));
 	
+
 #if I_HAD_A_DEBUG_MACRO
 	if (widget_name != NULL)
 	{
@@ -148,16 +143,24 @@ main (int argc, char *argv[])
 	}
 #endif
 	
-	glade_project_window_show_all (project_window);
-
-	if (files)
+	/* load files specified on commandline */
+	if (files != NULL)
 	{
-		for (l = files; l; l = l->next)
-			glade_project_window_open_project (project_window, l->data);
-		g_list_free (files);
+		guint i;
+		
+		for (i=0; files[i] ; ++i)
+		{
+			if (g_file_test (files[i], G_FILE_TEST_EXISTS) == TRUE)
+				glade_project_window_open_project (project_window, files[i]);
+			else
+				g_warning (_("Unable to open '%s', the file does not exist.\n"), files[i]);
+		}
+		g_strfreev (files);
 	}
-	else
+	else 
 		glade_project_window_new_project (project_window);
+
+	glade_project_window_show_all (project_window);
 
 	gtk_main ();
 
_______________________________________________
Glade-devel maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/glade-devel

Reply via email to