⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 glib-commandline-option-parser.html

📁 最新gtk中文资料集
💻 HTML
📖 第 1 页 / 共 5 页
字号:
static gint max_size = 8;static gboolean verbose = FALSE;static gboolean beep = FALSE;static gboolean rand = FALSE;static GOptionEntry entries[] = {  { "repeats", 'r', 0, G_OPTION_ARG_INT, &amp;repeats, "Average over N repetitions", "N" },  { "max-size", 'm', 0, G_OPTION_ARG_INT, &amp;max_size, "Test up to 2^M items", "M" },  { "verbose", 'v', 0, G_OPTION_ARG_NONE, &amp;verbose, "Be verbose", NULL },  { "beep", 'b', 0, G_OPTION_ARG_NONE, &amp;beep, "Beep when done", NULL },  { "rand", 0, 0, G_OPTION_ARG_NONE, &amp;rand, "Randomize the data", NULL },  { NULL }};int main (int argc, char *argv[]){  GError *error = NULL;  GOptionContext *context;  context = g_option_context_new ("- test tree model performance");  g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);  g_option_context_add_group (context, gtk_get_option_group (TRUE));  if (!g_option_context_parse (context, &amp;argc, &amp;argv, &amp;error))    {      g_print ("option parsing failed: %s\n", error-&gt;message);      exit (1);    }  /* ... */}</pre></div></div><div class="refsect1" lang="en"><a name="id3126838"></a><h2>Details</h2><div class="refsect2" lang="en"><a name="id3126849"></a><h3><a name="GOptionError"></a>enum GOptionError</h3><a class="indexterm" name="id3126862"></a><pre class="programlisting">typedef enum{  G_OPTION_ERROR_UNKNOWN_OPTION,  G_OPTION_ERROR_BAD_VALUE,  G_OPTION_ERROR_FAILED} GOptionError;</pre><p>Error codes returned by option parsing.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><a name="G-OPTION-ERROR-UNKNOWN-OPTION:CAPS"></a><code class="literal">G_OPTION_ERROR_UNKNOWN_OPTION</code></span></p></td><td>An option was not known to the parser.  This error will only be reported, if the parser hasn't been instructed  to ignore unknown options, see <a class="link" href="glib-Commandline-option-parser.html#g-option-context-set-ignore-unknown-options"><code class="function">g_option_context_set_ignore_unknown_options()</code></a>.</td></tr><tr><td><p><span class="term"><a name="G-OPTION-ERROR-BAD-VALUE:CAPS"></a><code class="literal">G_OPTION_ERROR_BAD_VALUE</code></span></p></td><td>A value couldn't be parsed.</td></tr><tr><td><p><span class="term"><a name="G-OPTION-ERROR-FAILED:CAPS"></a><code class="literal">G_OPTION_ERROR_FAILED</code></span></p></td><td>A <a class="link" href="glib-Commandline-option-parser.html#GOptionArgFunc"><span class="type">GOptionArgFunc</span></a> callback failed.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3126974"></a><h3><a name="G-OPTION-ERROR:CAPS"></a>G_OPTION_ERROR</h3><a class="indexterm" name="id3126987"></a><pre class="programlisting">#define G_OPTION_ERROR (g_option_error_quark ())</pre><p>Error domain for option parsing. Errors in this domain willbe from the <a class="link" href="glib-Commandline-option-parser.html#GOptionError"><span class="type">GOptionError</span></a> enumeration. See <a class="link" 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="id3127020"></a><h3><a name="GOptionArgFunc"></a>GOptionArgFunc ()</h3><a class="indexterm" name="id3127033"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a>            (*GOptionArgFunc)                   (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *option_name,                                                         const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *value,                                                         <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> data,                                                         <a class="link" href="glib-Error-Reporting.html#GError">GError</a> **error);</pre><p>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>options.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>option_name</code></em>&#160;:</span></p></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><p><span class="term"><em class="parameter"><code>value</code></em>&#160;:</span></p></td><td>The value to be parsed.</td></tr><tr><td><p><span class="term"><em class="parameter"><code>data</code></em>&#160;:</span></p></td><td>User data added to the <a class="link" href="glib-Commandline-option-parser.html#GOptionGroup"><span class="type">GOptionGroup</span></a> containing the option when it  was created with <a class="link" href="glib-Commandline-option-parser.html#g-option-group-new"><code class="function">g_option_group_new()</code></a></td></tr><tr><td><p><span class="term"><em class="parameter"><code>error</code></em>&#160;:</span></p></td><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>  is intended to be used for errors in <a class="link" href="glib-Commandline-option-parser.html#GOptionArgFunc"><span class="type">GOptionArgFunc</span></a> callbacks.</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td><td><a class="link" href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if the option was successfully parsed, <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> if an error   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"><code class="function">g_set_error()</code></a></td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3127249"></a><h3><a name="GOptionContext"></a>GOptionContext</h3><a class="indexterm" name="id3127262"></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="id3127284"></a><h3><a name="g-option-context-new"></a>g_option_context_new ()</h3><a class="indexterm" name="id3127299"></a><pre class="programlisting"><a class="link" href="glib-Commandline-option-parser.html#GOptionContext">GOptionContext</a>*     g_option_context_new                (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *parameter_string);</pre><p>Creates a new option context. </p><p>The <em class="parameter"><code>parameter_string</code></em> can serve multiple purposes. It can be usedto add descriptions for "rest" arguments, which are not parsed bythe <a class="link" href="glib-Commandline-option-parser.html#GOptionContext"><span class="type">GOptionContext</span></a>, typically something like "FILES" or"FILE1 FILE2...". If you are using <a class="link" href="glib-Commandline-option-parser.html#G-OPTION-REMAINING:CAPS"><span class="type">G_OPTION_REMAINING</span></a> forcollecting "rest" arguments, GLib handles this automatically byusing the <em class="parameter"><code>arg_description</code></em> of the corresponding <a class="link" href="glib-Commandline-option-parser.html#GOptionEntry"><span class="type">GOptionEntry</span></a> inthe usage summary.</p><p>Another usage is to give a short summary of the programfunctionality, like " - frob the strings", which will be displayedin the same line as the usage. For a longer description of theprogram functionality that should be displayed as a paragraphbelow the usage line, use <a class="link" href="glib-Commandline-option-parser.html#g-option-context-set-summary"><code class="function">g_option_context_set_summary()</code></a>.</p><p>Note that the <em class="parameter"><code>parameter_string</code></em> is translated using thefunction set with <a class="link" href="glib-Commandline-option-parser.html#g-option-context-set-translate-func"><code class="function">g_option_context_set_translate_func()</code></a>, soit should normally be passed untranslated.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>parameter_string</code></em>&#160;:</span></p></td><td> a string which is displayed in   the first line of <code class="option">--help</code> output, after the   usage summary    <code class="literal"><em class="replaceable"><code>programname</code></em> [OPTION...]</code></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td><td> a newly created <a class="link" href="glib-Commandline-option-parser.html#GOptionContext"><span class="type">GOptionContext</span></a>, which must be   freed with <a class="link" 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 class="since">Since  2.6</p></div><hr><div class="refsect2" lang="en"><a name="id3127488"></a><h3><a name="g-option-context-set-summary"></a>g_option_context_set_summary ()</h3><a class="indexterm" name="id3127504"></a><pre class="programlisting">void                g_option_context_set_summary        (<a class="link" href="glib-Commandline-option-parser.html#GOptionContext">GOptionContext</a> *context,                                                         const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *summary);</pre><p>Adds a string to be displayed in <code class="option">--help</code> outputbefore the list of options. This is typically a summary of theprogram functionality. </p><p>Note that the summary is translated (see <a class="link" href="glib-Commandline-option-parser.html#g-option-context-set-translate-func"><code class="function">g_option_context_set_translate_func()</code></a>, <a class="link" href="glib-Commandline-option-parser.html#g-option-context-set-translation-domain"><code class="function">g_option_context_set_translation_domain()</code></a>).</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>context</code></em>&#160;:</span></p></td><td> a <a class="link" href="glib-Commandline-option-parser.html#GOptionContext"><span class="type">GOptionContext</span></a></td></tr>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -