summaryrefslogtreecommitdiff
path: root/extra
diff options
context:
space:
mode:
authorunknown <jani@hynda.(none)>2002-05-22 23:54:24 +0300
committerunknown <jani@hynda.(none)>2002-05-22 23:54:24 +0300
commit2276e8aeb845f5186f48925ae4e6c1e80ff529a8 (patch)
treec01334461ba2741cbb5763ef8029cae9ea298d25 /extra
parent4d6819171d7e8f2ed8a5bea7acc45669f5953b7e (diff)
downloadmariadb-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')
-rw-r--r--extra/my_print_defaults.c97
-rw-r--r--extra/mysql_install.c61
-rw-r--r--extra/perror.c104
-rw-r--r--extra/resolve_stack_dump.c79
-rw-r--r--extra/resolveip.c70
5 files changed, 212 insertions, 199 deletions
diff --git a/extra/my_print_defaults.c b/extra/my_print_defaults.c
index 70ccb3797e6..2c87ee11820 100644
--- a/extra/my_print_defaults.c
+++ b/extra/my_print_defaults.c
@@ -23,71 +23,80 @@
#include <my_global.h>
#include <my_sys.h>
-#include <getopt.h>
+#include <my_getopt.h>
const char *config_file="my"; /* Default config file */
-static struct option long_options[] =
+static struct my_option my_long_options[] =
{
- {"config-file", required_argument, 0, 'c'},
- {"defaults-file", required_argument, 0, 'c'},
- {"defaults-extra-file", required_argument, 0, 'e'},
- {"extra-file", required_argument, 0, 'e'},
- {"no-defaults", no_argument, 0, 'n'},
- {"help", no_argument, 0, '?'},
- {"version", no_argument, 0, 'V'},
- {0, 0, 0, 0}
+ {"config-file", 'c', "The config file to be used",
+ (gptr*) &config_file, (gptr*) &config_file, 0, GET_STR, REQUIRED_ARG,
+ 0, 0, 0, 0, 0, 0},
+ {"defaults-file", 'c', "Synonym for --config-file",
+ (gptr*) &config_file, (gptr*) &config_file, 0, GET_STR, REQUIRED_ARG,
+ 0, 0, 0, 0, 0, 0},
+ {"defaults-extra-file", 'e',
+ "Read this file after the global /etc config file and before the config file in the users home directory.",
+ (gptr*) &defaults_extra_file, (gptr*) &defaults_extra_file, 0, GET_STR,
+ REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"extra-file", 'e',
+ "Synonym for --defaults-extra-file",
+ (gptr*) &defaults_extra_file, (gptr*) &defaults_extra_file, 0, GET_STR,
+ REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"no-defaults", 'n', "Return an empty string (useful for scripts)",
+ 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"help", '?', "Display this help message and exit.",
+ 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"version", 'V', "Output version information and exit.",
+ 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}
};
+
static void usage(my_bool version)
{
- printf("%s Ver 1.3 for %s at %s\n",my_progname,SYSTEM_TYPE,
+ printf("%s Ver 1.4 for %s at %s\n",my_progname,SYSTEM_TYPE,
MACHINE_TYPE);
if (version)
return;
puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n");
puts("Prints all arguments that is give to some program using the default files");
- printf("Usage: %s [OPTIONS] groups\n",my_progname);
- printf("\n\
- -c, --config-file=#, --defaults-file=#\n\
- The config file to use (default '%s')\n\
- -e, --extra-file=#, --defaults-extra-file=#\n\
- Read this file after the global /etc config file and\n\
- before the config file in the users home directory.\n\
- -n, --no-defaults Return an empty string (useful for scripts)\n\
- -?, --help Display this help message and exit.\n\
- -V, --version Output version information and exit.\n",
- config_file);
- printf("\nExample usage:\n%s --config-file=my client mysql\n",my_progname);
+ printf("Usage: %s [OPTIONS] groups\n", my_progname);
+ my_print_help(my_long_options);
+ my_print_variables(my_long_options);
+ printf("\nExample usage:\n%s --config-file=my client mysql\n", my_progname);
}
-static int get_options(int *argc,char ***argv)
-{
- int c,option_index;
- while ((c=getopt_long(*argc,*argv,"nc:e:V?I",
- long_options, &option_index)) != EOF)
- {
- switch (c) {
- case 'c':
- config_file=optarg;
- break;
- case 'e':
- defaults_extra_file=optarg; /* Used by the load_defaults */
- break;
+static my_bool
+get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
+ char *argument __attribute__((unused)))
+{
+ switch (optid) {
case 'n':
- exit(0);
+ exit(0);
case 'I':
case '?':
- usage(0);
- exit(0);
+ usage(0);
+ exit(0);
case 'V':
- usage(1);
- exit(0);
- }
+ usage(1);
+ exit(0);
+ }
+ return 0;
+}
+
+
+static int get_options(int *argc,char ***argv)
+{
+ int ho_error;
+
+ if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
+ {
+ printf("%s: handle_options() failed with error %d\n", my_progname,
+ ho_error);
+ exit(1);
}
- (*argc)-=optind;
- (*argv)+=optind;
if (*argc < 1)
{
usage(0);
diff --git a/extra/mysql_install.c b/extra/mysql_install.c
index d02c054d4eb..0153ad3bf70 100644
--- a/extra/mysql_install.c
+++ b/extra/mysql_install.c
@@ -18,7 +18,7 @@
/* Install or upgrade MySQL server. By Sasha Pachev <sasha@mysql.com>
*/
-#define INSTALL_VERSION "1.0"
+#define INSTALL_VERSION "1.1"
#define DONT_USE_RAID
#include <my_global.h>
@@ -27,17 +27,19 @@
#include <m_string.h>
#include <mysql_version.h>
#include <errno.h>
-#include <getopt.h>
+#include <my_getopt.h>
#define ANSWERS_CHUNCK 32
int have_gui=0;
-struct option long_options[] =
+static struct my_option my_long_options[] =
{
- {"help", no_argument, 0, '?'},
- {"version", no_argument, 0, 'V'},
- {0, 0,0,0}
+ {"help", '?', "Display this help and exit.",
+ 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"version", 'V', "Output version information and exit.",
+ 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}
};
/* For now, not much exciting here, but we'll add more once
@@ -195,26 +197,33 @@ static int ask_user(const char* question,int default_ind, ...)
return ans;
}
+
+static my_bool
+get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
+ char *argument __attribute__((unused)))
+{
+ switch(optid) {
+ case 'V':
+ print_version();
+ exit(0);
+ case '?':
+ usage();
+ exit(0);
+ }
+ return 0;
+}
+
+
static int parse_args(int argc, char **argv)
{
- int c, option_index = 0;
+ int ho_error;
- while((c = getopt_long(argc, argv, "?V",
- long_options, &option_index)) != EOF)
- {
- switch(c)
- {
- case 'V':
- print_version();
- exit(0);
- case '?':
- usage();
- exit(0);
- default:
- usage();
- exit(1);
- }
- }
+ if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
+ {
+ printf("%s: handle_options() failed with error %d\n", my_progname,
+ ho_error);
+ exit(1);
+ }
return 0;
}
@@ -231,10 +240,8 @@ static void usage()
printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
printf("Install or upgrade MySQL server.\n\n");
printf("Usage: %s [OPTIONS] \n", my_progname);
- printf("\n\
- -?, --help Display this help and exit.\n\
- -h, --host=... Connect to host.\n\
- -V, --version Output version information and exit.\n");
+ my_print_help(my_long_options);
+ my_print_variables(my_long_options);
}
int main(int argc, char** argv)
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();
diff --git a/extra/resolve_stack_dump.c b/extra/resolve_stack_dump.c
index 7c33bd51dbe..23f22e276a6 100644
--- a/extra/resolve_stack_dump.c
+++ b/extra/resolve_stack_dump.c
@@ -25,12 +25,12 @@
#include <m_string.h>
#include <mysql_version.h>
#include <errno.h>
-#include <getopt.h>
+#include <my_getopt.h>
#define INIT_SYM_TABLE 4096
#define INC_SYM_TABLE 4096
#define MAX_SYM_SIZE 128
-#define DUMP_VERSION "1.2"
+#define DUMP_VERSION "1.3"
#define HEX_INVALID (uchar)255
typedef ulong my_long_addr_t ; /* at some point, we need to fix configure
@@ -48,15 +48,21 @@ static char* dump_fname = 0, *sym_fname = 0;
static DYNAMIC_ARRAY sym_table; /* how do you like this , static DYNAMIC ? */
static FILE* fp_dump, *fp_sym = 0, *fp_out;
-struct option long_options[] =
+static struct my_option my_long_options[] =
{
- {"help", no_argument, 0, 'h'},
- {"version", no_argument, 0, 'V'},
- {"symbols-file", required_argument, 0, 's'},
- {"numeric-dump-file", required_argument, 0, 'n'},
- {0, 0,0,0}
+ {"help", 'h', "Display this help and exit.",
+ 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"version", 'V', "Output version information and exit.",
+ 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"symbols-file", 's', "Use specified symbols file.", (gptr*) &sym_fname,
+ (gptr*) &sym_fname, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"numeric-dump-file", 'n', "Read the dump from specified file.",
+ (gptr*) &dump_fname, (gptr*) &dump_fname, 0, GET_STR, REQUIRED_ARG,
+ 0, 0, 0, 0, 0, 0},
+ { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
+
static void verify_sort();
static void print_version(void)
@@ -72,11 +78,8 @@ static void usage()
printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
printf("Resolve numeric stack strace dump into symbols.\n\n");
printf("Usage: %s [OPTIONS] symbols-file [numeric-dump-file]\n", my_progname);
- printf("\n\
- -?, --help Display this help and exit.\n\
- -s, --symbols-file=... Use specified symbols file.\n\
- -n, --numeric-dump-file=... Read the dump from specified file.\n\
- -V, --version Output version information and exit.\n");
+ my_print_help(my_long_options);
+ my_print_variables(my_long_options);
printf("\n\
The symbols-file should include the output from: 'nm --numeric-sort mysqld'.\n\
The numeric-dump-file should contain a numeric stack trace from mysqld.\n\
@@ -97,40 +100,36 @@ static void die(const char* fmt, ...)
}
-static int parse_args(int argc, char **argv)
+static my_bool
+get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
+ char *argument __attribute__((unused)))
{
- int c, option_index = 0;
+ switch(optid) {
+ case 'V':
+ print_version();
+ exit(0);
+ case '?':
+ usage();
+ exit(0);
+ }
+ return 0;
+}
- while((c = getopt_long(argc, argv, "?Vn:s:",
- long_options, &option_index)) != EOF)
- {
- switch(c)
- {
- case 'n':
- dump_fname = optarg;
- break;
- case 's':
- sym_fname = optarg;
- break;
- case 'V':
- print_version();
- exit(0);
- case '?':
- usage();
- exit(0);
- default:
- usage();
- exit(1);
- }
- }
- argc-=optind;
- argv+=optind;
+static int parse_args(int argc, char **argv)
+{
+ int ho_error;
+ if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
+ {
+ printf("%s: handle_options() failed with error %d\n", my_progname,
+ ho_error);
+ exit(1);
+ }
/*
The following code is to make the command compatible with the old
version that required one to use the -n and -s options
- */
+ */
if (argc == 2)
{
diff --git a/extra/resolveip.c b/extra/resolveip.c
index 2d21d5c672c..8c2c264ea2e 100644
--- a/extra/resolveip.c
+++ b/extra/resolveip.c
@@ -16,7 +16,7 @@
/* Resolves IP's to hostname and hostnames to IP's */
-#define RESOLVE_VERSION "2.0"
+#define RESOLVE_VERSION "2.1"
#include <my_global.h>
#include <m_ctype.h>
@@ -30,7 +30,7 @@
#endif
#include <arpa/inet.h>
#include <netdb.h>
-#include <getopt.h>
+#include <my_getopt.h>
#ifdef SCO
#undef h_errno
@@ -42,15 +42,19 @@ extern int h_errno;
#endif
-static int silent=0;
+static my_bool silent;
-static struct option long_options[] =
+static struct my_option my_long_options[] =
{
- {"help", no_argument, 0, '?'},
- {"info", no_argument, 0, 'I'},
- {"silent", no_argument, 0, 's'},
- {"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},
+ {"silent", 's', "Be more silent.", (gptr*) &silent, (gptr*) &silent,
+ 0, GET_BOOL, NO_ARG, 0, 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}
};
@@ -67,41 +71,39 @@ static void usage(void)
puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n");
puts("Get hostname based on IP-address or IP-address based on hostname.\n");
printf("Usage: %s [OPTIONS] hostname or IP-address\n",my_progname);
- printf("\n\
- -?, --help Displays this help and exits.\n\
- -I, --info Synonym for the above.\n\
- -s, --silent Be more silent.\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 'V': print_version(); exit(0);
+ case 'I':
+ case '?':
+ usage();
+ exit(0);
+ }
+ return 0;
}
/*static my_string load_default_groups[]= { "resolveip","client",0 }; */
static int get_options(int *argc,char ***argv)
{
- int c,option_index;
+ int ho_error;
/* load_defaults("my",load_default_groups,argc,argv); */
- while ((c=getopt_long(*argc,*argv,"?IsV",
- long_options, &option_index)) != EOF)
+
+ if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
{
- switch (c) {
- case 's':
- silent=1;
- break;
- case 'V': print_version(); exit(0);
- case 'I':
- case '?':
- usage();
- exit(0);
- 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 == 0)
{
usage();