MySQL  8.0.18
Source Code Documentation
my_getopt.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
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 <stdio.h>
32 #include <sys/types.h>
33 
34 #include <mysql/components/services/system_variable_source_type.h> /* enum_variable_source */
35 #include "my_config.h"
36 #include "my_inttypes.h"
37 #include "my_io.h"
38 #include "my_macros.h"
39 #include "my_sys.h" /* loglevel */
40 
41 #define GET_NO_ARG 1
42 #define GET_BOOL 2
43 #define GET_INT 3
44 #define GET_UINT 4
45 #define GET_LONG 5
46 #define GET_ULONG 6
47 #define GET_LL 7
48 #define GET_ULL 8
49 #define GET_STR 9
50 #define GET_STR_ALLOC 10
51 #define GET_DISABLED 11
52 #define GET_ENUM 12
53 #define GET_SET 13
54 #define GET_DOUBLE 14
55 #define GET_FLAGSET 15
56 #define GET_PASSWORD 16
57 
58 #if SIZEOF_INT == 4
59 #define GET_INT32 GET_INT
60 #define GET_UINT32 GET_UINT
61 #elif SIZEOF_LONG == 4
62 #define GET_INT32 GET_LONG
63 #define GET_UINT32 GET_ULONG
64 #else
65 #error Neither int or long is of 4 bytes width
66 #endif
67 
68 #define GET_ASK_ADDR 128
69 #define GET_TYPE_MASK 127
70 
71 /**
72  Enumeration of the my_option::arg_type attributes.
73  It should be noted that for historical reasons variables with the combination
74  arg_type=NO_ARG, my_option::var_type=GET_BOOL still accepts
75  arguments. This is someone counter intuitive and care should be taken
76  if the code is refactored.
77 */
79 
81  /**
82  config file path OR compiled default values
83  */
86 };
87 
88 struct TYPELIB;
89 
90 struct my_option {
91  const char *name; /**< Name of the option. name=NULL
92  marks the end of the my_option[]
93  array.
94  */
95  int id; /**< For 0<id<=255 it's means one
96  character for a short option
97  (like -A), if >255 no short option
98  is created, but a long option still
99  can be identified uniquely in the
100  my_get_one_option() callback.
101  If an opton needs neither special
102  treatment in the my_get_one_option()
103  nor one-letter short equivalent
104  use id=0.
105  id=-1 is a special case and is used
106  to generate deprecation warnings for
107  plugin options. It should not be
108  used for anything else.
109  */
110  const char *comment; /**< option comment, for autom. --help.
111  if it's NULL the option is not
112  visible in --help.
113  */
114  void *value; /**< A pointer to the variable value */
115  void *u_max_value; /**< The user def. max variable value */
116  TYPELIB *typelib; /**< Pointer to possible values */
117  ulong var_type; /**< GET_BOOL, GET_ULL, etc */
118  enum get_opt_arg_type arg_type; /**< e.g. REQUIRED_ARG or OPT_ARG */
119  longlong def_value; /**< Default value */
120  longlong min_value; /**< Min allowed value (for numbers) */
121  ulonglong max_value; /**< Max allowed value (for numbers) */
122  struct get_opt_arg_source *arg_source; /**< Represents source/path from where
123  this variable is set. */
124  long block_size; /**< Value should be a mult. of this (for numbers) */
125  void *app_type; /**< To be used by an application */
126 };
127 
128 typedef bool (*my_get_one_option)(int, const struct my_option *, char *);
129 /**
130  Used to retrieve a reference to the object (variable) that holds the value
131  for the given option. For example, if var_type is GET_UINT, the function
132  must return a pointer to a variable of type uint. A argument is stored in
133  the location pointed to by the returned pointer.
134 */
135 typedef void *(*my_getopt_value)(const char *, size_t, const struct my_option *,
136  int *);
137 
138 extern char *disabled_my_option;
139 extern bool my_getopt_print_errors;
140 extern bool my_getopt_skip_unknown;
141 extern bool log_slave_updates_supplied;
144 
145 extern "C" int handle_options(int *argc, char ***argv,
146  const struct my_option *longopts,
148 extern int my_handle_options(int *argc, char ***argv,
149  const struct my_option *longopts,
150  my_get_one_option, const char **command_list,
151  bool ignore_unknown_option);
152 extern void print_cmdline_password_warning();
153 extern void my_cleanup_options(const struct my_option *options);
154 extern void my_print_help(const struct my_option *options);
155 extern void my_print_variables(const struct my_option *options);
156 extern void my_print_variables_ex(const struct my_option *options, FILE *file);
158 
159 ulonglong getopt_ull_limit_value(ulonglong num, const struct my_option *optp,
160  bool *fix);
161 longlong getopt_ll_limit_value(longlong, const struct my_option *, bool *fix);
162 double getopt_double_limit_value(double num, const struct my_option *optp,
163  bool *fix);
165 
168 int findopt(const char *, uint, const struct my_option **);
169 
170 bool is_key_cache_variable_suffix(const char *suffix);
171 
172 // Declared here, so we can unit test it.
173 template <typename LLorULL>
174 LLorULL eval_num_suffix(const char *argument, int *error,
175  const char *option_name);
176 
177 #endif /* _my_getopt_h */
get_opt_arg_type
Enumeration of the my_option::arg_type attributes.
Definition: my_getopt.h:78
int findopt(const char *, uint, const struct my_option **)
Find option.
Definition: my_getopt.cc:912
Some common macros.
void(* my_error_reporter)(enum loglevel level, uint ecode,...)
Definition: my_sys.h:494
unsigned long long int ulonglong
Definition: my_inttypes.h:55
const char * comment
option comment, for autom.
Definition: my_getopt.h:110
void my_cleanup_options(const struct my_option *options)
Definition: my_getopt.cc:1362
get_options & argc
Definition: do_ctype.cc:51
void my_print_help(const struct my_option *options)
Definition: my_getopt.cc:1418
void * value
A pointer to the variable value.
Definition: my_getopt.h:114
my_error_reporter my_getopt_error_reporter
Definition: my_getopt.cc:60
Some integer typedefs for easier portability.
#define bool
Definition: config_static.h:42
char * argv[]
Definition: do_ctype.cc:45
void * u_max_value
The user def.
Definition: my_getopt.h:115
bool my_getopt_skip_unknown
Definition: my_getopt.cc:108
const std::string FILE("FILE")
longlong getopt_ll_limit_value(longlong, const struct my_option *, bool *fix)
Definition: my_getopt.cc:1105
void * app_type
To be used by an application.
Definition: my_getopt.h:125
bool log_slave_updates_supplied
Definition: mysqld.cc:1418
ulonglong max_of_int_range(int var_type)
Maximum possible value for an integer GET_* variable type.
Definition: my_getopt.cc:1078
TYPELIB * typelib
Pointer to possible values.
Definition: my_getopt.h:116
enum_variable_source
This enum values define how system variables are set.
Definition: system_variable_source_type.h:32
ulong var_type
GET_BOOL, GET_ULL, etc.
Definition: my_getopt.h:117
void my_getopt_register_get_addr(my_getopt_value)
Definition: my_getopt.cc:112
bool(* my_get_one_option)(int, const struct my_option *, char *)
Definition: my_getopt.h:128
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:661
longlong min_value
Min allowed value (for numbers)
Definition: my_getopt.h:120
bool my_getopt_print_errors
Definition: my_getopt.cc:101
LLorULL eval_num_suffix(const char *argument, int *error, const char *option_name)
Definition: my_getopt.cc:956
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:139
unsigned int uint
Definition: uca-dump.cc:29
#define FN_REFLEN
Definition: my_io.h:82
long long int longlong
Definition: my_inttypes.h:54
Definition: my_getopt.h:90
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:1498
Definition: my_getopt.h:78
Definition: my_getopt.h:78
Common header for many mysys elements.
void my_print_variables(const struct my_option *options)
function: my_print_variables Print variables.
Definition: my_getopt.cc:1487
const char * name
Name of the option.
Definition: my_getopt.h:91
ulonglong max_value
Max allowed value (for numbers)
Definition: my_getopt.h:121
Definition: typelib.h:34
long block_size
Value should be a mult.
Definition: my_getopt.h:124
int id
For 0<id<=255 it&#39;s means one character for a short option (like -A), if >255 no short option is creat...
Definition: my_getopt.h:95
longlong def_value
Default value.
Definition: my_getopt.h:119
double getopt_ulonglong2double(ulonglong)
Returns the double value which corresponds to the given raw representation.
Definition: my_getopt.cc:164
double getopt_double_limit_value(double num, const struct my_option *optp, bool *fix)
Definition: my_getopt.cc:1212
static const Query_options options
Definition: show_query_builder.cc:48
Definition: my_getopt.h:78
Definition: my_getopt.h:80
bool slave_preserve_commit_order_supplied
Definition: mysqld.cc:1424
Common #defines and includes for file and socket I/O.
bool is_key_cache_variable_suffix(const char *suffix)
Definition: my_getopt.cc:116
char m_path_name[FN_REFLEN]
config file path OR compiled default values
Definition: my_getopt.h:84
enum get_opt_arg_type arg_type
e.g.
Definition: my_getopt.h:118
char * disabled_my_option
Definition: my_getopt.cc:91
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:240
enum enum_variable_source m_source
Definition: my_getopt.h:85
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:135
unsigned long ulong
Definition: my_inttypes.h:48
ulonglong getopt_double2ulonglong(double)
Returns an ulonglong value containing a raw representation of the given double value.
Definition: my_getopt.cc:153
struct get_opt_arg_source * arg_source
Represents source/path from where this variable is set.
Definition: my_getopt.h:122
ulonglong getopt_ull_limit_value(ulonglong num, const struct my_option *optp, bool *fix)
Definition: my_getopt.cc:1172
Log error(cerr, "ERROR")