X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=glib%2Fgoption.c;h=6438281200d255758b6feefd79b721db479a7245;hb=49b59e5ac4428a6a99a85d699c3662f96efc4e9d;hp=da04596f5787bbb336ff376b2da397e11b907417;hpb=7f36233042691d942982c4e6c4ea16f7e27aeb6b;p=platform%2Fupstream%2Fglib.git diff --git a/glib/goption.c b/glib/goption.c index da04596..6438281 100644 --- a/glib/goption.c +++ b/glib/goption.c @@ -26,7 +26,7 @@ * for the popt library. It supports short and long commandline options, * as shown in the following example: * - * testtreemodel -r 1 --max-size 20 --rand --display=:1.0 -vb -- file1 file2 + * `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: @@ -52,14 +52,11 @@ * 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 , , - * and - * 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. - * - * + * 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: * testtreemodel [OPTION...] - test tree model performance * @@ -75,7 +72,7 @@ * -v, --verbose Be verbose * -b, --beep Beep when done * --rand Randomize the data - * + * ]| * * GOption groups options in #GOptionGroups, which makes it easy to * incorporate options from multiple sources. The intended use for this is @@ -123,7 +120,7 @@ * exit (1); * } * - * /* ... */ + * ... * * } * ]| @@ -164,18 +161,18 @@ * 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); * - * /* ... */ + * ... * } * ]| */ @@ -188,9 +185,7 @@ #include #if defined __OpenBSD__ -#include #include -#include #include #endif @@ -326,9 +321,8 @@ G_DEFINE_QUARK (g-option-context-error-quark, g_option_error) /** * g_option_context_new: * @parameter_string: (allow-none): a string which is displayed in - * the first line of output, after the - * usage summary - * programname [OPTION...] + * the first line of `--help` output, after the usage summary + * `programname [OPTION...]` * * Creates a new option context. * @@ -408,14 +402,12 @@ void g_option_context_free (GOptionContext *context) /** * g_option_context_set_help_enabled: * @context: a #GOptionContext - * @help_enabled: %TRUE to enable , %FALSE to disable it + * @help_enabled: %TRUE to enable `--help`, %FALSE to disable it * - * Enables or disables automatic generation of - * output. By default, g_option_context_parse() recognizes - * , , - * , - * and groupname 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 */ @@ -432,7 +424,7 @@ void g_option_context_set_help_enabled (GOptionContext *context, * g_option_context_get_help_enabled: * @context: a #GOptionContext * - * Returns whether automatic generation + * Returns whether automatic `--help` generation * is turned on for @context. See g_option_context_set_help_enabled(). * * Returns: %TRUE if automatic help generation is turned on. @@ -537,7 +529,7 @@ g_option_context_add_group (GOptionContext *context, * Sets a #GOptionGroup as main group of the @context. * This has the same effect as calling g_option_context_add_group(), * the only difference is that the options in the main group are - * treated differently when generating output. + * treated differently when generating `--help` output. * * Since: 2.6 **/ @@ -564,7 +556,7 @@ g_option_context_set_main_group (GOptionContext *context, * * 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. * @@ -583,7 +575,7 @@ g_option_context_get_main_group (GOptionContext *context) * @context: a #GOptionContext * @entries: a %NULL-terminated array of #GOptionEntrys * @translation_domain: (allow-none): a translation domain to use for translating - * the output for the options in @entries + * the `--help` output for the options in @entries * with gettext(), or %NULL * * A convenience function which creates a main group if it doesn't @@ -755,12 +747,12 @@ context_has_h_entry (GOptionContext *context) * @group: (allow-none): the #GOptionGroup to create help for, or %NULL * * Returns a formatted, translated help text for the given context. - * To obtain the text produced by , call - * g_option_context_get_help (context, TRUE, NULL). - * To obtain the text produced by , call - * g_option_context_get_help (context, FALSE, NULL). + * To obtain the text produced by `--help`, call + * `g_option_context_get_help (context, TRUE, NULL)`. + * To obtain the text produced by `--help-all`, call + * `g_option_context_get_help (context, FALSE, NULL)`. * To obtain the help text for an option group, call - * g_option_context_get_help (context, FALSE, group). + * `g_option_context_get_help (context, FALSE, group)`. * * Returns: A newly allocated string containing the help text * @@ -1196,8 +1188,8 @@ parse_arg (GOptionContext *context, { 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; @@ -1769,13 +1761,16 @@ platform_get_argv0 (void) 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) { @@ -1814,18 +1809,17 @@ platform_get_argv0 (void) * or some of the options after it start with '-'. In case * of an error, @argc and @argv are left unmodified. * - * If automatic support is enabled + * If automatic `--help` support is enabled * (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 exit (0). + * call `exit (0)`. * - * Note that function depends on the - * current locale 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 @@ -2044,6 +2038,7 @@ g_option_context_parse (GOptionContext *context, if (new_arg) new_arg[arg_index] = '\0'; add_pending_null (context, &((*argv)[i]), new_arg); + i = new_i; } else if (parsed) { @@ -2157,11 +2152,11 @@ g_option_context_parse (GOptionContext *context, /** * g_option_group_new: * @name: the name for the option group, this is used to provide - * help for the options in this group with @name + * help for the options in this group with `--help-`@name * @description: a description for this group to be shown in - * . This string is translated using the translation + * `--help`. This string is translated using the translation * domain or translation function of the group - * @help_description: a description for the @name option. + * @help_description: a description for the `--help-`@name option. * This string is translated using the translation domain or translation function * of the group * @user_data: (allow-none): user data that will be passed to the pre- and post-parse hooks, @@ -2170,7 +2165,7 @@ g_option_context_parse (GOptionContext *context, * * 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 @@ -2339,10 +2334,9 @@ g_option_group_set_error_hook (GOptionGroup *group, * @data: (allow-none): user data to pass to @func, or %NULL * @destroy_notify: (allow-none): a function which gets called to free @data, or %NULL * - * Sets the function which is used to translate user-visible - * strings, for output. Different - * groups can use different #GTranslateFuncs. If @func - * is %NULL, strings are not translated. + * Sets the function which is used to translate user-visible strings, + * for `--help` output. Different groups can use different + * #GTranslateFuncs. If @func is %NULL, strings are not translated. * * If you are using gettext(), you only need to set the translation * domain, see g_option_group_set_translation_domain(). @@ -2402,8 +2396,8 @@ g_option_group_set_translation_domain (GOptionGroup *group, * @destroy_notify: (allow-none): a function which gets called to free @data, or %NULL * * Sets the function which is used to translate the contexts - * user-visible strings, for output. - * If @func is %NULL, strings are not translated. + * user-visible strings, for `--help` output. If @func is %NULL, + * strings are not translated. * * Note that option groups have their own translation functions, * this function only affects the @parameter_string (see g_option_context_new()), @@ -2456,12 +2450,11 @@ g_option_context_set_translation_domain (GOptionContext *context, /** * g_option_context_set_summary: * @context: a #GOptionContext - * @summary: (allow-none): a string to be shown in output + * @summary: (allow-none): a string to be shown in `--help` output * before the list of options, or %NULL * - * Adds a string to be displayed in output - * before the list of options. This is typically a summary of the - * program functionality. + * Adds a string to be displayed in `--help` output before the list + * of options. This is typically a summary of the program functionality. * * Note that the summary is translated (see * g_option_context_set_translate_func() and @@ -2501,12 +2494,11 @@ g_option_context_get_summary (GOptionContext *context) /** * g_option_context_set_description: * @context: a #GOptionContext - * @description: (allow-none): a string to be shown in output + * @description: (allow-none): a string to be shown in `--help` output * after the list of options, or %NULL * - * Adds a string to be displayed in output - * after the list of options. This text often includes a bug reporting - * address. + * Adds a string to be displayed in `--help` output after the list + * of options. This text often includes a bug reporting address. * * Note that the summary is translated (see * g_option_context_set_translate_func()).