diff options
author | unknown <ram@gw.mysql.r18.ru> | 2004-08-31 21:27:58 +0500 |
---|---|---|
committer | unknown <ram@gw.mysql.r18.ru> | 2004-08-31 21:27:58 +0500 |
commit | c9394a0f0da951a24f72598f00d82e27fcc55684 (patch) | |
tree | 03be22b4525ca6105700a5357899d4e1c249a6dd /mysys/my_getopt.c | |
parent | fb724e532c60cdcb7a2260d347444f421dda90a5 (diff) | |
download | mariadb-git-c9394a0f0da951a24f72598f00d82e27fcc55684.tar.gz |
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.
Diffstat (limited to 'mysys/my_getopt.c')
-rw-r--r-- | mysys/my_getopt.c | 101 |
1 files changed, 56 insertions, 45 deletions
diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c index f9df4afb55d..71f8819756a 100644 --- a/mysys/my_getopt.c +++ b/mysys/my_getopt.c @@ -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); |