diff options
author | unknown <jani@hynda.(none)> | 2002-05-22 23:54:24 +0300 |
---|---|---|
committer | unknown <jani@hynda.(none)> | 2002-05-22 23:54:24 +0300 |
commit | 2276e8aeb845f5186f48925ae4e6c1e80ff529a8 (patch) | |
tree | c01334461ba2741cbb5763ef8029cae9ea298d25 /extra/perror.c | |
parent | 4d6819171d7e8f2ed8a5bea7acc45669f5953b7e (diff) | |
download | mariadb-git-2276e8aeb845f5186f48925ae4e6c1e80ff529a8.tar.gz |
moved my_getopt.h under client_priv.h
Changed my_print_defaults, mysql_install, perror, resolve_stack_dump,
resolveip and pack_isam to use my_getopt.
client/client_priv.h:
getopt -> my_getopt
client/mysql.cc:
moved my_getopt.h under client_priv.h
client/mysqladmin.c:
moved my_getopt.h under client_priv.h
client/mysqlbinlog.cc:
moved my_getopt.h under client_priv.h
client/mysqlcheck.c:
moved my_getopt.h under client_priv.h
client/mysqldump.c:
moved my_getopt.h under client_priv.h
client/mysqlimport.c:
moved my_getopt.h under client_priv.h
client/mysqlshow.c:
moved my_getopt.h under client_priv.h
extra/my_print_defaults.c:
Changed from getopt to use my_getopt
extra/mysql_install.c:
Changed from getopt to use my_getopt
extra/perror.c:
Changed from getopt to use my_getopt
extra/resolve_stack_dump.c:
Changed from getopt to use my_getopt
extra/resolveip.c:
Changed from getopt to use my_getopt
fs/mysqlcorbafs.c:
Left reminder about my_getopt when this program is ready.
Currently it's not being compiled.
isam/pack_isam.c:
Changed from getopt to use my_getopt
Diffstat (limited to 'extra/perror.c')
-rw-r--r-- | extra/perror.c | 104 |
1 files changed, 50 insertions, 54 deletions
diff --git a/extra/perror.c b/extra/perror.c index aa4ee71c7d1..da62913b4a4 100644 --- a/extra/perror.c +++ b/extra/perror.c @@ -16,32 +16,42 @@ /* Return error-text for system error messages and nisam messages */ -#define PERROR_VERSION "2.7" +#define PERROR_VERSION "2.8" #include <my_global.h> #include <my_sys.h> #include <m_string.h> #include <errno.h> -#include <getopt.h> +#include <my_getopt.h> +static my_bool verbose, print_all_codes; -static struct option long_options[] = +static struct my_option my_long_options[] = { - {"help", no_argument, 0, '?'}, - {"info", no_argument, 0, 'I'}, - {"all", no_argument, 0, 'a'}, - {"silent", no_argument, 0, 's'}, - {"verbose", no_argument, 0, 'v'}, - {"version", no_argument, 0, 'V'}, - {0, 0, 0, 0} + {"help", '?', "Displays this help and exits.", 0, 0, 0, GET_NO_ARG, + NO_ARG, 0, 0, 0, 0, 0, 0}, + {"info", 'I', "Synonym for --help", 0, 0, 0, GET_NO_ARG, + NO_ARG, 0, 0, 0, 0, 0, 0}, +#ifdef HAVE_SYS_ERRLIST + {"all", 'a', "Print all the error messages and the number.", + (gptr*) &print_all_codes, (gptr*) &print_all_codes, 0, GET_BOOL, NO_ARG, + 0, 0, 0, 0, 0, 0}, +#endif + {"silent", 's', "Only print the error message", 0, 0, 0, GET_NO_ARG, NO_ARG, + 0, 0, 0, 0, 0, 0}, + {"verbose", 'v', "Print error code and message (default).", (gptr*) &verbose, + (gptr*) &verbose, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0}, + {"version", 'V', "Displays version information and exits.", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} }; + typedef struct ha_errors { int errcode; const char *msg; } HA_ERRORS; -static int verbose=1,print_all_codes=0; static HA_ERRORS ha_errlist[]= { @@ -99,57 +109,43 @@ static void usage(void) printf("Print a description for a system error code or a error code from\na MyISAM/ISAM/BDB table handler.\n"); printf("If you want to get the error for a negative error code, you should use\n-- before the first error code to tell perror that there was no more options.\n\n"); printf("Usage: %s [OPTIONS] [ERRORCODE [ERRORCODE...]]\n",my_progname); - printf("\n\ - -?, --help Displays this help and exits.\n\ - -I, --info Synonym for the above."); -#ifdef HAVE_SYS_ERRLIST - printf("\n\ - -a, --all Print all the error messages and the number."); -#endif - printf("\n\ - -s, --silent Only print the error message\n\ - -v, --verbose Print error code and message (default).\n\ - -V, --version Displays version information and exits.\n"); + my_print_help(my_long_options); + my_print_variables(my_long_options); +} + + +static my_bool +get_one_option(int optid, const struct my_option *opt __attribute__((unused)), + char *argument __attribute__((unused))) +{ + switch (optid) { + case 's': + verbose=0; + break; + case 'V': + print_version(); + exit(0); + break; + case 'I': + case '?': + usage(); + exit(0); + break; + } + return 0; } static int get_options(int *argc,char ***argv) { - int c,option_index; + int ho_error; - while ((c=getopt_long(*argc,*argv,"asvVI?",long_options, - &option_index)) != EOF) + if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option))) { - switch (c) { -#ifdef HAVE_SYS_ERRLIST - case 'a': - print_all_codes=1; - break; -#endif - case 'v': - verbose=1; - break; - case 's': - verbose=0; - break; - case 'V': - print_version(); - exit(0); - break; - case 'I': - case '?': - usage(); - exit(0); - break; - default: - fprintf(stderr,"%s: Illegal option character '%c'\n", - my_progname,opterr); - return(1); - break; - } + printf("%s: handle_options() failed with error %d\n", my_progname, + ho_error); + exit(1); } - (*argc)-=optind; - (*argv)+=optind; if (!*argc && !print_all_codes) { usage(); |