MySQL 8.0.30
Source Code Documentation
my_getopt.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2002, 2022, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is also distributed with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have included with MySQL.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef _my_getopt_h
25#define _my_getopt_h
26
27/**
28 @file include/my_getopt.h
29*/
30
31#include <sys/types.h>
32
33#include <cstdio>
34#include <string_view>
35
36#include <mysql/components/services/system_variable_source_type.h> /* enum_variable_source */
37#include "my_config.h"
38#include "my_inttypes.h"
39#include "my_io.h"
40#include "my_macros.h"
41#include "my_sys.h" /* loglevel */
42
43#define GET_NO_ARG 1
44#define GET_BOOL 2
45#define GET_INT 3
46#define GET_UINT 4
47#define GET_LONG 5
48#define GET_ULONG 6
49#define GET_LL 7
50#define GET_ULL 8
51#define GET_STR 9
52#define GET_STR_ALLOC 10
53#define GET_DISABLED 11
54#define GET_ENUM 12
55#define GET_SET 13
56#define GET_DOUBLE 14
57#define GET_FLAGSET 15
58#define GET_PASSWORD 16
59
60#if SIZEOF_INT == 4
61#define GET_INT32 GET_INT
62#define GET_UINT32 GET_UINT
63#elif SIZEOF_LONG == 4
64#define GET_INT32 GET_LONG
65#define GET_UINT32 GET_ULONG
66#else
67#error Neither int or long is of 4 bytes width
68#endif
69
70#define GET_ASK_ADDR 128
71#define GET_TYPE_MASK 127
72
73/**
74 Enumeration of the my_option::arg_type attributes.
75 It should be noted that for historical reasons variables with the combination
76 arg_type=NO_ARG, my_option::var_type=GET_BOOL still accepts
77 arguments. This is someone counter intuitive and care should be taken
78 if the code is refactored.
79*/
81
83 /**
84 config file path OR compiled default values
85 */
88};
89
90struct TYPELIB;
91
92struct my_option {
93 const char *name; /**< Name of the option. name=NULL
94 marks the end of the my_option[]
95 array.
96 */
97 int id; /**< For 0<id<=255 it's means one
98 character for a short option
99 (like -A), if >255 no short option
100 is created, but a long option still
101 can be identified uniquely in the
102 my_get_one_option() callback.
103 If an opton needs neither special
104 treatment in the my_get_one_option()
105 nor one-letter short equivalent
106 use id=0.
107 id=-1 is a special case and is used
108 to generate deprecation warnings for
109 plugin options. It should not be
110 used for anything else.
111 */
112 const char *comment; /**< option comment, for autom. --help.
113 if it's NULL the option is not
114 visible in --help.
115 */
116 void *value; /**< A pointer to the variable value */
117 void *u_max_value; /**< The user def. max variable value */
118 TYPELIB *typelib; /**< Pointer to possible values */
119 ulong var_type; /**< GET_BOOL, GET_ULL, etc */
120 enum get_opt_arg_type arg_type; /**< e.g. REQUIRED_ARG or OPT_ARG */
121 longlong def_value; /**< Default value */
122 longlong min_value; /**< Min allowed value (for numbers) */
123 ulonglong max_value; /**< Max allowed value (for numbers) */
124 struct get_opt_arg_source *arg_source; /**< Represents source/path from where
125 this variable is set. */
126 long block_size; /**< Value should be a mult. of this (for numbers) */
127 void *app_type; /**< To be used by an application */
128};
129
130typedef bool (*my_get_one_option)(int, const struct my_option *, char *);
131/**
132 Used to retrieve a reference to the object (variable) that holds the value
133 for the given option. For example, if var_type is GET_UINT, the function
134 must return a pointer to a variable of type uint. A argument is stored in
135 the location pointed to by the returned pointer.
136*/
137typedef void *(*my_getopt_value)(const char *, size_t, const struct my_option *,
138 int *);
139
140extern char *disabled_my_option;
141extern bool my_getopt_print_errors;
142extern bool my_getopt_skip_unknown;
146
147extern "C" int handle_options(int *argc, char ***argv,
148 const struct my_option *longopts,
150extern int my_handle_options(int *argc, char ***argv,
151 const struct my_option *longopts,
152 my_get_one_option, const char **command_list,
153 bool ignore_unknown_option);
155extern void my_cleanup_options(const struct my_option *options);
156extern void my_print_help(const struct my_option *options);
157extern void my_print_variables(const struct my_option *options);
158extern void my_print_variables_ex(const struct my_option *options, FILE *file);
160
162 bool *fix);
163longlong getopt_ll_limit_value(longlong, const struct my_option *, bool *fix);
164double getopt_double_limit_value(double num, const struct my_option *optp,
165 bool *fix);
167
170int findopt(const char *, uint, const struct my_option **);
171
172bool is_key_cache_variable_suffix(std::string_view suffix);
173
174bool get_bool_argument(const char *argument, bool *error);
175// Declared here, so we can unit test it.
176template <typename LLorULL>
177LLorULL eval_num_suffix(const char *argument, int *error,
178 const char *option_name);
179
180#endif /* _my_getopt_h */
char * argv[]
Definition: do_ctype.cc:45
get_options & argc
Definition: do_ctype.cc:51
void(* my_error_reporter)(enum loglevel level, uint ecode,...)
Definition: my_sys.h:478
void my_print_help(const struct my_option *options)
Definition: my_getopt.cc:1427
bool log_replica_updates_supplied
Definition: mysqld.cc:1640
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)...
Definition: my_getopt.cc:1507
get_opt_arg_type
Enumeration of the my_option::arg_type attributes.
Definition: my_getopt.h:80
@ OPT_ARG
Definition: my_getopt.h:80
@ REQUIRED_ARG
Definition: my_getopt.h:80
@ NO_ARG
Definition: my_getopt.h:80
bool replica_preserve_commit_order_supplied
Definition: mysqld.cc:1646
int handle_options(int *argc, char ***argv, const struct my_option *longopts, my_get_one_option)
Wrapper around my_handle_options() for interface compatibility.
Definition: my_getopt.cc:142
int findopt(const char *, uint, const struct my_option **)
Find option.
Definition: my_getopt.cc:920
LLorULL eval_num_suffix(const char *argument, int *error, const char *option_name)
Definition: my_getopt.cc:964
bool my_getopt_skip_unknown
Definition: my_getopt.cc:108
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)
Handle command line options.
Definition: my_getopt.cc:244
my_error_reporter my_getopt_error_reporter
Definition: my_getopt.cc:61
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.
Definition: my_getopt.h:137
void my_cleanup_options(const struct my_option *options)
Definition: my_getopt.cc:1371
ulonglong getopt_ull_limit_value(ulonglong num, const struct my_option *optp, bool *fix)
Definition: my_getopt.cc:1180
bool my_getopt_print_errors
Definition: my_getopt.cc:101
void my_getopt_register_get_addr(my_getopt_value)
Definition: my_getopt.cc:112
bool get_bool_argument(const char *argument, bool *error)
Parse a boolean command line argument.
Definition: my_getopt.cc:729
char * disabled_my_option
Definition: my_getopt.cc:91
bool is_key_cache_variable_suffix(std::string_view suffix)
Definition: my_getopt.cc:116
ulonglong getopt_double2ulonglong(double)
Returns an ulonglong value containing a raw representation of the given double value.
Definition: my_getopt.cc:157
double getopt_double_limit_value(double num, const struct my_option *optp, bool *fix)
Definition: my_getopt.cc:1220
void print_cmdline_password_warning()
This function should be called to print a warning message if password string is specified on the comm...
Definition: my_getopt.cc:669
double getopt_ulonglong2double(ulonglong)
Returns the double value which corresponds to the given raw representation.
Definition: my_getopt.cc:168
ulonglong max_of_int_range(int var_type)
Maximum possible value for an integer GET_* variable type.
Definition: my_getopt.cc:1086
bool(* my_get_one_option)(int, const struct my_option *, char *)
Definition: my_getopt.h:130
longlong getopt_ll_limit_value(longlong, const struct my_option *, bool *fix)
Definition: my_getopt.cc:1113
void my_print_variables(const struct my_option *options)
function: my_print_variables Print variables.
Definition: my_getopt.cc:1496
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:55
long long int longlong
Definition: my_inttypes.h:54
Common #defines and includes for file and socket I/O.
#define FN_REFLEN
Definition: my_io.h:82
Some common macros.
Common header for many mysys elements.
Log error(cerr, "ERROR")
const std::string FILE("FILE")
Definition: os0file.h:85
Definition: options.cc:48
Definition: typelib.h:34
Definition: my_getopt.h:82
char m_path_name[FN_REFLEN]
config file path OR compiled default values
Definition: my_getopt.h:86
enum enum_variable_source m_source
Definition: my_getopt.h:87
Definition: my_getopt.h:92
const char * comment
option comment, for autom.
Definition: my_getopt.h:112
longlong min_value
Min allowed value (for numbers)
Definition: my_getopt.h:122
ulonglong max_value
Max allowed value (for numbers)
Definition: my_getopt.h:123
longlong def_value
Default value.
Definition: my_getopt.h:121
void * app_type
To be used by an application.
Definition: my_getopt.h:127
long block_size
Value should be a mult.
Definition: my_getopt.h:126
const char * name
Name of the option.
Definition: my_getopt.h:93
void * u_max_value
The user def.
Definition: my_getopt.h:117
ulong var_type
GET_BOOL, GET_ULL, etc.
Definition: my_getopt.h:119
TYPELIB * typelib
Pointer to possible values.
Definition: my_getopt.h:118
void * value
A pointer to the variable value.
Definition: my_getopt.h:116
enum get_opt_arg_type arg_type
e.g.
Definition: my_getopt.h:120
int id
For 0<id<=255 it's means one character for a short option (like -A), if >255 no short option is creat...
Definition: my_getopt.h:97
struct get_opt_arg_source * arg_source
Represents source/path from where this variable is set.
Definition: my_getopt.h:124
enum_variable_source
This enum values define how system variables are set.
Definition: system_variable_source_type.h:32
unsigned int uint
Definition: uca-dump.cc:29