|
static bool | getopt_compare_strings (const char *, const char *, uint) |
|
static longlong | getopt_ll (const char *, bool, const my_option *, int *) |
|
static ulonglong | getopt_ull (const char *, bool, const my_option *, int *) |
|
static double | getopt_double (const char *, bool, const my_option *, int *) |
|
static void | init_variables (const struct my_option *, init_func_p) |
|
static void | init_one_value (const struct my_option *, void *, longlong) |
|
static void | fini_one_value (const struct my_option *, void *, longlong) |
|
static int | setval (const struct my_option *, void *, const char *, bool, bool) |
|
static void | setval_source (const struct my_option *opts, void *value) |
| Will set the source and file name from where this options is set in my_option struct. More...
|
|
static char * | check_struct_option (char *cur_arg, char *key_name) |
| Check for struct options. More...
|
|
static bool | get_bool_int_argument (const char *argument, bool *error) |
| Parse a boolean command line argument as the SQL interpreter does. More...
|
|
void | my_getopt_register_get_addr (my_getopt_value func_addr) |
|
bool | is_key_cache_variable_suffix (std::string_view suffix) |
|
int | handle_options (int *argc, char ***argv, const struct my_option *longopts, my_get_one_option get_one_option) |
| Wrapper around my_handle_options() for interface compatibility. More...
|
|
ulonglong | getopt_double2ulonglong (double v) |
| Returns an ulonglong value containing a raw representation of the given double value. More...
|
|
double | getopt_ulonglong2double (ulonglong v) |
| Returns the double value which corresponds to the given raw representation. More...
|
|
int | my_handle_options2 (int *argc, char ***argv, const struct my_option *longopts, my_get_one_option get_one_option, const char **command_list, bool ignore_unknown_option, bool boolean_as_int) |
| Handle command line options. More...
|
|
int | my_handle_options (int *argc, char ***argv, const struct my_option *longopts, my_get_one_option get_one_option, const char **command_list, bool ignore_unknown_option) |
|
void | print_cmdline_password_warning () |
| This function should be called to print a warning message if password string is specified on the command line. More...
|
|
bool | get_bool_argument (const char *argument, bool *error) |
| Parse a boolean command line argument. More...
|
|
int | findopt (const char *optpat, uint length, const struct my_option **opt_res) |
| Find option. More...
|
|
template<typename LLorULL > |
LLorULL | eval_num_suffix (const char *argument, int *error, const char *option_name) |
|
template longlong | eval_num_suffix< longlong > (const char *, int *, const char *) |
|
template ulonglong | eval_num_suffix< ulonglong > (const char *, int *, const char *) |
|
ulonglong | max_of_int_range (int var_type) |
| Maximum possible value for an integer GET_* variable type. More...
|
|
longlong | getopt_ll_limit_value (longlong num, const struct my_option *optp, bool *fix) |
|
static bool | is_negative_num (const char *num) |
|
ulonglong | getopt_ull_limit_value (ulonglong num, const struct my_option *optp, bool *fix) |
|
double | getopt_double_limit_value (double num, const struct my_option *optp, bool *fix) |
|
void | my_cleanup_options (const struct my_option *options) |
|
static uint | print_name (const struct my_option *optp, FILE *file=stdout) |
| Prints variable or option name, replacing _ with - to given file stream parameter (by default to stdout). More...
|
|
void | my_print_help (const struct my_option *options) |
|
void | my_print_variables (const struct my_option *options) |
| function: my_print_variables Print variables. More...
|
|
void | my_print_variables_ex (const struct my_option *options, FILE *file) |
| function: my_print_variables_ex Print variables to given file parameter stream (by default to stdout). More...
|
|
int my_handle_options2 |
( |
int * |
argc, |
|
|
char *** |
argv, |
|
|
const struct my_option * |
longopts, |
|
|
my_get_one_option |
get_one_option, |
|
|
const char ** |
command_list, |
|
|
bool |
ignore_unknown_option, |
|
|
bool |
boolean_as_int |
|
) |
| |
Handle command line options.
Sort options. Put options first, until special end of options (–), or until the end of argv. Parse options, check that the given option matches with one of the options in struct 'my_option'. Check that option was given an argument if it requires one Call the optional 'get_one_option()' function once for each option.
Note that handle_options() can be invoked multiple times to parse a command line in several steps. In this case, use the global flag my_getopt_skip_unknown
to indicate that options unknown in the current step should be preserved in the command line for later parsing in subsequent steps.
For 'long' options (–a_long_option), my_getopt_skip_unknown
is fully supported. Command line parameters such as:
- "--a_long_option"
- "--a_long_option=value"
- "--a_long_option value" will be preserved as is when the option is not known.
For 'short' options (-S), support for my_getopt_skip_unknown
comes with some limitation, because several short options can also be specified together in the same command line argument, as in "-XYZ".
The first use case supported is: all short options are declared. handle_options() will be able to interpret "-XYZ" as one of:
- an unknown X option
- "-X -Y -Z", three short options with no arguments
- "-X -YZ", where Y is a short option with argument Z
- "-XYZ", where X is a short option with argument YZ based on the full short options specifications.
The second use case supported is: no short option is declared. handle_options() will reject "-XYZ" as unknown, to be parsed later.
The use case that is explicitly not supported is to provide only a partial list of short options to handle_options(). This function can not be expected to extract some option Y in the middle of the string "-XYZ" in these conditions, without knowing if X will be declared an option later.
Note that this limitation only impacts parsing of several short options from the same command line argument, as in "mysqld -anW5". When each short option is properly separated out in the command line argument, for example in "mysqld -a -n -w5", the code would actually work even with partial options specs given at each stage.
- Parameters
-
[in,out] | argc | command line options (count) |
[in,out] | argv | command line options (values) |
[in] | longopts | descriptor of all valid options |
[in] | get_one_option | optional callback function to process each option, can be NULL. |
[in] | command_list | NULL-terminated list of strings (commands) which (if set) is looked up for all non-option strings found while parsing the command line parameters. The parsing terminates if a match is found. At exit, argv [out] would contain all the remaining unparsed options along with the matched command. |
[in] | ignore_unknown_option | When set to true, options are continued to be read even when unknown options are encountered. |
[in] | boolean_as_int | Parse boolean as integer value. Mimic the logic of parsing booleans at runtime: Instead of parsing bool_val = (str_val == '1' || str_val = 'ON') ?
true :
(str_val == '0' || str_val = 'OFF') ?
false :
false;
do: bool_val == (str_val == 'OFF') ?
false :
((str_val == 'ON') ?
true :
atoi(str_val) != 0)
|
- Returns
- error in case of ambiguous or unknown options, 0 on success.