summaryrefslogtreecommitdiff
path: root/mysys/my_getopt.c
diff options
context:
space:
mode:
authorunknown <rburnett@build.mysql.com>2004-08-14 03:38:37 +0200
committerunknown <rburnett@build.mysql.com>2004-08-14 03:38:37 +0200
commit767d880f9c641746ed0087c4a2395e2a66d43374 (patch)
tree8bab2307b9948e0dc6a489230cd690abe672411d /mysys/my_getopt.c
parent5ee446d9d0337f7c35ad8cb2b90f0a6aeac20a3c (diff)
downloadmariadb-git-767d880f9c641746ed0087c4a2395e2a66d43374.tar.gz
mysql_priv.h:
Added declarations for print_msg_to_log and vprint_msg_to_log. sql_print_error are simple functions that wrap calls to print_msg_to_log. Define the different error types with MY_ERROR_TYPE, MY_WARNING_TYPE, and MY_INFORMATION_TYPE gen_lex_hash.cc: Added NULL error reporting parameter to handle_options log.cc: Add print_msg_to_log, print_buffer_to_log, and vprint_msg_to_log. Print_msg_to_log will write the message to the windows event log if on NT. We now have error, warning, and information versions of sql_print_xxxx. T his is a variation of a similar changeset WAX did. mysqld.cc: Added option_error_reporter callback function and pass that into handle_options mysql.cc: Added NULL as error reporter arg to the end of handle_options Many files: Added NULL error reporter parameter as the last paramter to handle_options my_getopt.c: Added second function pointer to server as an error reporting callback. Added local function report_option_error that will either write the error to stderr or to the error reporting callback. changed all calls in handle_options from fprintf(stderr, ... ) to report_option_error my_getopt.h: Changed declaration of handle_options to use typedefs for the two function pointers. added second function pointer to server as an error reporting callback mysqld.dsp: Added custom build step for compiling message file and added message resource file (output of mc) VC++Files/sql/mysqld.dsp: Added custom build step for compiling message file and added message resource file (output of mc) client/mysqladmin.c: Added NULL error reporter parameter as the last paramter to handle_options client/mysqlcheck.c: Added NULL error reporter parameter as the last paramter to handle_options client/mysqldump.c: Added NULL error reporter parameter as the last paramter to handle_options client/mysqlimport.c: Added NULL error reporter parameter as the last paramter to handle_options client/mysqlmanager-pwgen.c: Added NULL error reporter parameter as the last paramter to handle_options client/mysqlmanagerc.c: Added NULL error reporter parameter as the last paramter to handle_options client/mysqlbinlog.cc: Added NULL error reporter parameter as the last paramter to handle_options client/mysqlshow.c: Added NULL error reporter parameter as the last paramter to handle_options client/mysqltest.c: Added NULL error reporter parameter as the last paramter to handle_options extra/my_print_defaults.c: Added NULL error reporter parameter as the last paramter to handle_options extra/mysql_install.c: Added NULL error reporter parameter as the last paramter to handle_options extra/mysql_waitpid.c: Added NULL error reporter parameter as the last paramter to handle_options extra/perror.c: Added NULL error reporter parameter as the last paramter to handle_options extra/resolve_stack_dump.c: Added NULL error reporter parameter as the last paramter to handle_options extra/resolveip.c: Added NULL error reporter parameter as the last paramter to handle_options isam/isamchk.c: Added NULL error reporter parameter as the last paramter to handle_options isam/pack_isam.c: Added NULL error reporter parameter as the last paramter to handle_options myisam/mi_test1.c: Added NULL error reporter parameter as the last paramter to handle_options myisam/myisam_ftdump.c: Added NULL error reporter parameter as the last paramter to handle_options myisam/myisamchk.c: Added NULL error reporter parameter as the last paramter to handle_options myisam/myisampack.c: Added NULL error reporter parameter as the last paramter to handle_options include/my_getopt.h: Changed declaration of handle_options to use typedefs for the two function pointers. added second function pointer to server as an error reporting callback mysys/my_getopt.c: Added second function pointer to server as an error reporting callback. Added local function report_option_error that will either write the error to stderr or to the error reporting callback. changed all calls in handle_options from fprintf(stderr, ... ) to report_option_error tools/mysqlmanager.c: Added NULL error reporter parameter as the last paramter to handle_options client/mysql.cc: Added NULL as error reporter arg to the end of handle_options sql/mysqld.cc: Added option_error_reporter callback function and pass that into handle_options sql/log.cc: Add print_msg_to_log, print_buffer_to_log, and vprint_msg_to_log. Print_msg_to_log will write the message to the windows event log if on NT. We now have error, warning, and information versions of sql_print_xxxx. T his is a variation of a similar changeset WAX did. sql/gen_lex_hash.cc: Added NULL error reporting parameter to handle_options sql/mysql_priv.h: Added declarations for print_msg_to_log and vprint_msg_to_log. sql_print_error are simple functions that wrap calls to print_msg_to_log. Define the different error types with MY_ERROR_TYPE, MY_WARNING_TYPE, and MY_INFORMATION_TYPE BitKeeper/etc/logging_ok: Logging to logging@openlogging.org accepted
Diffstat (limited to 'mysys/my_getopt.c')
-rw-r--r--mysys/my_getopt.c48
1 files changed, 29 insertions, 19 deletions
diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c
index 694c4685667..7524bbf318d 100644
--- a/mysys/my_getopt.c
+++ b/mysys/my_getopt.c
@@ -56,6 +56,19 @@ char *disabled_my_option= (char*) "0";
my_bool my_getopt_print_errors= 1;
+void report_option_error( hoErrorReporter reporter, const char *format, ... )
+{
+ va_list args;
+ va_start( args, format );
+
+
+ if (reporter != NULL)
+ reporter( format, args );
+ else
+ vfprintf( stderr, format, args );
+
+ va_end( args );
+}
/*
function: handle_options
@@ -68,10 +81,7 @@ my_bool my_getopt_print_errors= 1;
*/
int handle_options(int *argc, char ***argv,
- const struct my_option *longopts,
- my_bool (*get_one_option)(int,
- const struct my_option *,
- char *))
+ const struct my_option *longopts, hoGetOneOption get_one_option, hoErrorReporter reporter )
{
uint opt_found, argvpos= 0, length, i;
my_bool end_of_options= 0, must_be_var, set_maximum_value, special_used,
@@ -109,7 +119,7 @@ int handle_options(int *argc, char ***argv,
if (!*++pos)
{
if (my_getopt_print_errors)
- fprintf(stderr, "%s: Option '-O' requires an argument\n",
+ report_option_error(reporter, "%s: Option '-O' requires an argument\n",
progname);
return EXIT_ARGUMENT_REQUIRED;
}
@@ -126,7 +136,7 @@ int handle_options(int *argc, char ***argv,
if (!*cur_arg)
{
if (my_getopt_print_errors)
- fprintf(stderr,
+ report_option_error(reporter,
"%s: Option '--set-variable' requires an argument\n",
progname);
return EXIT_ARGUMENT_REQUIRED;
@@ -140,7 +150,7 @@ int handle_options(int *argc, char ***argv,
if (!*++pos)
{
if (my_getopt_print_errors)
- fprintf(stderr,
+ report_option_error( reporter,
"%s: Option '--set-variable' requires an argument\n",
progname);
return EXIT_ARGUMENT_REQUIRED;
@@ -201,7 +211,7 @@ int handle_options(int *argc, char ***argv,
if (opt_found > 1)
{
if (my_getopt_print_errors)
- fprintf(stderr,
+ report_option_error( reporter,
"%s: ambiguous option '--%s-%s' (--%s-%s)\n",
progname, special_opt_prefix[i], cur_arg,
special_opt_prefix[i], prev_found);
@@ -236,7 +246,7 @@ int handle_options(int *argc, char ***argv,
if (must_be_var)
{
if (my_getopt_print_errors)
- fprintf(stderr,
+ report_option_error( reporter,
"%s: %s: unknown variable '%s'\n", progname,
option_is_loose ? "WARNING" : "ERROR", cur_arg);
if (!option_is_loose)
@@ -245,7 +255,7 @@ int handle_options(int *argc, char ***argv,
else
{
if (my_getopt_print_errors)
- fprintf(stderr,
+ report_option_error( reporter,
"%s: %s: unknown option '--%s'\n", progname,
option_is_loose ? "WARNING" : "ERROR", cur_arg);
if (!option_is_loose)
@@ -263,14 +273,14 @@ int handle_options(int *argc, char ***argv,
if (must_be_var)
{
if (my_getopt_print_errors)
- fprintf(stderr, "%s: variable prefix '%s' is not unique\n",
+ report_option_error( reporter, "%s: variable prefix '%s' is not unique\n",
progname, cur_arg);
return EXIT_VAR_PREFIX_NOT_UNIQUE;
}
else
{
if (my_getopt_print_errors)
- fprintf(stderr, "%s: ambiguous option '--%s' (%s, %s)\n",
+ report_option_error( reporter, "%s: ambiguous option '--%s' (%s, %s)\n",
progname, cur_arg, prev_found, optp->name);
return EXIT_AMBIGUOUS_OPTION;
}
@@ -278,7 +288,7 @@ int handle_options(int *argc, char ***argv,
if (must_be_var && optp->var_type == GET_NO_ARG)
{
if (my_getopt_print_errors)
- fprintf(stderr, "%s: option '%s' cannot take an argument\n",
+ report_option_error( reporter, "%s: option '%s' cannot take an argument\n",
progname, optp->name);
return EXIT_NO_ARGUMENT_ALLOWED;
}
@@ -287,7 +297,7 @@ int handle_options(int *argc, char ***argv,
if (optend && optp->var_type != GET_BOOL)
{
if (my_getopt_print_errors)
- fprintf(stderr, "%s: option '--%s' cannot take an argument\n",
+ report_option_error( reporter, "%s: option '--%s' cannot take an argument\n",
progname, optp->name);
return EXIT_NO_ARGUMENT_ALLOWED;
}
@@ -325,7 +335,7 @@ int handle_options(int *argc, char ***argv,
if (!*++pos)
{
if (my_getopt_print_errors)
- fprintf(stderr, "%s: option '--%s' requires an argument\n",
+ report_option_error( reporter, "%s: option '--%s' requires an argument\n",
progname, optp->name);
return EXIT_ARGUMENT_REQUIRED;
}
@@ -375,7 +385,7 @@ int handle_options(int *argc, char ***argv,
if (!pos[1])
{
if (my_getopt_print_errors)
- fprintf(stderr,
+ report_option_error( reporter,
"%s: option '-%c' requires an argument\n",
progname, optp->id);
return EXIT_ARGUMENT_REQUIRED;
@@ -387,7 +397,7 @@ int handle_options(int *argc, char ***argv,
}
if ((error= setval(optp, argument, set_maximum_value)))
{
- fprintf(stderr,
+ report_option_error( reporter,
"%s: Error while setting value '%s' to '%s'\n",
progname, argument, optp->name);
return error;
@@ -399,7 +409,7 @@ int handle_options(int *argc, char ***argv,
if (!opt_found)
{
if (my_getopt_print_errors)
- fprintf(stderr,
+ report_option_error( reporter,
"%s: unknown option '-%c'\n", progname, *optend);
return EXIT_UNKNOWN_OPTION;
}
@@ -409,7 +419,7 @@ int handle_options(int *argc, char ***argv,
}
if ((error= setval(optp, argument, set_maximum_value)))
{
- fprintf(stderr,
+ report_option_error( reporter,
"%s: Error while setting value '%s' to '%s'\n",
progname, argument, optp->name);
return error;