![]() |
MySQL 9.2.0
Source Code Documentation
|
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <type_traits>
#include "m_string.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_default.h"
#include "my_getopt.h"
#include "my_inttypes.h"
#include "my_io.h"
#include "my_macros.h"
#include "mysql/my_loglevel.h"
#include "mysql/service_mysql_alloc.h"
#include "mysql/strings/dtoa.h"
#include "mysql/strings/int2str.h"
#include "mysql/strings/m_ctype.h"
#include "mysql_version.h"
#include "mysys/mysys_priv.h"
#include "mysys_err.h"
#include "strmake.h"
#include "typelib.h"
Classes | |
union | ull_dbl |
Typedefs | |
typedef void(* | init_func_p) (const struct my_option *option, void *variable, longlong value) |
Enumerations | |
enum | enum_special_opt { OPT_SKIP , OPT_DISABLE , OPT_ENABLE , OPT_MAXIMUM , OPT_LOOSE } |
Functions | |
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... | |
Variables | |
my_error_reporter | my_getopt_error_reporter = &my_message_local |
static const char * | special_opt_prefix [] |
static const uint | special_opt_prefix_lengths [] = {4, 7, 6, 7, 5, 0} |
char * | disabled_my_option = const_cast<char *>("0") |
static char | enabled_my_option [] = "1" |
static char | space_char [] = " " |
bool | my_getopt_print_errors = true |
bool | my_getopt_skip_unknown = false |
static my_getopt_value | getopt_get_addr |
enum enum_special_opt |
|
static |
Check for struct options.
[in] | cur_arg | Current argument under processing from argv |
[in] | key_name | variable where to store the possible key name |
In case option is a struct option, returns a pointer to the current argument at the position where the struct option (key_name) ends, the next character after the dot. In case argument is not a struct option, returns a pointer to the argument. key_name will hold the name of the key, or 0 if not found.
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 * | |||
) |
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 |
|
static |
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 |
|
static |
Parse a boolean command line argument as the SQL interpreter does.
"ON" and "TRUE" will return true, "OFF" and FALSE" will return false;
Non-zero numeric values will return true, zero will return false.
argument | The value argument | |
[out] | error | Error indicator |
|
static |
|
static |
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 | ||
) |
|
static |
|
static |
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. |
|
static |
|
static |
bool is_key_cache_variable_suffix | ( | std::string_view | suffix | ) |
|
inlinestatic |
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.
|
static |
Prints variable or option name, replacing _ with - to given file stream parameter (by default to stdout).
[in] | optp | my_option parameter |
[in] | file | stream where the output of optp parameter name goes (by default to stdout). |
|
static |
|
static |
Will set the source and file name from where this options is set in my_option struct.
char* disabled_my_option = const_cast<char *>("0") |
|
static |
|
static |
my_error_reporter my_getopt_error_reporter = &my_message_local |
bool my_getopt_print_errors = true |
bool my_getopt_skip_unknown = false |
|
static |
|
static |
|
static |