Commit c3f7e3bb authored by unknown's avatar unknown

Added global my_getopt_error_reporter function pointer which is

used in the handle_options() function (instead of using additional 
handle_option() parameter). The default value of the 
my_getopt_error_reporter is default_reporter(). One can set it to
other functions if case of need.


client/mysql.cc:
  Removed extra handle_optins()'s parameter.
client/mysqladmin.c:
  Removed extra handle_optins()'s parameter.
client/mysqlbinlog.cc:
  Removed extra handle_optins()'s parameter.
client/mysqlcheck.c:
  Removed extra handle_optins()'s parameter.
client/mysqldump.c:
  Removed extra handle_optins()'s parameter.
client/mysqlimport.c:
  Removed extra handle_optins()'s parameter.
client/mysqlmanager-pwgen.c:
  Removed extra handle_optins()'s parameter.
client/mysqlmanagerc.c:
  Removed extra handle_optins()'s parameter.
client/mysqlshow.c:
  Removed extra handle_optins()'s parameter.
client/mysqltest.c:
  Removed extra handle_optins()'s parameter.
extra/my_print_defaults.c:
  Removed extra handle_optins()'s parameter.
extra/mysql_install.c:
  Removed extra handle_optins()'s parameter.
extra/mysql_waitpid.c:
  Removed extra handle_optins()'s parameter.
extra/perror.c:
  Removed extra handle_optins()'s parameter.
extra/resolve_stack_dump.c:
  Removed extra handle_optins()'s parameter.
extra/resolveip.c:
  Removed extra handle_optins()'s parameter.
include/my_getopt.h:
  Removed extra handle_optins()'s parameter.
isam/isamchk.c:
  Removed extra handle_optins()'s parameter.
isam/pack_isam.c:
  Removed extra handle_optins()'s parameter.
myisam/mi_test1.c:
  Removed extra handle_optins()'s parameter.
myisam/myisam_ftdump.c:
  Removed extra handle_optins()'s parameter.
myisam/myisamchk.c:
  Removed extra handle_optins()'s parameter.
myisam/myisampack.c:
  Removed extra handle_optins()'s parameter.
sql/gen_lex_hash.cc:
  Removed extra handle_optins()'s parameter.
sql/mysqld.cc:
  Removed extra handle_optins()'s parameter.
tools/mysqlmanager.c:
  Removed extra handle_optins()'s parameter.
