* for the popt library. It supports short and long commandline options,
* as shown in the following example:
*
- * <literal>testtreemodel -r 1 --max-size 20 --rand --display=:1.0 -vb -- file1 file2</literal>
+ * `testtreemodel -r 1 --max-size 20 --rand --display=:1.0 -vb -- file1 file2`
*
* The example demonstrates a number of features of the GOption
* commandline parser:
* Another important feature of GOption is that it can automatically
* generate nicely formatted help output. Unless it is explicitly turned
* off with g_option_context_set_help_enabled(), GOption will recognize
- * the `--help`, `-?`, `--help-all` and
- * `--help-`<replaceable>groupname</replaceable> options
- * (where <replaceable>groupname</replaceable> is the name of a
- * #GOptionGroup) and write a text similar to the one shown in the
- * following example to stdout.
+ * the `--help`, `-?`, `--help-all` and `--help-groupname` options
+ * (where `groupname` is the name of a #GOptionGroup) and write a text
+ * similar to the one shown in the following example to stdout.
*
* |[
* Usage:
* exit (1);
* }
*
- * /* ... */
+ * ...
*
* }
* ]|
* args = g_strdupv (argv);
* #endif
*
- * /* ... setup context ... */
+ * // set up context
*
* if (!g_option_context_parse_strv (context, &args, &error))
* {
- * /* ... error ... */
+ * // error happened
* }
*
- * /* ... */
+ * ...
*
* g_strfreev (args);
*
- * /* ... */
+ * ...
* }
* ]|
*/
#include <errno.h>
#if defined __OpenBSD__
-#include <sys/types.h>
#include <unistd.h>
-#include <sys/param.h>
#include <sys/sysctl.h>
#endif
/**
* g_option_context_new:
* @parameter_string: (allow-none): a string which is displayed in
- * the first line of `--help` output, after the
- * usage summary
- * <literal><replaceable>programname</replaceable> [OPTION...]</literal>
+ * the first line of `--help` output, after the usage summary
+ * `programname [OPTION...]`
*
* Creates a new option context.
*
* @context: a #GOptionContext
* @help_enabled: %TRUE to enable `--help`, %FALSE to disable it
*
- * Enables or disables automatic generation of `--help`
- * output. By default, g_option_context_parse() recognizes
- * `--help`, `-h`, `-?`, `--help-all`
- * and `--help-`<replaceable>groupname</replaceable> and creates
- * suitable output to stdout.
+ * Enables or disables automatic generation of `--help` output.
+ * By default, g_option_context_parse() recognizes `--help`, `-h`,
+ * `-?`, `--help-all` and `--help-groupname` and creates suitable
+ * output to stdout.
*
* Since: 2.6
*/
*
* Returns a pointer to the main group of @context.
*
- * Return value: the main group of @context, or %NULL if @context doesn't
+ * Returns: the main group of @context, or %NULL if @context doesn't
* have a main group. Note that group belongs to @context and should
* not be modified or freed.
*
*
* Returns a formatted, translated help text for the given context.
* To obtain the text produced by `--help`, call
- * <literal>g_option_context_get_help (context, TRUE, NULL)</literal>.
+ * `g_option_context_get_help (context, TRUE, NULL)`.
* To obtain the text produced by `--help-all`, call
- * <literal>g_option_context_get_help (context, FALSE, NULL)</literal>.
+ * `g_option_context_get_help (context, FALSE, NULL)`.
* To obtain the help text for an option group, call
- * <literal>g_option_context_get_help (context, FALSE, group)</literal>.
+ * `g_option_context_get_help (context, FALSE, group)`.
*
* Returns: A newly allocated string containing the help text
*
{
case G_OPTION_ARG_NONE:
{
- change = get_change (context, G_OPTION_ARG_NONE,
- entry->arg_data);
+ (void) get_change (context, G_OPTION_ARG_NONE,
+ entry->arg_data);
*(gboolean *)entry->arg_data = !(entry->flags & G_OPTION_FLAG_REVERSE);
break;
g_free (cmdline);
return base_arg0;
#elif defined __OpenBSD__
- char **cmdline = NULL;
+ char **cmdline;
char *base_arg0;
- gsize len = PATH_MAX;
+ gsize len;
int mib[] = { CTL_KERN, KERN_PROC_ARGS, getpid(), KERN_PROC_ARGV };
- cmdline = (char **) realloc (cmdline, len);
+ if (sysctl (mib, G_N_ELEMENTS (mib), NULL, &len, NULL, 0) == -1)
+ return NULL;
+
+ cmdline = g_malloc0 (len);
if (sysctl (mib, G_N_ELEMENTS (mib), cmdline, &len, NULL, 0) == -1)
{
* (see g_option_context_set_help_enabled()), and the
* @argv array contains one of the recognized help options,
* this function will produce help output to stdout and
- * call <literal>exit (0)</literal>.
+ * call `exit (0)`.
*
- * Note that function depends on the
- * <link linkend="setlocale">current locale</link> for
+ * Note that function depends on the [current locale][setlocale] for
* automatic character set conversion of string and filename
* arguments.
*
- * Return value: %TRUE if the parsing was successful,
+ * Returns: %TRUE if the parsing was successful,
* %FALSE if an error occurred
*
* Since: 2.6
if (new_arg)
new_arg[arg_index] = '\0';
add_pending_null (context, &((*argv)[i]), new_arg);
+ i = new_i;
}
else if (parsed)
{
*
* Creates a new #GOptionGroup.
*
- * Return value: a newly created option group. It should be added
+ * Returns: a newly created option group. It should be added
* to a #GOptionContext or freed with g_option_group_free().
*
* Since: 2.6