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