9
3

my_getopt.h 5.4 KB

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