?? glib-commandline-option-parser.html
字號:
<p>Error domain for option parsing. Errors in this domain willbe from the <a href="glib-Commandline-option-parser.html#GOptionError"><span class="type">GOptionError</span></a> enumeration. See <a href="glib-Error-Reporting.html#GError"><span class="type">GError</span></a> for information on error domains.</p></div><hr><div class="refsect2" lang="en"><a name="id3063585"></a><h3><a name="GOptionArgFunc"></a>GOptionArgFunc ()</h3><a class="indexterm" name="id3063596"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gboolean">gboolean</a> (*GOptionArgFunc) (const <a href="glib-Basic-Types.html#gchar">gchar</a> *option_name, const <a href="glib-Basic-Types.html#gchar">gchar</a> *value, <a href="glib-Basic-Types.html#gpointer">gpointer</a> data, <a href="glib-Error-Reporting.html#GError">GError</a> **error);</pre><p>The type of function to be passed as callback for <code class="literal">G_OPTION_ARG_CALLBACK</code>options.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>option_name</code></em> :</span></td><td>The name of the option being parsed. This will be either a single dash followed by a single letter (for a short name) or two dashes followed by a long option name.</td></tr><tr><td><span class="term"><em class="parameter"><code>value</code></em> :</span></td><td>The value to be parsed.</td></tr><tr><td><span class="term"><em class="parameter"><code>data</code></em> :</span></td><td>User data added to the <a href="glib-Commandline-option-parser.html#GOptionGroup"><span class="type">GOptionGroup</span></a> containing the option when it was created with <a href="glib-Commandline-option-parser.html#g-option-group-new"><code class="function">g_option_group_new()</code></a></td></tr><tr><td><span class="term"><em class="parameter"><code>error</code></em> :</span></td><td>A return location for errors. The error code <code class="literal">G_OPTION_ERROR_FAILED</code> is intended to be used for errors in <a href="glib-Commandline-option-parser.html#GOptionArgFunc"><span class="type">GOptionArgFunc</span></a> callbacks.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td><code class="literal">TRUE</code> if the option was successfully parsed, <code class="literal">FALSE</code> if an error occurred</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3063774"></a><h3><a name="GOptionContext"></a>GOptionContext</h3><a class="indexterm" name="id3063785"></a><pre class="programlisting">typedef struct _GOptionContext GOptionContext;</pre><p>A <span class="structname">GOptionContext</span> struct defines which optionsare accepted by the commandline option parser. The struct has only private fields and should not be directly accessed.</p></div><hr><div class="refsect2" lang="en"><a name="id3063807"></a><h3><a name="g-option-context-new"></a>g_option_context_new ()</h3><a class="indexterm" name="id3063818"></a><pre class="programlisting"><a href="glib-Commandline-option-parser.html#GOptionContext">GOptionContext</a>* g_option_context_new (const <a href="glib-Basic-Types.html#gchar">gchar</a> *parameter_string);</pre><p>Creates a new option context.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>parameter_string</code></em> :</span></td><td> a string which is displayed in the first line of <code class="option">--help</code> output, after <code class="literal"><em class="replaceable"><code>programname</code></em> [OPTION...]</code></td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> a newly created <a href="glib-Commandline-option-parser.html#GOptionContext"><span class="type">GOptionContext</span></a>, which must be freed with <a href="glib-Commandline-option-parser.html#g-option-context-free"><code class="function">g_option_context_free()</code></a> after use.</td></tr></tbody></table></div><p>Since 2.6</p></div><hr><div class="refsect2" lang="en"><a name="id3063917"></a><h3><a name="g-option-context-free"></a>g_option_context_free ()</h3><a class="indexterm" name="id3063928"></a><pre class="programlisting">void g_option_context_free (<a href="glib-Commandline-option-parser.html#GOptionContext">GOptionContext</a> *context);</pre><p>Frees context and all the groups which have been added to it.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>context</code></em> :</span></td><td> a <a href="glib-Commandline-option-parser.html#GOptionContext"><span class="type">GOptionContext</span></a> </td></tr></tbody></table></div><p>Since 2.6</p></div><hr><div class="refsect2" lang="en"><a name="id3063991"></a><h3><a name="g-option-context-parse"></a>g_option_context_parse ()</h3><a class="indexterm" name="id3064002"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gboolean">gboolean</a> g_option_context_parse (<a href="glib-Commandline-option-parser.html#GOptionContext">GOptionContext</a> *context, <a href="glib-Basic-Types.html#gint">gint</a> *argc, <a href="glib-Basic-Types.html#gchar">gchar</a> ***argv, <a href="glib-Error-Reporting.html#GError">GError</a> **error);</pre><p>Parses the command line arguments, recognizing optionswhich have been added to <em class="parameter"><code>context</code></em>. A side-effect of calling this function is that <a href="glib-Miscellaneous-Utility-Functions.html#g-set-prgname"><code class="function">g_set_prgname()</code></a> will becalled.</p><p>If the parsing is successful, any parsed arguments areremoved from the array and <em class="parameter"><code>argc</code></em> and <em class="parameter"><code>argv</code></em> are updated accordingly. A '--' option is stripped from <em class="parameter"><code>argv</code></em>unless there are unparsed options before and after it, or some of the options after it start with '-'. In case of an error, <em class="parameter"><code>argc</code></em> and <em class="parameter"><code>argv</code></em> are left unmodified. </p><p>If automatic <code class="option">--help</code> support is enabled(see <a href="glib-Commandline-option-parser.html#g-option-context-set-help-enabled"><code class="function">g_option_context_set_help_enabled()</code></a>), and the <em class="parameter"><code>argv</code></em> array contains one of the recognized help options,this function will produce help output to stdout andcall <code class="literal">exit (0)</code>.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>context</code></em> :</span></td><td> a <a href="glib-Commandline-option-parser.html#GOptionContext"><span class="type">GOptionContext</span></a></td></tr><tr><td><span class="term"><em class="parameter"><code>argc</code></em> :</span></td><td> a pointer to the number of command line arguments.</td></tr><tr><td><span class="term"><em class="parameter"><code>argv</code></em> :</span></td><td> a pointer to the array of command line arguments.</td></tr><tr><td><span class="term"><em class="parameter"><code>error</code></em> :</span></td><td> a return location for errors </td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> <code class="literal">TRUE</code> if the parsing was successful, <code class="literal">FALSE</code> if an error occurred</td></tr></tbody></table></div><p>Since 2.6</p></div><hr><div class="refsect2" lang="en"><a name="id3064243"></a><h3><a name="g-option-context-set-help-enabled"></a>g_option_context_set_help_enabled ()</h3><a class="indexterm" name="id3064255"></a><pre class="programlisting">void g_option_context_set_help_enabled (<a href="glib-Commandline-option-parser.html#GOptionContext">GOptionContext</a> *context, <a href="glib-Basic-Types.html#gboolean">gboolean</a> help_enabled);</pre><p>Enables or disables automatic generation of <code class="option">--help</code> output. By default, <a href="glib-Commandline-option-parser.html#g-option-context-parse"><code class="function">g_option_context_parse()</code></a> recognizes<code class="option">--help</code>, <code class="option">-?</code>, <code class="option">--help-all</code>and <code class="option">--help-</code><em class="replaceable"><code>groupname</code></em> and createssuitable output to stdout.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>context</code></em> :</span></td><td> a <a href="glib-Commandline-option-parser.html#GOptionContext"><span class="type">GOptionContext</span></a></td></tr><tr><td><span class="term"><em class="parameter"><code>help_enabled</code></em> :</span></td><td> <code class="literal">TRUE</code> to enable <code class="option">--help</code>, <code class="literal">FALSE</code> to disable it</td></tr></tbody></table></div><p>Since 2.6</p></div><hr><div class="refsect2" lang="en"><a name="id3064388"></a><h3><a name="g-option-context-get-help-enabled"></a>g_option_context_get_help_enabled ()</h3><a class="indexterm" name="id3064400"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gboolean">gboolean</a> g_option_context_get_help_enabled (<a href="glib-Commandline-option-parser.html#GOptionContext">GOptionContext</a> *context);</pre><p>Returns whether automatic <code class="option">--help</code> generationis turned on for <em class="parameter"><code>context</code></em>. See <a href="glib-Commandline-option-parser.html#g-option-context-set-help-enabled"><code class="function">g_option_context_set_help_enabled()</code></a>.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>context</code></em> :</span></td><td> a <a href="glib-Commandline-option-parser.html#GOptionContext"><span class="type">GOptionContext</span></a></td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> <code class="literal">TRUE</code> if automatic help generation is turned on.</td></tr></tbody></table></div><p>Since 2.6</p></div><hr><div class="refsect2" lang="en"><a name="id3064501"></a><h3><a name="g-option-context-set-ignore-unknown-options"></a>g_option_context_set_ignore_unknown_options ()</h3><a class="indexterm" name="id3064514"></a><pre class="programlisting">void g_option_context_set_ignore_unknown_options (<a href="glib-Commandline-option-parser.html#GOptionContext">GOptionContext</a> *context, <a href="glib-Basic-Types.html#gboolean">gboolean</a> ignore_unknown);</pre><p>Sets whether to ignore unknown options or not. If an argument is ignored, it is left in the <em class="parameter"><code>argv</code></em> array after parsing. By default,
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -