| 1 | /* |
| 2 | Copyright (c) 2002, 2013, 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 as published by |
| 6 | the Free Software Foundation; version 2 of the License. |
| 7 | |
| 8 | This program is distributed in the hope that it will be useful, |
| 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | GNU General Public License for more details. |
| 12 | |
| 13 | You should have received a copy of the GNU General Public License |
| 14 | along with this program; if not, write to the Free Software |
| 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
| 16 | |
| 17 | #ifndef _my_getopt_h |
| 18 | #define _my_getopt_h |
| 19 | |
| 20 | #include "my_sys.h" /* loglevel */ |
| 21 | /* my_getopt and my_default are almost always used together */ |
| 22 | #include <my_default.h> |
| 23 | |
| 24 | C_MODE_START |
| 25 | |
| 26 | #define GET_NO_ARG 1 |
| 27 | #define GET_BOOL 2 |
| 28 | #define GET_INT 3 |
| 29 | #define GET_UINT 4 |
| 30 | #define GET_LONG 5 |
| 31 | #define GET_ULONG 6 |
| 32 | #define GET_LL 7 |
| 33 | #define GET_ULL 8 |
| 34 | #define GET_STR 9 |
| 35 | #define GET_STR_ALLOC 10 |
| 36 | #define GET_DISABLED 11 |
| 37 | #define GET_ENUM 12 |
| 38 | #define GET_SET 13 |
| 39 | #define GET_DOUBLE 14 |
| 40 | #define GET_FLAGSET 15 |
| 41 | #define GET_BIT 16 |
| 42 | |
| 43 | #define GET_ASK_ADDR 128 |
| 44 | #define GET_AUTO 64 |
| 45 | #define GET_TYPE_MASK 63 |
| 46 | |
| 47 | /** |
| 48 | Enumeration of the my_option::arg_type attributes. |
| 49 | It should be noted that for historical reasons variables with the combination |
| 50 | arg_type=NO_ARG, my_option::var_type=GET_BOOL still accepts |
| 51 | arguments. This is someone counter intuitive and care should be taken |
| 52 | if the code is refactored. |
| 53 | */ |
| 54 | enum get_opt_arg_type { NO_ARG, OPT_ARG, REQUIRED_ARG }; |
| 55 | |
| 56 | struct st_typelib; |
| 57 | |
| 58 | struct my_option |
| 59 | { |
| 60 | const char *name; /**< Name of the option. name=NULL |
| 61 | marks the end of the my_option[] |
| 62 | array. |
| 63 | */ |
| 64 | int id; /**< For 0<id<255 it's means one |
| 65 | character for a short option |
| 66 | (like -A), if >255 no short option |
| 67 | is created, but a long option still |
| 68 | can be identified uniquely in the |
| 69 | my_get_one_option() callback. |
| 70 | If an opton needs neither special |
| 71 | treatment in the my_get_one_option() |
| 72 | nor one-letter short equivalent |
| 73 | use id=0 |
| 74 | */ |
| 75 | const char *; /**< option comment, for autom. --help. |
| 76 | if it's NULL the option is not |
| 77 | visible in --help. |
| 78 | */ |
| 79 | void *value; /**< A pointer to the variable value */ |
| 80 | void *u_max_value; /**< The user def. max variable value */ |
| 81 | struct st_typelib *typelib; /**< Pointer to possible values */ |
| 82 | ulong var_type; /**< GET_BOOL, GET_ULL, etc */ |
| 83 | enum get_opt_arg_type arg_type; /**< e.g. REQUIRED_ARG or OPT_ARG */ |
| 84 | longlong def_value; /**< Default value */ |
| 85 | longlong min_value; /**< Min allowed value (for numbers) */ |
| 86 | ulonglong max_value; /**< Max allowed value (for numbers) */ |
| 87 | longlong sub_size; /**< Unused */ |
| 88 | long block_size; /**< Value should be a mult. of this (for numbers) */ |
| 89 | void *app_type; /**< To be used by an application */ |
| 90 | }; |
| 91 | |
| 92 | typedef my_bool (*my_get_one_option)(int, const struct my_option *, char *); |
| 93 | |
| 94 | /** |
| 95 | Used to retrieve a reference to the object (variable) that holds the value |
| 96 | for the given option. For example, if var_type is GET_UINT, the function |
| 97 | must return a pointer to a variable of type uint. A argument is stored in |
| 98 | the location pointed to by the returned pointer. |
| 99 | */ |
| 100 | typedef void *(*my_getopt_value)(const char *, uint, const struct my_option *, |
| 101 | int *); |
| 102 | |
| 103 | |
| 104 | extern char *disabled_my_option; |
| 105 | extern char *autoset_my_option; |
| 106 | extern my_bool my_getopt_print_errors; |
| 107 | extern my_bool my_getopt_skip_unknown; |
| 108 | extern my_bool my_getopt_prefix_matching; |
| 109 | extern my_error_reporter my_getopt_error_reporter; |
| 110 | |
| 111 | extern int handle_options (int *argc, char ***argv, |
| 112 | const struct my_option *longopts, my_get_one_option); |
| 113 | extern void my_cleanup_options(const struct my_option *options); |
| 114 | extern void my_print_help(const struct my_option *options); |
| 115 | extern void my_print_variables(const struct my_option *options); |
| 116 | extern void my_getopt_register_get_addr(my_getopt_value); |
| 117 | |
| 118 | ulonglong getopt_ull_limit_value(ulonglong num, const struct my_option *optp, |
| 119 | my_bool *fix); |
| 120 | longlong getopt_ll_limit_value(longlong, const struct my_option *, |
| 121 | my_bool *fix); |
| 122 | double getopt_double_limit_value(double num, const struct my_option *optp, |
| 123 | my_bool *fix); |
| 124 | my_bool getopt_compare_strings(const char *s, const char *t, uint length); |
| 125 | |
| 126 | ulonglong getopt_double2ulonglong(double); |
| 127 | double getopt_ulonglong2double(ulonglong); |
| 128 | |
| 129 | C_MODE_END |
| 130 | |
| 131 | #endif /* _my_getopt_h */ |
| 132 | |
| 133 | |