1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <title>Commandline option parser</title>
6 <meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
7 <link rel="home" href="index.html" title="GLib Reference Manual">
8 <link rel="up" href="glib-utilities.html" title="GLib Utilities">
9 <link rel="prev" href="glib-Shell-related-Utilities.html" title="Shell-related Utilities">
10 <link rel="next" href="glib-Glob-style-pattern-matching.html" title="Glob-style pattern matching">
11 <meta name="generator" content="GTK-Doc V1.13 (XML mode)">
12 <link rel="stylesheet" href="style.css" type="text/css">
13 <link rel="chapter" href="glib.html" title="GLib Overview">
14 <link rel="chapter" href="glib-fundamentals.html" title="GLib Fundamentals">
15 <link rel="chapter" href="glib-core.html" title="GLib Core Application Support">
16 <link rel="chapter" href="glib-utilities.html" title="GLib Utilities">
17 <link rel="chapter" href="glib-data-types.html" title="GLib Data Types">
18 <link rel="chapter" href="tools.html" title="GLib Tools">
19 <link rel="index" href="api-index-full.html" title="Index">
20 <link rel="index" href="api-index-deprecated.html" title="Index of deprecated symbols">
21 <link rel="index" href="api-index-2-2.html" title="Index of new symbols in 2.2">
22 <link rel="index" href="api-index-2-4.html" title="Index of new symbols in 2.4">
23 <link rel="index" href="api-index-2-6.html" title="Index of new symbols in 2.6">
24 <link rel="index" href="api-index-2-8.html" title="Index of new symbols in 2.8">
25 <link rel="index" href="api-index-2-10.html" title="Index of new symbols in 2.10">
26 <link rel="index" href="api-index-2-12.html" title="Index of new symbols in 2.12">
27 <link rel="index" href="api-index-2-14.html" title="Index of new symbols in 2.14">
28 <link rel="index" href="api-index-2-16.html" title="Index of new symbols in 2.16">
29 <link rel="index" href="api-index-2-18.html" title="Index of new symbols in 2.18">
30 <link rel="index" href="api-index-2-20.html" title="Index of new symbols in 2.20">
31 <link rel="index" href="api-index-2-22.html" title="Index of new symbols in 2.22">
32 <link rel="index" href="api-index-2-24.html" title="Index of new symbols in 2.24">
34 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
35 <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
37 <td><a accesskey="p" href="glib-Shell-related-Utilities.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
38 <td><a accesskey="u" href="glib-utilities.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
39 <td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
40 <th width="100%" align="center">GLib Reference Manual</th>
41 <td><a accesskey="n" href="glib-Glob-style-pattern-matching.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
43 <tr><td colspan="5" class="shortcuts">
44 <a href="#glib-Commandline-option-parser.synopsis" class="shortcut">Top</a>
46 <a href="#glib-Commandline-option-parser.description" class="shortcut">Description</a>
49 <div class="refentry" title="Commandline option parser">
50 <a name="glib-Commandline-option-parser"></a><div class="titlepage"></div>
51 <div class="refnamediv"><table width="100%"><tr>
53 <h2><span class="refentrytitle"><a name="glib-Commandline-option-parser.top_of_page"></a>Commandline option parser</span></h2>
54 <p>Commandline option parser — parses commandline options</p>
56 <td valign="top" align="right"></td>
58 <div class="refsynopsisdiv" title="Synopsis">
59 <a name="glib-Commandline-option-parser.synopsis"></a><h2>Synopsis</h2>
60 <pre class="synopsis">
61 #include <glib.h>
63 enum <a class="link" href="glib-Commandline-option-parser.html#GOptionError" title="enum GOptionError">GOptionError</a>;
64 #define <a class="link" href="glib-Commandline-option-parser.html#G-OPTION-ERROR:CAPS" title="G_OPTION_ERROR">G_OPTION_ERROR</a>
65 <a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> (<a class="link" href="glib-Commandline-option-parser.html#GOptionArgFunc" title="GOptionArgFunc ()">*GOptionArgFunc</a>) (const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *option_name,
66 const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *value,
67 <a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> data,
68 <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="returnvalue">GError</span></a> **error);
69 <a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext">GOptionContext</a>;
70 <a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> * <a class="link" href="glib-Commandline-option-parser.html#g-option-context-new" title="g_option_context_new ()">g_option_context_new</a> (const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *parameter_string);
71 <span class="returnvalue">void</span> <a class="link" href="glib-Commandline-option-parser.html#g-option-context-set-summary" title="g_option_context_set_summary ()">g_option_context_set_summary</a> (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context,
72 const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *summary);
73 const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> * <a class="link" href="glib-Commandline-option-parser.html#g-option-context-get-summary" title="g_option_context_get_summary ()">g_option_context_get_summary</a> (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context);
74 <span class="returnvalue">void</span> <a class="link" href="glib-Commandline-option-parser.html#g-option-context-set-description" title="g_option_context_set_description ()">g_option_context_set_description</a> (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context,
75 const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *description);
76 const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> * <a class="link" href="glib-Commandline-option-parser.html#g-option-context-get-description" title="g_option_context_get_description ()">g_option_context_get_description</a> (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context);
77 const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> * (<a class="link" href="glib-Commandline-option-parser.html#GTranslateFunc" title="GTranslateFunc ()">*GTranslateFunc</a>) (const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *str,
78 <a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> data);
79 <span class="returnvalue">void</span> <a class="link" href="glib-Commandline-option-parser.html#g-option-context-set-translate-func" title="g_option_context_set_translate_func ()">g_option_context_set_translate_func</a> (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context,
80 <a class="link" href="glib-Commandline-option-parser.html#GTranslateFunc" title="GTranslateFunc ()"><span class="returnvalue">GTranslateFunc</span></a> func,
81 <a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> data,
82 <a class="link" href="glib-Datasets.html#GDestroyNotify" title="GDestroyNotify ()"><span class="returnvalue">GDestroyNotify</span></a> destroy_notify);
83 <span class="returnvalue">void</span> <a class="link" href="glib-Commandline-option-parser.html#g-option-context-set-translation-domain" title="g_option_context_set_translation_domain ()">g_option_context_set_translation_domain</a>
84 (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context,
85 const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *domain);
86 <span class="returnvalue">void</span> <a class="link" href="glib-Commandline-option-parser.html#g-option-context-free" title="g_option_context_free ()">g_option_context_free</a> (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context);
87 <a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> <a class="link" href="glib-Commandline-option-parser.html#g-option-context-parse" title="g_option_context_parse ()">g_option_context_parse</a> (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context,
88 <a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="returnvalue">gint</span></a> *argc,
89 <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> ***argv,
90 <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="returnvalue">GError</span></a> **error);
91 <span class="returnvalue">void</span> <a class="link" href="glib-Commandline-option-parser.html#g-option-context-set-help-enabled" title="g_option_context_set_help_enabled ()">g_option_context_set_help_enabled</a> (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context,
92 <a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> help_enabled);
93 <a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> <a class="link" href="glib-Commandline-option-parser.html#g-option-context-get-help-enabled" title="g_option_context_get_help_enabled ()">g_option_context_get_help_enabled</a> (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context);
94 <span class="returnvalue">void</span> <a class="link" href="glib-Commandline-option-parser.html#g-option-context-set-ignore-unknown-options" title="g_option_context_set_ignore_unknown_options ()">g_option_context_set_ignore_unknown_options</a>
95 (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context,
96 <a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> ignore_unknown);
97 <a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> <a class="link" href="glib-Commandline-option-parser.html#g-option-context-get-ignore-unknown-options" title="g_option_context_get_ignore_unknown_options ()">g_option_context_get_ignore_unknown_options</a>
98 (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context);
99 <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> * <a class="link" href="glib-Commandline-option-parser.html#g-option-context-get-help" title="g_option_context_get_help ()">g_option_context_get_help</a> (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context,
100 <a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> main_help,
101 <a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="returnvalue">GOptionGroup</span></a> *group);
102 enum <a class="link" href="glib-Commandline-option-parser.html#GOptionArg" title="enum GOptionArg">GOptionArg</a>;
103 enum <a class="link" href="glib-Commandline-option-parser.html#GOptionFlags" title="enum GOptionFlags">GOptionFlags</a>;
104 #define <a class="link" href="glib-Commandline-option-parser.html#G-OPTION-REMAINING:CAPS" title="G_OPTION_REMAINING">G_OPTION_REMAINING</a>
105 <a class="link" href="glib-Commandline-option-parser.html#GOptionEntry" title="GOptionEntry">GOptionEntry</a>;
106 <span class="returnvalue">void</span> <a class="link" href="glib-Commandline-option-parser.html#g-option-context-add-main-entries" title="g_option_context_add_main_entries ()">g_option_context_add_main_entries</a> (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context,
107 const <a class="link" href="glib-Commandline-option-parser.html#GOptionEntry" title="GOptionEntry"><span class="returnvalue">GOptionEntry</span></a> *entries,
108 const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *translation_domain);
109 <a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup">GOptionGroup</a>;
110 <span class="returnvalue">void</span> <a class="link" href="glib-Commandline-option-parser.html#g-option-context-add-group" title="g_option_context_add_group ()">g_option_context_add_group</a> (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context,
111 <a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="returnvalue">GOptionGroup</span></a> *group);
112 <span class="returnvalue">void</span> <a class="link" href="glib-Commandline-option-parser.html#g-option-context-set-main-group" title="g_option_context_set_main_group ()">g_option_context_set_main_group</a> (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context,
113 <a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="returnvalue">GOptionGroup</span></a> *group);
114 <a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="returnvalue">GOptionGroup</span></a> * <a class="link" href="glib-Commandline-option-parser.html#g-option-context-get-main-group" title="g_option_context_get_main_group ()">g_option_context_get_main_group</a> (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context);
115 <a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="returnvalue">GOptionGroup</span></a> * <a class="link" href="glib-Commandline-option-parser.html#g-option-group-new" title="g_option_group_new ()">g_option_group_new</a> (const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *name,
116 const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *description,
117 const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *help_description,
118 <a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> user_data,
119 <a class="link" href="glib-Datasets.html#GDestroyNotify" title="GDestroyNotify ()"><span class="returnvalue">GDestroyNotify</span></a> destroy);
120 <span class="returnvalue">void</span> <a class="link" href="glib-Commandline-option-parser.html#g-option-group-free" title="g_option_group_free ()">g_option_group_free</a> (<a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="returnvalue">GOptionGroup</span></a> *group);
121 <span class="returnvalue">void</span> <a class="link" href="glib-Commandline-option-parser.html#g-option-group-add-entries" title="g_option_group_add_entries ()">g_option_group_add_entries</a> (<a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="returnvalue">GOptionGroup</span></a> *group,
122 const <a class="link" href="glib-Commandline-option-parser.html#GOptionEntry" title="GOptionEntry"><span class="returnvalue">GOptionEntry</span></a> *entries);
123 <a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> (<a class="link" href="glib-Commandline-option-parser.html#GOptionParseFunc" title="GOptionParseFunc ()">*GOptionParseFunc</a>) (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context,
124 <a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="returnvalue">GOptionGroup</span></a> *group,
125 <a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> data,
126 <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="returnvalue">GError</span></a> **error);
127 <span class="returnvalue">void</span> <a class="link" href="glib-Commandline-option-parser.html#g-option-group-set-parse-hooks" title="g_option_group_set_parse_hooks ()">g_option_group_set_parse_hooks</a> (<a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="returnvalue">GOptionGroup</span></a> *group,
128 <a class="link" href="glib-Commandline-option-parser.html#GOptionParseFunc" title="GOptionParseFunc ()"><span class="returnvalue">GOptionParseFunc</span></a> pre_parse_func,
129 <a class="link" href="glib-Commandline-option-parser.html#GOptionParseFunc" title="GOptionParseFunc ()"><span class="returnvalue">GOptionParseFunc</span></a> post_parse_func);
130 <span class="returnvalue">void</span> (<a class="link" href="glib-Commandline-option-parser.html#GOptionErrorFunc" title="GOptionErrorFunc ()">*GOptionErrorFunc</a>) (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context,
131 <a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="returnvalue">GOptionGroup</span></a> *group,
132 <a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> data,
133 <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="returnvalue">GError</span></a> **error);
134 <span class="returnvalue">void</span> <a class="link" href="glib-Commandline-option-parser.html#g-option-group-set-error-hook" title="g_option_group_set_error_hook ()">g_option_group_set_error_hook</a> (<a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="returnvalue">GOptionGroup</span></a> *group,
135 <a class="link" href="glib-Commandline-option-parser.html#GOptionErrorFunc" title="GOptionErrorFunc ()"><span class="returnvalue">GOptionErrorFunc</span></a> error_func);
136 <span class="returnvalue">void</span> <a class="link" href="glib-Commandline-option-parser.html#g-option-group-set-translate-func" title="g_option_group_set_translate_func ()">g_option_group_set_translate_func</a> (<a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="returnvalue">GOptionGroup</span></a> *group,
137 <a class="link" href="glib-Commandline-option-parser.html#GTranslateFunc" title="GTranslateFunc ()"><span class="returnvalue">GTranslateFunc</span></a> func,
138 <a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> data,
139 <a class="link" href="glib-Datasets.html#GDestroyNotify" title="GDestroyNotify ()"><span class="returnvalue">GDestroyNotify</span></a> destroy_notify);
140 <span class="returnvalue">void</span> <a class="link" href="glib-Commandline-option-parser.html#g-option-group-set-translation-domain" title="g_option_group_set_translation_domain ()">g_option_group_set_translation_domain</a>
141 (<a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="returnvalue">GOptionGroup</span></a> *group,
142 const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *domain);
145 <div class="refsect1" title="Description">
146 <a name="glib-Commandline-option-parser.description"></a><h2>Description</h2>
148 The GOption commandline parser is intended to be a simpler replacement for the
149 popt library. It supports short and long commandline options, as shown in the
153 <code class="literal">testtreemodel -r 1 --max-size 20 --rand --display=:1.0 -vb -- file1 file2</code>
156 The example demonstrates a number of features of the GOption commandline parser
158 <div class="itemizedlist"><ul class="itemizedlist" type="disc">
159 <li class="listitem"><p>
160 Options can be single letters, prefixed by a single dash. Multiple
161 short options can be grouped behind a single dash.
163 <li class="listitem"><p>
164 Long options are prefixed by two consecutive dashes.
166 <li class="listitem"><p>
167 Options can have an extra argument, which can be a number, a string or a
168 filename. For long options, the extra argument can be appended with an
169 equals sign after the option name.
171 <li class="listitem"><p>
172 Non-option arguments are returned to the application as rest arguments.
174 <li class="listitem"><p>
175 An argument consisting solely of two dashes turns off further parsing,
176 any remaining arguments (even those starting with a dash) are returned
177 to the application as rest arguments.
183 Another important feature of GOption is that it can automatically generate
184 nicely formatted help output. Unless it is explicitly turned off with
185 <a class="link" href="glib-Commandline-option-parser.html#g-option-context-set-help-enabled" title="g_option_context_set_help_enabled ()"><code class="function">g_option_context_set_help_enabled()</code></a>, GOption will recognize the
186 <code class="option">--help</code>, <code class="option">-?</code>, <code class="option">--help-all</code>
187 and <code class="option">--help-</code><em class="replaceable"><code>groupname</code></em> options
188 (where <em class="replaceable"><code>groupname</code></em> is the name of a <a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="type">GOptionGroup</span></a>)
189 and write a text similar to the one shown in the following example to stdout.
193 <div class="informalexample"><pre class="screen">
195 testtreemodel [OPTION...] - test tree model performance
198 -h, --help Show help options
199 --help-all Show all help options
200 --help-gtk Show GTK+ Options
203 -r, --repeats=N Average over N repetitions
204 -m, --max-size=M Test up to 2^M items
205 --display=DISPLAY X display to use
206 -v, --verbose Be verbose
207 -b, --beep Beep when done
208 --rand Randomize the data
213 GOption groups options in <a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="type">GOptionGroup</span></a>s, which makes it easy to
214 incorporate options from multiple sources. The intended use for this is
215 to let applications collect option groups from the libraries it uses,
216 add them to their <a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="type">GOptionContext</span></a>, and parse all options by a single call
217 to <a class="link" href="glib-Commandline-option-parser.html#g-option-context-parse" title="g_option_context_parse ()"><code class="function">g_option_context_parse()</code></a>. See <a href="http://library.gnome.org/devel/gtk/unstable/gtk-General.html#gtk-get-option-group"><code class="function">gtk_get_option_group()</code></a> for an example.
220 If an option is declared to be of type string or filename, GOption takes
221 care of converting it to the right encoding; strings are returned in UTF-8,
222 filenames are returned in the GLib filename encoding. Note that this only
223 works if <a class="link" href="glib-running.html#setlocale" title="Locale"><code class="function">setlocale()</code></a> has been called before <a class="link" href="glib-Commandline-option-parser.html#g-option-context-parse" title="g_option_context_parse ()"><code class="function">g_option_context_parse()</code></a>.
226 Here is a complete example of setting up GOption to parse the example
227 commandline above and produce the example help output.
231 <div class="informalexample"><pre class="programlisting">
232 static gint repeats = 2;
233 static gint max_size = 8;
234 static gboolean verbose = FALSE;
235 static gboolean beep = FALSE;
236 static gboolean rand = FALSE;
238 static GOptionEntry entries[] =
240 { "repeats", 'r', 0, G_OPTION_ARG_INT, &repeats, "Average over N repetitions", "N" },
241 { "max-size", 'm', 0, G_OPTION_ARG_INT, &max_size, "Test up to 2^M items", "M" },
242 { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Be verbose", NULL },
243 { "beep", 'b', 0, G_OPTION_ARG_NONE, &beep, "Beep when done", NULL },
244 { "rand", 0, 0, G_OPTION_ARG_NONE, &rand, "Randomize the data", NULL },
249 main (int argc, char *argv[])
251 GError *error = NULL;
252 GOptionContext *context;
254 context = g_option_context_new ("- test tree model performance");
255 g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
256 g_option_context_add_group (context, gtk_get_option_group (TRUE));
257 if (!g_option_context_parse (context, &argc, &argv, &error))
259 g_print ("option parsing failed: %s\n", error->message);
268 <div class="refsect1" title="Details">
269 <a name="glib-Commandline-option-parser.details"></a><h2>Details</h2>
270 <div class="refsect2" title="enum GOptionError">
271 <a name="GOptionError"></a><h3>enum GOptionError</h3>
272 <pre class="programlisting">typedef enum
274 G_OPTION_ERROR_UNKNOWN_OPTION,
275 G_OPTION_ERROR_BAD_VALUE,
276 G_OPTION_ERROR_FAILED
280 Error codes returned by option parsing.</p>
281 <div class="variablelist"><table border="0">
282 <col align="left" valign="top">
285 <td><p><a name="G-OPTION-ERROR-UNKNOWN-OPTION:CAPS"></a><span class="term"><code class="literal">G_OPTION_ERROR_UNKNOWN_OPTION</code></span></p></td>
286 <td> An option was not known to the parser.
287 This error will only be reported, if the parser hasn't been instructed
288 to ignore unknown options, see <a class="link" href="glib-Commandline-option-parser.html#g-option-context-set-ignore-unknown-options" title="g_option_context_set_ignore_unknown_options ()"><code class="function">g_option_context_set_ignore_unknown_options()</code></a>.
292 <td><p><a name="G-OPTION-ERROR-BAD-VALUE:CAPS"></a><span class="term"><code class="literal">G_OPTION_ERROR_BAD_VALUE</code></span></p></td>
293 <td> A value couldn't be parsed.
297 <td><p><a name="G-OPTION-ERROR-FAILED:CAPS"></a><span class="term"><code class="literal">G_OPTION_ERROR_FAILED</code></span></p></td>
298 <td> A <a class="link" href="glib-Commandline-option-parser.html#GOptionArgFunc" title="GOptionArgFunc ()"><span class="type">GOptionArgFunc</span></a> callback failed.
305 <div class="refsect2" title="G_OPTION_ERROR">
306 <a name="G-OPTION-ERROR:CAPS"></a><h3>G_OPTION_ERROR</h3>
307 <pre class="programlisting">#define G_OPTION_ERROR (g_option_error_quark ())
310 Error domain for option parsing. Errors in this domain will
311 be from the <a class="link" href="glib-Commandline-option-parser.html#GOptionError" title="enum GOptionError"><span class="type">GOptionError</span></a> enumeration. See <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a> for information on
315 <div class="refsect2" title="GOptionArgFunc ()">
316 <a name="GOptionArgFunc"></a><h3>GOptionArgFunc ()</h3>
317 <pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> (*GOptionArgFunc) (const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *option_name,
318 const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *value,
319 <a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> data,
320 <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="returnvalue">GError</span></a> **error);</pre>
322 The type of function to be passed as callback for <a class="link" href="glib-Commandline-option-parser.html#G-OPTION-ARG-CALLBACK:CAPS"><code class="literal">G_OPTION_ARG_CALLBACK</code></a>
324 <div class="variablelist"><table border="0">
325 <col align="left" valign="top">
328 <td><p><span class="term"><em class="parameter"><code>option_name</code></em> :</span></p></td>
329 <td> The name of the option being parsed. This will be either a
330 single dash followed by a single letter (for a short name) or two dashes
331 followed by a long option name.
335 <td><p><span class="term"><em class="parameter"><code>value</code></em> :</span></p></td>
336 <td> The value to be parsed.
340 <td><p><span class="term"><em class="parameter"><code>data</code></em> :</span></p></td>
341 <td> User data added to the <a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="type">GOptionGroup</span></a> containing the option when it
342 was created with <a class="link" href="glib-Commandline-option-parser.html#g-option-group-new" title="g_option_group_new ()"><code class="function">g_option_group_new()</code></a>
346 <td><p><span class="term"><em class="parameter"><code>error</code></em> :</span></p></td>
347 <td> A return location for errors. The error code <a class="link" href="glib-Commandline-option-parser.html#G-OPTION-ERROR-FAILED:CAPS"><code class="literal">G_OPTION_ERROR_FAILED</code></a>
348 is intended to be used for errors in <a class="link" href="glib-Commandline-option-parser.html#GOptionArgFunc" title="GOptionArgFunc ()"><span class="type">GOptionArgFunc</span></a> callbacks.
352 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
353 <td> <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> if the option was successfully parsed, <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS" title="FALSE"><code class="literal">FALSE</code></a> if an error
354 occurred, in which case <em class="parameter"><code>error</code></em> should be set with <a class="link" href="glib-Error-Reporting.html#g-set-error" title="g_set_error ()"><code class="function">g_set_error()</code></a>
361 <div class="refsect2" title="GOptionContext">
362 <a name="GOptionContext"></a><h3>GOptionContext</h3>
363 <pre class="programlisting">typedef struct _GOptionContext GOptionContext;</pre>
365 A <span class="structname">GOptionContext</span> struct defines which options
366 are accepted by the commandline option parser. The struct has only private
367 fields and should not be directly accessed.</p>
370 <div class="refsect2" title="g_option_context_new ()">
371 <a name="g-option-context-new"></a><h3>g_option_context_new ()</h3>
372 <pre class="programlisting"><a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> * g_option_context_new (const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *parameter_string);</pre>
374 Creates a new option context.
377 The <em class="parameter"><code>parameter_string</code></em> can serve multiple purposes. It can be used
378 to add descriptions for "rest" arguments, which are not parsed by
379 the <a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="type">GOptionContext</span></a>, typically something like "FILES" or
380 "FILE1 FILE2...". If you are using <a class="link" href="glib-Commandline-option-parser.html#G-OPTION-REMAINING:CAPS" title="G_OPTION_REMAINING"><span class="type">G_OPTION_REMAINING</span></a> for
381 collecting "rest" arguments, GLib handles this automatically by
382 using the <em class="parameter"><code>arg_description</code></em> of the corresponding <a class="link" href="glib-Commandline-option-parser.html#GOptionEntry" title="GOptionEntry"><span class="type">GOptionEntry</span></a> in
386 Another usage is to give a short summary of the program
387 functionality, like " - frob the strings", which will be displayed
388 in the same line as the usage. For a longer description of the
389 program functionality that should be displayed as a paragraph
390 below the usage line, use <a class="link" href="glib-Commandline-option-parser.html#g-option-context-set-summary" title="g_option_context_set_summary ()"><code class="function">g_option_context_set_summary()</code></a>.
393 Note that the <em class="parameter"><code>parameter_string</code></em> is translated using the
394 function set with <a class="link" href="glib-Commandline-option-parser.html#g-option-context-set-translate-func" title="g_option_context_set_translate_func ()"><code class="function">g_option_context_set_translate_func()</code></a>, so
395 it should normally be passed untranslated.</p>
396 <div class="variablelist"><table border="0">
397 <col align="left" valign="top">
400 <td><p><span class="term"><em class="parameter"><code>parameter_string</code></em> :</span></p></td>
401 <td> a string which is displayed in
402 the first line of <code class="option">--help</code> output, after the
404 <code class="literal"><em class="replaceable"><code>programname</code></em> [OPTION...]</code>
408 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
409 <td> a newly created <a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="type">GOptionContext</span></a>, which must be
410 freed with <a class="link" href="glib-Commandline-option-parser.html#g-option-context-free" title="g_option_context_free ()"><code class="function">g_option_context_free()</code></a> after use.
416 <p class="since">Since 2.6</p>
419 <div class="refsect2" title="g_option_context_set_summary ()">
420 <a name="g-option-context-set-summary"></a><h3>g_option_context_set_summary ()</h3>
421 <pre class="programlisting"><span class="returnvalue">void</span> g_option_context_set_summary (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context,
422 const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *summary);</pre>
424 Adds a string to be displayed in <code class="option">--help</code> output
425 before the list of options. This is typically a summary of the
426 program functionality.
429 Note that the summary is translated (see
430 <a class="link" href="glib-Commandline-option-parser.html#g-option-context-set-translate-func" title="g_option_context_set_translate_func ()"><code class="function">g_option_context_set_translate_func()</code></a> and
431 <a class="link" href="glib-Commandline-option-parser.html#g-option-context-set-translation-domain" title="g_option_context_set_translation_domain ()"><code class="function">g_option_context_set_translation_domain()</code></a>).</p>
432 <div class="variablelist"><table border="0">
433 <col align="left" valign="top">
436 <td><p><span class="term"><em class="parameter"><code>context</code></em> :</span></p></td>
437 <td> a <a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="type">GOptionContext</span></a>
441 <td><p><span class="term"><em class="parameter"><code>summary</code></em> :</span></p></td>
442 <td> a string to be shown in <code class="option">--help</code> output
443 before the list of options, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>
448 <p class="since">Since 2.12</p>
451 <div class="refsect2" title="g_option_context_get_summary ()">
452 <a name="g-option-context-get-summary"></a><h3>g_option_context_get_summary ()</h3>
453 <pre class="programlisting">const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> * g_option_context_get_summary (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context);</pre>
455 Returns the summary. See <a class="link" href="glib-Commandline-option-parser.html#g-option-context-set-summary" title="g_option_context_set_summary ()"><code class="function">g_option_context_set_summary()</code></a>.</p>
456 <div class="variablelist"><table border="0">
457 <col align="left" valign="top">
460 <td><p><span class="term"><em class="parameter"><code>context</code></em> :</span></p></td>
461 <td> a <a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="type">GOptionContext</span></a>
465 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
472 <p class="since">Since 2.12</p>
475 <div class="refsect2" title="g_option_context_set_description ()">
476 <a name="g-option-context-set-description"></a><h3>g_option_context_set_description ()</h3>
477 <pre class="programlisting"><span class="returnvalue">void</span> g_option_context_set_description (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context,
478 const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *description);</pre>
480 Adds a string to be displayed in <code class="option">--help</code> output
481 after the list of options. This text often includes a bug reporting
485 Note that the summary is translated (see
486 <a class="link" href="glib-Commandline-option-parser.html#g-option-context-set-translate-func" title="g_option_context_set_translate_func ()"><code class="function">g_option_context_set_translate_func()</code></a>).</p>
487 <div class="variablelist"><table border="0">
488 <col align="left" valign="top">
491 <td><p><span class="term"><em class="parameter"><code>context</code></em> :</span></p></td>
492 <td> a <a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="type">GOptionContext</span></a>
496 <td><p><span class="term"><em class="parameter"><code>description</code></em> :</span></p></td>
497 <td> a string to be shown in <code class="option">--help</code> output
498 after the list of options, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>
503 <p class="since">Since 2.12</p>
506 <div class="refsect2" title="g_option_context_get_description ()">
507 <a name="g-option-context-get-description"></a><h3>g_option_context_get_description ()</h3>
508 <pre class="programlisting">const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> * g_option_context_get_description (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context);</pre>
510 Returns the description. See <a class="link" href="glib-Commandline-option-parser.html#g-option-context-set-description" title="g_option_context_set_description ()"><code class="function">g_option_context_set_description()</code></a>.</p>
511 <div class="variablelist"><table border="0">
512 <col align="left" valign="top">
515 <td><p><span class="term"><em class="parameter"><code>context</code></em> :</span></p></td>
516 <td> a <a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="type">GOptionContext</span></a>
520 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
527 <p class="since">Since 2.12</p>
530 <div class="refsect2" title="GTranslateFunc ()">
531 <a name="GTranslateFunc"></a><h3>GTranslateFunc ()</h3>
532 <pre class="programlisting">const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> * (*GTranslateFunc) (const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *str,
533 <a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> data);</pre>
535 The type of functions which are used to translate user-visible
536 strings, for <code class="option">--help</code> output.</p>
537 <div class="variablelist"><table border="0">
538 <col align="left" valign="top">
541 <td><p><span class="term"><em class="parameter"><code>str</code></em> :</span></p></td>
542 <td> the untranslated string
546 <td><p><span class="term"><em class="parameter"><code>data</code></em> :</span></p></td>
547 <td> user data specified when installing the function, e.g.
548 in <a class="link" href="glib-Commandline-option-parser.html#g-option-group-set-translate-func" title="g_option_group_set_translate_func ()"><code class="function">g_option_group_set_translate_func()</code></a>
552 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
553 <td> a translation of the string for the current locale.
554 The returned string is owned by GLib and must not be freed.
561 <div class="refsect2" title="g_option_context_set_translate_func ()">
562 <a name="g-option-context-set-translate-func"></a><h3>g_option_context_set_translate_func ()</h3>
563 <pre class="programlisting"><span class="returnvalue">void</span> g_option_context_set_translate_func (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context,
564 <a class="link" href="glib-Commandline-option-parser.html#GTranslateFunc" title="GTranslateFunc ()"><span class="returnvalue">GTranslateFunc</span></a> func,
565 <a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> data,
566 <a class="link" href="glib-Datasets.html#GDestroyNotify" title="GDestroyNotify ()"><span class="returnvalue">GDestroyNotify</span></a> destroy_notify);</pre>
568 Sets the function which is used to translate the contexts
569 user-visible strings, for <code class="option">--help</code> output.
570 If <em class="parameter"><code>func</code></em> is <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>, strings are not translated.
573 Note that option groups have their own translation functions,
574 this function only affects the <em class="parameter"><code>parameter_string</code></em> (see <a class="link" href="glib-Commandline-option-parser.html#g-option-context-new" title="g_option_context_new ()"><code class="function">g_option_context_new()</code></a>),
575 the summary (see <a class="link" href="glib-Commandline-option-parser.html#g-option-context-set-summary" title="g_option_context_set_summary ()"><code class="function">g_option_context_set_summary()</code></a>) and the description
576 (see <a class="link" href="glib-Commandline-option-parser.html#g-option-context-set-description" title="g_option_context_set_description ()"><code class="function">g_option_context_set_description()</code></a>).
579 If you are using <code class="function">gettext()</code>, you only need to set the translation
580 domain, see <a class="link" href="glib-Commandline-option-parser.html#g-option-context-set-translation-domain" title="g_option_context_set_translation_domain ()"><code class="function">g_option_context_set_translation_domain()</code></a>.</p>
581 <div class="variablelist"><table border="0">
582 <col align="left" valign="top">
585 <td><p><span class="term"><em class="parameter"><code>context</code></em> :</span></p></td>
586 <td> a <a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="type">GOptionContext</span></a>
590 <td><p><span class="term"><em class="parameter"><code>func</code></em> :</span></p></td>
591 <td> the <a class="link" href="glib-Commandline-option-parser.html#GTranslateFunc" title="GTranslateFunc ()"><span class="type">GTranslateFunc</span></a>, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>
595 <td><p><span class="term"><em class="parameter"><code>data</code></em> :</span></p></td>
596 <td> user data to pass to <em class="parameter"><code>func</code></em>, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>
600 <td><p><span class="term"><em class="parameter"><code>destroy_notify</code></em> :</span></p></td>
601 <td> a function which gets called to free <em class="parameter"><code>data</code></em>, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>
606 <p class="since">Since 2.12</p>
609 <div class="refsect2" title="g_option_context_set_translation_domain ()">
610 <a name="g-option-context-set-translation-domain"></a><h3>g_option_context_set_translation_domain ()</h3>
611 <pre class="programlisting"><span class="returnvalue">void</span> g_option_context_set_translation_domain
612 (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context,
613 const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *domain);</pre>
615 A convenience function to use <code class="function">gettext()</code> for translating
616 user-visible strings.</p>
617 <div class="variablelist"><table border="0">
618 <col align="left" valign="top">
621 <td><p><span class="term"><em class="parameter"><code>context</code></em> :</span></p></td>
622 <td> a <a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="type">GOptionContext</span></a>
626 <td><p><span class="term"><em class="parameter"><code>domain</code></em> :</span></p></td>
627 <td> the domain to use
632 <p class="since">Since 2.12</p>
635 <div class="refsect2" title="g_option_context_free ()">
636 <a name="g-option-context-free"></a><h3>g_option_context_free ()</h3>
637 <pre class="programlisting"><span class="returnvalue">void</span> g_option_context_free (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context);</pre>
639 Frees context and all the groups which have been
643 Please note that parsed arguments need to be freed separately (see
644 <a class="link" href="glib-Commandline-option-parser.html#GOptionEntry" title="GOptionEntry"><span class="type">GOptionEntry</span></a>).</p>
645 <div class="variablelist"><table border="0">
646 <col align="left" valign="top">
648 <td><p><span class="term"><em class="parameter"><code>context</code></em> :</span></p></td>
649 <td> a <a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="type">GOptionContext</span></a>
653 <p class="since">Since 2.6</p>
656 <div class="refsect2" title="g_option_context_parse ()">
657 <a name="g-option-context-parse"></a><h3>g_option_context_parse ()</h3>
658 <pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> g_option_context_parse (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context,
659 <a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="returnvalue">gint</span></a> *argc,
660 <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> ***argv,
661 <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="returnvalue">GError</span></a> **error);</pre>
663 Parses the command line arguments, recognizing options
664 which have been added to <em class="parameter"><code>context</code></em>. A side-effect of
665 calling this function is that <a class="link" href="glib-Miscellaneous-Utility-Functions.html#g-set-prgname" title="g_set_prgname ()"><code class="function">g_set_prgname()</code></a> will be
669 If the parsing is successful, any parsed arguments are
670 removed from the array and <em class="parameter"><code>argc</code></em> and <em class="parameter"><code>argv</code></em> are updated
671 accordingly. A '--' option is stripped from <em class="parameter"><code>argv</code></em>
672 unless there are unparsed options before and after it,
673 or some of the options after it start with '-'. In case
674 of an error, <em class="parameter"><code>argc</code></em> and <em class="parameter"><code>argv</code></em> are left unmodified.
677 If automatic <code class="option">--help</code> support is enabled
678 (see <a class="link" href="glib-Commandline-option-parser.html#g-option-context-set-help-enabled" title="g_option_context_set_help_enabled ()"><code class="function">g_option_context_set_help_enabled()</code></a>), and the
679 <em class="parameter"><code>argv</code></em> array contains one of the recognized help options,
680 this function will produce help output to stdout and
681 call <code class="literal">exit (0)</code>.
684 Note that function depends on the
685 <a class="link" href="glib-running.html#setlocale" title="Locale">current locale</a> for
686 automatic character set conversion of string and filename
688 <div class="variablelist"><table border="0">
689 <col align="left" valign="top">
692 <td><p><span class="term"><em class="parameter"><code>context</code></em> :</span></p></td>
693 <td> a <a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="type">GOptionContext</span></a>
697 <td><p><span class="term"><em class="parameter"><code>argc</code></em> :</span></p></td>
698 <td> a pointer to the number of command line arguments
702 <td><p><span class="term"><em class="parameter"><code>argv</code></em> :</span></p></td>
703 <td> a pointer to the array of command line arguments
707 <td><p><span class="term"><em class="parameter"><code>error</code></em> :</span></p></td>
708 <td> a return location for errors
712 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
713 <td> <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> if the parsing was successful,
714 <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS" title="FALSE"><code class="literal">FALSE</code></a> if an error occurred
720 <p class="since">Since 2.6</p>
723 <div class="refsect2" title="g_option_context_set_help_enabled ()">
724 <a name="g-option-context-set-help-enabled"></a><h3>g_option_context_set_help_enabled ()</h3>
725 <pre class="programlisting"><span class="returnvalue">void</span> g_option_context_set_help_enabled (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context,
726 <a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> help_enabled);</pre>
728 Enables or disables automatic generation of <code class="option">--help</code>
729 output. By default, <a class="link" href="glib-Commandline-option-parser.html#g-option-context-parse" title="g_option_context_parse ()"><code class="function">g_option_context_parse()</code></a> recognizes
730 <code class="option">--help</code>, <code class="option">-h</code>,
731 <code class="option">-?</code>, <code class="option">--help-all</code>
732 and <code class="option">--help-</code><em class="replaceable"><code>groupname</code></em> and creates
733 suitable output to stdout.</p>
734 <div class="variablelist"><table border="0">
735 <col align="left" valign="top">
738 <td><p><span class="term"><em class="parameter"><code>context</code></em> :</span></p></td>
739 <td> a <a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="type">GOptionContext</span></a>
743 <td><p><span class="term"><em class="parameter"><code>help_enabled</code></em> :</span></p></td>
744 <td> <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> to enable <code class="option">--help</code>, <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS" title="FALSE"><code class="literal">FALSE</code></a> to disable it
749 <p class="since">Since 2.6</p>
752 <div class="refsect2" title="g_option_context_get_help_enabled ()">
753 <a name="g-option-context-get-help-enabled"></a><h3>g_option_context_get_help_enabled ()</h3>
754 <pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> g_option_context_get_help_enabled (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context);</pre>
756 Returns whether automatic <code class="option">--help</code> generation
757 is turned on for <em class="parameter"><code>context</code></em>. See <a class="link" href="glib-Commandline-option-parser.html#g-option-context-set-help-enabled" title="g_option_context_set_help_enabled ()"><code class="function">g_option_context_set_help_enabled()</code></a>.</p>
758 <div class="variablelist"><table border="0">
759 <col align="left" valign="top">
762 <td><p><span class="term"><em class="parameter"><code>context</code></em> :</span></p></td>
763 <td> a <a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="type">GOptionContext</span></a>
767 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
768 <td> <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> if automatic help generation is turned on.
774 <p class="since">Since 2.6</p>
777 <div class="refsect2" title="g_option_context_set_ignore_unknown_options ()">
778 <a name="g-option-context-set-ignore-unknown-options"></a><h3>g_option_context_set_ignore_unknown_options ()</h3>
779 <pre class="programlisting"><span class="returnvalue">void</span> g_option_context_set_ignore_unknown_options
780 (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context,
781 <a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> ignore_unknown);</pre>
783 Sets whether to ignore unknown options or not. If an argument is
784 ignored, it is left in the <em class="parameter"><code>argv</code></em> array after parsing. By default,
785 <a class="link" href="glib-Commandline-option-parser.html#g-option-context-parse" title="g_option_context_parse ()"><code class="function">g_option_context_parse()</code></a> treats unknown options as error.
788 This setting does not affect non-option arguments (i.e. arguments
789 which don't start with a dash). But note that GOption cannot reliably
790 determine whether a non-option belongs to a preceding unknown option.</p>
791 <div class="variablelist"><table border="0">
792 <col align="left" valign="top">
795 <td><p><span class="term"><em class="parameter"><code>context</code></em> :</span></p></td>
796 <td> a <a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="type">GOptionContext</span></a>
800 <td><p><span class="term"><em class="parameter"><code>ignore_unknown</code></em> :</span></p></td>
801 <td> <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> to ignore unknown options, <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS" title="FALSE"><code class="literal">FALSE</code></a> to produce
802 an error when unknown options are met
807 <p class="since">Since 2.6</p>
810 <div class="refsect2" title="g_option_context_get_ignore_unknown_options ()">
811 <a name="g-option-context-get-ignore-unknown-options"></a><h3>g_option_context_get_ignore_unknown_options ()</h3>
812 <pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> g_option_context_get_ignore_unknown_options
813 (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context);</pre>
815 Returns whether unknown options are ignored or not. See
816 <a class="link" href="glib-Commandline-option-parser.html#g-option-context-set-ignore-unknown-options" title="g_option_context_set_ignore_unknown_options ()"><code class="function">g_option_context_set_ignore_unknown_options()</code></a>.</p>
817 <div class="variablelist"><table border="0">
818 <col align="left" valign="top">
821 <td><p><span class="term"><em class="parameter"><code>context</code></em> :</span></p></td>
822 <td> a <a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="type">GOptionContext</span></a>
826 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
827 <td> <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> if unknown options are ignored.
833 <p class="since">Since 2.6</p>
836 <div class="refsect2" title="g_option_context_get_help ()">
837 <a name="g-option-context-get-help"></a><h3>g_option_context_get_help ()</h3>
838 <pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> * g_option_context_get_help (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context,
839 <a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> main_help,
840 <a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="returnvalue">GOptionGroup</span></a> *group);</pre>
842 Returns a formatted, translated help text for the given context.
843 To obtain the text produced by <code class="option">--help</code>, call
844 <code class="literal">g_option_context_get_help (context, TRUE, NULL)</code>.
845 To obtain the text produced by <code class="option">--help-all</code>, call
846 <code class="literal">g_option_context_get_help (context, FALSE, NULL)</code>.
847 To obtain the help text for an option group, call
848 <code class="literal">g_option_context_get_help (context, FALSE, group)</code>.</p>
849 <div class="variablelist"><table border="0">
850 <col align="left" valign="top">
853 <td><p><span class="term"><em class="parameter"><code>context</code></em> :</span></p></td>
854 <td> a <a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="type">GOptionContext</span></a>
858 <td><p><span class="term"><em class="parameter"><code>main_help</code></em> :</span></p></td>
859 <td> if <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a>, only include the main group
863 <td><p><span class="term"><em class="parameter"><code>group</code></em> :</span></p></td>
864 <td> the <a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="type">GOptionGroup</span></a> to create help for, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>
868 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
869 <td> A newly allocated string containing the help text
875 <p class="since">Since 2.14</p>
878 <div class="refsect2" title="enum GOptionArg">
879 <a name="GOptionArg"></a><h3>enum GOptionArg</h3>
880 <pre class="programlisting">typedef enum
885 G_OPTION_ARG_CALLBACK,
886 G_OPTION_ARG_FILENAME,
887 G_OPTION_ARG_STRING_ARRAY,
888 G_OPTION_ARG_FILENAME_ARRAY,
894 The <a class="link" href="glib-Commandline-option-parser.html#GOptionArg" title="enum GOptionArg"><span class="type">GOptionArg</span></a> enum values determine which type of extra argument the
895 options expect to find. If an option expects an extra argument, it
896 can be specified in several ways; with a short option:
897 <code class="option">-x arg</code>, with a long option: <code class="option">--name arg</code>
898 or combined in a single argument: <code class="option">--name=arg</code>.</p>
899 <div class="variablelist"><table border="0">
900 <col align="left" valign="top">
903 <td><p><a name="G-OPTION-ARG-NONE:CAPS"></a><span class="term"><code class="literal">G_OPTION_ARG_NONE</code></span></p></td>
904 <td> No extra argument. This is useful for simple flags.
908 <td><p><a name="G-OPTION-ARG-STRING:CAPS"></a><span class="term"><code class="literal">G_OPTION_ARG_STRING</code></span></p></td>
909 <td> The option takes a string argument.
913 <td><p><a name="G-OPTION-ARG-INT:CAPS"></a><span class="term"><code class="literal">G_OPTION_ARG_INT</code></span></p></td>
914 <td> The option takes an integer argument.
918 <td><p><a name="G-OPTION-ARG-CALLBACK:CAPS"></a><span class="term"><code class="literal">G_OPTION_ARG_CALLBACK</code></span></p></td>
919 <td> The option provides a callback to parse the
924 <td><p><a name="G-OPTION-ARG-FILENAME:CAPS"></a><span class="term"><code class="literal">G_OPTION_ARG_FILENAME</code></span></p></td>
925 <td> The option takes a filename as argument.
929 <td><p><a name="G-OPTION-ARG-STRING-ARRAY:CAPS"></a><span class="term"><code class="literal">G_OPTION_ARG_STRING_ARRAY</code></span></p></td>
930 <td> The option takes a string argument, multiple
931 uses of the option are collected into an array of strings.
935 <td><p><a name="G-OPTION-ARG-FILENAME-ARRAY:CAPS"></a><span class="term"><code class="literal">G_OPTION_ARG_FILENAME_ARRAY</code></span></p></td>
936 <td> The option takes a filename as argument,
937 multiple uses of the option are collected into an array of strings.
941 <td><p><a name="G-OPTION-ARG-DOUBLE:CAPS"></a><span class="term"><code class="literal">G_OPTION_ARG_DOUBLE</code></span></p></td>
942 <td> The option takes a double argument. The argument
943 can be formatted either for the user's locale or for the "C" locale. Since 2.12
947 <td><p><a name="G-OPTION-ARG-INT64:CAPS"></a><span class="term"><code class="literal">G_OPTION_ARG_INT64</code></span></p></td>
948 <td> The option takes a 64-bit integer. Like <a class="link" href="glib-Commandline-option-parser.html#G-OPTION-ARG-INT:CAPS"><code class="literal">G_OPTION_ARG_INT</code></a>
949 but for larger numbers. The number can be in decimal base, or in hexadecimal
950 (when prefixed with <code class="literal">0x</code>, for example, <code class="literal">0xffffffff</code>).
958 <div class="refsect2" title="enum GOptionFlags">
959 <a name="GOptionFlags"></a><h3>enum GOptionFlags</h3>
960 <pre class="programlisting">typedef enum
962 G_OPTION_FLAG_HIDDEN = 1 << 0,
963 G_OPTION_FLAG_IN_MAIN = 1 << 1,
964 G_OPTION_FLAG_REVERSE = 1 << 2,
965 G_OPTION_FLAG_NO_ARG = 1 << 3,
966 G_OPTION_FLAG_FILENAME = 1 << 4,
967 G_OPTION_FLAG_OPTIONAL_ARG = 1 << 5,
968 G_OPTION_FLAG_NOALIAS = 1 << 6
972 Flags which modify individual options.</p>
973 <div class="variablelist"><table border="0">
974 <col align="left" valign="top">
977 <td><p><a name="G-OPTION-FLAG-HIDDEN:CAPS"></a><span class="term"><code class="literal">G_OPTION_FLAG_HIDDEN</code></span></p></td>
978 <td> The option doesn't appear in <code class="option">--help</code>
983 <td><p><a name="G-OPTION-FLAG-IN-MAIN:CAPS"></a><span class="term"><code class="literal">G_OPTION_FLAG_IN_MAIN</code></span></p></td>
984 <td> The option appears in the main section of the
985 <code class="option">--help</code> output, even if it is defined in a group.
989 <td><p><a name="G-OPTION-FLAG-REVERSE:CAPS"></a><span class="term"><code class="literal">G_OPTION_FLAG_REVERSE</code></span></p></td>
990 <td> For options of the <a class="link" href="glib-Commandline-option-parser.html#G-OPTION-ARG-NONE:CAPS"><code class="literal">G_OPTION_ARG_NONE</code></a> kind, this flag
991 indicates that the sense of the option is reversed.
995 <td><p><a name="G-OPTION-FLAG-NO-ARG:CAPS"></a><span class="term"><code class="literal">G_OPTION_FLAG_NO_ARG</code></span></p></td>
996 <td> For options of the <a class="link" href="glib-Commandline-option-parser.html#G-OPTION-ARG-CALLBACK:CAPS"><code class="literal">G_OPTION_ARG_CALLBACK</code></a> kind,
997 this flag indicates that the callback does not take any argument
998 (like a <a class="link" href="glib-Commandline-option-parser.html#G-OPTION-ARG-NONE:CAPS"><code class="literal">G_OPTION_ARG_NONE</code></a> option). Since 2.8
1002 <td><p><a name="G-OPTION-FLAG-FILENAME:CAPS"></a><span class="term"><code class="literal">G_OPTION_FLAG_FILENAME</code></span></p></td>
1003 <td> For options of the <a class="link" href="glib-Commandline-option-parser.html#G-OPTION-ARG-CALLBACK:CAPS"><code class="literal">G_OPTION_ARG_CALLBACK</code></a>
1004 kind, this flag indicates that the argument should be passed to the
1005 callback in the GLib filename encoding rather than UTF-8. Since 2.8
1009 <td><p><a name="G-OPTION-FLAG-OPTIONAL-ARG:CAPS"></a><span class="term"><code class="literal">G_OPTION_FLAG_OPTIONAL_ARG</code></span></p></td>
1010 <td> For options of the <a class="link" href="glib-Commandline-option-parser.html#G-OPTION-ARG-CALLBACK:CAPS"><code class="literal">G_OPTION_ARG_CALLBACK</code></a>
1011 kind, this flag indicates that the argument supply is optional. If no argument
1012 is given then data of <a class="link" href="glib-Commandline-option-parser.html#GOptionParseFunc" title="GOptionParseFunc ()"><code class="literal">GOptionParseFunc</code></a> will be set to NULL. Since 2.8
1016 <td><p><a name="G-OPTION-FLAG-NOALIAS:CAPS"></a><span class="term"><code class="literal">G_OPTION_FLAG_NOALIAS</code></span></p></td>
1017 <td> This flag turns off the automatic conflict resolution
1018 which prefixes long option names with <code class="literal">groupname-</code> if
1019 there is a conflict. This option should only be used in situations where
1020 aliasing is necessary to model some legacy commandline interface. It is
1021 not safe to use this option, unless all option groups are under your
1022 direct control. Since 2.8.
1029 <div class="refsect2" title="G_OPTION_REMAINING">
1030 <a name="G-OPTION-REMAINING:CAPS"></a><h3>G_OPTION_REMAINING</h3>
1031 <pre class="programlisting">#define G_OPTION_REMAINING ""
1034 If a long option in the main group has this name, it is not treated as a
1035 regular option. Instead it collects all non-option arguments which would
1036 otherwise be left in <code class="literal">argv</code>. The option must be of type
1037 <a class="link" href="glib-Commandline-option-parser.html#G-OPTION-ARG-CALLBACK:CAPS"><code class="literal">G_OPTION_ARG_CALLBACK</code></a>, <a class="link" href="glib-Commandline-option-parser.html#G-OPTION-ARG-STRING-ARRAY:CAPS"><code class="literal">G_OPTION_ARG_STRING_ARRAY</code></a>
1038 or <a class="link" href="glib-Commandline-option-parser.html#G-OPTION-ARG-FILENAME-ARRAY:CAPS"><code class="literal">G_OPTION_ARG_FILENAME_ARRAY</code></a>.
1041 Using <a class="link" href="glib-Commandline-option-parser.html#G-OPTION-REMAINING:CAPS" title="G_OPTION_REMAINING"><span class="type">G_OPTION_REMAINING</span></a> instead of simply scanning <code class="literal">argv</code>
1042 for leftover arguments has the advantage that GOption takes care of
1043 necessary encoding conversions for strings or filenames.</p>
1044 <p class="since">Since 2.6</p>
1047 <div class="refsect2" title="GOptionEntry">
1048 <a name="GOptionEntry"></a><h3>GOptionEntry</h3>
1049 <pre class="programlisting">typedef struct {
1050 const gchar *long_name;
1057 const gchar *description;
1058 const gchar *arg_description;
1062 A <span class="structname">GOptionEntry</span> defines a single option.
1063 To have an effect, they must be added to a <a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="type">GOptionGroup</span></a> with
1064 <a class="link" href="glib-Commandline-option-parser.html#g-option-context-add-main-entries" title="g_option_context_add_main_entries ()"><code class="function">g_option_context_add_main_entries()</code></a> or <a class="link" href="glib-Commandline-option-parser.html#g-option-group-add-entries" title="g_option_group_add_entries ()"><code class="function">g_option_group_add_entries()</code></a>.</p>
1065 <div class="variablelist"><table border="0">
1066 <col align="left" valign="top">
1069 <td><p><span class="term">const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *<em class="structfield"><code><a name="GOptionEntry.long-name"></a>long_name</code></em>;</span></p></td>
1070 <td> The long name of an option can be used to specify it
1071 in a commandline as --<em class="replaceable"><code>long_name</code></em>. Every
1072 option must have a long name. To resolve conflicts if multiple
1073 option groups contain the same long name, it is also possible to
1074 specify the option as
1075 --<em class="replaceable"><code>groupname</code></em>-<em class="replaceable"><code>long_name</code></em>.
1079 <td><p><span class="term"><a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> <em class="structfield"><code><a name="GOptionEntry.short-name"></a>short_name</code></em>;</span></p></td>
1080 <td> If an option has a short name, it can be specified
1081 -<em class="replaceable"><code>short_name</code></em> in a commandline. <em class="parameter"><code>short_name</code></em> must be
1082 a printable ASCII character different from '-', or zero if the option has no
1087 <td><p><span class="term"><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> <em class="structfield"><code><a name="GOptionEntry.flags"></a>flags</code></em>;</span></p></td>
1088 <td> Flags from <a class="link" href="glib-Commandline-option-parser.html#GOptionFlags" title="enum GOptionFlags"><span class="type">GOptionFlags</span></a>.
1092 <td><p><span class="term"><a class="link" href="glib-Commandline-option-parser.html#GOptionArg" title="enum GOptionArg"><span class="type">GOptionArg</span></a> <em class="structfield"><code><a name="GOptionEntry.arg"></a>arg</code></em>;</span></p></td>
1093 <td> The type of the option, as a <a class="link" href="glib-Commandline-option-parser.html#GOptionArg" title="enum GOptionArg"><span class="type">GOptionArg</span></a>.
1097 <td><p><span class="term"><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> <em class="structfield"><code><a name="GOptionEntry.arg-data"></a>arg_data</code></em>;</span></p></td>
1098 <td> If the <em class="parameter"><code>arg</code></em> type is <a class="link" href="glib-Commandline-option-parser.html#G-OPTION-ARG-CALLBACK:CAPS"><code class="literal">G_OPTION_ARG_CALLBACK</code></a>, then <em class="parameter"><code>arg_data</code></em> must
1099 point to a <a class="link" href="glib-Commandline-option-parser.html#GOptionArgFunc" title="GOptionArgFunc ()"><span class="type">GOptionArgFunc</span></a> callback function, which will be called to handle
1100 the extra argument. Otherwise, <em class="parameter"><code>arg_data</code></em> is a pointer to a location to store
1101 the value, the required type of the location depends on the <em class="parameter"><code>arg</code></em> type:
1102 <div class="variablelist"><table border="0">
1103 <col align="left" valign="top">
1106 <td><p><span class="term"><a class="link" href="glib-Commandline-option-parser.html#G-OPTION-ARG-NONE:CAPS"><code class="literal">G_OPTION_ARG_NONE</code></a></span></p></td>
1107 <td><p><a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><code class="literal">gboolean</code></a></p></td>
1110 <td><p><span class="term"><a class="link" href="glib-Commandline-option-parser.html#G-OPTION-ARG-STRING:CAPS"><code class="literal">G_OPTION_ARG_STRING</code></a></span></p></td>
1111 <td><p><a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><code class="literal">gchar</code></a>*</p></td>
1114 <td><p><span class="term"><a class="link" href="glib-Commandline-option-parser.html#G-OPTION-ARG-INT:CAPS"><code class="literal">G_OPTION_ARG_INT</code></a></span></p></td>
1115 <td><p><a class="link" href="glib-Basic-Types.html#gint" title="gint"><code class="literal">gint</code></a></p></td>
1118 <td><p><span class="term"><a class="link" href="glib-Commandline-option-parser.html#G-OPTION-ARG-FILENAME:CAPS"><code class="literal">G_OPTION_ARG_FILENAME</code></a></span></p></td>
1119 <td><p><a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><code class="literal">gchar</code></a>*</p></td>
1122 <td><p><span class="term"><a class="link" href="glib-Commandline-option-parser.html#G-OPTION-ARG-STRING-ARRAY:CAPS"><code class="literal">G_OPTION_ARG_STRING_ARRAY</code></a></span></p></td>
1123 <td><p><a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><code class="literal">gchar</code></a>**</p></td>
1126 <td><p><span class="term"><a class="link" href="glib-Commandline-option-parser.html#G-OPTION-ARG-FILENAME-ARRAY:CAPS"><code class="literal">G_OPTION_ARG_FILENAME_ARRAY</code></a></span></p></td>
1127 <td><p><a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><code class="literal">gchar</code></a>**</p></td>
1130 <td><p><span class="term"><a class="link" href="glib-Commandline-option-parser.html#G-OPTION-ARG-DOUBLE:CAPS"><code class="literal">G_OPTION_ARG_DOUBLE</code></a></span></p></td>
1131 <td><p><a class="link" href="glib-Basic-Types.html#gdouble" title="gdouble"><code class="literal">gdouble</code></a></p></td>
1135 If <em class="parameter"><code>arg</code></em> type is <a class="link" href="glib-Commandline-option-parser.html#G-OPTION-ARG-STRING:CAPS"><code class="literal">G_OPTION_ARG_STRING</code></a> or <a class="link" href="glib-Commandline-option-parser.html#G-OPTION-ARG-FILENAME:CAPS"><code class="literal">G_OPTION_ARG_FILENAME</code></a> the location
1136 will contain a newly allocated string if the option was given. That string
1137 needs to be freed by the callee using <a class="link" href="glib-Memory-Allocation.html#g-free" title="g_free ()"><code class="function">g_free()</code></a>. Likewise if <em class="parameter"><code>arg</code></em> type is
1138 <a class="link" href="glib-Commandline-option-parser.html#G-OPTION-ARG-STRING-ARRAY:CAPS"><code class="literal">G_OPTION_ARG_STRING_ARRAY</code></a> or <a class="link" href="glib-Commandline-option-parser.html#G-OPTION-ARG-FILENAME-ARRAY:CAPS"><code class="literal">G_OPTION_ARG_FILENAME_ARRAY</code></a>, the data should
1139 be freed using <a class="link" href="glib-String-Utility-Functions.html#g-strfreev" title="g_strfreev ()"><code class="function">g_strfreev()</code></a>.
1143 <td><p><span class="term">const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *<em class="structfield"><code><a name="GOptionEntry.description"></a>description</code></em>;</span></p></td>
1144 <td> the description for the option in <code class="option">--help</code>
1145 output. The <em class="parameter"><code>description</code></em> is translated using the <em class="parameter"><code>translate_func</code></em> of the
1146 group, see <a class="link" href="glib-Commandline-option-parser.html#g-option-group-set-translation-domain" title="g_option_group_set_translation_domain ()"><code class="function">g_option_group_set_translation_domain()</code></a>.
1150 <td><p><span class="term">const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *<em class="structfield"><code><a name="GOptionEntry.arg-description"></a>arg_description</code></em>;</span></p></td>
1151 <td> The placeholder to use for the extra argument parsed
1152 by the option in <code class="option">--help</code>
1153 output. The <em class="parameter"><code>arg_description</code></em> is translated using the <em class="parameter"><code>translate_func</code></em> of the
1154 group, see <a class="link" href="glib-Commandline-option-parser.html#g-option-group-set-translation-domain" title="g_option_group_set_translation_domain ()"><code class="function">g_option_group_set_translation_domain()</code></a>.
1161 <div class="refsect2" title="g_option_context_add_main_entries ()">
1162 <a name="g-option-context-add-main-entries"></a><h3>g_option_context_add_main_entries ()</h3>
1163 <pre class="programlisting"><span class="returnvalue">void</span> g_option_context_add_main_entries (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context,
1164 const <a class="link" href="glib-Commandline-option-parser.html#GOptionEntry" title="GOptionEntry"><span class="returnvalue">GOptionEntry</span></a> *entries,
1165 const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *translation_domain);</pre>
1167 A convenience function which creates a main group if it doesn't
1168 exist, adds the <em class="parameter"><code>entries</code></em> to it and sets the translation domain.</p>
1169 <div class="variablelist"><table border="0">
1170 <col align="left" valign="top">
1173 <td><p><span class="term"><em class="parameter"><code>context</code></em> :</span></p></td>
1174 <td> a <a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="type">GOptionContext</span></a>
1178 <td><p><span class="term"><em class="parameter"><code>entries</code></em> :</span></p></td>
1179 <td> a <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>-terminated array of <a class="link" href="glib-Commandline-option-parser.html#GOptionEntry" title="GOptionEntry"><span class="type">GOptionEntry</span></a>s
1183 <td><p><span class="term"><em class="parameter"><code>translation_domain</code></em> :</span></p></td>
1184 <td> a translation domain to use for translating
1185 the <code class="option">--help</code> output for the options in <em class="parameter"><code>entries</code></em>
1186 with <code class="function">gettext()</code>, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>
1191 <p class="since">Since 2.6</p>
1194 <div class="refsect2" title="GOptionGroup">
1195 <a name="GOptionGroup"></a><h3>GOptionGroup</h3>
1196 <pre class="programlisting">typedef struct _GOptionGroup GOptionGroup;</pre>
1198 A <span class="structname">GOptionGroup</span> struct defines the options in a single
1199 group. The struct has only private fields and should not be directly accessed.
1202 All options in a group share the same translation function. Libraries which
1203 need to parse commandline options are expected to provide a function for
1204 getting a <span class="structname">GOptionGroup</span> holding their options, which
1205 the application can then add to its <a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="type">GOptionContext</span></a>.</p>
1208 <div class="refsect2" title="g_option_context_add_group ()">
1209 <a name="g-option-context-add-group"></a><h3>g_option_context_add_group ()</h3>
1210 <pre class="programlisting"><span class="returnvalue">void</span> g_option_context_add_group (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context,
1211 <a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="returnvalue">GOptionGroup</span></a> *group);</pre>
1213 Adds a <a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="type">GOptionGroup</span></a> to the <em class="parameter"><code>context</code></em>, so that parsing with <em class="parameter"><code>context</code></em>
1214 will recognize the options in the group. Note that the group will
1215 be freed together with the context when <a class="link" href="glib-Commandline-option-parser.html#g-option-context-free" title="g_option_context_free ()"><code class="function">g_option_context_free()</code></a> is
1216 called, so you must not free the group yourself after adding it
1218 <div class="variablelist"><table border="0">
1219 <col align="left" valign="top">
1222 <td><p><span class="term"><em class="parameter"><code>context</code></em> :</span></p></td>
1223 <td> a <a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="type">GOptionContext</span></a>
1227 <td><p><span class="term"><em class="parameter"><code>group</code></em> :</span></p></td>
1228 <td> the group to add
1233 <p class="since">Since 2.6</p>
1236 <div class="refsect2" title="g_option_context_set_main_group ()">
1237 <a name="g-option-context-set-main-group"></a><h3>g_option_context_set_main_group ()</h3>
1238 <pre class="programlisting"><span class="returnvalue">void</span> g_option_context_set_main_group (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context,
1239 <a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="returnvalue">GOptionGroup</span></a> *group);</pre>
1241 Sets a <a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="type">GOptionGroup</span></a> as main group of the <em class="parameter"><code>context</code></em>.
1242 This has the same effect as calling <a class="link" href="glib-Commandline-option-parser.html#g-option-context-add-group" title="g_option_context_add_group ()"><code class="function">g_option_context_add_group()</code></a>,
1243 the only difference is that the options in the main group are
1244 treated differently when generating <code class="option">--help</code> output.</p>
1245 <div class="variablelist"><table border="0">
1246 <col align="left" valign="top">
1249 <td><p><span class="term"><em class="parameter"><code>context</code></em> :</span></p></td>
1250 <td> a <a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="type">GOptionContext</span></a>
1254 <td><p><span class="term"><em class="parameter"><code>group</code></em> :</span></p></td>
1255 <td> the group to set as main group
1260 <p class="since">Since 2.6</p>
1263 <div class="refsect2" title="g_option_context_get_main_group ()">
1264 <a name="g-option-context-get-main-group"></a><h3>g_option_context_get_main_group ()</h3>
1265 <pre class="programlisting"><a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="returnvalue">GOptionGroup</span></a> * g_option_context_get_main_group (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context);</pre>
1267 Returns a pointer to the main group of <em class="parameter"><code>context</code></em>.</p>
1268 <div class="variablelist"><table border="0">
1269 <col align="left" valign="top">
1272 <td><p><span class="term"><em class="parameter"><code>context</code></em> :</span></p></td>
1273 <td> a <a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="type">GOptionContext</span></a>
1277 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
1278 <td> the main group of <em class="parameter"><code>context</code></em>, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> if <em class="parameter"><code>context</code></em> doesn't
1279 have a main group. Note that group belongs to <em class="parameter"><code>context</code></em> and should
1280 not be modified or freed.
1286 <p class="since">Since 2.6</p>
1289 <div class="refsect2" title="g_option_group_new ()">
1290 <a name="g-option-group-new"></a><h3>g_option_group_new ()</h3>
1291 <pre class="programlisting"><a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="returnvalue">GOptionGroup</span></a> * g_option_group_new (const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *name,
1292 const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *description,
1293 const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *help_description,
1294 <a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> user_data,
1295 <a class="link" href="glib-Datasets.html#GDestroyNotify" title="GDestroyNotify ()"><span class="returnvalue">GDestroyNotify</span></a> destroy);</pre>
1297 Creates a new <a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="type">GOptionGroup</span></a>.</p>
1298 <div class="variablelist"><table border="0">
1299 <col align="left" valign="top">
1302 <td><p><span class="term"><em class="parameter"><code>name</code></em> :</span></p></td>
1303 <td> the name for the option group, this is used to provide
1304 help for the options in this group with <code class="option">--help-</code><em class="parameter"><code>name</code></em>
1308 <td><p><span class="term"><em class="parameter"><code>description</code></em> :</span></p></td>
1309 <td> a description for this group to be shown in
1310 <code class="option">--help</code>. This string is translated using the translation
1311 domain or translation function of the group
1315 <td><p><span class="term"><em class="parameter"><code>help_description</code></em> :</span></p></td>
1316 <td> a description for the <code class="option">--help-</code><em class="parameter"><code>name</code></em> option.
1317 This string is translated using the translation domain or translation function
1322 <td><p><span class="term"><em class="parameter"><code>user_data</code></em> :</span></p></td>
1323 <td> user data that will be passed to the pre- and post-parse hooks,
1324 the error hook and to callbacks of <a class="link" href="glib-Commandline-option-parser.html#G-OPTION-ARG-CALLBACK:CAPS"><code class="literal">G_OPTION_ARG_CALLBACK</code></a> options, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>
1328 <td><p><span class="term"><em class="parameter"><code>destroy</code></em> :</span></p></td>
1329 <td> a function that will be called to free <em class="parameter"><code>user_data</code></em>, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>
1333 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
1334 <td> a newly created option group. It should be added
1335 to a <a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="type">GOptionContext</span></a> or freed with <a class="link" href="glib-Commandline-option-parser.html#g-option-group-free" title="g_option_group_free ()"><code class="function">g_option_group_free()</code></a>.
1341 <p class="since">Since 2.6</p>
1344 <div class="refsect2" title="g_option_group_free ()">
1345 <a name="g-option-group-free"></a><h3>g_option_group_free ()</h3>
1346 <pre class="programlisting"><span class="returnvalue">void</span> g_option_group_free (<a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="returnvalue">GOptionGroup</span></a> *group);</pre>
1348 Frees a <a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="type">GOptionGroup</span></a>. Note that you must <span class="emphasis"><em>not</em></span>
1349 free groups which have been added to a <a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="type">GOptionContext</span></a>.</p>
1350 <div class="variablelist"><table border="0">
1351 <col align="left" valign="top">
1353 <td><p><span class="term"><em class="parameter"><code>group</code></em> :</span></p></td>
1354 <td> a <a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="type">GOptionGroup</span></a>
1358 <p class="since">Since 2.6</p>
1361 <div class="refsect2" title="g_option_group_add_entries ()">
1362 <a name="g-option-group-add-entries"></a><h3>g_option_group_add_entries ()</h3>
1363 <pre class="programlisting"><span class="returnvalue">void</span> g_option_group_add_entries (<a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="returnvalue">GOptionGroup</span></a> *group,
1364 const <a class="link" href="glib-Commandline-option-parser.html#GOptionEntry" title="GOptionEntry"><span class="returnvalue">GOptionEntry</span></a> *entries);</pre>
1366 Adds the options specified in <em class="parameter"><code>entries</code></em> to <em class="parameter"><code>group</code></em>.</p>
1367 <div class="variablelist"><table border="0">
1368 <col align="left" valign="top">
1371 <td><p><span class="term"><em class="parameter"><code>group</code></em> :</span></p></td>
1372 <td> a <a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="type">GOptionGroup</span></a>
1376 <td><p><span class="term"><em class="parameter"><code>entries</code></em> :</span></p></td>
1377 <td> a <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>-terminated array of <a class="link" href="glib-Commandline-option-parser.html#GOptionEntry" title="GOptionEntry"><span class="type">GOptionEntry</span></a>s
1382 <p class="since">Since 2.6</p>
1385 <div class="refsect2" title="GOptionParseFunc ()">
1386 <a name="GOptionParseFunc"></a><h3>GOptionParseFunc ()</h3>
1387 <pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> (*GOptionParseFunc) (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context,
1388 <a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="returnvalue">GOptionGroup</span></a> *group,
1389 <a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> data,
1390 <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="returnvalue">GError</span></a> **error);</pre>
1392 The type of function that can be called before and after parsing.</p>
1393 <div class="variablelist"><table border="0">
1394 <col align="left" valign="top">
1397 <td><p><span class="term"><em class="parameter"><code>context</code></em> :</span></p></td>
1398 <td> The active <a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="type">GOptionContext</span></a>
1402 <td><p><span class="term"><em class="parameter"><code>group</code></em> :</span></p></td>
1403 <td> The group to which the function belongs
1407 <td><p><span class="term"><em class="parameter"><code>data</code></em> :</span></p></td>
1408 <td> User data added to the <a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="type">GOptionGroup</span></a> containing the option when it
1409 was created with <a class="link" href="glib-Commandline-option-parser.html#g-option-group-new" title="g_option_group_new ()"><code class="function">g_option_group_new()</code></a>
1413 <td><p><span class="term"><em class="parameter"><code>error</code></em> :</span></p></td>
1414 <td> A return location for error details
1418 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
1419 <td> <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> if the function completed successfully, <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS" title="FALSE"><code class="literal">FALSE</code></a> if an error
1420 occurred, in which case <em class="parameter"><code>error</code></em> should be set with <a class="link" href="glib-Error-Reporting.html#g-set-error" title="g_set_error ()"><code class="function">g_set_error()</code></a>
1427 <div class="refsect2" title="g_option_group_set_parse_hooks ()">
1428 <a name="g-option-group-set-parse-hooks"></a><h3>g_option_group_set_parse_hooks ()</h3>
1429 <pre class="programlisting"><span class="returnvalue">void</span> g_option_group_set_parse_hooks (<a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="returnvalue">GOptionGroup</span></a> *group,
1430 <a class="link" href="glib-Commandline-option-parser.html#GOptionParseFunc" title="GOptionParseFunc ()"><span class="returnvalue">GOptionParseFunc</span></a> pre_parse_func,
1431 <a class="link" href="glib-Commandline-option-parser.html#GOptionParseFunc" title="GOptionParseFunc ()"><span class="returnvalue">GOptionParseFunc</span></a> post_parse_func);</pre>
1433 Associates two functions with <em class="parameter"><code>group</code></em> which will be called
1434 from <a class="link" href="glib-Commandline-option-parser.html#g-option-context-parse" title="g_option_context_parse ()"><code class="function">g_option_context_parse()</code></a> before the first option is parsed
1435 and after the last option has been parsed, respectively.
1438 Note that the user data to be passed to <em class="parameter"><code>pre_parse_func</code></em> and
1439 <em class="parameter"><code>post_parse_func</code></em> can be specified when constructing the group
1440 with <a class="link" href="glib-Commandline-option-parser.html#g-option-group-new" title="g_option_group_new ()"><code class="function">g_option_group_new()</code></a>.</p>
1441 <div class="variablelist"><table border="0">
1442 <col align="left" valign="top">
1445 <td><p><span class="term"><em class="parameter"><code>group</code></em> :</span></p></td>
1446 <td> a <a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="type">GOptionGroup</span></a>
1450 <td><p><span class="term"><em class="parameter"><code>pre_parse_func</code></em> :</span></p></td>
1451 <td> a function to call before parsing, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>
1455 <td><p><span class="term"><em class="parameter"><code>post_parse_func</code></em> :</span></p></td>
1456 <td> a function to call after parsing, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>
1461 <p class="since">Since 2.6</p>
1464 <div class="refsect2" title="GOptionErrorFunc ()">
1465 <a name="GOptionErrorFunc"></a><h3>GOptionErrorFunc ()</h3>
1466 <pre class="programlisting"><span class="returnvalue">void</span> (*GOptionErrorFunc) (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="returnvalue">GOptionContext</span></a> *context,
1467 <a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="returnvalue">GOptionGroup</span></a> *group,
1468 <a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> data,
1469 <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="returnvalue">GError</span></a> **error);</pre>
1471 The type of function to be used as callback when a parse error occurs.</p>
1472 <div class="variablelist"><table border="0">
1473 <col align="left" valign="top">
1476 <td><p><span class="term"><em class="parameter"><code>context</code></em> :</span></p></td>
1477 <td> The active <a class="link" href="glib-Commandline-option-parser.html#GOptionContext" title="GOptionContext"><span class="type">GOptionContext</span></a>
1481 <td><p><span class="term"><em class="parameter"><code>group</code></em> :</span></p></td>
1482 <td> The group to which the function belongs
1486 <td><p><span class="term"><em class="parameter"><code>data</code></em> :</span></p></td>
1487 <td> User data added to the <a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="type">GOptionGroup</span></a> containing the option when it
1488 was created with <a class="link" href="glib-Commandline-option-parser.html#g-option-group-new" title="g_option_group_new ()"><code class="function">g_option_group_new()</code></a>
1492 <td><p><span class="term"><em class="parameter"><code>error</code></em> :</span></p></td>
1493 <td> The <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a> containing details about the parse error
1500 <div class="refsect2" title="g_option_group_set_error_hook ()">
1501 <a name="g-option-group-set-error-hook"></a><h3>g_option_group_set_error_hook ()</h3>
1502 <pre class="programlisting"><span class="returnvalue">void</span> g_option_group_set_error_hook (<a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="returnvalue">GOptionGroup</span></a> *group,
1503 <a class="link" href="glib-Commandline-option-parser.html#GOptionErrorFunc" title="GOptionErrorFunc ()"><span class="returnvalue">GOptionErrorFunc</span></a> error_func);</pre>
1505 Associates a function with <em class="parameter"><code>group</code></em> which will be called
1506 from <a class="link" href="glib-Commandline-option-parser.html#g-option-context-parse" title="g_option_context_parse ()"><code class="function">g_option_context_parse()</code></a> when an error occurs.
1509 Note that the user data to be passed to <em class="parameter"><code>error_func</code></em> can be
1510 specified when constructing the group with <a class="link" href="glib-Commandline-option-parser.html#g-option-group-new" title="g_option_group_new ()"><code class="function">g_option_group_new()</code></a>.</p>
1511 <div class="variablelist"><table border="0">
1512 <col align="left" valign="top">
1515 <td><p><span class="term"><em class="parameter"><code>group</code></em> :</span></p></td>
1516 <td> a <a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="type">GOptionGroup</span></a>
1520 <td><p><span class="term"><em class="parameter"><code>error_func</code></em> :</span></p></td>
1521 <td> a function to call when an error occurs
1526 <p class="since">Since 2.6</p>
1529 <div class="refsect2" title="g_option_group_set_translate_func ()">
1530 <a name="g-option-group-set-translate-func"></a><h3>g_option_group_set_translate_func ()</h3>
1531 <pre class="programlisting"><span class="returnvalue">void</span> g_option_group_set_translate_func (<a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="returnvalue">GOptionGroup</span></a> *group,
1532 <a class="link" href="glib-Commandline-option-parser.html#GTranslateFunc" title="GTranslateFunc ()"><span class="returnvalue">GTranslateFunc</span></a> func,
1533 <a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> data,
1534 <a class="link" href="glib-Datasets.html#GDestroyNotify" title="GDestroyNotify ()"><span class="returnvalue">GDestroyNotify</span></a> destroy_notify);</pre>
1536 Sets the function which is used to translate user-visible
1537 strings, for <code class="option">--help</code> output. Different
1538 groups can use different <a class="link" href="glib-Commandline-option-parser.html#GTranslateFunc" title="GTranslateFunc ()"><span class="type">GTranslateFunc</span></a>s. If <em class="parameter"><code>func</code></em>
1539 is <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>, strings are not translated.
1542 If you are using <code class="function">gettext()</code>, you only need to set the translation
1543 domain, see <a class="link" href="glib-Commandline-option-parser.html#g-option-group-set-translation-domain" title="g_option_group_set_translation_domain ()"><code class="function">g_option_group_set_translation_domain()</code></a>.</p>
1544 <div class="variablelist"><table border="0">
1545 <col align="left" valign="top">
1548 <td><p><span class="term"><em class="parameter"><code>group</code></em> :</span></p></td>
1549 <td> a <a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="type">GOptionGroup</span></a>
1553 <td><p><span class="term"><em class="parameter"><code>func</code></em> :</span></p></td>
1554 <td> the <a class="link" href="glib-Commandline-option-parser.html#GTranslateFunc" title="GTranslateFunc ()"><span class="type">GTranslateFunc</span></a>, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>
1558 <td><p><span class="term"><em class="parameter"><code>data</code></em> :</span></p></td>
1559 <td> user data to pass to <em class="parameter"><code>func</code></em>, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>
1563 <td><p><span class="term"><em class="parameter"><code>destroy_notify</code></em> :</span></p></td>
1564 <td> a function which gets called to free <em class="parameter"><code>data</code></em>, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>
1569 <p class="since">Since 2.6</p>
1572 <div class="refsect2" title="g_option_group_set_translation_domain ()">
1573 <a name="g-option-group-set-translation-domain"></a><h3>g_option_group_set_translation_domain ()</h3>
1574 <pre class="programlisting"><span class="returnvalue">void</span> g_option_group_set_translation_domain
1575 (<a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="returnvalue">GOptionGroup</span></a> *group,
1576 const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *domain);</pre>
1578 A convenience function to use <code class="function">gettext()</code> for translating
1579 user-visible strings.</p>
1580 <div class="variablelist"><table border="0">
1581 <col align="left" valign="top">
1584 <td><p><span class="term"><em class="parameter"><code>group</code></em> :</span></p></td>
1585 <td> a <a class="link" href="glib-Commandline-option-parser.html#GOptionGroup" title="GOptionGroup"><span class="type">GOptionGroup</span></a>
1589 <td><p><span class="term"><em class="parameter"><code>domain</code></em> :</span></p></td>
1590 <td> the domain to use
1595 <p class="since">Since 2.6</p>
1599 <div class="footer">
1601 Generated by GTK-Doc V1.13</div>