prgname in goption usage



Calling g_set_prgname is necessary to use GOption?

I wrote a sample program based on the code in tests/option-test.c.

    $./a.out -help
    Usage:
      (null) [OPTION...] 
    ...

I got (null) as the program name.
I was surprised that the command line parser didn't know
argv[0].
How do you think calling g_set_prgname inside g_option_context_parse
Only if the program name is not set yet?

Masatake YAMATO

2004-08-26  Masatake YAMATO  <jet gyve org>

	* glib/goption.c (g_option_context_parse): Only if 
	the program name is not set yet, set it.

Index: glib/goption.c
===================================================================
RCS file: /cvs/gnome/glib/glib/goption.c,v
retrieving revision 1.4
diff -u -r1.4 goption.c
--- glib/goption.c	23 Aug 2004 23:15:08 -0000	1.4
+++ glib/goption.c	26 Aug 2004 06:59:17 -0000
@@ -819,6 +819,11 @@
 {
   gint i, j, k;
   GList *list;
+  gchar * prg_name = (*argv)[0];
+  
+  /* Only if the program name is not set yet, set it here. */
+  if (!g_get_prgname ())
+    g_set_prgname(prg_name);
 
   /* Call pre-parse hooks */
   list = context->groups;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]