Add G_OPTION_FLAG_NO_ARG and G_OPTION_FLAG_FILENAME to allow greater
[platform/upstream/glib.git] / glib / goption.c
1 /* goption.c - Option parser
2  *
3  *  Copyright (C) 1999, 2003 Red Hat Software
4  *  Copyright (C) 2004       Anders Carlsson <andersca@gnome.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22 #include "config.h"
23
24 #include "goption.h"
25 #include "glib.h"
26 #include "gi18n.h"
27
28 #include "galias.h"
29
30 #include <string.h>
31 #include <stdlib.h>
32 #include <errno.h>
33
34 #define TRANSLATE(group, str) (((group)->translate_func ? (* (group)->translate_func) ((str), (group)->translate_data) : (str)))
35
36 #define NO_ARG(entry) ((entry)->arg == G_OPTION_ARG_NONE ||       \
37                        ((entry)->arg == G_OPTION_ARG_CALLBACK &&  \
38                         ((entry)->flags & G_OPTION_FLAG_NO_ARG)))
39
40 typedef struct 
41 {
42   GOptionArg arg_type;
43   gpointer arg_data;  
44   union 
45   {
46     gboolean bool;
47     gint integer;
48     gchar *str;
49     gchar **array;
50   } prev;
51   union 
52   {
53     gchar *str;
54     struct 
55     {
56       gint len;
57       gchar **data;
58     } array;
59   } allocated;
60 } Change;
61
62 typedef struct
63 {
64   gchar **ptr;
65   gchar *value;
66 } PendingNull;
67
68 struct _GOptionContext
69 {
70   GList *groups;
71
72   gchar *parameter_string;
73
74   gboolean help_enabled;
75   gboolean ignore_unknown;
76   
77   GOptionGroup *main_group;
78
79   /* We keep a list of change so we can revert them */
80   GList *changes;
81   
82   /* We also keep track of all argv elements that should be NULLed or
83    * modified.
84    */
85   GList *pending_nulls;
86 };
87
88 struct _GOptionGroup
89 {
90   gchar *name;
91   gchar *description;
92   gchar *help_description;
93
94   GDestroyNotify  destroy_notify;
95   gpointer        user_data;
96
97   GTranslateFunc  translate_func;
98   GDestroyNotify  translate_notify;
99   gpointer        translate_data;
100
101   GOptionEntry *entries;
102   gint         n_entries;
103
104   GOptionParseFunc pre_parse_func;
105   GOptionParseFunc post_parse_func;
106   GOptionErrorFunc error_func;
107 };
108
109 static void free_changes_list (GOptionContext *context,
110                                gboolean        revert);
111 static void free_pending_nulls (GOptionContext *context,
112                                 gboolean        perform_nulls);
113
114 GQuark
115 g_option_error_quark (void)
116 {
117   static GQuark q = 0;
118   
119   if (q == 0)
120     q = g_quark_from_static_string ("g-option-context-error-quark");
121
122   return q;
123 }
124
125 /**
126  * g_option_context_new:
127  * @parameter_string: a string which is displayed in
128  *    the first line of <option>--help</option> output, after 
129  *    <literal><replaceable>programname</replaceable> [OPTION...]</literal>
130  *
131  * Creates a new option context. 
132  *
133  * Returns: a newly created #GOptionContext, which must be
134  *    freed with g_option_context_free() after use.
135  *
136  * Since: 2.6
137  */
138 GOptionContext *
139 g_option_context_new (const gchar *parameter_string)
140
141 {
142   GOptionContext *context;
143
144   context = g_new0 (GOptionContext, 1);
145
146   context->parameter_string = g_strdup (parameter_string);
147   context->help_enabled = TRUE;
148   context->ignore_unknown = FALSE;
149
150   return context;
151 }
152
153 /**
154  * g_option_context_free:
155  * @context: a #GOptionContext 
156  *
157  * Frees context and all the groups which have been 
158  * added to it.
159  *
160  * Since: 2.6
161  */
162 void g_option_context_free (GOptionContext *context) 
163 {
164   g_return_if_fail (context != NULL);
165
166   g_list_foreach (context->groups, (GFunc)g_option_group_free, NULL);
167   g_list_free (context->groups);
168
169   if (context->main_group) 
170     g_option_group_free (context->main_group);
171
172   free_changes_list (context, FALSE);
173   free_pending_nulls (context, FALSE);
174   
175   g_free (context->parameter_string);
176   
177   g_free (context);
178 }
179
180
181 /**
182  * g_option_context_set_help_enabled:
183  * @context: a #GOptionContext
184  * @help_enabled: %TRUE to enable <option>--help</option>, %FALSE to disable it
185  *
186  * Enables or disables automatic generation of <option>--help</option> 
187  * output. By default, g_option_context_parse() recognizes
188  * <option>--help</option>, <option>-?</option>, <option>--help-all</option>
189  * and <option>--help-</option><replaceable>groupname</replaceable> and creates
190  * suitable output to stdout. 
191  *
192  * Since: 2.6
193  */
194 void g_option_context_set_help_enabled (GOptionContext *context,
195                                         gboolean        help_enabled)
196
197 {
198   g_return_if_fail (context != NULL);
199
200   context->help_enabled = help_enabled;
201 }
202
203 /**
204  * g_option_context_get_help_enabled:
205  * @context: a #GOptionContext
206  * 
207  * Returns whether automatic <option>--help</option> generation
208  * is turned on for @context. See g_option_context_set_help_enabled().
209  * 
210  * Returns: %TRUE if automatic help generation is turned on.
211  *
212  * Since: 2.6
213  */
214 gboolean 
215 g_option_context_get_help_enabled (GOptionContext *context) 
216 {
217   g_return_val_if_fail (context != NULL, FALSE);
218   
219   return context->help_enabled;
220 }
221
222 /**
223  * g_option_context_set_ignore_unknown_options:
224  * @context: a #GOptionContext
225  * @ignore_unknown: %TRUE to ignore unknown options, %FALSE to produce
226  *    an error when unknown options are met
227  * 
228  * Sets whether to ignore unknown options or not. If an argument is 
229  * ignored, it is left in the @argv array after parsing. By default, 
230  * g_option_context_parse() treats unknown options as error.
231  * 
232  * This setting does not affect non-option arguments (i.e. arguments 
233  * which don't start with a dash). But note that GOption cannot reliably
234  * determine whether a non-option belongs to a preceding unknown option.
235  *
236  * Since: 2.6
237  **/
238 void
239 g_option_context_set_ignore_unknown_options (GOptionContext *context,
240                                              gboolean        ignore_unknown)
241 {
242   g_return_if_fail (context != NULL);
243
244   context->ignore_unknown = ignore_unknown;
245 }
246
247 /**
248  * g_option_context_get_ignore_unknown_options:
249  * @context: a #GOptionContext
250  * 
251  * Returns whether unknown options are ignored or not. See
252  * g_option_context_set_ignore_unknown_options().
253  * 
254  * Returns: %TRUE if unknown options are ignored.
255  * 
256  * Since: 2.6
257  **/
258 gboolean
259 g_option_context_get_ignore_unknown_options (GOptionContext *context)
260 {
261   g_return_val_if_fail (context != NULL, FALSE);
262
263   return context->ignore_unknown;
264 }
265
266 /**
267  * g_option_context_add_group:
268  * @context: a #GOptionContext
269  * @group: the group to add
270  * 
271  * Adds a #GOptionGroup to the @context, so that parsing with @context
272  * will recognize the options in the group. Note that the group will
273  * be freed together with the context when g_option_context_free() is
274  * called, so you must not free the group yourself after adding it
275  * to a context.
276  *
277  * Since: 2.6
278  **/
279 void
280 g_option_context_add_group (GOptionContext *context,
281                             GOptionGroup   *group)
282 {
283   GList *list;
284
285   g_return_if_fail (context != NULL);
286   g_return_if_fail (group != NULL);
287   g_return_if_fail (group->name != NULL);
288   g_return_if_fail (group->description != NULL);
289   g_return_if_fail (group->help_description != NULL);
290
291   for (list = context->groups; list; list = list->next)
292     {
293       GOptionGroup *g = (GOptionGroup *)list->data;
294
295       if ((group->name == NULL && g->name == NULL) ||
296           (group->name && g->name && strcmp (group->name, g->name) == 0))
297         g_warning ("A group named \"%s\" is already part of this GOptionContext", 
298                    group->name);
299     }
300
301   context->groups = g_list_append (context->groups, group);
302 }
303
304 /**
305  * g_option_context_set_main_group:
306  * @context: a #GOptionContext
307  * @group: the group to set as main group
308  * 
309  * Sets a #GOptionGroup as main group of the @context. 
310  * This has the same effect as calling g_option_context_add_group(), 
311  * the only difference is that the options in the main group are 
312  * treated differently when generating <option>--help</option> output.
313  *
314  * Since: 2.6
315  **/
316 void
317 g_option_context_set_main_group (GOptionContext *context,
318                                  GOptionGroup   *group)
319 {
320   g_return_if_fail (context != NULL);
321   g_return_if_fail (group != NULL);
322
323   if (context->main_group)
324     {
325       g_warning ("This GOptionContext already has a main group");
326
327       return;
328     }
329   
330   context->main_group = group;
331 }
332
333 /**
334  * g_option_context_get_main_group:
335  * @context: a #GOptionContext
336  * 
337  * Returns a pointer to the main group of @context.
338  * 
339  * Return value: the main group of @context, or %NULL if @context doesn't
340  *  have a main group. Note that group belongs to @context and should
341  *  not be modified or freed.
342  *
343  * Since: 2.6
344  **/
345 GOptionGroup *
346 g_option_context_get_main_group (GOptionContext *context)
347 {
348   g_return_val_if_fail (context != NULL, NULL);
349
350   return context->main_group;
351 }
352
353 /**
354  * g_option_context_add_main_entries:
355  * @context: a #GOptionContext
356  * @entries: a %NULL-terminated array of #GOptionEntry<!-- -->s
357  * @translation_domain: a translation domain to use for translating
358  *    the <option>--help</option> output for the options in @entries
359  *    with gettext(), or %NULL
360  * 
361  * A convenience function which creates a main group if it doesn't 
362  * exist, adds the @entries to it and sets the translation domain.
363  * 
364  * Since: 2.6
365  **/
366 void
367 g_option_context_add_main_entries (GOptionContext      *context,
368                                    const GOptionEntry  *entries,
369                                    const gchar         *translation_domain)
370 {
371   g_return_if_fail (entries != NULL);
372
373   if (!context->main_group)
374     context->main_group = g_option_group_new (NULL, NULL, NULL, NULL, NULL);
375   
376   g_option_group_add_entries (context->main_group, entries);
377   g_option_group_set_translation_domain (context->main_group, translation_domain);
378 }
379
380 static gint
381 calculate_max_length (GOptionGroup *group)
382 {
383   GOptionEntry *entry;
384   gint i, len, max_length;
385
386   max_length = 0;
387
388   for (i = 0; i < group->n_entries; i++)
389     {
390       entry = &group->entries[i];
391
392       if (entry->flags & G_OPTION_FLAG_HIDDEN)
393         continue;
394
395       len = g_utf8_strlen (entry->long_name, -1);
396       
397       if (entry->short_name)
398         len += 4;
399       
400       if (!NO_ARG (entry) && entry->arg_description)
401         len += 1 + g_utf8_strlen (TRANSLATE (group, entry->arg_description), -1);
402       
403       max_length = MAX (max_length, len);
404     }
405
406   return max_length;
407 }
408
409 static void
410 print_entry (GOptionGroup       *group,
411              gint                max_length,
412              const GOptionEntry *entry)
413 {
414   GString *str;
415
416   if (entry->flags & G_OPTION_FLAG_HIDDEN)
417     return;
418
419   if (entry->long_name[0] == 0)
420     return;
421
422   str = g_string_new (NULL);
423   
424   if (entry->short_name)
425     g_string_append_printf (str, "  -%c, --%s", entry->short_name, entry->long_name);
426   else
427     g_string_append_printf (str, "  --%s", entry->long_name);
428   
429   if (entry->arg_description)
430     g_string_append_printf (str, "=%s", TRANSLATE (group, entry->arg_description));
431   
432   g_print ("%-*s %s\n", max_length + 4, str->str,
433            entry->description ? TRANSLATE (group, entry->description) : "");
434   g_string_free (str, TRUE);  
435 }
436
437 static void
438 print_help (GOptionContext *context,
439             gboolean        main_help,
440             GOptionGroup   *group) 
441 {
442   GList *list;
443   gint max_length, len;
444   gint i;
445   GOptionEntry *entry;
446   GHashTable *shadow_map;
447   gboolean seen[256];
448   const gchar *rest_description;
449   
450   rest_description = NULL;
451   if (context->main_group)
452     {
453       for (i = 0; i < context->main_group->n_entries; i++)
454         {
455           entry = &context->main_group->entries[i];
456           if (entry->long_name[0] == 0)
457             {
458               rest_description = entry->arg_description;
459               break;
460             }
461         }
462     }
463   
464   g_print ("%s\n  %s %s%s%s%s%s\n\n", 
465            _("Usage:"), g_get_prgname(), _("[OPTION...]"),
466            rest_description ? " " : "",
467            rest_description ? rest_description : "",
468            context->parameter_string ? " " : "",
469            context->parameter_string ? context->parameter_string : "");
470
471   memset (seen, 0, sizeof (gboolean) * 256);
472   shadow_map = g_hash_table_new (g_str_hash, g_str_equal);
473
474   if (context->main_group)
475     {
476       for (i = 0; i < context->main_group->n_entries; i++)
477         {
478           entry = &context->main_group->entries[i];
479           g_hash_table_insert (shadow_map, 
480                                (gpointer)entry->long_name, 
481                                entry);
482           
483           if (seen[(guchar)entry->short_name])
484             entry->short_name = 0;
485           else
486             seen[(guchar)entry->short_name] = TRUE;
487         }
488     }
489
490   list = context->groups;
491   while (list != NULL)
492     {
493       GOptionGroup *group = list->data;
494       for (i = 0; i < group->n_entries; i++)
495         {
496           entry = &group->entries[i];
497           if (g_hash_table_lookup (shadow_map, entry->long_name))
498             entry->long_name = g_strdup_printf ("%s-%s", group->name, entry->long_name);
499           else  
500             g_hash_table_insert (shadow_map, (gpointer)entry->long_name, entry);
501
502           if (seen[(guchar)entry->short_name])
503             entry->short_name = 0;
504           else
505             seen[(guchar)entry->short_name] = TRUE;
506         }
507       list = list->next;
508     }
509
510   g_hash_table_destroy (shadow_map);
511
512   list = context->groups;
513
514   max_length = g_utf8_strlen ("-?, --help", -1);
515
516   if (list)
517     {
518       len = g_utf8_strlen ("--help-all", -1);
519       max_length = MAX (max_length, len);
520     }
521
522   if (context->main_group)
523     {
524       len = calculate_max_length (context->main_group);
525       max_length = MAX (max_length, len);
526     }
527
528   while (list != NULL)
529     {
530       GOptionGroup *group = list->data;
531       
532       /* First, we check the --help-<groupname> options */
533       len = g_utf8_strlen ("--help-", -1) + g_utf8_strlen (group->name, -1);
534       max_length = MAX (max_length, len);
535
536       /* Then we go through the entries */
537       len = calculate_max_length (group);
538       max_length = MAX (max_length, len);
539       
540       list = list->next;
541     }
542
543   /* Add a bit of padding */
544   max_length += 4;
545
546   if (!group)
547     {
548       list = context->groups;
549       
550       g_print ("%s\n  -%c, --%-*s %s\n", 
551                _("Help Options:"), '?', max_length - 4, "help", 
552                _("Show help options"));
553       
554       /* We only want --help-all when there are groups */
555       if (list)
556         g_print ("  --%-*s %s\n", max_length, "help-all", 
557                  _("Show all help options"));
558       
559       while (list)
560         {
561           GOptionGroup *group = list->data;
562           
563           g_print ("  --help-%-*s %s\n", max_length - 5, group->name, 
564                    TRANSLATE (group, group->help_description));
565           
566           list = list->next;
567         }
568
569       g_print ("\n");
570     }
571
572   if (group)
573     {
574       /* Print a certain group */
575       
576       g_print ("%s\n", TRANSLATE (group, group->description));
577       for (i = 0; i < group->n_entries; i++)
578         print_entry (group, max_length, &group->entries[i]);
579       g_print ("\n");
580     }
581   else if (!main_help)
582     {
583       /* Print all groups */
584
585       list = context->groups;
586
587       while (list)
588         {
589           GOptionGroup *group = list->data;
590
591           g_print ("%s\n", group->description);
592
593           for (i = 0; i < group->n_entries; i++)
594             if (!(group->entries[i].flags & G_OPTION_FLAG_IN_MAIN))
595               print_entry (group, max_length, &group->entries[i]);
596           
597           g_print ("\n");
598           list = list->next;
599         }
600     }
601   
602   /* Print application options if --help or --help-all has been specified */
603   if (main_help || !group)
604     {
605       list = context->groups;
606
607       g_print ("%s\n", _("Application Options:"));
608
609       if (context->main_group)
610         for (i = 0; i < context->main_group->n_entries; i++) 
611           print_entry (context->main_group, max_length, 
612                        &context->main_group->entries[i]);
613
614       while (list != NULL)
615         {
616           GOptionGroup *group = list->data;
617
618           /* Print main entries from other groups */
619           for (i = 0; i < group->n_entries; i++)
620             if (group->entries[i].flags & G_OPTION_FLAG_IN_MAIN)
621               print_entry (group, max_length, &group->entries[i]);
622           
623           list = list->next;
624         }
625
626       g_print ("\n");
627     }
628   
629   exit (0);
630 }
631
632 static gboolean
633 parse_int (const gchar *arg_name,
634            const gchar *arg,
635            gint        *result,
636            GError     **error)
637 {
638   gchar *end;
639   glong tmp;
640
641   errno = 0;
642   tmp = strtol (arg, &end, 0);
643   
644   if (*arg == '\0' || *end != '\0')
645     {
646       g_set_error (error,
647                    G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
648                    _("Cannot parse integer value '%s' for %s"),
649                    arg, arg_name);
650       return FALSE;
651     }
652
653   *result = tmp;
654   if (*result != tmp || errno == ERANGE)
655     {
656       g_set_error (error,
657                    G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
658                    _("Integer value '%s' for %s out of range"),
659                    arg, arg_name);
660       return FALSE;
661     }
662
663   return TRUE;
664 }
665
666 static Change *
667 get_change (GOptionContext *context,
668             GOptionArg      arg_type,
669             gpointer        arg_data)
670 {
671   GList *list;
672   Change *change = NULL;
673   
674   for (list = context->changes; list != NULL; list = list->next)
675     {
676       change = list->data;
677
678       if (change->arg_data == arg_data)
679         goto found;
680     }
681
682   change = g_new0 (Change, 1);
683   change->arg_type = arg_type;
684   change->arg_data = arg_data;
685   
686   context->changes = g_list_prepend (context->changes, change);
687   
688  found:
689
690   return change;
691 }
692
693 static void
694 add_pending_null (GOptionContext *context,
695                   gchar         **ptr,
696                   gchar          *value)
697 {
698   PendingNull *n;
699
700   n = g_new0 (PendingNull, 1);
701   n->ptr = ptr;
702   n->value = value;
703
704   context->pending_nulls = g_list_prepend (context->pending_nulls, n);
705 }
706                   
707 static gboolean
708 parse_arg (GOptionContext *context,
709            GOptionGroup   *group,
710            GOptionEntry   *entry,
711            const gchar    *value,
712            const gchar    *option_name,
713            GError        **error)
714      
715 {
716   Change *change;
717   
718   switch (entry->arg)
719     {
720     case G_OPTION_ARG_NONE:
721       {
722         change = get_change (context, G_OPTION_ARG_NONE,
723                              entry->arg_data);
724
725         *(gboolean *)entry->arg_data = !(entry->flags & G_OPTION_FLAG_REVERSE);
726         break;
727       }      
728     case G_OPTION_ARG_STRING:
729       {
730         gchar *data;
731
732         data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
733
734         if (!data)
735           return FALSE;
736
737         change = get_change (context, G_OPTION_ARG_STRING,
738                              entry->arg_data);
739         g_free (change->allocated.str);
740         
741         change->prev.str = *(gchar **)entry->arg_data;
742         change->allocated.str = data;
743         
744         *(gchar **)entry->arg_data = data;
745         break;
746       }
747     case G_OPTION_ARG_STRING_ARRAY:
748       {
749         gchar *data;
750         
751         data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
752
753         if (!data)
754           return FALSE;
755
756         change = get_change (context, G_OPTION_ARG_STRING_ARRAY,
757                              entry->arg_data);
758
759         if (change->allocated.array.len == 0)
760           {
761             change->prev.array = entry->arg_data;
762             change->allocated.array.data = g_new (gchar *, 2);
763           }
764         else
765           change->allocated.array.data =
766             g_renew (gchar *, change->allocated.array.data,
767                      change->allocated.array.len + 2);
768
769         change->allocated.array.data[change->allocated.array.len] = data;
770         change->allocated.array.data[change->allocated.array.len + 1] = NULL;
771
772         change->allocated.array.len ++;
773
774         *(gchar ***)entry->arg_data = change->allocated.array.data;
775
776         break;
777       }
778       
779     case G_OPTION_ARG_FILENAME:
780       {
781         gchar *data;
782
783 #ifdef G_OS_WIN32
784         data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
785         
786         if (!data)
787           return FALSE;
788 #else
789         data = g_strdup (value);
790 #endif
791         change = get_change (context, G_OPTION_ARG_FILENAME,
792                              entry->arg_data);
793         g_free (change->allocated.str);
794         
795         change->prev.str = *(gchar **)entry->arg_data;
796         change->allocated.str = data;
797
798         *(gchar **)entry->arg_data = data;
799         break;
800       }
801
802     case G_OPTION_ARG_FILENAME_ARRAY:
803       {
804         gchar *data;
805         
806 #ifdef G_OS_WIN32
807         data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
808         
809         if (!data)
810           return FALSE;
811 #else
812         data = g_strdup (value);
813 #endif
814         change = get_change (context, G_OPTION_ARG_STRING_ARRAY,
815                              entry->arg_data);
816
817         if (change->allocated.array.len == 0)
818           {
819             change->prev.array = entry->arg_data;
820             change->allocated.array.data = g_new (gchar *, 2);
821           }
822         else
823           change->allocated.array.data =
824             g_renew (gchar *, change->allocated.array.data,
825                      change->allocated.array.len + 2);
826
827         change->allocated.array.data[change->allocated.array.len] = data;
828         change->allocated.array.data[change->allocated.array.len + 1] = NULL;
829
830         change->allocated.array.len ++;
831
832         *(gchar ***)entry->arg_data = change->allocated.array.data;
833
834         break;
835       }
836       
837     case G_OPTION_ARG_INT:
838       {
839         gint data;
840
841         if (!parse_int (option_name, value,
842                         &data,
843                         error))
844           return FALSE;
845
846         change = get_change (context, G_OPTION_ARG_INT,
847                              entry->arg_data);
848         change->prev.integer = *(gint *)entry->arg_data;
849         *(gint *)entry->arg_data = data;
850         break;
851       }
852     case G_OPTION_ARG_CALLBACK:
853       {
854         gchar *data;
855         gboolean retval;
856         
857         if (entry->flags & G_OPTION_FLAG_NO_ARG)
858           data = NULL;
859         else if (entry->flags & G_OPTION_FLAG_FILENAME)
860           {
861 #ifdef G_OS_WIN32
862             data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
863 #else
864             data = g_strdup (value);
865 #endif
866           }
867         else
868           data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
869
870         if (!(entry->flags & G_OPTION_FLAG_NO_ARG) && !data)
871           return FALSE;
872
873         retval = (* (GOptionArgFunc) entry->arg_data) (option_name, data, group->user_data, error);
874         
875         g_free (data);
876         
877         return retval;
878         
879         break;
880       }
881     default:
882       g_assert_not_reached ();
883     }
884
885   return TRUE;
886 }
887
888 static gboolean
889 parse_short_option (GOptionContext *context,
890                     GOptionGroup   *group,
891                     gint            index,
892                     gint           *new_index,
893                     gchar           arg,
894                     gint           *argc,
895                     gchar        ***argv,
896                     GError        **error,
897                     gboolean       *parsed)
898 {
899   gint j;
900     
901   for (j = 0; j < group->n_entries; j++)
902     {
903       if (arg == group->entries[j].short_name)
904         {
905           if (NO_ARG (&group->entries[j]))
906             {
907               parse_arg (context, group, &group->entries[j],
908                          NULL, NULL, error);
909               *parsed = TRUE;
910             }
911           else
912             {
913               gchar *value = NULL;
914               gchar *option_name;
915               
916               if (*new_index > index)
917                 {
918                   g_warning ("FIXME: figure out the correct error here");
919
920                   return FALSE;
921                 }
922
923               option_name = g_strdup_printf ("-%c", group->entries[j].short_name);
924               
925               if (index < *argc - 1)
926                 {
927                   value = (*argv)[index + 1];
928                   add_pending_null (context, &((*argv)[index + 1]), NULL);
929                   *new_index = index + 1;
930                 }
931               else
932                 {
933                   g_set_error (error, 
934                                G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
935                                _("Missing argument for %s"), option_name);
936                   g_free (option_name);
937                   return FALSE;
938                 }
939               
940               if (!parse_arg (context, group, &group->entries[j], value, option_name, error))
941                 {
942                   g_free (option_name);
943                   return FALSE;
944                 }
945
946               g_free (option_name);
947               *parsed = TRUE;
948             }
949         }
950     }
951
952   return TRUE;
953 }
954
955 static gboolean
956 parse_long_option (GOptionContext *context,
957                    GOptionGroup   *group,
958                    gint           *index,
959                    gchar          *arg,
960                    gint           *argc,
961                    gchar        ***argv,
962                    GError        **error,
963                    gboolean       *parsed)
964 {
965   gint j;
966
967   for (j = 0; j < group->n_entries; j++)
968     {
969       if (*index >= *argc)
970         return TRUE;
971
972       if (NO_ARG (&group->entries[j]) &&
973           strcmp (arg, group->entries[j].long_name) == 0)
974         {
975           parse_arg (context, group, &group->entries[j],
976                      NULL, NULL, error);
977           
978           add_pending_null (context, &((*argv)[*index]), NULL);
979           *parsed = TRUE;
980         }
981       else
982         {
983           gint len = strlen (group->entries[j].long_name);
984           
985           if (strncmp (arg, group->entries[j].long_name, len) == 0 &&
986               (arg[len] == '=' || arg[len] == 0))
987             {
988               gchar *value = NULL;
989               gchar *option_name;
990
991               add_pending_null (context, &((*argv)[*index]), NULL);
992               option_name = g_strconcat ("--", group->entries[j].long_name, NULL);
993
994               if (arg[len] == '=')
995                 value = arg + len + 1;
996               else if (*index < *argc - 1)
997                 {
998                   value = (*argv)[*index + 1];
999                   add_pending_null (context, &((*argv)[*index + 1]), NULL);
1000                   (*index)++;
1001                 }
1002               else
1003                 {
1004                   g_set_error (error, 
1005                                G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
1006                                _("Missing argument for %s"), option_name);
1007                   g_free (option_name);
1008                   return FALSE;
1009                 }
1010
1011               if (!parse_arg (context, group, &group->entries[j], value, option_name, error))
1012                 {
1013                   g_free (option_name);
1014                   return FALSE;
1015                 }
1016
1017               g_free (option_name);
1018               *parsed = TRUE;
1019             }
1020         }
1021     }
1022   
1023   return TRUE;
1024 }
1025
1026 static gboolean
1027 parse_remaining_arg (GOptionContext *context,
1028                      GOptionGroup   *group,
1029                      gint           *index,
1030                      gint           *argc,
1031                      gchar        ***argv,
1032                      GError        **error,
1033                      gboolean       *parsed)
1034 {
1035   gint j;
1036
1037   for (j = 0; j < group->n_entries; j++)
1038     {
1039       if (*index >= *argc)
1040         return TRUE;
1041
1042       if (group->entries[j].long_name[0])
1043         continue;
1044
1045       g_return_val_if_fail (group->entries[j].arg == G_OPTION_ARG_STRING_ARRAY ||
1046                             group->entries[j].arg == G_OPTION_ARG_FILENAME_ARRAY, FALSE);
1047       
1048       add_pending_null (context, &((*argv)[*index]), NULL);
1049       
1050       if (!parse_arg (context, group, &group->entries[j], (*argv)[*index], "", error))
1051         return FALSE;
1052       
1053       *parsed = TRUE;
1054       return TRUE;
1055     }
1056
1057   return TRUE;
1058 }
1059
1060 static void
1061 free_changes_list (GOptionContext *context,
1062                    gboolean        revert)
1063 {
1064   GList *list;
1065
1066   for (list = context->changes; list != NULL; list = list->next)
1067     {
1068       Change *change = list->data;
1069
1070       if (revert)
1071         {
1072           switch (change->arg_type)
1073             {
1074             case G_OPTION_ARG_NONE:
1075               *(gboolean *)change->arg_data = change->prev.bool;
1076               break;
1077             case G_OPTION_ARG_INT:
1078               *(gint *)change->arg_data = change->prev.integer;
1079               break;
1080             case G_OPTION_ARG_STRING:
1081             case G_OPTION_ARG_FILENAME:
1082               g_free (change->allocated.str);
1083               *(gchar **)change->arg_data = change->prev.str;
1084               break;
1085             case G_OPTION_ARG_STRING_ARRAY:
1086             case G_OPTION_ARG_FILENAME_ARRAY:
1087               g_strfreev (change->allocated.array.data);
1088               *(gchar ***)change->arg_data = change->prev.array;
1089               break;
1090             default:
1091               g_assert_not_reached ();
1092             }
1093         }
1094       
1095       g_free (change);
1096     }
1097
1098   g_list_free (context->changes);
1099   context->changes = NULL;
1100 }
1101
1102 static void
1103 free_pending_nulls (GOptionContext *context,
1104                     gboolean        perform_nulls)
1105 {
1106   GList *list;
1107
1108   for (list = context->pending_nulls; list != NULL; list = list->next)
1109     {
1110       PendingNull *n = list->data;
1111
1112       if (perform_nulls)
1113         {
1114           if (n->value)
1115             {
1116               /* Copy back the short options */
1117               *(n->ptr)[0] = '-';             
1118               strcpy (*n->ptr + 1, n->value);
1119             }
1120           else
1121             *n->ptr = NULL;
1122         }
1123       
1124       g_free (n->value);
1125       g_free (n);
1126     }
1127
1128   g_list_free (context->pending_nulls);
1129   context->pending_nulls = NULL;
1130 }
1131
1132 /**
1133  * g_option_context_parse:
1134  * @context: a #GOptionContext
1135  * @argc: a pointer to the number of command line arguments.
1136  * @argv: a pointer to the array of command line arguments.
1137  * @error: a return location for errors 
1138  * 
1139  * Parses the command line arguments, recognizing options
1140  * which have been added to @context. A side-effect of 
1141  * calling this function is that g_set_prgname() will be
1142  * called.
1143  *
1144  * If the parsing is successful, any parsed arguments are
1145  * removed from the array and @argc and @argv are updated 
1146  * accordingly. A '--' option is stripped from @argv
1147  * unless there are unparsed options before and after it, 
1148  * or some of the options after it start with '-'. In case 
1149  * of an error, @argc and @argv are left unmodified. 
1150  *
1151  * If automatic <option>--help</option> support is enabled
1152  * (see g_option_context_set_help_enabled()), and the 
1153  * @argv array contains one of the recognized help options,
1154  * this function will produce help output to stdout and
1155  * call <literal>exit (0)</literal>.
1156  * 
1157  * Return value: %TRUE if the parsing was successful, 
1158  *               %FALSE if an error occurred
1159  *
1160  * Since: 2.6
1161  **/
1162 gboolean
1163 g_option_context_parse (GOptionContext   *context,
1164                         gint             *argc,
1165                         gchar          ***argv,
1166                         GError          **error)
1167 {
1168   gint i, j, k;
1169   GList *list;
1170
1171   /* Set program name */
1172   if (argc && argv && *argc)
1173     {
1174       gchar *prgname;
1175       
1176       prgname = g_path_get_basename ((*argv)[0]);
1177       g_set_prgname (prgname);
1178       g_free (prgname);
1179     }
1180   else
1181     {
1182       g_set_prgname ("<unknown>");
1183     }
1184   
1185   /* Call pre-parse hooks */
1186   list = context->groups;
1187   while (list)
1188     {
1189       GOptionGroup *group = list->data;
1190       
1191       if (group->pre_parse_func)
1192         {
1193           if (!(* group->pre_parse_func) (context, group,
1194                                           group->user_data, error))
1195             goto fail;
1196         }
1197       
1198       list = list->next;
1199     }
1200
1201   if (context->main_group && context->main_group->pre_parse_func)
1202     {
1203       if (!(* context->main_group->pre_parse_func) (context, context->main_group,
1204                                                     context->main_group->user_data, error))
1205         goto fail;
1206     }
1207
1208   if (argc && argv)
1209     {
1210       gboolean stop_parsing = FALSE;
1211       gboolean has_unknown = FALSE;
1212       gint separator_pos = 0;
1213
1214       for (i = 1; i < *argc; i++)
1215         {
1216           gchar *arg, *dash;
1217           gboolean parsed = FALSE;
1218
1219           if ((*argv)[i][0] == '-' && (*argv)[i][1] != '\0' && !stop_parsing)
1220             {
1221               if ((*argv)[i][1] == '-')
1222                 {
1223                   /* -- option */
1224
1225                   arg = (*argv)[i] + 2;
1226
1227                   /* '--' terminates list of arguments */
1228                   if (*arg == 0)
1229                     {
1230                       separator_pos = i;
1231                       stop_parsing = TRUE;
1232                       continue;
1233                     }
1234
1235                   /* Handle help options */
1236                   if (context->help_enabled)
1237                     {
1238                       if (strcmp (arg, "help") == 0)
1239                         print_help (context, TRUE, NULL);
1240                       else if (strcmp (arg, "help-all") == 0)
1241                         print_help (context, FALSE, NULL);                    
1242                       else if (strncmp (arg, "help-", 5) == 0)
1243                         {
1244                           GList *list;
1245                           
1246                           list = context->groups;
1247                           
1248                           while (list)
1249                             {
1250                               GOptionGroup *group = list->data;
1251                               
1252                               if (strcmp (arg + 5, group->name) == 0)
1253                                 print_help (context, FALSE, group);                                           
1254                               
1255                               list = list->next;
1256                             }
1257                         }
1258                     }
1259
1260                   if (context->main_group &&
1261                       !parse_long_option (context, context->main_group, &i, arg,
1262                                           argc, argv, error, &parsed))
1263                     goto fail;
1264
1265                   if (parsed)
1266                     continue;
1267                   
1268                   /* Try the groups */
1269                   list = context->groups;
1270                   while (list)
1271                     {
1272                       GOptionGroup *group = list->data;
1273                       
1274                       if (!parse_long_option (context, group, &i, arg,
1275                                               argc, argv, error, &parsed))
1276                         goto fail;
1277                       
1278                       if (parsed)
1279                         break;
1280                       
1281                       list = list->next;
1282                     }
1283                   
1284                   if (parsed)
1285                     continue;
1286
1287                   /* Now look for --<group>-<option> */
1288                   dash = strchr (arg, '-');
1289                   if (dash)
1290                     {
1291                       /* Try the groups */
1292                       list = context->groups;
1293                       while (list)
1294                         {
1295                           GOptionGroup *group = list->data;
1296                           
1297                           if (strncmp (group->name, arg, dash - arg) == 0)
1298                             {
1299                               if (!parse_long_option (context, group, &i, dash + 1,
1300                                                       argc, argv, error, &parsed))
1301                                 goto fail;
1302                               
1303                               if (parsed)
1304                                 break;
1305                             }
1306                           
1307                           list = list->next;
1308                         }
1309                     }
1310                   
1311                   if (context->ignore_unknown)
1312                     continue;
1313                 }
1314               else
1315                 {
1316                   /* short option */
1317
1318                   gint new_i, j;
1319                   gboolean *nulled_out = NULL;
1320                   
1321                   arg = (*argv)[i] + 1;
1322
1323                   new_i = i;
1324
1325                   if (context->ignore_unknown)
1326                     nulled_out = g_new0 (gboolean, strlen (arg));
1327                   
1328                   for (j = 0; j < strlen (arg); j++)
1329                     {
1330                       if (context->help_enabled && arg[j] == '?')
1331                         print_help (context, TRUE, NULL);
1332                       
1333                       parsed = FALSE;
1334                       
1335                       if (context->main_group &&
1336                           !parse_short_option (context, context->main_group,
1337                                                i, &new_i, arg[j],
1338                                                argc, argv, error, &parsed))
1339                         {
1340
1341                           g_free (nulled_out);
1342                           goto fail;
1343                         }
1344
1345                       if (!parsed)
1346                         {
1347                           /* Try the groups */
1348                           list = context->groups;
1349                           while (list)
1350                             {
1351                               GOptionGroup *group = list->data;
1352                               
1353                               if (!parse_short_option (context, group, i, &new_i, arg[j],
1354                                                        argc, argv, error, &parsed))
1355                                 goto fail;
1356                               
1357                               if (parsed)
1358                                 break;
1359                           
1360                               list = list->next;
1361                             }
1362                         }
1363
1364                       if (context->ignore_unknown)
1365                         {
1366                           if (parsed)
1367                             nulled_out[j] = TRUE;
1368                           else
1369                             continue;
1370                         }
1371
1372                       if (!parsed)
1373                         break;
1374                     }
1375
1376                   if (context->ignore_unknown)
1377                     {
1378                       gchar *new_arg = NULL; 
1379                       gint arg_index = 0;
1380                       
1381                       for (j = 0; j < strlen (arg); j++)
1382                         {
1383                           if (!nulled_out[j])
1384                             {
1385                               if (!new_arg)
1386                                 new_arg = g_malloc (strlen (arg) + 1);
1387                               new_arg[arg_index++] = arg[j];
1388                             }
1389                         }
1390                       if (new_arg)
1391                         new_arg[arg_index] = '\0';
1392                       
1393                       add_pending_null (context, &((*argv)[i]), new_arg);
1394                     }
1395                   else if (parsed)
1396                     {
1397                       add_pending_null (context, &((*argv)[i]), NULL);
1398                       i = new_i;
1399                     }
1400                 }
1401               
1402               if (!parsed)
1403                 has_unknown = TRUE;
1404
1405               if (!parsed && !context->ignore_unknown)
1406                 {
1407                   g_set_error (error,
1408                                G_OPTION_ERROR, G_OPTION_ERROR_UNKNOWN_OPTION,
1409                                    _("Unknown option %s"), (*argv)[i]);
1410                   goto fail;
1411                 }
1412             }
1413           else
1414             {
1415               /* Collect remaining args */
1416               if (context->main_group &&
1417                   !parse_remaining_arg (context, context->main_group, &i,
1418                                         argc, argv, error, &parsed))
1419                 goto fail;
1420               
1421               if (!parsed && (has_unknown || (*argv)[i][0] == '-'))
1422                 separator_pos = 0;
1423             }
1424         }
1425
1426       if (separator_pos > 0)
1427         add_pending_null (context, &((*argv)[separator_pos]), NULL);
1428         
1429     }
1430
1431   /* Call post-parse hooks */
1432   list = context->groups;
1433   while (list)
1434     {
1435       GOptionGroup *group = list->data;
1436       
1437       if (group->post_parse_func)
1438         {
1439           if (!(* group->post_parse_func) (context, group,
1440                                            group->user_data, error))
1441             goto fail;
1442         }
1443       
1444       list = list->next;
1445     }
1446   
1447   if (context->main_group && context->main_group->post_parse_func)
1448     {
1449       if (!(* context->main_group->post_parse_func) (context, context->main_group,
1450                                                      context->main_group->user_data, error))
1451         goto fail;
1452     }
1453   
1454   if (argc && argv)
1455     {
1456       free_pending_nulls (context, TRUE);
1457       
1458       for (i = 1; i < *argc; i++)
1459         {
1460           for (k = i; k < *argc; k++)
1461             if ((*argv)[k] != NULL)
1462               break;
1463           
1464           if (k > i)
1465             {
1466               k -= i;
1467               for (j = i + k; j < *argc; j++)
1468                 {
1469                   (*argv)[j-k] = (*argv)[j];
1470                   (*argv)[j] = NULL;
1471                 }
1472               *argc -= k;
1473             }
1474         }      
1475     }
1476
1477   return TRUE;
1478
1479  fail:
1480   
1481   /* Call error hooks */
1482   list = context->groups;
1483   while (list)
1484     {
1485       GOptionGroup *group = list->data;
1486       
1487       if (group->error_func)
1488         (* group->error_func) (context, group,
1489                                group->user_data, error);
1490       
1491       list = list->next;
1492     }
1493
1494   if (context->main_group && context->main_group->error_func)
1495     (* context->main_group->error_func) (context, context->main_group,
1496                                          context->main_group->user_data, error);
1497   
1498   free_changes_list (context, TRUE);
1499   free_pending_nulls (context, FALSE);
1500
1501   return FALSE;
1502 }
1503                                    
1504 /**
1505  * g_option_group_new:
1506  * @name: the name for the option group, this is used to provide
1507  *   help for the options in this group with <option>--help-</option>@name
1508  * @description: a description for this group to be shown in 
1509  *   <option>--help</option>. This string is translated using the translation
1510  *   domain or translation function of the group
1511  * @help_description: a description for the <option>--help-</option>@name option.
1512  *   This string is translated using the translation domain or translation function
1513  *   of the group
1514  * @user_data: user data that will be passed to the pre- and post-parse hooks,
1515  *   the error hook and to callbacks of %G_OPTION_ARG_CALLBACK options, or %NULL
1516  * @destroy: a function that will be called to free @user_data, or %NULL
1517  * 
1518  * Creates a new #GOptionGroup.
1519  * 
1520  * Return value: a newly created option group. It should be added 
1521  *   to a #GOptionContext or freed with g_option_group_free().
1522  *
1523  * Since: 2.6
1524  **/
1525 GOptionGroup *
1526 g_option_group_new (const gchar    *name,
1527                     const gchar    *description,
1528                     const gchar    *help_description,
1529                     gpointer        user_data,
1530                     GDestroyNotify  destroy)
1531
1532 {
1533   GOptionGroup *group;
1534
1535   group = g_new0 (GOptionGroup, 1);
1536   group->name = g_strdup (name);
1537   group->description = g_strdup (description);
1538   group->help_description = g_strdup (help_description);
1539   group->user_data = user_data;
1540   group->destroy_notify = destroy;
1541   
1542   return group;
1543 }
1544
1545
1546 /**
1547  * g_option_group_free:
1548  * @group: a #GOptionGroup
1549  * 
1550  * Frees a #GOptionGroup. Note that you must <emphasis>not</emphasis>
1551  * free groups which have been added to a #GOptionContext.
1552  *
1553  * Since: 2.6
1554  **/
1555 void
1556 g_option_group_free (GOptionGroup *group)
1557 {
1558   g_return_if_fail (group != NULL);
1559
1560   g_free (group->name);
1561   g_free (group->description);
1562   g_free (group->help_description);
1563
1564   g_free (group->entries);
1565   
1566   if (group->destroy_notify)
1567     (* group->destroy_notify) (group->user_data);
1568
1569   if (group->translate_notify)
1570     (* group->translate_notify) (group->translate_data);
1571   
1572   g_free (group);
1573 }
1574
1575
1576 /**
1577  * g_option_group_add_entries:
1578  * @group: a #GOptionGroup
1579  * @entries: a %NULL-terminated array of #GOptionEntry<!-- -->s
1580  * 
1581  * Adds the options specified in @entries to @group.
1582  *
1583  * Since: 2.6
1584  **/
1585 void
1586 g_option_group_add_entries (GOptionGroup       *group,
1587                             const GOptionEntry *entries)
1588 {
1589   gint n_entries;
1590   
1591   g_return_if_fail (entries != NULL);
1592
1593   for (n_entries = 0; entries[n_entries].long_name != NULL; n_entries++);
1594
1595   group->entries = g_renew (GOptionEntry, group->entries, group->n_entries + n_entries);
1596
1597   memcpy (group->entries + group->n_entries, entries, sizeof (GOptionEntry) * n_entries);
1598
1599   group->n_entries += n_entries;
1600 }
1601
1602 /**
1603  * g_option_group_set_parse_hooks:
1604  * @group: a #GOptionGroup
1605  * @pre_parse_func: a function to call before parsing, or %NULL
1606  * @post_parse_func: a function to call after parsing, or %NULL
1607  * 
1608  * Associates two functions with @group which will be called 
1609  * from g_option_context_parse() before the first option is parsed
1610  * and after the last option has been parsed, respectively.
1611  *
1612  * Note that the user data to be passed to @pre_parse_func and
1613  * @post_parse_func can be specified when constructing the group
1614  * with g_option_group_new().
1615  *
1616  * Since: 2.6
1617  **/
1618 void
1619 g_option_group_set_parse_hooks (GOptionGroup     *group,
1620                                 GOptionParseFunc  pre_parse_func,
1621                                 GOptionParseFunc  post_parse_func)
1622 {
1623   g_return_if_fail (group != NULL);
1624
1625   group->pre_parse_func = pre_parse_func;
1626   group->post_parse_func = post_parse_func;  
1627 }
1628
1629 /**
1630  * g_option_group_set_error_hook:
1631  * @group: a #GOptionGroup
1632  * @error_func: a function to call when an error occurs
1633  * 
1634  * Associates a function with @group which will be called 
1635  * from g_option_context_parse() when an error occurs.
1636  *
1637  * Note that the user data to be passed to @pre_parse_func and
1638  * @post_parse_func can be specified when constructing the group
1639  * with g_option_group_new().
1640  *
1641  * Since: 2.6
1642  **/
1643 void
1644 g_option_group_set_error_hook (GOptionGroup     *group,
1645                                GOptionErrorFunc  error_func)
1646 {
1647   g_return_if_fail (group != NULL);
1648
1649   group->error_func = error_func;  
1650 }
1651
1652
1653 /**
1654  * g_option_group_set_translate_func:
1655  * @group: a #GOptionGroup
1656  * @func: the #GTranslateFunc, or %NULL 
1657  * @data: user data to pass to @func, or %NULL
1658  * @destroy_notify: a function which gets called to free @data, or %NULL
1659  * 
1660  * Sets the function which is used to translate user-visible
1661  * strings, for <option>--help</option> output. Different
1662  * groups can use different #GTranslateFunc<!-- -->s. If @func
1663  * is %NULL, strings are not translated.
1664  *
1665  * If you are using gettext(), you only need to set the translation
1666  * domain, see g_option_group_set_translation_domain().
1667  *
1668  * Since: 2.6
1669  **/
1670 void
1671 g_option_group_set_translate_func (GOptionGroup   *group,
1672                                    GTranslateFunc  func,
1673                                    gpointer        data,
1674                                    GDestroyNotify  destroy_notify)
1675 {
1676   g_return_if_fail (group != NULL);
1677   
1678   if (group->translate_notify)
1679     group->translate_notify (group->translate_data);
1680       
1681   group->translate_func = func;
1682   group->translate_data = data;
1683   group->translate_notify = destroy_notify;
1684 }
1685
1686 static gchar *
1687 dgettext_swapped (const gchar *msgid, 
1688                   const gchar *domainname)
1689 {
1690   return dgettext (domainname, msgid);
1691 }
1692
1693 /**
1694  * g_option_group_set_translation_domain:
1695  * @group: a #GOptionGroup
1696  * @domain: the domain to use
1697  * 
1698  * A convenience function to use gettext() for translating
1699  * user-visible strings. 
1700  * 
1701  * Since: 2.6
1702  **/
1703 void
1704 g_option_group_set_translation_domain (GOptionGroup *group,
1705                                        const gchar  *domain)
1706 {
1707   g_return_if_fail (group != NULL);
1708
1709   g_option_group_set_translate_func (group, 
1710                                      (GTranslateFunc)dgettext_swapped,
1711                                      g_strdup (domain),
1712                                      g_free);
1713
1714
1715 #define __G_OPTION_C__
1716 #include "galiasdef.c"