1 /*
2    Copyright (c) 2002, 2014, 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 #include "my_sys.h"                             /* loglevel */
28 
29 C_MODE_START
30 
31 #define GET_NO_ARG     1
32 #define GET_BOOL       2
33 #define GET_INT        3
34 #define GET_UINT       4
35 #define GET_LONG       5
36 #define GET_ULONG      6
37 #define GET_LL         7
38 #define GET_ULL        8
39 #define GET_STR        9
40 #define GET_STR_ALLOC 10
41 #define GET_DISABLED  11
42 #define GET_ENUM      12
43 #define GET_SET       13
44 #define GET_DOUBLE    14
45 #define GET_FLAGSET   15
46 #define GET_PASSWORD  16
47 
48 #define GET_ASK_ADDR	 128
49 #define GET_TYPE_MASK	 127
50 
51 /**
52   Enumeration of the my_option::arg_type attributes.
53   It should be noted that for historical reasons variables with the combination
54   arg_type=NO_ARG, my_option::var_type=GET_BOOL still accepts
55   arguments. This is someone counter intuitive and care should be taken
56   if the code is refactored.
57 */
58 enum get_opt_arg_type { NO_ARG, OPT_ARG, REQUIRED_ARG };
59 
60 struct st_typelib;
61 
62 struct my_option
63 {
64   const char *name;                     /**< Name of the option. name=NULL
65                                            marks the end of the my_option[]
66                                            array.
67                                          */
68   int        id;                        /**< For 0<id<255 it's means one
69                                            character for a short option
70                                            (like -A), if >255 no short option
71                                            is created, but a long option still
72                                            can be identified uniquely in the
73                                            my_get_one_option() callback.
74                                            If an opton needs neither special
75                                            treatment in the my_get_one_option()
76                                            nor one-letter short equivalent
77                                            use id=0.
78                                            id=-1 is a special case and is used
79                                            to generate deprecation warnings for
80                                            plugin options. It should not be
81                                            used for anything else.
82                                          */
83   const char *comment;                  /**< option comment, for autom. --help.
84                                            if it's NULL the option is not
85                                            visible in --help.
86                                          */
87   void       *value;                    /**< A pointer to the variable value */
88   void       *u_max_value;              /**< The user def. max variable value */
89   struct st_typelib *typelib;           /**< Pointer to possible values */
90   ulong     var_type;                   /**< GET_BOOL, GET_ULL, etc */
91   enum get_opt_arg_type arg_type;       /**< e.g. REQUIRED_ARG or OPT_ARG */
92   longlong   def_value;                 /**< Default value */
93   longlong   min_value;                 /**< Min allowed value (for numbers) */
94   ulonglong  max_value;                 /**< Max allowed value (for numbers) */
95   longlong   sub_size;                  /**< Unused                          */
96   long       block_size;                /**< Value should be a mult. of this (for numbers) */
97   void       *app_type;                 /**< To be used by an application */
98 };
99 
100 
101 typedef my_bool (*my_get_one_option)(int, const struct my_option *, char *);
102 /**
103   Used to retrieve a reference to the object (variable) that holds the value
104   for the given option. For example, if var_type is GET_UINT, the function
105   must return a pointer to a variable of type uint. A argument is stored in
106   the location pointed to by the returned pointer.
107 */
108 typedef void *(*my_getopt_value)(const char *, uint, const struct my_option *,
109                                  int *);
110 
111 
112 extern char *disabled_my_option;
113 extern my_bool my_getopt_print_errors;
114 extern my_bool my_getopt_skip_unknown;
115 extern my_error_reporter my_getopt_error_reporter;
116 
117 extern int handle_options (int *argc, char ***argv,
118 			   const struct my_option *longopts, my_get_one_option);
119 extern int my_handle_options (int *argc, char ***argv,
120                               const struct my_option *longopts,
121                               my_get_one_option,
122                               const char **command_list);
123 extern void print_cmdline_password_warning();
124 extern void my_cleanup_options(const struct my_option *options);
125 extern void my_handle_options_end();
126 extern void my_cleanup_options(const struct my_option *options);
127 extern void my_print_help(const struct my_option *options);
128 extern void my_print_variables(const struct my_option *options);
129 extern void my_getopt_register_get_addr(my_getopt_value);
130 
131 ulonglong getopt_ull_limit_value(ulonglong num, const struct my_option *optp,
132                                  my_bool *fix);
133 longlong getopt_ll_limit_value(longlong, const struct my_option *,
134                                my_bool *fix);
135 double getopt_double_limit_value(double num, const struct my_option *optp,
136                                  my_bool *fix);
137 my_bool getopt_compare_strings(const char *s, const char *t, uint length);
138 ulonglong max_of_int_range(int var_type);
139 
140 /* Get the specific range constraint for the value named. If you do not
141    have the name length availa ble, specify 0. Specify 0 for 'create' to
142    simply obtain the existong value or specify a size value to have the
143    storage allocated if it does not yet exist. */
144 extern const void* getopt_constraint_get_max_value(const char *name,
145                                                    size_t length,
146                                                    size_t create);
147 extern const void* getopt_constraint_get_min_value(const char *name,
148                                                    size_t length,
149                                                    size_t create);
150 extern const my_bool* getopt_constraint_get_hidden_value(const char *name,
151                                                          size_t length,
152                                                          my_bool create);
153 extern const my_bool* getopt_constraint_get_readonly_value(const char *name,
154                                                            size_t length,
155                                                            my_bool create);
156 
157 ulonglong getopt_double2ulonglong(double);
158 double getopt_ulonglong2double(ulonglong);
159 
160 C_MODE_END
161 
162 #endif /* _my_getopt_h */
163 
164