908e53191990f455a55b8d04deefc5b69e644f94
[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   G_OPTION_FLAG_REVERSE         = 1 << 2,
38   G_OPTION_FLAG_NO_ARG          = 1 << 3,
39   G_OPTION_FLAG_FILENAME        = 1 << 4,
40   G_OPTION_FLAG_OPTIONAL_ARG    = 1 << 5,
41   G_OPTION_FLAG_NOALIAS         = 1 << 6
42 } GOptionFlags;
43
44 typedef enum
45 {
46   G_OPTION_ARG_NONE,
47   G_OPTION_ARG_STRING,
48   G_OPTION_ARG_INT,
49   G_OPTION_ARG_CALLBACK,
50   G_OPTION_ARG_FILENAME,
51   G_OPTION_ARG_STRING_ARRAY,
52   G_OPTION_ARG_FILENAME_ARRAY,
53   G_OPTION_ARG_DOUBLE,
54   G_OPTION_ARG_INT64
55 } GOptionArg;
56
57 typedef gboolean (*GOptionArgFunc) (const gchar    *option_name,
58                                     const gchar    *value,
59                                     gpointer        data,
60                                     GError        **error);
61
62 typedef gboolean (*GOptionParseFunc) (GOptionContext *context,
63                                       GOptionGroup   *group,
64                                       gpointer        data,
65                                       GError        **error);
66
67 typedef void (*GOptionErrorFunc) (GOptionContext *context,
68                                   GOptionGroup   *group,
69                                   gpointer        data,
70                                   GError        **error);
71
72 #define G_OPTION_ERROR (g_option_error_quark ())
73
74 typedef enum
75 {
76   G_OPTION_ERROR_UNKNOWN_OPTION,
77   G_OPTION_ERROR_BAD_VALUE,
78   G_OPTION_ERROR_FAILED
79 } GOptionError;
80
81 GQuark g_option_error_quark (void);
82
83
84 struct _GOptionEntry
85 {
86   const gchar *long_name;
87   gchar        short_name;
88   gint         flags;
89
90   GOptionArg   arg;
91   gpointer     arg_data;
92   
93   const gchar *description;
94   const gchar *arg_description;
95 };
96
97 #define G_OPTION_REMAINING ""
98
99 GOptionContext *g_option_context_new              (const gchar         *parameter_string);
100 void            g_option_context_set_summary      (GOptionContext      *context,
101                                                    const gchar         *summary);
102 G_CONST_RETURN gchar *g_option_context_get_summary (GOptionContext     *context);
103 void            g_option_context_set_description  (GOptionContext      *context,
104                                                    const gchar         *description);
105 G_CONST_RETURN gchar *g_option_context_get_description (GOptionContext     *context);
106 void            g_option_context_free             (GOptionContext      *context);
107 void            g_option_context_set_help_enabled (GOptionContext      *context,
108                                                    gboolean             help_enabled);
109 gboolean        g_option_context_get_help_enabled (GOptionContext      *context);
110 void            g_option_context_set_ignore_unknown_options (GOptionContext *context,
111                                                              gboolean        ignore_unknown);
112 gboolean        g_option_context_get_ignore_unknown_options (GOptionContext *context);
113
114 void            g_option_context_add_main_entries (GOptionContext      *context,
115                                                    const GOptionEntry  *entries,
116                                                    const gchar         *translation_domain);
117 gboolean        g_option_context_parse            (GOptionContext      *context,
118                                                    gint                *argc,
119                                                    gchar             ***argv,
120                                                    GError             **error);
121 void            g_option_context_set_translate_func (GOptionContext     *context,
122                                                      GTranslateFunc      func,
123                                                      gpointer            data,
124                                                      GDestroyNotify      destroy_notify);
125 void            g_option_context_set_translation_domain (GOptionContext  *context,
126                                                          const gchar     *domain);
127
128 void            g_option_context_add_group      (GOptionContext *context,
129                                                  GOptionGroup   *group);
130 void          g_option_context_set_main_group (GOptionContext *context,
131                                                GOptionGroup   *group);
132 GOptionGroup *g_option_context_get_main_group (GOptionContext *context);
133 gchar        *g_option_context_get_help       (GOptionContext *context,
134                                                gboolean        main_help,
135                                                GOptionGroup   *group);
136
137 GOptionGroup *g_option_group_new                    (const gchar        *name,
138                                                      const gchar        *description,
139                                                      const gchar        *help_description,
140                                                      gpointer            user_data,
141                                                      GDestroyNotify      destroy);
142 void          g_option_group_set_parse_hooks        (GOptionGroup       *group,
143                                                      GOptionParseFunc    pre_parse_func,
144                                                      GOptionParseFunc    post_parse_func);
145 void          g_option_group_set_error_hook         (GOptionGroup       *group,
146                                                      GOptionErrorFunc    error_func);
147 void          g_option_group_free                   (GOptionGroup       *group);
148 void          g_option_group_add_entries            (GOptionGroup       *group,
149                                                      const GOptionEntry *entries);
150 void          g_option_group_set_translate_func     (GOptionGroup       *group,
151                                                      GTranslateFunc      func,
152                                                      gpointer            data,
153                                                      GDestroyNotify      destroy_notify);
154 void          g_option_group_set_translation_domain (GOptionGroup       *group,
155                                                      const gchar        *domain);
156
157
158 G_END_DECLS
159
160 #endif /* __G_OPTION_H__ */