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