diff options
author | unknown <jani@hynda.(none)> | 2002-05-29 15:07:30 +0300 |
---|---|---|
committer | unknown <jani@hynda.(none)> | 2002-05-29 15:07:30 +0300 |
commit | a90b2f309eed146670390b7d4a31a20192685ac7 (patch) | |
tree | f5eba07b104573f7bffdb03106d52dd2c350b85a /mysys/my_getopt.c | |
parent | bb4cf4c24ee92de34ec2314eb84e0a9a4169172d (diff) | |
download | mariadb-git-a90b2f309eed146670390b7d4a31a20192685ac7.tar.gz |
Added useful exit error code for programs using my_getopt in case
of an error in option handling. This can sometimes be useful in
scripts.
Changed some exit code names and corresponding numbers.
Fixed a bug in mysqld.cc, in replication related options.
Added a global flag in my_getopt, which can be set by any program
that is using my_getopt, which tells whether the client should
print the error message itself, or whether my_getopt should do it.
The default is that my_getopt will print the error messages.
client/mysql.cc:
Added useful exit error code for programs using my_getopt in case
of an error in option handling. This can sometimes be useful in
scripts.
client/mysqladmin.c:
Added useful exit error code for programs using my_getopt in case
of an error in option handling. This can sometimes be useful in
scripts.
client/mysqlbinlog.cc:
Added useful exit error code for programs using my_getopt in case
of an error in option handling. This can sometimes be useful in
scripts.
client/mysqlcheck.c:
Added useful exit error code for programs using my_getopt in case
of an error in option handling. This can sometimes be useful in
scripts.
client/mysqldump.c:
Added useful exit error code for programs using my_getopt in case
of an error in option handling. This can sometimes be useful in
scripts.
client/mysqlimport.c:
Added useful exit error code for programs using my_getopt in case
of an error in option handling. This can sometimes be useful in
scripts.
client/mysqlmanager-pwgen.c:
Added useful exit error code for programs using my_getopt in case
of an error in option handling. This can sometimes be useful in
scripts.
client/mysqlmanagerc.c:
Added useful exit error code for programs using my_getopt in case
of an error in option handling. This can sometimes be useful in
scripts.
client/mysqlshow.c:
Added useful exit error code for programs using my_getopt in case
of an error in option handling. This can sometimes be useful in
scripts.
client/mysqltest.c:
Added useful exit error code for programs using my_getopt in case
of an error in option handling. This can sometimes be useful in
scripts.
client/thread_test.c:
Added useful exit error code for programs using my_getopt in case
of an error in option handling. This can sometimes be useful in
scripts.
extra/my_print_defaults.c:
Added useful exit error code for programs using my_getopt in case
of an error in option handling. This can sometimes be useful in
scripts.
extra/mysql_install.c:
Added useful exit error code for programs using my_getopt in case
of an error in option handling. This can sometimes be useful in
scripts.
extra/perror.c:
Added useful exit error code for programs using my_getopt in case
of an error in option handling. This can sometimes be useful in
scripts.
extra/resolve_stack_dump.c:
Added useful exit error code for programs using my_getopt in case
of an error in option handling. This can sometimes be useful in
scripts.
extra/resolveip.c:
Added useful exit error code for programs using my_getopt in case
of an error in option handling. This can sometimes be useful in
scripts.
include/my_getopt.h:
Added global (flag) variable which tells my_getopt whether to
print errors or just silently exit with proper error code.
include/mysys_err.h:
Changed exit code names and corresponding numbers.
isam/isamchk.c:
Added useful exit error code for programs using my_getopt in case
of an error in option handling. This can sometimes be useful in
scripts.
isam/pack_isam.c:
Added useful exit error code for programs using my_getopt in case
of an error in option handling. This can sometimes be useful in
scripts.
myisam/ft_dump.c:
Added useful exit error code for programs using my_getopt in case
of an error in option handling. This can sometimes be useful in
scripts.
myisam/ft_eval.c:
Added useful exit error code for programs using my_getopt in case
of an error in option handling. This can sometimes be useful in
scripts.
myisam/ft_test1.c:
Added useful exit error code for programs using my_getopt in case
of an error in option handling. This can sometimes be useful in
scripts.
myisam/mi_test1.c:
Added useful exit error code for programs using my_getopt in case
of an error in option handling. This can sometimes be useful in
scripts.
myisam/myisamchk.c:
Added useful exit error code for programs using my_getopt in case
of an error in option handling. This can sometimes be useful in
scripts.
myisam/myisampack.c:
Added useful exit error code for programs using my_getopt in case
of an error in option handling. This can sometimes be useful in
scripts.
mysys/my_getopt.c:
Changed exit code names and corresponding numbers. Added a flag
for checking whether my_getopt should print the error message,
or whether it should be printed by the client itself.
sql/gen_lex_hash.cc:
Added useful exit error code for programs using my_getopt in case
of an error in option handling. This can sometimes be useful in
scripts.
sql/mysqld.cc:
Added useful exit error code for programs using my_getopt in case
of an error in option handling. This can sometimes be useful in
scripts.
Fixed a bug when compiling in non-debug mode, some replication
related options were not enabled while they should be. This made
'make test' to fail in rpl000010 when --with-debug was not used.
tools/mysqlmanager.c:
Added useful exit error code for programs using my_getopt in case
of an error in option handling. This can sometimes be useful in
scripts.
Diffstat (limited to 'mysys/my_getopt.c')
-rw-r--r-- | mysys/my_getopt.c | 125 |
1 files changed, 67 insertions, 58 deletions
diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c index 80904fb46f6..720dae7520a 100644 --- a/mysys/my_getopt.c +++ b/mysys/my_getopt.c @@ -20,6 +20,7 @@ #include <my_getopt.h> #include <assert.h> #include <my_sys.h> +#include <mysys_err.h> static int findopt (char *optpat, uint length, const struct my_option **opt_res, @@ -42,17 +43,11 @@ static const char *special_opt_prefix[]= char *disabled_my_option= (char*) "0"; -/* Return error values from handle_options */ +/* This is a flag that can be set in client programs. 0 means that + my_getopt will not print error messages, but the client should do + it by itself */ -#define ERR_UNKNOWN_OPTION 1 -#define ERR_AMBIGUOUS_OPTION 2 -#define ERR_NO_ARGUMENT_ALLOWED 3 -#define ERR_ARGUMENT_REQUIRED 4 -#define ERR_VAR_PREFIX_NOT_UNIQUE 5 -#define ERR_UNKNOWN_VARIABLE 6 -#define ERR_OUT_OF_MEMORY 7 -#define ERR_UNKNOWN_SUFFIX 8 -#define ERR_NO_PTR_TO_VARIABLE 9 +my_bool my_getopt_print_errors= 1; /* @@ -106,9 +101,10 @@ int handle_options(int *argc, char ***argv, /* the argument must be in next argv */ if (!*++pos) { - fprintf(stderr, "%s: Option '-O' requires an argument\n", - progname); - return ERR_ARGUMENT_REQUIRED; + if (my_getopt_print_errors) + fprintf(stderr, "%s: Option '-O' requires an argument\n", + progname); + return EXIT_ARGUMENT_REQUIRED; } cur_arg= *pos; (*argc)--; @@ -128,10 +124,11 @@ int handle_options(int *argc, char ***argv, cur_arg+= 14; if (!*cur_arg) { - fprintf(stderr, - "%s: Option '--set-variable' requires an argument\n", - progname); - return ERR_ARGUMENT_REQUIRED; + if (my_getopt_print_errors) + fprintf(stderr, + "%s: Option '--set-variable' requires an argument\n", + progname); + return EXIT_ARGUMENT_REQUIRED; } } else if (cur_arg[14]) /* garbage, or another option. break out */ @@ -141,10 +138,11 @@ int handle_options(int *argc, char ***argv, /* the argument must be in next argv */ if (!*++pos) { - fprintf(stderr, - "%s: Option '--set-variable' requires an argument\n", - progname); - return ERR_ARGUMENT_REQUIRED; + if (my_getopt_print_errors) + fprintf(stderr, + "%s: Option '--set-variable' requires an argument\n", + progname); + return EXIT_ARGUMENT_REQUIRED; } cur_arg= *pos; (*argc)--; @@ -200,11 +198,12 @@ int handle_options(int *argc, char ***argv, { if (opt_found > 1) { - fprintf(stderr, - "%s: ambiguous option '--%s-%s' (--%s-%s)\n", - progname, special_opt_prefix[i], cur_arg, - special_opt_prefix[i], prev_found); - return ERR_AMBIGUOUS_OPTION; + if (my_getopt_print_errors) + fprintf(stderr, + "%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; } if (i < DISABLE_OPTION_COUNT) optend= disabled_my_option; @@ -224,19 +223,21 @@ int handle_options(int *argc, char ***argv, { if (must_be_var) { - fprintf(stderr, - "%s: %s: unknown variable '%s'\n", progname, - option_is_loose ? "WARNING" : "ERROR", cur_arg); + if (my_getopt_print_errors) + fprintf(stderr, + "%s: %s: unknown variable '%s'\n", progname, + option_is_loose ? "WARNING" : "ERROR", cur_arg); if (!option_is_loose) - return ERR_UNKNOWN_VARIABLE; + return EXIT_UNKNOWN_VARIABLE; } else { - fprintf(stderr, - "%s: %s: unknown option '--%s'\n", progname, - option_is_loose ? "WARNING" : "ERROR", cur_arg); + if (my_getopt_print_errors) + fprintf(stderr, + "%s: %s: unknown option '--%s'\n", progname, + option_is_loose ? "WARNING" : "ERROR", cur_arg); if (!option_is_loose) - return ERR_UNKNOWN_OPTION; + return EXIT_UNKNOWN_OPTION; } if (option_is_loose) { @@ -249,30 +250,34 @@ int handle_options(int *argc, char ***argv, { if (must_be_var) { - fprintf(stderr, "%s: variable prefix '%s' is not unique\n", - progname, cur_arg); - return ERR_VAR_PREFIX_NOT_UNIQUE; + if (my_getopt_print_errors) + fprintf(stderr, "%s: variable prefix '%s' is not unique\n", + progname, cur_arg); + return EXIT_VAR_PREFIX_NOT_UNIQUE; } else { - fprintf(stderr, "%s: ambiguous option '--%s' (%s, %s)\n", - progname, cur_arg, prev_found, optp->name); - return ERR_AMBIGUOUS_OPTION; + if (my_getopt_print_errors) + fprintf(stderr, "%s: ambiguous option '--%s' (%s, %s)\n", + progname, cur_arg, prev_found, optp->name); + return EXIT_AMBIGUOUS_OPTION; } } if (must_be_var && (!optp->value || optp->var_type == GET_BOOL)) { - fprintf(stderr, "%s: option '%s' cannot take an argument\n", - progname, optp->name); - return ERR_NO_ARGUMENT_ALLOWED; + if (my_getopt_print_errors) + fprintf(stderr, "%s: option '%s' cannot take an argument\n", + progname, optp->name); + return EXIT_NO_ARGUMENT_ALLOWED; } if (optp->arg_type == NO_ARG) { if (optend && !special_used) { - fprintf(stderr, "%s: option '--%s' cannot take an argument\n", - progname, optp->name); - return ERR_NO_ARGUMENT_ALLOWED; + if (my_getopt_print_errors) + fprintf(stderr, "%s: option '--%s' cannot take an argument\n", + progname, optp->name); + return EXIT_NO_ARGUMENT_ALLOWED; } if (optp->var_type == GET_BOOL) { @@ -306,9 +311,10 @@ int handle_options(int *argc, char ***argv, /* Check if there are more arguments after this one */ if (!*++pos) { - fprintf(stderr, "%s: option '--%s' requires an argument\n", - progname, optp->name); - return ERR_ARGUMENT_REQUIRED; + if (my_getopt_print_errors) + fprintf(stderr, "%s: option '--%s' requires an argument\n", + progname, optp->name); + return EXIT_ARGUMENT_REQUIRED; } argument= *pos; (*argc)--; @@ -347,9 +353,11 @@ int handle_options(int *argc, char ***argv, /* Check if there are more arguments after this one */ if (!*++pos) { - fprintf(stderr, "%s: option '-%c' requires an argument\n", - progname, optp->id); - return ERR_ARGUMENT_REQUIRED; + if (my_getopt_print_errors) + fprintf(stderr, + "%s: option '-%c' requires an argument\n", + progname, optp->id); + return EXIT_ARGUMENT_REQUIRED; } argument= *pos; (*argc)--; @@ -369,9 +377,10 @@ int handle_options(int *argc, char ***argv, } if (!opt_found) { - fprintf(stderr, - "%s: unknown option '-%c'\n", progname, *cur_arg); - return ERR_UNKNOWN_OPTION; + if (my_getopt_print_errors) + fprintf(stderr, + "%s: unknown option '-%c'\n", progname, *cur_arg); + return EXIT_UNKNOWN_OPTION; } } (*argc)--; /* option handled (short), decrease argument count */ @@ -412,7 +421,7 @@ static int setval (const struct my_option *opts, char *argument, opts->u_max_value : opts->value; if (!result_pos) - return ERR_NO_PTR_TO_VARIABLE; + return EXIT_NO_PTR_TO_VARIABLE; switch (opts->var_type) { case GET_INT: @@ -437,13 +446,13 @@ static int setval (const struct my_option *opts, char *argument, my_free((*(char**) result_pos), MYF(MY_WME | MY_FAE)); if (!(*((char**) result_pos)= my_strdup(argument, MYF(MY_WME)))) - return ERR_OUT_OF_MEMORY; + return EXIT_OUT_OF_MEMORY; break; default: /* dummy default to avoid compiler warnings */ break; } if (err) - return ERR_UNKNOWN_SUFFIX; + return EXIT_UNKNOWN_SUFFIX; } return 0; } |