diff options
author | unril <unril@yandex-team.ru> | 2022-02-10 16:46:05 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:05 +0300 |
commit | 3b241dd57cf58f20bbbd63fa6a0a758dbec09b68 (patch) | |
tree | 1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /contrib/restricted/aws/aws-c-common/source/command_line_parser.c | |
parent | 11ae9eca250d0188b7962459cbc6706719e7dca9 (diff) | |
download | ydb-3b241dd57cf58f20bbbd63fa6a0a758dbec09b68.tar.gz |
Restoring authorship annotation for <unril@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/restricted/aws/aws-c-common/source/command_line_parser.c')
-rw-r--r-- | contrib/restricted/aws/aws-c-common/source/command_line_parser.c | 196 |
1 files changed, 98 insertions, 98 deletions
diff --git a/contrib/restricted/aws/aws-c-common/source/command_line_parser.c b/contrib/restricted/aws/aws-c-common/source/command_line_parser.c index bfb3f9f1aa..ccbe6d1820 100644 --- a/contrib/restricted/aws/aws-c-common/source/command_line_parser.c +++ b/contrib/restricted/aws/aws-c-common/source/command_line_parser.c @@ -1,109 +1,109 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ -#include <aws/common/command_line_parser.h> - -int aws_cli_optind = 1; -int aws_cli_opterr = -1; -int aws_cli_optopt = 0; - -const char *aws_cli_optarg = NULL; - -static const struct aws_cli_option *s_find_option_from_char( - const struct aws_cli_option *longopts, - char search_for, - int *longindex) { - int index = 0; - const struct aws_cli_option *option = &longopts[index]; - - while (option->val != 0 || option->name) { - if (option->val == search_for) { - if (longindex) { - *longindex = index; - } - return option; - } - - option = &longopts[++index]; - } - - return NULL; -} - -static const struct aws_cli_option *s_find_option_from_c_str( - const struct aws_cli_option *longopts, - const char *search_for, - int *longindex) { - int index = 0; - const struct aws_cli_option *option = &longopts[index]; - - while (option->name || option->val != 0) { - if (option->name) { - if (option->name && !strcmp(search_for, option->name)) { - if (longindex) { - *longindex = index; - } - return option; - } - } - - option = &longopts[++index]; - } - - return NULL; -} - -int aws_cli_getopt_long( - int argc, - char *const argv[], - const char *optstring, - const struct aws_cli_option *longopts, - int *longindex) { - aws_cli_optarg = NULL; - - if (aws_cli_optind >= argc) { - return -1; - } - - char first_char = argv[aws_cli_optind][0]; - char second_char = argv[aws_cli_optind][1]; - char *option_start = NULL; - const struct aws_cli_option *option = NULL; - - if (first_char == '-' && second_char != '-') { - option_start = &argv[aws_cli_optind][1]; - option = s_find_option_from_char(longopts, *option_start, longindex); - } else if (first_char == '-' && second_char == '-') { - option_start = &argv[aws_cli_optind][2]; - option = s_find_option_from_c_str(longopts, option_start, longindex); - } else { - return -1; - } - - aws_cli_optind++; - if (option) { - bool has_arg = false; - + */ +#include <aws/common/command_line_parser.h> + +int aws_cli_optind = 1; +int aws_cli_opterr = -1; +int aws_cli_optopt = 0; + +const char *aws_cli_optarg = NULL; + +static const struct aws_cli_option *s_find_option_from_char( + const struct aws_cli_option *longopts, + char search_for, + int *longindex) { + int index = 0; + const struct aws_cli_option *option = &longopts[index]; + + while (option->val != 0 || option->name) { + if (option->val == search_for) { + if (longindex) { + *longindex = index; + } + return option; + } + + option = &longopts[++index]; + } + + return NULL; +} + +static const struct aws_cli_option *s_find_option_from_c_str( + const struct aws_cli_option *longopts, + const char *search_for, + int *longindex) { + int index = 0; + const struct aws_cli_option *option = &longopts[index]; + + while (option->name || option->val != 0) { + if (option->name) { + if (option->name && !strcmp(search_for, option->name)) { + if (longindex) { + *longindex = index; + } + return option; + } + } + + option = &longopts[++index]; + } + + return NULL; +} + +int aws_cli_getopt_long( + int argc, + char *const argv[], + const char *optstring, + const struct aws_cli_option *longopts, + int *longindex) { + aws_cli_optarg = NULL; + + if (aws_cli_optind >= argc) { + return -1; + } + + char first_char = argv[aws_cli_optind][0]; + char second_char = argv[aws_cli_optind][1]; + char *option_start = NULL; + const struct aws_cli_option *option = NULL; + + if (first_char == '-' && second_char != '-') { + option_start = &argv[aws_cli_optind][1]; + option = s_find_option_from_char(longopts, *option_start, longindex); + } else if (first_char == '-' && second_char == '-') { + option_start = &argv[aws_cli_optind][2]; + option = s_find_option_from_c_str(longopts, option_start, longindex); + } else { + return -1; + } + + aws_cli_optind++; + if (option) { + bool has_arg = false; + char *opt_value = memchr(optstring, option->val, strlen(optstring)); if (!opt_value) { return '?'; - } - + } + if (opt_value[1] == ':') { has_arg = true; } - if (has_arg) { + if (has_arg) { if (aws_cli_optind >= argc) { - return '?'; - } - - aws_cli_optarg = argv[aws_cli_optind++]; - } - - return option->val; - } - - return '?'; -} + return '?'; + } + + aws_cli_optarg = argv[aws_cli_optind++]; + } + + return option->val; + } + + return '?'; +} |