Clone of PhatAC @ https://github.com/floaterxk/PhatAC

my_getopt.h 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
  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. C_MODE_START
  17. #define GET_NO_ARG 1
  18. #define GET_BOOL 2
  19. #define GET_INT 3
  20. #define GET_UINT 4
  21. #define GET_LONG 5
  22. #define GET_ULONG 6
  23. #define GET_LL 7
  24. #define GET_ULL 8
  25. #define GET_STR 9
  26. #define GET_STR_ALLOC 10
  27. #define GET_DISABLED 11
  28. #define GET_ENUM 12
  29. #define GET_SET 13
  30. #define GET_DOUBLE 14
  31. #define GET_FLAGSET 15
  32. #define GET_PASSWORD 16
  33. #if SIZEOF_INT == 4
  34. #define GET_INT32 GET_INT
  35. #define GET_UINT32 GET_UINT
  36. #elif SIZEOF_LONG == 4
  37. #define GET_INT32 GET_LONG
  38. #define GET_UINT32 GET_ULONG
  39. #else
  40. #error Neither int or long is of 4 bytes width
  41. #endif
  42. #define GET_ASK_ADDR 128
  43. #define GET_TYPE_MASK 127
  44. /**
  45. Enumeration of the my_option::arg_type attributes.
  46. It should be noted that for historical reasons variables with the combination
  47. arg_type=NO_ARG, my_option::var_type=GET_BOOL still accepts
  48. arguments. This is someone counter intuitive and care should be taken
  49. if the code is refactored.
  50. */
  51. enum get_opt_arg_type { NO_ARG, OPT_ARG, REQUIRED_ARG };
  52. struct st_typelib;
  53. struct my_option
  54. {
  55. const char *name; /**< Name of the option. name=NULL
  56. marks the end of the my_option[]
  57. array.
  58. */
  59. int id; /**< For 0<id<=255 it's means one
  60. character for a short option
  61. (like -A), if >255 no short option
  62. is created, but a long option still
  63. can be identified uniquely in the
  64. my_get_one_option() callback.
  65. If an opton needs neither special
  66. treatment in the my_get_one_option()
  67. nor one-letter short equivalent
  68. use id=0.
  69. id=-1 is a special case and is used
  70. to generate deprecation warnings for
  71. plugin options. It should not be
  72. used for anything else.
  73. */
  74. const char *comment; /**< option comment, for autom. --help.
  75. if it's NULL the option is not
  76. visible in --help.
  77. */
  78. void *value; /**< A pointer to the variable value */
  79. void *u_max_value; /**< The user def. max variable value */
  80. struct st_typelib *typelib; /**< Pointer to possible values */
  81. ulong var_type; /**< GET_BOOL, GET_ULL, etc */
  82. enum get_opt_arg_type arg_type; /**< e.g. REQUIRED_ARG or OPT_ARG */
  83. longlong def_value; /**< Default value */
  84. longlong min_value; /**< Min allowed value (for numbers) */
  85. ulonglong max_value; /**< Max allowed value (for numbers) */
  86. longlong sub_size; /**< Unused */
  87. long block_size; /**< Value should be a mult. of this (for numbers) */
  88. void *app_type; /**< To be used by an application */
  89. };
  90. typedef my_bool (*my_get_one_option)(int, const struct my_option *, char *);
  91. /**
  92. Used to retrieve a reference to the object (variable) that holds the value
  93. for the given option. For example, if var_type is GET_UINT, the function
  94. must return a pointer to a variable of type uint. A argument is stored in
  95. the location pointed to by the returned pointer.
  96. */
  97. typedef void *(*my_getopt_value)(const char *, size_t, const struct my_option *,
  98. int *);
  99. extern char *disabled_my_option;
  100. extern my_bool my_getopt_print_errors;
  101. extern my_bool my_getopt_skip_unknown;
  102. extern my_error_reporter my_getopt_error_reporter;
  103. extern int handle_options (int *argc, char ***argv,
  104. const struct my_option *longopts, my_get_one_option);
  105. extern int my_handle_options (int *argc, char ***argv,
  106. const struct my_option *longopts,
  107. my_get_one_option,
  108. const char **command_list, my_bool ignore_unknown_option);
  109. extern void print_cmdline_password_warning();
  110. extern void my_cleanup_options(const struct my_option *options);
  111. extern void my_cleanup_options(const struct my_option *options);
  112. extern void my_print_help(const struct my_option *options);
  113. extern void my_print_variables(const struct my_option *options);
  114. extern void my_print_variables_ex(const struct my_option *options, FILE* file);
  115. extern void my_getopt_register_get_addr(my_getopt_value);
  116. ulonglong getopt_ull_limit_value(ulonglong num, const struct my_option *optp,
  117. my_bool *fix);
  118. longlong getopt_ll_limit_value(longlong, const struct my_option *,
  119. my_bool *fix);
  120. double getopt_double_limit_value(double num, const struct my_option *optp,
  121. my_bool *fix);
  122. my_bool getopt_compare_strings(const char *s, const char *t, uint length);
  123. ulonglong max_of_int_range(int var_type);
  124. ulonglong getopt_double2ulonglong(double);
  125. double getopt_ulonglong2double(ulonglong);
  126. C_MODE_END
  127. #endif /* _my_getopt_h */