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

📄 z77.html

📁 gtk_text program sample&eg
💻 HTML
📖 第 1 页 / 共 2 页
字号:
        after parsing, you have to combine a pair of flags with        <span class="STRUCTNAME">POPT_ARG_CALLBACK</span>. For        example, the following <span class="STRUCTNAME">struct        poptOption</span> initializer specifies a callback to be        invoked both before and after argument parsing:      </p>      <table border="0" bgcolor="#E0E0E0" width="100%">        <tr>          <td><pre class="PROGRAMLISTING">&#13;{ NULL, '\0', POPT_ARG_CALLBACK|POPT_CBFLAG_PRE|POPT_CBFLAG_POST,  &amp;parse_an_arg_callback, 0, NULL}&#13;</pre>          </td>        </tr>      </table>      <p>        The <span class="STRUCTNAME">opt</span> argument to the        callback is the <span class="STRUCTNAME">struct        poptOption</span> corresponding to the most recently-seen        command line option (you can access the <span class=         "STRUCTNAME">val</span> member of this struct to determine        which option you are looking at). The <span class=         "STRUCTNAME">arg</span> argument is the text of any        argument passed to the command line option; the <span        class="STRUCTNAME">data</span> argument is the callback        data, given as the <span class="STRUCTNAME">descrip</span>        member of the <span class="STRUCTNAME">struct        poptOption</span> which specified the callback.      </p>      <p>        The <span class="STRUCTNAME">flags</span> argument to <tt        class="FUNCTION">gnome_init_with_popt_table()</tt> can        basically be ignored in a Gnome context; the available        flags are not very useful.      </p>      <p>        If you pass a non-<span class="STRUCTNAME">NULL</span>        pointer for <span class="STRUCTNAME">return_ctx</span>, the        final argument to <tt class="FUNCTION">        gnome_init_with_popt_table()</tt>, the current context will        be returned; you can use this to extract the non-option        components of the command line, such as filenames. This is        done with the function <tt class="FUNCTION">        poptGetArgs()</tt>---here's an example:      </p>      <table border="0" bgcolor="#E0E0E0" width="100%">        <tr>          <td><pre class="PROGRAMLISTING">&#13;  char** args;  poptContext ctx;  int i;  bindtextdomain (PACKAGE, GNOMELOCALEDIR);  textdomain (PACKAGE);  gnome_init_with_popt_table(APPNAME, VERSION, argc, argv,                              options, 0, &amp;ctx);  args = poptGetArgs(ctx);  if (args != NULL)    {      i = 0;      while (args[i] != NULL)         {          /* Do something with each argument */          ++i;        }    }  poptFreeContext(ctx);&#13;</pre>          </td>        </tr>      </table>      <p>        Notice that you must free the <span class="STRUCTNAME">        poptContext</span> if you ask for it; however, if you pass        <span class="STRUCTNAME">NULL</span> for <span class=         "STRUCTNAME">return_ctx</span> the library will free it for        you. Also keep in mind that <tt class="FUNCTION">        poptGetArgs()</tt> will return <span class="STRUCTNAME">        NULL</span> if there are no arguments on the command line.      </p>      <div class="SECT2">        <h2 class="SECT2">          <a name="Z78">Argument Parsing in GnomeHello</a>        </h2>        <p>          The GnomeHello application outputs the following if you          invoke it with the <tt class="APPLICATION">--help</tt>          option:        </p>        <table border="0" bgcolor="#E0E0E0" width="100%">          <tr>            <td><pre class="PROGRAMLISTING">&#13;$ ./hello --helpUsage: hello [OPTION...]GNOME Options  --disable-sound             Disable sound server usage  --enable-sound              Enable sound server usage  --espeaker=HOSTNAME:PORT    Host:port on which the sound server to use is                              runningHelp options  -?, --help                  Show this help message  --usage                     Display brief usage messageGTK options  --gdk-debug=FLAGS           Gdk debugging flags to set  --gdk-no-debug=FLAGS        Gdk debugging flags to unset  --display=DISPLAY           X display to use  --sync                      Make X calls synchronous  --no-xshm                   Don't use X shared memory extension  --name=NAME                 Program name as used by the window manager  --class=CLASS               Program class as used by the window manager  --gxid_host=HOST  --gxid_port=PORT  --xim-preedit=STYLE  --xim-status=STYLE  --gtk-debug=FLAGS           Gtk+ debugging flags to set  --gtk-no-debug=FLAGS        Gtk+ debugging flags to unset  --g-fatal-warnings          Make all warnings fatal  --gtk-module=MODULE         Load an additional Gtk moduleGNOME GUI options  -V, --versionHelp options  -?, --help                  Show this help message  --usage                     Display brief usage messageSession management options  --sm-client-id=ID           Specify session management ID  --sm-config-prefix=PREFIX   Specify prefix of saved configuration  --sm-disable                Disable connection to session managerGnomeHello options  -g, --greet                 Say hello to specific people listed on the                              command line  -m, --message=MESSAGE       Specify a message other than "Hello, World!"  --geometry=GEOMETRY         Specify the geometry of the main window$ &#13;</pre>            </td>          </tr>        </table>        <p>          Almost all of these options are common to all Gnome          applications; only the last three, labelled "GnomeHello          options," are specific to GnomeHello. The <tt class=           "APPLICATION">--greet</tt> or <tt class="APPLICATION">          -g</tt> option turns on "greet mode"; GnomeHello will          expect a list of names on the command line, and create a          dialog to say hello to each person named. The <tt class=           "APPLICATION">--message</tt> option expects a string          argument which replaces the usual "Hello, World!"          message; the <tt class="APPLICATION">--geometry</tt>          option expects a standard X geometry string, specifying          the position and size of the main application window.        </p>        <p>          Here are the variables and <tt class="APPLICATION">          popt</tt> table GnomeHello uses to do its argument          parsing:        </p>        <table border="0" bgcolor="#E0E0E0" width="100%">          <tr>            <td><pre class="PROGRAMLISTING">&#13;static int greet_mode = FALSE;static char* message  = NULL;static char* geometry = NULL;struct poptOption options[] = {  {    "greet",    'g',    POPT_ARG_NONE,    &amp;greet_mode,    0,    N_("Say hello to specific people listed on the command line"),    NULL  },  {     "message",    'm',    POPT_ARG_STRING,    &amp;message,    0,    N_("Specify a message other than \"Hello, World!\""),    N_("MESSAGE")  },  {     "geometry",    '\0',    POPT_ARG_STRING,    &amp;geometry,    0,    N_("Specify the geometry of the main window"),    N_("GEOMETRY")  },  {    NULL,    '\0',    0,    NULL,    0,    NULL,    NULL  }};&#13;</pre>            </td>          </tr>        </table>        <p>          And here's the first part of <tt class="FUNCTION">          main()</tt>, where GnomeHello checks that the arguments          are properly combined and assembles a list of people to          greet:        </p>        <table border="0" bgcolor="#E0E0E0" width="100%">          <tr>            <td><pre class="PROGRAMLISTING">&#13;  GtkWidget* app;    poptContext pctx;  char** args;  int i;  GSList* greet = NULL;  GnomeClient* client;  bindtextdomain(PACKAGE, GNOMELOCALEDIR);    textdomain(PACKAGE);  gnome_init_with_popt_table(PACKAGE, VERSION, argc, argv,                              options, 0, &amp;pctx);    /* Argument parsing */  args = poptGetArgs(pctx);  if (greet_mode &amp;&amp; args)    {      i = 0;      while (args[i] != NULL)         {          greet = g_slist_prepend(greet, args[i]);          ++i;        }      /* Put them in order */      greet = g_slist_reverse(greet);     }  else if (greet_mode &amp;&amp; args == NULL)    {      g_error(_("You must specify someone to greet."));    }  else if (args != NULL)    {      g_error(_("Command line arguments are only allowed with --greet."));    }  else    {       g_assert(!greet_mode &amp;&amp; args == NULL);    }  poptFreeContext(pctx);&#13;</pre>            </td>          </tr>        </table>        <p>          Again, complete source for GnomeHello is included in          Appendix E.        </p>      </div>    </div>    <div class="NAVFOOTER">      <br>      <br>      <table width="100%" border="0" bgcolor="#ffffff" cellpadding=       "1" cellspacing="0">        <tr>          <td width="25%" bgcolor="#ffffff" align="left">            <a href="sec-i18n.html"><font color="#0000ff" size="2">            <b>&lt;&lt;&lt; Previous</b></font></a>          </td>          <td width="25%" colspan="2" bgcolor="#ffffff" align=           "center">            <font color="#0000ff" size="2"><b><a href="ggad.html">            <font color="#0000ff" size="2"><b>            Home</b></font></a></b></font>          </td>          <td width="25%" bgcolor="#ffffff" align="right">            <a href="z79.html"><font color="#0000ff" size="2"><b>            Next &gt;&gt;&gt;</b></font></a>          </td>        </tr>        <tr>          <td colspan="2" align="left">            <font color="#000000" size="2"><b>            Internationalization</b></font>          </td>          <td colspan="2" align="right">            <font color="#000000" size="2"><b>Saving Configuration            Information</b></font>          </td>        </tr>      </table>    </div>  </body></html>

⌨️ 快捷键说明

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