Commit eb3431d5 authored by Sergei Golubchik's avatar Sergei Golubchik

cleanup: my_getopt, consistency

almost all my_getopt settings and callbacks are global variables,
directly assignable to configure my_getopt. Only getopt_get_addr
was using a setter function. Get rid of it, make it a global
directly assignable variable like all other settings.

Also make getopt_compare_strings() static.
parent 8965ae27
...@@ -107,13 +107,13 @@ extern my_bool my_getopt_print_errors; ...@@ -107,13 +107,13 @@ extern my_bool my_getopt_print_errors;
extern my_bool my_getopt_skip_unknown; extern my_bool my_getopt_skip_unknown;
extern my_bool my_getopt_prefix_matching; extern my_bool my_getopt_prefix_matching;
extern my_error_reporter my_getopt_error_reporter; extern my_error_reporter my_getopt_error_reporter;
extern my_getopt_value my_getopt_get_addr;
extern int handle_options (int *argc, char ***argv, extern int handle_options (int *argc, char ***argv,
const struct my_option *longopts, my_get_one_option); const struct my_option *longopts, my_get_one_option);
extern void my_cleanup_options(const struct my_option *options); extern void my_cleanup_options(const struct my_option *options);
extern void my_print_help(const struct my_option *options); extern void my_print_help(const struct my_option *options);
extern void my_print_variables(const struct my_option *options); extern void my_print_variables(const struct my_option *options);
extern void my_getopt_register_get_addr(my_getopt_value);
ulonglong getopt_ull_limit_value(ulonglong num, const struct my_option *optp, ulonglong getopt_ull_limit_value(ulonglong num, const struct my_option *optp,
my_bool *fix); my_bool *fix);
...@@ -121,7 +121,6 @@ longlong getopt_ll_limit_value(longlong, const struct my_option *, ...@@ -121,7 +121,6 @@ longlong getopt_ll_limit_value(longlong, const struct my_option *,
my_bool *fix); my_bool *fix);
double getopt_double_limit_value(double num, const struct my_option *optp, double getopt_double_limit_value(double num, const struct my_option *optp,
my_bool *fix); my_bool *fix);
my_bool getopt_compare_strings(const char *s, const char *t, uint length);
ulonglong getopt_double2ulonglong(double); ulonglong getopt_double2ulonglong(double);
double getopt_ulonglong2double(ulonglong); double getopt_ulonglong2double(ulonglong);
......
...@@ -31,7 +31,7 @@ static void default_reporter(enum loglevel level, const char *format, ...); ...@@ -31,7 +31,7 @@ static void default_reporter(enum loglevel level, const char *format, ...);
my_error_reporter my_getopt_error_reporter= &default_reporter; my_error_reporter my_getopt_error_reporter= &default_reporter;
static int findopt(char *, uint, const struct my_option **, const char **); static int findopt(char *, uint, const struct my_option **, const char **);
my_bool getopt_compare_strings(const char *, const char *, uint); static my_bool getopt_compare_strings(const char *, const char *, uint);
static longlong getopt_ll(char *arg, const struct my_option *optp, int *err); static longlong getopt_ll(char *arg, const struct my_option *optp, int *err);
static ulonglong getopt_ull(char *, const struct my_option *, int *); static ulonglong getopt_ull(char *, const struct my_option *, int *);
static double getopt_double(char *arg, const struct my_option *optp, int *err); static double getopt_double(char *arg, const struct my_option *optp, int *err);
...@@ -79,8 +79,9 @@ my_bool my_getopt_skip_unknown= 0; ...@@ -79,8 +79,9 @@ my_bool my_getopt_skip_unknown= 0;
*/ */
my_bool my_getopt_prefix_matching= 1; my_bool my_getopt_prefix_matching= 1;
static void default_reporter(enum loglevel level, my_getopt_value my_getopt_get_addr= 0;
const char *format, ...)
static void default_reporter(enum loglevel level, const char *format, ...)
{ {
va_list args; va_list args;
DBUG_ENTER("default_reporter"); DBUG_ENTER("default_reporter");
...@@ -97,13 +98,6 @@ static void default_reporter(enum loglevel level, ...@@ -97,13 +98,6 @@ static void default_reporter(enum loglevel level,
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
static my_getopt_value getopt_get_addr;
void my_getopt_register_get_addr(my_getopt_value func_addr)
{
getopt_get_addr= func_addr;
}
union ull_dbl union ull_dbl
{ {
ulonglong ull; ulonglong ull;
...@@ -408,9 +402,9 @@ int handle_options(int *argc, char ***argv, ...@@ -408,9 +402,9 @@ int handle_options(int *argc, char ***argv,
DBUG_RETURN(EXIT_OPTION_DISABLED); DBUG_RETURN(EXIT_OPTION_DISABLED);
} }
error= 0; error= 0;
value= optp->var_type & GET_ASK_ADDR ? value= optp->var_type & GET_ASK_ADDR
(*getopt_get_addr)(key_name, (uint) strlen(key_name), optp, &error) : ? (*my_getopt_get_addr)(key_name, (uint)strlen(key_name), optp, &error)
optp->value; : optp->value;
if (error) if (error)
DBUG_RETURN(error); DBUG_RETURN(error);
...@@ -1430,8 +1424,8 @@ static void init_variables(const struct my_option *options, ...@@ -1430,8 +1424,8 @@ static void init_variables(const struct my_option *options,
*/ */
if (options->u_max_value) if (options->u_max_value)
func_init_one_value(options, options->u_max_value, options->max_value); func_init_one_value(options, options->u_max_value, options->max_value);
value= (options->var_type & GET_ASK_ADDR ? value= options->var_type & GET_ASK_ADDR ?
(*getopt_get_addr)("", 0, options, 0) : options->value); (*my_getopt_get_addr)("", 0, options, 0) : options->value;
if (value) if (value)
func_init_one_value(options, value, options->def_value); func_init_one_value(options, value, options->def_value);
} }
...@@ -1635,8 +1629,8 @@ void my_print_variables(const struct my_option *options) ...@@ -1635,8 +1629,8 @@ void my_print_variables(const struct my_option *options)
for (optp= options; optp->name; optp++) for (optp= options; optp->name; optp++)
{ {
void *value= (optp->var_type & GET_ASK_ADDR ? void *value= optp->var_type & GET_ASK_ADDR ?
(*getopt_get_addr)("", 0, optp, 0) : optp->value); (*my_getopt_get_addr)("", 0, optp, 0) : optp->value;
if (value) if (value)
{ {
length= print_name(optp); length= print_name(optp);
......
...@@ -6357,7 +6357,6 @@ int handle_early_options() ...@@ -6357,7 +6357,6 @@ int handle_early_options()
int ho_error; int ho_error;
DYNAMIC_ARRAY all_early_options; DYNAMIC_ARRAY all_early_options;
my_getopt_register_get_addr(NULL);
/* Skip unknown options so that they may be processed later */ /* Skip unknown options so that they may be processed later */
my_getopt_skip_unknown= TRUE; my_getopt_skip_unknown= TRUE;
...@@ -8532,13 +8531,12 @@ static int get_options(int *argc_ptr, char ***argv_ptr) ...@@ -8532,13 +8531,12 @@ static int get_options(int *argc_ptr, char ***argv_ptr)
{ {
int ho_error; int ho_error;
my_getopt_register_get_addr(mysql_getopt_value); my_getopt_get_addr= mysql_getopt_value;
my_getopt_error_reporter= option_error_reporter; my_getopt_error_reporter= option_error_reporter;
/* prepare all_options array */ /* prepare all_options array */
my_init_dynamic_array(&all_options, sizeof(my_option), my_init_dynamic_array(&all_options, sizeof(my_option),
array_elements(my_long_options) + array_elements(my_long_options) + sys_var_elements(),
sys_var_elements(),
array_elements(my_long_options)/4, MYF(0)); array_elements(my_long_options)/4, MYF(0));
add_many_options(&all_options, my_long_options, array_elements(my_long_options)); add_many_options(&all_options, my_long_options, array_elements(my_long_options));
sys_var_add_options(&all_options, 0); sys_var_add_options(&all_options, 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment