diff options
author | nga <nga@yandex-team.ru> | 2022-02-10 16:48:09 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:48:09 +0300 |
commit | 1f553f46fb4f3c5eec631352cdd900a0709016af (patch) | |
tree | a231fba2c03b440becaea6c86a2702d0bfb0336e /library/cpp/getopt/small/posix_getopt.cpp | |
parent | c4de7efdedc25b49cbea74bd589eecb61b55b60a (diff) | |
download | ydb-1f553f46fb4f3c5eec631352cdd900a0709016af.tar.gz |
Restoring authorship annotation for <nga@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/getopt/small/posix_getopt.cpp')
-rw-r--r-- | library/cpp/getopt/small/posix_getopt.cpp | 110 |
1 files changed, 55 insertions, 55 deletions
diff --git a/library/cpp/getopt/small/posix_getopt.cpp b/library/cpp/getopt/small/posix_getopt.cpp index bd06f3499f..cae224133a 100644 --- a/library/cpp/getopt/small/posix_getopt.cpp +++ b/library/cpp/getopt/small/posix_getopt.cpp @@ -2,76 +2,76 @@ #include <util/generic/ptr.h> -#include <ctype.h> - -namespace NLastGetopt { - char* optarg; - int optind; - int optopt; - int opterr; - int optreset; - - static THolder<TOpts> Opts; - static THolder<TOptsParser> OptsParser; - +#include <ctype.h> + +namespace NLastGetopt { + char* optarg; + int optind; + int optopt; + int opterr; + int optreset; + + static THolder<TOpts> Opts; + static THolder<TOptsParser> OptsParser; + int getopt_long_impl(int argc, char* const* argv, const char* optstring, const struct option* longopts, int* longindex, bool long_only) { - if (!Opts || optreset == 1) { + if (!Opts || optreset == 1) { optarg = nullptr; - optind = 1; - opterr = 1; - optreset = 0; - Opts.Reset(new TOpts(TOpts::Default(optstring))); - - Opts->AllowSingleDashForLong_ = long_only; - + optind = 1; + opterr = 1; + optreset = 0; + Opts.Reset(new TOpts(TOpts::Default(optstring))); + + Opts->AllowSingleDashForLong_ = long_only; + for (const struct option* o = longopts; o != nullptr && o->name != nullptr; ++o) { - TOpt* opt; + TOpt* opt; if ((unsigned)o->val < 0x80 && isalnum(o->val)) { - opt = &Opts->CharOption(char(o->val)); + opt = &Opts->CharOption(char(o->val)); opt->AddLongName(o->name); - } else { - Opts->AddLongOption(o->name); - opt = const_cast<TOpt*>(&Opts->GetLongOption(o->name)); - } - opt->HasArg_ = EHasArg(o->has_arg); + } else { + Opts->AddLongOption(o->name); + opt = const_cast<TOpt*>(&Opts->GetLongOption(o->name)); + } + opt->HasArg_ = EHasArg(o->has_arg); opt->UserValue(o->flag); - } - + } + OptsParser.Reset(new TOptsParser(&*Opts, argc, (const char**)argv)); - } - + } + optarg = nullptr; - - try { - if (!OptsParser->Next()) { - return -1; - } else { + + try { + if (!OptsParser->Next()) { + return -1; + } else { optarg = (char*)OptsParser->CurVal(); optind = (int)OptsParser->Pos_; if (longindex && OptsParser->CurOpt()) *longindex = (int)Opts->IndexOf(OptsParser->CurOpt()); return OptsParser->CurOpt() ? OptsParser->CurOpt()->GetCharOr0() : 1; - } - } catch (const NLastGetopt::TException&) { - return '?'; - } - } - + } + } catch (const NLastGetopt::TException&) { + return '?'; + } + } + int getopt_long(int argc, char* const* argv, const char* optstring, const struct option* longopts, int* longindex) { - return getopt_long_impl(argc, argv, optstring, longopts, longindex, false); - } - - int getopt_long_only(int argc, char* const* argv, const char* optstring, + return getopt_long_impl(argc, argv, optstring, longopts, longindex, false); + } + + int getopt_long_only(int argc, char* const* argv, const char* optstring, const struct option* longopts, int* longindex) { - return getopt_long_impl(argc, argv, optstring, longopts, longindex, true); - } - - // XXX: leading colon is not supported - // XXX: updating optind by client is not supported - int getopt(int argc, char* const* argv, const char* optstring) { + return getopt_long_impl(argc, argv, optstring, longopts, longindex, true); + } + + // XXX: leading colon is not supported + // XXX: updating optind by client is not supported + int getopt(int argc, char* const* argv, const char* optstring) { return getopt_long(argc, argv, optstring, nullptr, nullptr); - } - -} + } + +} |