parent 832cdfff
......@@ -759,7 +759,7 @@ static int get_options(int argc, char **argv)
opt_max_allowed_packet= *mysql_params->p_max_allowed_packet;
opt_net_buffer_length= *mysql_params->p_net_buffer_length;
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option, 0)))
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
exit(ho_error);
*mysql_params->p_max_allowed_packet= opt_max_allowed_packet;
......
......@@ -254,7 +254,7 @@ int main(int argc,char *argv[])
mysql_init(&mysql);
load_defaults("my",load_default_groups,&argc,&argv);
save_argv = argv; /* Save for free_defaults */
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option, 0)))
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
{
free_defaults(save_argv);
exit(ho_error);
......
......@@ -559,7 +559,7 @@ static int parse_args(int *argc, char*** argv)
result_file = stdout;
load_defaults("my",load_default_groups,argc,argv);
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option, NULL)))
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
exit(ho_error);
return 0;
......
......@@ -273,7 +273,7 @@ static int get_options(int *argc, char ***argv)
load_defaults("my", load_default_groups, argc, argv);
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option, 0)))
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
exit(ho_error);
if (!what_to_do)
......
......@@ -413,7 +413,7 @@ static int get_options(int *argc, char ***argv)
md_result_file= stdout;
load_defaults("my",load_default_groups,argc,argv);
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option, 0)))
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
exit(ho_error);
*mysql_params->p_max_allowed_packet= opt_max_allowed_packet;
......
......@@ -206,7 +206,7 @@ static int get_options(int *argc, char ***argv)
{
int ho_error;
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option, 0)))
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
exit(ho_error);
if (enclosed && opt_enclosed)
......
......@@ -95,7 +95,7 @@ int parse_args(int argc, char** argv)
{
int ho_error;
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option, NULL)))
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
exit(ho_error);
return 0;
......
......@@ -133,7 +133,7 @@ int parse_args(int argc, char **argv)
load_defaults("my",load_default_groups,&argc,&argv);
default_argv= argv;
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option, NULL)))
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
exit(ho_error);
return 0;
......
......@@ -261,7 +261,7 @@ get_options(int *argc,char ***argv)
{
int ho_error;
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option, 0)))
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
exit(ho_error);
if (tty_password)
......
......@@ -2062,7 +2062,7 @@ int parse_args(int argc, char **argv)
load_defaults("my",load_default_groups,&argc,&argv);
default_argv= argv;
if ((handle_options(&argc, &argv, my_long_options, get_one_option, 0)))
if ((handle_options(&argc, &argv, my_long_options, get_one_option)))
exit(1);
if (argc > 1)
......
......@@ -100,7 +100,7 @@ static int get_options(int *argc,char ***argv)
{
int ho_error;
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option, NULL)))
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
exit(ho_error);
if (*argc < 1)
......
......@@ -218,7 +218,7 @@ static int parse_args(int argc, char **argv)
{
int ho_error;
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option, NULL)))
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
exit(ho_error);
return 0;
......
......@@ -67,7 +67,7 @@ int main(int argc, char *argv[])
progname= argv[0];
if (handle_options(&argc, &argv, my_long_options, get_one_option, NULL))
if (handle_options(&argc, &argv, my_long_options, get_one_option))
exit(-1);
if (!argv[0] || !argv[1] || (pid= atoi(argv[0])) <= 0 ||
(t= atoi(argv[1])) <= 0)
......
......@@ -145,7 +145,7 @@ static int get_options(int *argc,char ***argv)
{
int ho_error;
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option, NULL)))
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
exit(ho_error);
if (!*argc && !print_all_codes)
......
......@@ -121,7 +121,7 @@ static int parse_args(int argc, char **argv)
{
int ho_error;
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option, NULL)))
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
exit(ho_error);
/*
......
......@@ -90,7 +90,7 @@ static int get_options(int *argc,char ***argv)
{
int ho_error;
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option, NULL)))
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
exit(ho_error);
if (*argc == 0)
......
......@@ -50,15 +50,15 @@ struct my_option
int app_type; /* To be used by an application */
};
extern char *disabled_my_option;
extern my_bool my_getopt_print_errors;
typedef my_bool (* my_get_one_option) (int, const struct my_option *, char * );
typedef void (* my_error_reporter) (enum loglevel level, const char *format, ... );
extern char *disabled_my_option;
extern my_bool my_getopt_print_errors;
extern my_error_reporter my_getopt_error_reporter;
extern int handle_options (int *argc, char ***argv,
const struct my_option *longopts, my_get_one_option,
my_error_reporter );
const struct my_option *longopts, my_get_one_option);
extern void my_print_help(const struct my_option *options);
extern void my_print_variables(const struct my_option *options);
......
......@@ -670,7 +670,7 @@ static void get_options(register int *argc, register char ***argv)
if (isatty(fileno(stdout)))
testflag|=T_WRITE_LOOP;
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option, NULL)))
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
exit(ho_error);
if (*argc == 0)
......
......@@ -353,7 +353,7 @@ static void get_options(int *argc, char ***argv)
{
int ho_error;
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option, NULL)))
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
exit(ho_error);
my_progname= argv[0][0];
......
......@@ -643,7 +643,7 @@ static void get_options(int argc, char *argv[])
{
int ho_error;
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option, NULL)))
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
exit(ho_error);
return;
......
......@@ -66,7 +66,7 @@ int main(int argc,char *argv[])
struct { MI_INFO *info; } aio0, *aio=&aio0; /* for GWS_IN_USE */
MY_INIT(argv[0]);
if (error=handle_options(&argc, &argv, my_long_options, get_one_option, NULL))
if (error=handle_options(&argc, &argv, my_long_options, get_one_option))
exit(error);
if (count || dump)
verbose=0;
......
......@@ -677,7 +677,7 @@ static void get_options(register int *argc,register char ***argv)
if (isatty(fileno(stdout)))
check_param.testflag|=T_WRITE_LOOP;
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option, NULL)))
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
exit(ho_error);
/* If using repair, then update checksum if one uses --update-state */
......
......@@ -350,7 +350,7 @@ static void get_options(int *argc,char ***argv)
if (isatty(fileno(stdout)))
write_loop=1;
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option, NULL)))
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
exit(ho_error);
if (!*argc)
......
......@@ -22,6 +22,9 @@
#include <mysys_err.h>
#include <my_getopt.h>
static void default_reporter(enum loglevel level, const char *format, ...);
my_error_reporter my_getopt_error_reporter= &default_reporter;
static int findopt(char *optpat, uint length,
const struct my_option **opt_res,
char **ffname);
......@@ -56,7 +59,8 @@ char *disabled_my_option= (char*) "0";
my_bool my_getopt_print_errors= 1;
void default_reporter(enum loglevel level, const char *format, ...)
static void default_reporter(enum loglevel level __attribute__((unused)),
const char *format, ...)
{
va_list args;
va_start(args, format);
......@@ -76,8 +80,7 @@ void default_reporter(enum loglevel level, const char *format, ...)
int handle_options(int *argc, char ***argv,
const struct my_option *longopts,
my_get_one_option get_one_option,
my_error_reporter reporter)
my_get_one_option get_one_option)
{
uint opt_found, argvpos= 0, length, i;
my_bool end_of_options= 0, must_be_var, set_maximum_value, special_used,
......@@ -91,9 +94,6 @@ int handle_options(int *argc, char ***argv,
(*argv)++; /* --- || ---- */
init_variables(longopts);
if (! reporter)
reporter= &default_reporter;
for (pos= *argv, pos_end=pos+ *argc; pos != pos_end ; pos++)
{
char *cur_arg= *pos;
......@@ -118,8 +118,9 @@ int handle_options(int *argc, char ***argv,
if (!*++pos)
{
if (my_getopt_print_errors)
reporter(ERROR_LEVEL,
"%s: Option '-O' requires an argument\n", progname);
my_getopt_error_reporter(ERROR_LEVEL,
"%s: Option '-O' requires an argument\n",
progname);
return EXIT_ARGUMENT_REQUIRED;
}
cur_arg= *pos;
......@@ -135,9 +136,9 @@ int handle_options(int *argc, char ***argv,
if (!*cur_arg)
{
if (my_getopt_print_errors)
reporter(ERROR_LEVEL,
"%s: Option '--set-variable' requires an argument\n",
progname);
my_getopt_error_reporter(ERROR_LEVEL,
"%s: Option '--set-variable' requires an argument\n",
progname);
return EXIT_ARGUMENT_REQUIRED;
}
}
......@@ -149,9 +150,9 @@ int handle_options(int *argc, char ***argv,
if (!*++pos)
{
if (my_getopt_print_errors)
reporter(ERROR_LEVEL,
"%s: Option '--set-variable' requires an argument\n",
progname);
my_getopt_error_reporter(ERROR_LEVEL,
"%s: Option '--set-variable' requires an argument\n",
progname);
return EXIT_ARGUMENT_REQUIRED;
}
cur_arg= *pos;
......@@ -210,10 +211,11 @@ int handle_options(int *argc, char ***argv,
if (opt_found > 1)
{
if (my_getopt_print_errors)
reporter(ERROR_LEVEL,
"%s: ambiguous option '--%s-%s' (--%s-%s)\n",
progname, special_opt_prefix[i], cur_arg,
special_opt_prefix[i], prev_found);
my_getopt_error_reporter(ERROR_LEVEL,
"%s: ambiguous option '--%s-%s' (--%s-%s)\n",
progname, special_opt_prefix[i],
cur_arg, special_opt_prefix[i],
prev_found);
return EXIT_AMBIGUOUS_OPTION;
}
switch (i) {
......@@ -245,16 +247,20 @@ int handle_options(int *argc, char ***argv,
if (must_be_var)
{
if (my_getopt_print_errors)
reporter(option_is_loose ? WARNING_LEVEL : ERROR_LEVEL,
"%s: unknown variable '%s'\n", progname, cur_arg);
my_getopt_error_reporter(option_is_loose ?
WARNING_LEVEL : ERROR_LEVEL,
"%s: unknown variable '%s'\n",
progname, cur_arg);
if (!option_is_loose)
return EXIT_UNKNOWN_VARIABLE;
}
else
{
if (my_getopt_print_errors)
reporter(option_is_loose ? WARNING_LEVEL : ERROR_LEVEL,
"%s: unknown option '--%s'\n", progname, cur_arg);
my_getopt_error_reporter(option_is_loose ?
WARNING_LEVEL : ERROR_LEVEL,
"%s: unknown option '--%s'\n",
progname, cur_arg);
if (!option_is_loose)
return EXIT_UNKNOWN_OPTION;
}
......@@ -270,23 +276,27 @@ int handle_options(int *argc, char ***argv,
if (must_be_var)
{
if (my_getopt_print_errors)
reporter(ERROR_LEVEL, "%s: variable prefix '%s' is not unique\n",
progname, cur_arg);
my_getopt_error_reporter(ERROR_LEVEL,
"%s: variable prefix '%s' is not unique\n",
progname, cur_arg);
return EXIT_VAR_PREFIX_NOT_UNIQUE;
}
else
{
if (my_getopt_print_errors)
reporter(ERROR_LEVEL, "%s: ambiguous option '--%s' (%s, %s)\n",
progname, cur_arg, prev_found, optp->name);
my_getopt_error_reporter(ERROR_LEVEL,
"%s: ambiguous option '--%s' (%s, %s)\n",
progname, cur_arg, prev_found,
optp->name);
return EXIT_AMBIGUOUS_OPTION;
}
}
if (must_be_var && optp->var_type == GET_NO_ARG)
{
if (my_getopt_print_errors)
reporter(ERROR_LEVEL, "%s: option '%s' cannot take an argument\n",
progname, optp->name);
my_getopt_error_reporter(ERROR_LEVEL,
"%s: option '%s' cannot take an argument\n",
progname, optp->name);
return EXIT_NO_ARGUMENT_ALLOWED;
}
if (optp->arg_type == NO_ARG)
......@@ -294,9 +304,9 @@ int handle_options(int *argc, char ***argv,
if (optend && optp->var_type != GET_BOOL)
{
if (my_getopt_print_errors)
reporter(ERROR_LEVEL,
"%s: option '--%s' cannot take an argument\n",
progname, optp->name);
my_getopt_error_reporter(ERROR_LEVEL,
"%s: option '--%s' cannot take an argument\n",
progname, optp->name);
return EXIT_NO_ARGUMENT_ALLOWED;
}
if (optp->var_type == GET_BOOL)
......@@ -333,9 +343,9 @@ int handle_options(int *argc, char ***argv,
if (!*++pos)
{
if (my_getopt_print_errors)
reporter(ERROR_LEVEL,
"%s: option '--%s' requires an argument\n",
progname, optp->name);
my_getopt_error_reporter(ERROR_LEVEL,
"%s: option '--%s' requires an argument\n",
progname, optp->name);
return EXIT_ARGUMENT_REQUIRED;
}
argument= *pos;
......@@ -384,9 +394,9 @@ int handle_options(int *argc, char ***argv,
if (!pos[1])
{
if (my_getopt_print_errors)
reporter(ERROR_LEVEL,
"%s: option '-%c' requires an argument\n",
progname, optp->id);
my_getopt_error_reporter(ERROR_LEVEL,
"%s: option '-%c' requires an argument\n",
progname, optp->id);
return EXIT_ARGUMENT_REQUIRED;
}
argument= *++pos;
......@@ -396,9 +406,9 @@ int handle_options(int *argc, char ***argv,
}
if ((error= setval(optp, argument, set_maximum_value)))
{
reporter(ERROR_LEVEL,
"%s: Error while setting value '%s' to '%s'\n",
progname, argument, optp->name);
my_getopt_error_reporter(ERROR_LEVEL,
"%s: Error while setting value '%s' to '%s'\n",
progname, argument, optp->name);
return error;
}
get_one_option(optp->id, optp, argument);
......@@ -408,8 +418,9 @@ int handle_options(int *argc, char ***argv,
if (!opt_found)
{
if (my_getopt_print_errors)
reporter(ERROR_LEVEL,
"%s: unknown option '-%c'\n", progname, *optend);
my_getopt_error_reporter(ERROR_LEVEL,
"%s: unknown option '-%c'\n",
progname, *optend);
return EXIT_UNKNOWN_OPTION;
}
}
......@@ -418,9 +429,9 @@ int handle_options(int *argc, char ***argv,
}
if ((error= setval(optp, argument, set_maximum_value)))
{
reporter(ERROR_LEVEL,
"%s: Error while setting value '%s' to '%s'\n",
progname, argument, optp->name);
my_getopt_error_reporter(ERROR_LEVEL,
"%s: Error while setting value '%s' to '%s'\n",
progname, argument, optp->name);
return error;
}
get_one_option(optp->id, optp, argument);
......
......@@ -384,7 +384,7 @@ static int get_options(int argc, char **argv)
{
int ho_error;
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option, 0)))
if ((ho_error= handle_options(&argc, &argv, my_long_options, get_one_option)))
exit(ho_error);
if (argc >= 1)
......
......@@ -5119,8 +5119,8 @@ static void get_options(int argc,char **argv)
{
int ho_error;
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option,
option_error_reporter)))
my_getopt_error_reporter= option_error_reporter;
if ((ho_error= handle_options(&argc, &argv, my_long_options, get_one_option)))
exit(ho_error);
#if defined(HAVE_BROKEN_REALPATH)
......
......@@ -1333,7 +1333,7 @@ static int parse_args(int argc, char **argv)
{
int ho_error;
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option, NULL)))
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
exit(ho_error);
return 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