Pedantically use g types throughout.
[platform/upstream/glib.git] / glib / goption.h
1 /* goption.h - Option parser
2  *
3  *  Copyright (C) 2004  Anders Carlsson <andersca@gnome.org>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #ifndef __G_OPTION_H__
22 #define __G_OPTION_H__
23
24 #include <glib/gerror.h>
25 #include <glib/gquark.h>
26
27 G_BEGIN_DECLS
28
29 typedef struct _GOptionContext GOptionContext;
30 typedef struct _GOptionGroup   GOptionGroup;
31 typedef struct _GOptionEntry   GOptionEntry;
32
33 typedef enum
34 {
35   G_OPTION_FLAG_HIDDEN       = 1 << 0,
36   G_OPTION_FLAG_IN_MAIN      = 1 << 1,
37 } GOptionFlags;
38
39 typedef enum
40 {
41   G_OPTION_ARG_NONE,
42   G_OPTION_ARG_STRING,
43   G_OPTION_ARG_INT,
44   G_OPTION_ARG_CALLBACK,
45   G_OPTION_ARG_FILENAME,
46   G_OPTION_ARG_STRING_ARRAY,
47   G_OPTION_ARG_FILENAME_ARRAY,
48 } GOptionArg;
49
50 typedef gboolean (*GOptionArgFunc) (const gchar    *option_name,
51                                     const gchar    *value,
52                                     gpointer        data,
53                                     GError        **error);
54
55 typedef gboolean (*GOptionParseFunc) (GOptionContext *context,
56                                       GOptionGroup   *group,
57                                       gpointer        data,
58                                       GError        **error);
59
60 typedef void (*GOptionErrorFunc) (GOptionContext *context,
61                                   GOptionGroup   *group,
62                                   gpointer        data,
63                                   GError        **error);
64
65 #define G_OPTION_ERROR (g_option_context_error_quark ())
66
67 typedef enum
68 {
69   G_OPTION_ERROR_UNKNOWN_OPTION,
70   G_OPTION_ERROR_BAD_VALUE,
71   G_OPTION_ERROR_FAILED
72 } GOptionError;
73
74 GQuark g_option_context_error_quark (void) G_GNUC_CONST;
75
76
77 struct _GOptionEntry
78 {
79   const gchar *long_name;
80   gchar        short_name;
81   gint         flags;
82
83   GOptionArg   arg;
84   gpointer     arg_data;
85   
86   const gchar *description;
87   const gchar *arg_description;
88 };
89
90 GOptionContext *g_option_context_new              (const gchar         *parameter_string);
91 void            g_option_context_free             (GOptionContext      *context);
92 void            g_option_context_set_help_enabled (GOptionContext      *context,
93                                                    gboolean             help_enabled);
94 gboolean        g_option_context_get_help_enabled (GOptionContext      *context);
95 void            g_option_context_set_ignore_unknown_options (GOptionContext *context,
96                                                              gboolean        ignore_unknown);
97 gboolean        g_option_context_get_ignore_unknown_options (GOptionContext *context);
98
99 void            g_option_context_add_main_entries (GOptionContext      *context,
100                                                    const GOptionEntry  *entries,
101                                                    const gchar         *translation_domain);
102 gboolean        g_option_context_parse            (GOptionContext      *context,
103                                                    gint                *argc,
104                                                    gchar             ***argv,
105                                                    GError             **error);
106
107 void          g_option_context_add_group      (GOptionContext *context,
108                                                GOptionGroup   *group);
109 void          g_option_context_set_main_group (GOptionContext *context,
110                                                GOptionGroup   *group);
111 GOptionGroup *g_option_context_get_main_group (GOptionContext *context);
112
113
114 GOptionGroup *g_option_group_new                    (const gchar        *name,
115                                                      const gchar        *description,
116                                                      const gchar        *help_description,
117                                                      gpointer            user_data,
118                                                      GDestroyNotify      destroy);
119 void          g_option_group_set_parse_hooks        (GOptionGroup       *group,
120                                                      GOptionParseFunc    pre_parse_func,
121                                                      GOptionParseFunc    post_parse_func);
122 void          g_option_group_set_error_hook         (GOptionGroup       *group,
123                                                      GOptionErrorFunc    error_func);
124 void          g_option_group_free                   (GOptionGroup       *group);
125 void          g_option_group_add_entries            (GOptionGroup       *group,
126                                                      const GOptionEntry *entries);
127 void          g_option_group_set_translate_func     (GOptionGroup       *group,
128                                                      GTranslateFunc      func,
129                                                      gpointer            data,
130                                                      GDestroyNotify      destroy_notify);
131 void          g_option_group_set_translation_domain (GOptionGroup       *group,
132                                                      const gchar        *domain);
133
134
135
136
137
138 G_END_DECLS
139
140 #endif /* __G_OPTION_H__ */