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