diff options
Diffstat (limited to 'subversion/libsvn_subr/opt.c')
-rw-r--r-- | subversion/libsvn_subr/opt.c | 222 |
1 files changed, 124 insertions, 98 deletions
diff --git a/subversion/libsvn_subr/opt.c b/subversion/libsvn_subr/opt.c index fd8c73a..1a9beb6 100644 --- a/subversion/libsvn_subr/opt.c +++ b/subversion/libsvn_subr/opt.c @@ -55,8 +55,8 @@ /*** Code. ***/ -const svn_opt_subcommand_desc2_t * -svn_opt_get_canonical_subcommand2(const svn_opt_subcommand_desc2_t *table, +const svn_opt_subcommand_desc3_t * +svn_opt_get_canonical_subcommand3(const svn_opt_subcommand_desc3_t *table, const char *cmd_name) { int i = 0; @@ -80,9 +80,9 @@ svn_opt_get_canonical_subcommand2(const svn_opt_subcommand_desc2_t *table, } const apr_getopt_option_t * -svn_opt_get_option_from_code2(int code, +svn_opt_get_option_from_code3(int code, const apr_getopt_option_t *option_table, - const svn_opt_subcommand_desc2_t *command, + const svn_opt_subcommand_desc3_t *command, apr_pool_t *pool) { apr_size_t i; @@ -111,34 +111,19 @@ svn_opt_get_option_from_code2(int code, return NULL; } - -const apr_getopt_option_t * -svn_opt_get_option_from_code(int code, - const apr_getopt_option_t *option_table) -{ - apr_size_t i; - - for (i = 0; option_table[i].optch; i++) - if (option_table[i].optch == code) - return &(option_table[i]); - - return NULL; -} - - -/* Like svn_opt_get_option_from_code2(), but also, if CODE appears a second +/* Like svn_opt_get_option_from_code3(), but also, if CODE appears a second * time in OPTION_TABLE with a different name, then set *LONG_ALIAS to that * second name, else set it to NULL. */ static const apr_getopt_option_t * -get_option_from_code(const char **long_alias, - int code, - const apr_getopt_option_t *option_table, - const svn_opt_subcommand_desc2_t *command, - apr_pool_t *pool) +get_option_from_code3(const char **long_alias, + int code, + const apr_getopt_option_t *option_table, + const svn_opt_subcommand_desc3_t *command, + apr_pool_t *pool) { const apr_getopt_option_t *i; const apr_getopt_option_t *opt - = svn_opt_get_option_from_code2(code, option_table, command, pool); + = svn_opt_get_option_from_code3(code, option_table, command, pool); /* Find a long alias in the table, if there is one. */ *long_alias = NULL; @@ -205,7 +190,7 @@ svn_opt_format_option(const char **string, svn_boolean_t -svn_opt_subcommand_takes_option3(const svn_opt_subcommand_desc2_t *command, +svn_opt_subcommand_takes_option4(const svn_opt_subcommand_desc3_t *command, int option_code, const int *global_options) { @@ -223,38 +208,19 @@ svn_opt_subcommand_takes_option3(const svn_opt_subcommand_desc2_t *command, return FALSE; } -svn_boolean_t -svn_opt_subcommand_takes_option2(const svn_opt_subcommand_desc2_t *command, - int option_code) -{ - return svn_opt_subcommand_takes_option3(command, - option_code, - NULL); -} - - -svn_boolean_t -svn_opt_subcommand_takes_option(const svn_opt_subcommand_desc_t *command, - int option_code) -{ - apr_size_t i; - - for (i = 0; i < SVN_OPT_MAX_OPTIONS; i++) - if (command->valid_options[i] == option_code) - return TRUE; - - return FALSE; -} - /* Print the canonical command name for CMD, and all its aliases, to STREAM. If HELP is set, print CMD's help string too, in which case - obtain option usage from OPTIONS_TABLE. */ + obtain option usage from OPTIONS_TABLE. + + Include global and experimental options iff VERBOSE is true. + */ static svn_error_t * -print_command_info2(const svn_opt_subcommand_desc2_t *cmd, +print_command_info3(const svn_opt_subcommand_desc3_t *cmd, const apr_getopt_option_t *options_table, const int *global_options, svn_boolean_t help, + svn_boolean_t verbose, apr_pool_t *pool, FILE *stream) { @@ -289,8 +255,14 @@ print_command_info2(const svn_opt_subcommand_desc2_t *cmd, const apr_getopt_option_t *option; const char *long_alias; svn_boolean_t have_options = FALSE; + svn_boolean_t have_experimental = FALSE; - SVN_ERR(svn_cmdline_fprintf(stream, pool, ": %s", _(cmd->help))); + SVN_ERR(svn_cmdline_fprintf(stream, pool, ": ")); + + for (i = 0; i < SVN_OPT_MAX_PARAGRAPHS && cmd->help[i]; i++) + { + SVN_ERR(svn_cmdline_fprintf(stream, pool, "%s", _(cmd->help[i]))); + } /* Loop over all valid option codes attached to the subcommand */ for (i = 0; i < SVN_OPT_MAX_OPTIONS; i++) @@ -305,13 +277,24 @@ print_command_info2(const svn_opt_subcommand_desc2_t *cmd, } /* convert each option code into an option */ - option = get_option_from_code(&long_alias, cmd->valid_options[i], - options_table, cmd, pool); + option = get_option_from_code3(&long_alias, cmd->valid_options[i], + options_table, cmd, pool); /* print the option's docstring */ if (option && option->description) { const char *optstr; + + if (option->name && strncmp(option->name, "x-", 2) == 0) + { + if (verbose && !have_experimental) + SVN_ERR(svn_cmdline_fputs(_("\nExperimental options:\n"), + stream, pool)); + have_experimental = TRUE; + if (!verbose) + continue; + } + format_option(&optstr, option, long_alias, TRUE, pool); SVN_ERR(svn_cmdline_fprintf(stream, pool, " %s\n", optstr)); @@ -319,7 +302,7 @@ print_command_info2(const svn_opt_subcommand_desc2_t *cmd, } } /* And global options too */ - if (global_options && *global_options) + if (verbose && global_options && *global_options) { SVN_ERR(svn_cmdline_fputs(_("\nGlobal options:\n"), stream, pool)); @@ -329,8 +312,8 @@ print_command_info2(const svn_opt_subcommand_desc2_t *cmd, { /* convert each option code into an option */ - option = get_option_from_code(&long_alias, global_options[i], - options_table, cmd, pool); + option = get_option_from_code3(&long_alias, global_options[i], + options_table, cmd, pool); /* print the option's docstring */ if (option && option->description) @@ -343,6 +326,9 @@ print_command_info2(const svn_opt_subcommand_desc2_t *cmd, } } + if (!verbose) + SVN_ERR(svn_cmdline_fputs(_("\n(Use '-v' to show global and experimental options.)\n"), + stream, pool)); if (have_options) SVN_ERR(svn_cmdline_fprintf(stream, pool, "\n")); } @@ -350,30 +336,44 @@ print_command_info2(const svn_opt_subcommand_desc2_t *cmd, return SVN_NO_ERROR; } -/* The body for svn_opt_print_generic_help2() function with standard error +/* The body for svn_opt_print_generic_help3() function with standard error * handling semantic. Handling of errors implemented at caller side. */ static svn_error_t * -print_generic_help_body(const char *header, - const svn_opt_subcommand_desc2_t *cmd_table, - const apr_getopt_option_t *opt_table, - const char *footer, - apr_pool_t *pool, FILE *stream) +print_generic_help_body3(const char *header, + const svn_opt_subcommand_desc3_t *cmd_table, + const apr_getopt_option_t *opt_table, + const char *footer, + svn_boolean_t with_experimental, + apr_pool_t *pool, FILE *stream) { - int i = 0; + svn_boolean_t have_experimental = FALSE; + int i; if (header) SVN_ERR(svn_cmdline_fputs(header, stream, pool)); - while (cmd_table[i].name) + for (i = 0; cmd_table[i].name; i++) { + if (strncmp(cmd_table[i].name, "x-", 2) == 0) + { + if (with_experimental && !have_experimental) + SVN_ERR(svn_cmdline_fputs(_("\nExperimental subcommands:\n"), + stream, pool)); + have_experimental = TRUE; + if (!with_experimental) + continue; + } SVN_ERR(svn_cmdline_fputs(" ", stream, pool)); - SVN_ERR(print_command_info2(cmd_table + i, opt_table, - NULL, FALSE, + SVN_ERR(print_command_info3(cmd_table + i, opt_table, + NULL, FALSE, FALSE, pool, stream)); SVN_ERR(svn_cmdline_fputs("\n", stream, pool)); - i++; } + if (have_experimental && !with_experimental) + SVN_ERR(svn_cmdline_fputs(_("\n(Use '-v' to show experimental subcommands.)\n"), + stream, pool)); + SVN_ERR(svn_cmdline_fputs("\n", stream, pool)); if (footer) @@ -382,17 +382,19 @@ print_generic_help_body(const char *header, return SVN_NO_ERROR; } -void -svn_opt_print_generic_help2(const char *header, - const svn_opt_subcommand_desc2_t *cmd_table, - const apr_getopt_option_t *opt_table, - const char *footer, - apr_pool_t *pool, FILE *stream) +static void +print_generic_help(const char *header, + const svn_opt_subcommand_desc3_t *cmd_table, + const apr_getopt_option_t *opt_table, + const char *footer, + svn_boolean_t with_experimental, + apr_pool_t *pool, FILE *stream) { svn_error_t *err; - err = print_generic_help_body(header, cmd_table, opt_table, footer, pool, - stream); + err = print_generic_help_body3(header, cmd_table, opt_table, footer, + with_experimental, + pool, stream); /* Issue #3014: * Don't print anything on broken pipes. The pipe was likely @@ -406,21 +408,37 @@ svn_opt_print_generic_help2(const char *header, svn_error_clear(err); } - void -svn_opt_subcommand_help3(const char *subcommand, - const svn_opt_subcommand_desc2_t *table, - const apr_getopt_option_t *options_table, - const int *global_options, - apr_pool_t *pool) +svn_opt_print_generic_help3(const char *header, + const svn_opt_subcommand_desc3_t *cmd_table, + const apr_getopt_option_t *opt_table, + const char *footer, + apr_pool_t *pool, FILE *stream) { - const svn_opt_subcommand_desc2_t *cmd = - svn_opt_get_canonical_subcommand2(table, subcommand); + print_generic_help(header, cmd_table, opt_table, footer, + TRUE, pool, stream); +} + + +/* The body of svn_opt_subcommand_help4(), which see. + * + * VERBOSE means show also the subcommand's global and experimental options. + */ +static void +subcommand_help(const char *subcommand, + const svn_opt_subcommand_desc3_t *table, + const apr_getopt_option_t *options_table, + const int *global_options, + svn_boolean_t verbose, + apr_pool_t *pool) +{ + const svn_opt_subcommand_desc3_t *cmd = + svn_opt_get_canonical_subcommand3(table, subcommand); svn_error_t *err; if (cmd) - err = print_command_info2(cmd, options_table, global_options, - TRUE, pool, stdout); + err = print_command_info3(cmd, options_table, global_options, + TRUE, verbose, pool, stdout); else err = svn_cmdline_fprintf(stderr, pool, _("\"%s\": unknown command.\n\n"), subcommand); @@ -433,6 +451,17 @@ svn_opt_subcommand_help3(const char *subcommand, } } +void +svn_opt_subcommand_help4(const char *subcommand, + const svn_opt_subcommand_desc3_t *table, + const apr_getopt_option_t *options_table, + const int *global_options, + apr_pool_t *pool) +{ + subcommand_help(subcommand, table, options_table, global_options, + TRUE, pool); +} + /*** Parsing revision and date options. ***/ @@ -1194,14 +1223,14 @@ svn_opt__print_version_info(const char *pgm_name, } svn_error_t * -svn_opt_print_help4(apr_getopt_t *os, +svn_opt_print_help5(apr_getopt_t *os, const char *pgm_name, svn_boolean_t print_version, svn_boolean_t quiet, svn_boolean_t verbose, const char *version_footer, const char *header, - const svn_opt_subcommand_desc2_t *cmd_table, + const svn_opt_subcommand_desc3_t *cmd_table, const apr_getopt_option_t *option_table, const int *global_options, const char *footer, @@ -1218,9 +1247,9 @@ svn_opt_print_help4(apr_getopt_t *os, for (i = 0; i < targets->nelts; i++) { - svn_opt_subcommand_help3(APR_ARRAY_IDX(targets, i, const char *), - cmd_table, option_table, - global_options, pool); + subcommand_help(APR_ARRAY_IDX(targets, i, const char *), + cmd_table, option_table, global_options, + verbose, pool); } } else if (print_version) /* just --version */ @@ -1230,12 +1259,9 @@ svn_opt_print_help4(apr_getopt_t *os, quiet, verbose, pool)); } else if (os && !targets->nelts) /* `-h', `--help', or `help' */ - svn_opt_print_generic_help2(header, - cmd_table, - option_table, - footer, - pool, - stdout); + print_generic_help(header, cmd_table, option_table, footer, + verbose, + pool, stdout); else /* unknown option or cmd */ SVN_ERR(svn_cmdline_fprintf(stderr, pool, _("Type '%s help' for usage.\n"), pgm_name)); |