Motr
M0
|
Data Structures | |
struct | m0_getopts_opt |
Macros | |
#define | M0_GETOPTS(progname, argc, argv, ...) |
#define | M0_VOIDARG(ch, desc, func) |
#define | M0_NUMBERARG(ch, desc, func) |
#define | M0_SCALEDARG(ch, desc, func) |
#define | M0_STRINGARG(ch, desc, func) |
#define | M0_FORMATARG(ch, desc, fmt, ptr) |
#define | M0_FLAGARG(ch, desc, ptr) |
#define | M0_HELPARG(ch) |
Enumerations | |
enum | m0_getopts_opt_type { GOT_VOID, GOT_NUMBER, GOT_SCALED, GOT_STRING, GOT_FORMAT, GOT_FLAG, GOT_HELP } |
Functions | |
M0_INTERNAL int | m0_bcount_get (const char *arg, m0_bcount_t *out) |
M0_INTERNAL int | m0_time_get (const char *arg, m0_time_t *out) |
int | m0_getopts (const char *progname, int argc, char *const *argv, const struct m0_getopts_opt *opts, unsigned nr) |
static void | usage (const char *progname, const struct m0_getopts_opt *opts, unsigned nr) |
static int | getnum (const char *arg, const char *desc, int64_t *out) |
static int | getscaled (const char *arg, const char *desc, m0_bcount_t *out) |
Variables | |
const char | M0_GETOPTS_DECIMAL_POINT |
m0_getopts() is a higher-level analogue of a standard getopt(3) function. The interface is designed to avoid proliferation of nearly identical code fragments, typical for getopt(3) usage (switches nested in loops) and to hide global state exposed by getopt(3).
m0_getopts() interface is especially convenient when used together with anonymous functions (see LAMBDA() macro in lib/user_space/thread.h).
m0_getopts() is implemented on top of getopt(3).
#define M0_FLAGARG | ( | ch, | |
desc, | |||
ptr | |||
) |
Defines a GOT_FLAG option, with a given description and a flag address.
Defines a GOT_FORMAT option, with a given description, argument format and address.
#define M0_GETOPTS | ( | progname, | |
argc, | |||
argv, | |||
... | |||
) |
A wrapper around m0_getopts(), calculating the size of options array.
#define M0_HELPARG | ( | ch | ) |
Defines a GOT_HELP option.
#define M0_NUMBERARG | ( | ch, | |
desc, | |||
func | |||
) |
Defines a GOT_NUMBER option, with a given description and a call-back.
#define M0_SCALEDARG | ( | ch, | |
desc, | |||
func | |||
) |
Defines a GOT_SCALED option, with a given description and a call-back.
#define M0_STRINGARG | ( | ch, | |
desc, | |||
func | |||
) |
Defines a GOT_STRING option, with a given description and a call-back.
#define M0_VOIDARG | ( | ch, | |
desc, | |||
func | |||
) |
Defines a GOT_VOID option, with a given description and a call-back.
enum m0_getopts_opt_type |
Types of options supported by m0_getopts().
Enumerator | |
---|---|
GOT_VOID | An option without an argument. When this option is encountered, its call-back m0_getopts_opt::go_u::got_void() is executed for its side-effects. |
GOT_NUMBER | An option with a numerical argument. The argument is expected in the format that strtoull(..., 0) can parse. When this option is encountered, its call-back m0_getopts_opt::go_u::got_number() is invoked with the parsed argument as its sole parameter. |
GOT_SCALED | An option with a numerical argument, followed by a optional multiplier suffix. The argument is expected in the format that m0_bcount_get() can parse. When this option is encountered, its call-back m0_getopts_opt::go_u::got_scaled() is invoked with the parsed argument as its sole parameter. |
GOT_STRING | An option with a string argument. When this option is encountered, its call-back m0_getopts_opt::go_u::got_string() is invoked with the string argument as its sole parameter. |
GOT_FORMAT | An options with an argument with a format that can be parsed by scanf(3). The argument string is parsed by a call to sscanf(3) with a caller-supplied format string and caller-supplied address to store the result at. No call-back is invoked. The caller is expected to analyse the contents of the address after m0_getopts() returns. |
GOT_FLAG | An option without an argument, serving as a binary flag. When this option is encountered, a user supplied boolean stored at m0_getopts_opt::go_u::got_flag is set to true. If the option wasn't encountered, the flag is set to false. No call-back is invoked. The user is expected to inspect the flag after m0_getopts() returns. |
GOT_HELP | An option without an argument. When this option encountered, program usage is printed to STDERR and program terminates immediately with exit(3). |
|
static |
Definition at line 74 of file ugetopts.c.
|
static |
Definition at line 87 of file ugetopts.c.
M0_INTERNAL int m0_bcount_get | ( | const char * | arg, |
m0_bcount_t * | out | ||
) |
Convert numerical argument, followed by a optional multiplier suffix, to an uint64_t value. The numerical argument is expected in the format that strtoull(..., 0) can parse. The multiplier suffix should be a char from "bkmgKMG" string. The char matches factor which will be multiplied by numerical part of argument.
Suffix char matches:
Definition at line 35 of file getopts.c.
int m0_getopts | ( | const char * | progname, |
int | argc, | ||
char *const * | argv, | ||
const struct m0_getopts_opt * | opts, | ||
unsigned | nr | ||
) |
Parses command line stored in argv[] array with argc elements according to a traditional UNIX/POSIX fashion.
Recognized options are supplied in opts[] array with nr elements.
When a parsing error occurs (unrecognized option, invalid argument format, etc.), a error message is printed on stderr, followed by a usage summary. The summary enumerates all the recognized options, their argument requirements and human-readable descriptions. Caller-supplied progname is used as a prefix of error messages.
Definition at line 98 of file ugetopts.c.
M0_INTERNAL int m0_time_get | ( | const char * | arg, |
m0_time_t * | out | ||
) |
Convert numerical argument, followed by a optional multiplier suffix, to an m0_time_t value. The numerical argument is expected in the format "[integer].[integer]" or just "integer", where [integer] is optional integer value in format that strtoull(..., 10) can parse, and at least one integer should be present in the numerical argument. The multiplier suffix matches unit of time and should be a string from the following list.
Suffix string matches:
Definition at line 69 of file getopts.c.
|
static |