📄 opt.c
字号:
/* * opt.c : option and argument parsing for Subversion command lines * * ==================================================================== * Copyright (c) 2000-2006 CollabNet. All rights reserved. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at http://subversion.tigris.org/license-1.html. * If newer versions of this license are posted there, you may use a * newer version instead, at your option. * * This software consists of voluntary contributions made by many * individuals. For exact contribution history, see the revision * history and logs, available at http://subversion.tigris.org/. * ==================================================================== */#define APR_WANT_STRFUNC#include <apr_want.h>#include <stdio.h>#include <assert.h>#include <apr_pools.h>#include <apr_general.h>#include <apr_lib.h>#include <apr_file_info.h>#include "svn_cmdline.h"#include "svn_version.h"#include "svn_types.h"#include "svn_opt.h"#include "svn_error.h"#include "svn_path.h"#include "svn_utf.h"#include "svn_time.h"#include "svn_private_config.h"/*** Code. ***/const svn_opt_subcommand_desc2_t *svn_opt_get_canonical_subcommand2(const svn_opt_subcommand_desc2_t *table, const char *cmd_name){ int i = 0; if (cmd_name == NULL) return NULL; while (table[i].name) { int j; if (strcmp(cmd_name, table[i].name) == 0) return table + i; for (j = 0; (j < SVN_OPT_MAX_ALIASES) && table[i].aliases[j]; j++) if (strcmp(cmd_name, table[i].aliases[j]) == 0) return table + i; i++; } /* If we get here, there was no matching subcommand name or alias. */ return NULL;}const svn_opt_subcommand_desc_t *svn_opt_get_canonical_subcommand(const svn_opt_subcommand_desc_t *table, const char *cmd_name){ int i = 0; if (cmd_name == NULL) return NULL; while (table[i].name) { int j; if (strcmp(cmd_name, table[i].name) == 0) return table + i; for (j = 0; (j < SVN_OPT_MAX_ALIASES) && table[i].aliases[j]; j++) if (strcmp(cmd_name, table[i].aliases[j]) == 0) return table + i; i++; } /* If we get here, there was no matching subcommand name or alias. */ return NULL;}const apr_getopt_option_t *svn_opt_get_option_from_code2(int code, const apr_getopt_option_t *option_table, const svn_opt_subcommand_desc2_t *command, apr_pool_t *pool){ apr_size_t i; for (i = 0; option_table[i].optch; i++) if (option_table[i].optch == code) { int j; if (command) for (j = 0; ((j < SVN_OPT_MAX_OPTIONS) && command->desc_overrides[j].optch); j++) if (command->desc_overrides[j].optch == code) { apr_getopt_option_t *tmpopt = apr_palloc(pool, sizeof(*tmpopt)); *tmpopt = option_table[i]; tmpopt->description = command->desc_overrides[j].desc; return tmpopt; } return &(option_table[i]); } 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;}svn_boolean_tsvn_opt_subcommand_takes_option2(const svn_opt_subcommand_desc2_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;}svn_boolean_tsvn_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. */static svn_error_t *print_command_info2(const svn_opt_subcommand_desc2_t *cmd, const apr_getopt_option_t *options_table, svn_boolean_t help, apr_pool_t *pool, FILE *stream){ svn_boolean_t first_time; apr_size_t i; /* Print the canonical command name. */ SVN_ERR(svn_cmdline_fputs(cmd->name, stream, pool)); /* Print the list of aliases. */ first_time = TRUE; for (i = 0; i < SVN_OPT_MAX_ALIASES; i++) { if (cmd->aliases[i] == NULL) break; if (first_time) { SVN_ERR(svn_cmdline_fputs(" (", stream, pool)); first_time = FALSE; } else SVN_ERR(svn_cmdline_fputs(", ", stream, pool)); SVN_ERR(svn_cmdline_fputs(cmd->aliases[i], stream, pool)); } if (! first_time) SVN_ERR(svn_cmdline_fputs(")", stream, pool)); if (help) { const apr_getopt_option_t *option; svn_boolean_t have_options = FALSE; SVN_ERR(svn_cmdline_fprintf(stream, pool, ": %s", _(cmd->help))); /* Loop over all valid option codes attached to the subcommand */ for (i = 0; i < SVN_OPT_MAX_OPTIONS; i++) { if (cmd->valid_options[i]) { if (have_options == FALSE) { SVN_ERR(svn_cmdline_fputs(_("\nValid options:\n"), stream, pool)); have_options = TRUE; } /* convert each option code into an option */ option = svn_opt_get_option_from_code2(cmd->valid_options[i], options_table, cmd, pool); /* print the option's docstring */ if (option) { const char *optstr; svn_opt_format_option(&optstr, option, TRUE, pool); SVN_ERR(svn_cmdline_fprintf(stream, pool, " %s\n", optstr)); } } } if (have_options) SVN_ERR(svn_cmdline_fprintf(stream, pool, "\n")); } return SVN_NO_ERROR;}/* Same as print_command_info2(), but with deprecated struct revision. */static svn_error_t *print_command_info(const svn_opt_subcommand_desc_t *cmd, const apr_getopt_option_t *options_table, svn_boolean_t help, apr_pool_t *pool, FILE *stream){ svn_boolean_t first_time; apr_size_t i; /* Print the canonical command name. */ SVN_ERR(svn_cmdline_fputs(cmd->name, stream, pool)); /* Print the list of aliases. */ first_time = TRUE; for (i = 0; i < SVN_OPT_MAX_ALIASES; i++) { if (cmd->aliases[i] == NULL) break; if (first_time) { SVN_ERR(svn_cmdline_fputs(" (", stream, pool)); first_time = FALSE; } else SVN_ERR(svn_cmdline_fputs(", ", stream, pool)); SVN_ERR(svn_cmdline_fputs(cmd->aliases[i], stream, pool)); } if (! first_time) SVN_ERR(svn_cmdline_fputs(")", stream, pool)); if (help) { const apr_getopt_option_t *option; svn_boolean_t have_options = FALSE; SVN_ERR(svn_cmdline_fprintf(stream, pool, ": %s", _(cmd->help))); /* Loop over all valid option codes attached to the subcommand */ for (i = 0; i < SVN_OPT_MAX_OPTIONS; i++) { if (cmd->valid_options[i]) { if (have_options == FALSE) { SVN_ERR(svn_cmdline_fputs(_("\nValid options:\n"), stream, pool)); have_options = TRUE; } /* convert each option code into an option */ option = svn_opt_get_option_from_code(cmd->valid_options[i], options_table); /* print the option's docstring */ if (option) { const char *optstr; svn_opt_format_option(&optstr, option, TRUE, pool); SVN_ERR(svn_cmdline_fprintf(stream, pool, " %s\n", optstr)); } } } if (have_options) SVN_ERR(svn_cmdline_fprintf(stream, pool, "\n")); } return SVN_NO_ERROR;}voidsvn_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){ int i = 0; svn_error_t *err; if (header) if ((err = svn_cmdline_fputs(header, stream, pool))) goto print_error; while (cmd_table[i].name) { if ((err = svn_cmdline_fputs(" ", stream, pool)) || (err = print_command_info2(cmd_table + i, opt_table, FALSE, pool, stream)) || (err = svn_cmdline_fputs("\n", stream, pool))) goto print_error; i++; } if ((err = svn_cmdline_fputs("\n", stream, pool))) goto print_error; if (footer) if ((err = svn_cmdline_fputs(footer, stream, pool))) goto print_error; return; print_error: svn_handle_error2(err, stderr, FALSE, "svn: "); svn_error_clear(err);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -