diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /library/cpp/getopt/small/opt.h | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/getopt/small/opt.h')
-rw-r--r-- | library/cpp/getopt/small/opt.h | 94 |
1 files changed, 47 insertions, 47 deletions
diff --git a/library/cpp/getopt/small/opt.h b/library/cpp/getopt/small/opt.h index ecb57439bc..1bbd3811a3 100644 --- a/library/cpp/getopt/small/opt.h +++ b/library/cpp/getopt/small/opt.h @@ -1,8 +1,8 @@ #pragma once -#include "last_getopt.h" - -#include <util/generic/ptr.h> +#include "last_getopt.h" + +#include <util/generic/ptr.h> #include <util/generic/noncopyable.h> // implementation of Opt class using last getopt @@ -54,20 +54,20 @@ */ #define OPT_RETURN_IN_ORDER "-" -#define OPT_REQUIRE_ORDER "+" -#define OPT_DONT_STORE_ARG ((void*)0) +#define OPT_REQUIRE_ORDER "+" +#define OPT_DONT_STORE_ARG ((void*)0) -class Opt : TNonCopyable { +class Opt : TNonCopyable { public: - enum HasArg { WithoutArg, - WithArg, - PossibleArg }; + enum HasArg { WithoutArg, + WithArg, + PossibleArg }; struct Ion { - const char* name; - HasArg has_arg; - int* flag; - int val; + const char* name; + HasArg has_arg; + int* flag; + int val; }; private: @@ -75,7 +75,7 @@ private: THolder<NLastGetopt::TOptsParser> OptsParser_; const Ion* Ions_; bool GotError_; - + void Init(int argc, char* argv[], const char* optString, const Ion* longOptions = nullptr, bool longOnly = false, bool isOpen = false); public: @@ -89,19 +89,19 @@ public: return Get(); } - const char* GetArg() const { - return Arg; - } + const char* GetArg() const { + return Arg; + } TVector<TString> GetFreeArgs() const { return NLastGetopt::TOptsParseResult(&*Opts_, GetArgC(), GetArgV()).GetFreeArgs(); } // obsolete, use GetArg() instead - char* Arg; /* option argument if any or NULL */ + char* Arg; /* option argument if any or NULL */ - int Ind; /* command line index */ - bool Err; /* flag to print error messages */ + int Ind; /* command line index */ + bool Err; /* flag to print error messages */ int GetArgC() const; const char** GetArgV() const; @@ -111,32 +111,32 @@ public: // call before getopt. returns non-negative int, removing it from arguments (not found: -1) // Example: returns 11 for "progname -11abc", -1 for "progname -a11" -int opt_get_number(int& argc, char* argv[]); - -#define OPTION_HANDLING_PROLOG \ - { \ - int optlet; \ - while (EOF != (optlet = opt.Get())) { \ - switch (optlet) { -#define OPTION_HANDLING_PROLOG_ANON(S) \ - { \ - Opt opt(argc, argv, (S)); \ - int optlet; \ - while (EOF != (optlet = opt.Get())) { \ - switch (optlet) { -#define OPTION_HANDLE_BEGIN(opt) case opt: { -#define OPTION_HANDLE_END \ - } \ - break; +int opt_get_number(int& argc, char* argv[]); + +#define OPTION_HANDLING_PROLOG \ + { \ + int optlet; \ + while (EOF != (optlet = opt.Get())) { \ + switch (optlet) { +#define OPTION_HANDLING_PROLOG_ANON(S) \ + { \ + Opt opt(argc, argv, (S)); \ + int optlet; \ + while (EOF != (optlet = opt.Get())) { \ + switch (optlet) { +#define OPTION_HANDLE_BEGIN(opt) case opt: { +#define OPTION_HANDLE_END \ + } \ + break; #define OPTION_HANDLE(opt, handle) \ - OPTION_HANDLE_BEGIN(opt) \ - handle; \ - OPTION_HANDLE_END - -#define OPTION_HANDLING_EPILOG \ - default: \ - ythrow yexception() << "unknown optlet"; \ - } \ - } \ - } + OPTION_HANDLE_BEGIN(opt) \ + handle; \ + OPTION_HANDLE_END + +#define OPTION_HANDLING_EPILOG \ + default: \ + ythrow yexception() << "unknown optlet"; \ + } \ + } \ + } |