MySQL 8.4.3
Source Code Documentation
|
#include <sys/types.h>
#include <cstdio>
#include <string_view>
#include <mysql/components/services/system_variable_source_type.h>
#include "my_config.h"
#include "my_inttypes.h"
#include "my_io.h"
#include "my_macros.h"
#include "my_sys.h"
Go to the source code of this file.
Classes | |
struct | get_opt_arg_source |
struct | my_option |
Macros | |
#define | GET_NO_ARG 1 |
#define | GET_BOOL 2 |
#define | GET_INT 3 |
#define | GET_UINT 4 |
#define | GET_LONG 5 |
#define | GET_ULONG 6 |
#define | GET_LL 7 |
#define | GET_ULL 8 |
#define | GET_STR 9 |
#define | GET_STR_ALLOC 10 |
#define | GET_DISABLED 11 |
#define | GET_ENUM 12 |
#define | GET_SET 13 |
#define | GET_DOUBLE 14 |
#define | GET_FLAGSET 15 |
#define | GET_PASSWORD 16 |
#define | GET_INT32 GET_INT |
#define | GET_UINT32 GET_UINT |
#define | GET_ASK_ADDR 128 |
#define | GET_TYPE_MASK 127 |
Typedefs | |
typedef bool(* | my_get_one_option) (int, const struct my_option *, char *) |
typedef void *(* | my_getopt_value) (const char *, size_t, const struct my_option *, int *) |
Used to retrieve a reference to the object (variable) that holds the value for the given option. More... | |
Enumerations | |
enum | get_opt_arg_type { NO_ARG , OPT_ARG , REQUIRED_ARG } |
Enumeration of the my_option::arg_type attributes. More... | |
Functions | |
int | handle_options (int *argc, char ***argv, const struct my_option *longopts, my_get_one_option) |
Wrapper around my_handle_options() for interface compatibility. More... | |
int | my_handle_options (int *argc, char ***argv, const struct my_option *longopts, my_get_one_option, const char **command_list, bool ignore_unknown_option) |
int | my_handle_options2 (int *argc, char ***argv, const struct my_option *longopts, my_get_one_option, const char **command_list, bool ignore_unknown_option, bool boolean_as_int) |
Handle command line options. More... | |
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... | |
void | my_cleanup_options (const struct my_option *options) |
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... | |
void | my_getopt_register_get_addr (my_getopt_value) |
ulonglong | getopt_ull_limit_value (ulonglong num, const struct my_option *optp, bool *fix) |
longlong | getopt_ll_limit_value (longlong, const struct my_option *, bool *fix) |
double | getopt_double_limit_value (double num, const struct my_option *optp, bool *fix) |
ulonglong | max_of_int_range (int var_type) |
Maximum possible value for an integer GET_* variable type. More... | |
ulonglong | getopt_double2ulonglong (double) |
Returns an ulonglong value containing a raw representation of the given double value. More... | |
double | getopt_ulonglong2double (ulonglong) |
Returns the double value which corresponds to the given raw representation. More... | |
int | findopt (const char *, uint, const struct my_option **) |
Find option. More... | |
bool | is_key_cache_variable_suffix (std::string_view suffix) |
bool | get_bool_argument (const char *argument, bool *error) |
Parse a boolean command line argument. More... | |
template<typename LLorULL > | |
LLorULL | eval_num_suffix (const char *argument, int *error, const char *option_name) |
Variables | |
char * | disabled_my_option |
bool | my_getopt_print_errors |
bool | my_getopt_skip_unknown |
bool | log_replica_updates_supplied |
bool | replica_preserve_commit_order_supplied |
my_error_reporter | my_getopt_error_reporter |
#define GET_ASK_ADDR 128 |
#define GET_BOOL 2 |
#define GET_DISABLED 11 |
#define GET_DOUBLE 14 |
#define GET_ENUM 12 |
#define GET_FLAGSET 15 |
#define GET_INT 3 |
#define GET_INT32 GET_INT |
#define GET_LL 7 |
#define GET_LONG 5 |
#define GET_NO_ARG 1 |
#define GET_PASSWORD 16 |
#define GET_SET 13 |
#define GET_STR 9 |
#define GET_STR_ALLOC 10 |
#define GET_TYPE_MASK 127 |
#define GET_UINT 4 |
#define GET_UINT32 GET_UINT |
#define GET_ULL 8 |
#define GET_ULONG 6 |
typedef bool(* my_get_one_option) (int, const struct my_option *, char *) |
typedef void *(* my_getopt_value) (const char *, size_t, const struct my_option *, int *) |
Used to retrieve a reference to the object (variable) that holds the value for the given option.
For example, if var_type is GET_UINT, the function must return a pointer to a variable of type uint. A argument is stored in the location pointed to by the returned pointer.
enum get_opt_arg_type |
Enumeration of the my_option::arg_type attributes.
It should be noted that for historical reasons variables with the combination arg_type=NO_ARG, my_option::var_type=GET_BOOL still accepts arguments. This is someone counter intuitive and care should be taken if the code is refactored.
Enumerator | |
---|---|
NO_ARG | |
OPT_ARG | |
REQUIRED_ARG |
LLorULL eval_num_suffix | ( | const char * | argument, |
int * | error, | ||
const char * | option_name | ||
) |
int findopt | ( | const char * | optpat, |
uint | length, | ||
const struct my_option ** | opt_res | ||
) |
Find option.
IMPLEMENTATION Go through all options in the my_option struct. Return true if an option is found. sets opt_res to the option found, if any.
optpat | name of option to find (with - or _) | |
length | Length of optpat | |
[in,out] | opt_res | Options |
0 | No matching options |
1 | Found an option |
bool get_bool_argument | ( | const char * | argument, |
bool * | error | ||
) |
Parse a boolean command line argument.
"ON", "TRUE" and "1" will return true, other values will return false.
argument | The value argument | |
[out] | error | Error indicator |
ulonglong getopt_double2ulonglong | ( | double | v | ) |
Returns an ulonglong value containing a raw representation of the given double value.
double getopt_double_limit_value | ( | double | num, |
const struct my_option * | optp, | ||
bool * | fix | ||
) |
double getopt_ulonglong2double | ( | ulonglong | v | ) |
Returns the double value which corresponds to the given raw representation.
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.
[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. |
bool is_key_cache_variable_suffix | ( | std::string_view | suffix | ) |
ulonglong max_of_int_range | ( | int | var_type | ) |
Maximum possible value for an integer GET_* variable type.
var_type | type of integer variable (GET_*) |
void my_cleanup_options | ( | const struct my_option * | options | ) |
void my_getopt_register_get_addr | ( | my_getopt_value | func_addr | ) |
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 | ||
) |
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:
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:
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.
[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;
bool_val == (str_val == 'OFF') ?
false :
((str_val == 'ON') ?
true :
atoi(str_val) != 0)
|
void my_print_help | ( | const struct my_option * | options | ) |
void my_print_variables | ( | const struct my_option * | options | ) |
function: my_print_variables Print variables.
[in] | options | my_option list |
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).
[in] | options | my_options list |
[in] | file | stream where the output goes. |
void print_cmdline_password_warning | ( | ) |
This function should be called to print a warning message if password string is specified on the command line.
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |