Commit a5ec0a90 authored by jani@hynda.(none)'s avatar jani@hynda.(none)

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.
parent c6b21b93
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#include <mysql_embed.h> #include <mysql_embed.h>
#include <mysql.h> #include <mysql.h>
#include <errmsg.h> #include <errmsg.h>
#include <getopt.h> #include <my_getopt.h>
/* We have to define 'enum options' identical in all files to keep OS2 happy */ /* We have to define 'enum options' identical in all files to keep OS2 happy */
......
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
#include "client_priv.h" #include "client_priv.h"
#include <m_ctype.h> #include <m_ctype.h>
#include <stdarg.h> #include <stdarg.h>
#include <my_getopt.h>
#include <my_dir.h> #include <my_dir.h>
#ifndef __GNU_LIBRARY__ #ifndef __GNU_LIBRARY__
#define __GNU_LIBRARY__ // Skip warnings in getopt.h #define __GNU_LIBRARY__ // Skip warnings in getopt.h
...@@ -41,7 +40,7 @@ ...@@ -41,7 +40,7 @@
#include <signal.h> #include <signal.h>
#include <violite.h> #include <violite.h>
const char *VER= "12.5"; const char *VER= "12.6";
/* Don't try to make a nice table if the data is too big */ /* Don't try to make a nice table if the data is too big */
#define MAX_COLUMN_LENGTH 1024 #define MAX_COLUMN_LENGTH 1024
......
...@@ -19,12 +19,11 @@ ...@@ -19,12 +19,11 @@
#include "client_priv.h" #include "client_priv.h"
#include <signal.h> #include <signal.h>
#include <my_getopt.h>
#ifdef THREAD #ifdef THREAD
#include <my_pthread.h> /* because of signal() */ #include <my_pthread.h> /* because of signal() */
#endif #endif
#define ADMIN_VERSION "8.32" #define ADMIN_VERSION "8.34"
#define MAX_MYSQL_VAR 64 #define MAX_MYSQL_VAR 64
#define SHUTDOWN_DEF_TIMEOUT 3600 /* Wait for shutdown */ #define SHUTDOWN_DEF_TIMEOUT 3600 /* Wait for shutdown */
#define MAX_TRUNC_LENGTH 3 #define MAX_TRUNC_LENGTH 3
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include "client_priv.h" #include "client_priv.h"
#include <time.h> #include <time.h>
#include "log_event.h" #include "log_event.h"
#include <my_getopt.h>
#define PROBE_HEADER_LEN (4+EVENT_LEN_OFFSET+4) #define PROBE_HEADER_LEN (4+EVENT_LEN_OFFSET+4)
...@@ -125,7 +124,7 @@ static void die(const char* fmt, ...) ...@@ -125,7 +124,7 @@ static void die(const char* fmt, ...)
static void print_version() static void print_version()
{ {
printf("%s Ver 2.1 for %s at %s\n", my_progname, SYSTEM_TYPE, MACHINE_TYPE); printf("%s Ver 2.2 for %s at %s\n", my_progname, SYSTEM_TYPE, MACHINE_TYPE);
} }
......
...@@ -16,10 +16,9 @@ ...@@ -16,10 +16,9 @@
/* By Jani Tolonen, 2001-04-20, MySQL Development Team */ /* By Jani Tolonen, 2001-04-20, MySQL Development Team */
#define CHECK_VERSION "2.2" #define CHECK_VERSION "2.3"
#include "client_priv.h" #include "client_priv.h"
#include <my_getopt.h>
#include <m_ctype.h> #include <m_ctype.h>
#include "mysql_version.h" #include "mysql_version.h"
#include "mysqld_error.h" #include "mysqld_error.h"
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
** and adapted to mysqldump 05/11/01 by Jani Tolonen ** and adapted to mysqldump 05/11/01 by Jani Tolonen
*/ */
#define DUMP_VERSION "9.04" #define DUMP_VERSION "9.05"
#include <my_global.h> #include <my_global.h>
#include <my_sys.h> #include <my_sys.h>
...@@ -46,7 +46,6 @@ ...@@ -46,7 +46,6 @@
#include "mysql.h" #include "mysql.h"
#include "mysql_version.h" #include "mysql_version.h"
#include "mysqld_error.h" #include "mysqld_error.h"
#include <my_getopt.h>
/* Exit codes */ /* Exit codes */
......
...@@ -25,11 +25,10 @@ ...@@ -25,11 +25,10 @@
** * * ** * *
** ************************* ** *************************
*/ */
#define IMPORT_VERSION "3.2" #define IMPORT_VERSION "3.3"
#include "client_priv.h" #include "client_priv.h"
#include "mysql_version.h" #include "mysql_version.h"
#include <my_getopt.h>
static void db_error_with_table(MYSQL *mysql, char *table); static void db_error_with_table(MYSQL *mysql, char *table);
static void db_error(MYSQL *mysql); static void db_error(MYSQL *mysql);
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
/* Show databases, tables or columns */ /* Show databases, tables or columns */
#define SHOW_VERSION "9.2" #define SHOW_VERSION "9.3"
#include <my_global.h> #include <my_global.h>
#include "client_priv.h" #include "client_priv.h"
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
#include "mysqld_error.h" #include "mysqld_error.h"
#include <signal.h> #include <signal.h>
#include <stdarg.h> #include <stdarg.h>
#include <my_getopt.h>
#include "sslopt-vars.h" #include "sslopt-vars.h"
static my_string host=0,opt_password=0,user=0; static my_string host=0,opt_password=0,user=0;
......
...@@ -23,58 +23,56 @@ ...@@ -23,58 +23,56 @@
#include <my_global.h> #include <my_global.h>
#include <my_sys.h> #include <my_sys.h>
#include <getopt.h> #include <my_getopt.h>
const char *config_file="my"; /* Default config file */ 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'}, {"config-file", 'c', "The config file to be used",
{"defaults-file", required_argument, 0, 'c'}, (gptr*) &config_file, (gptr*) &config_file, 0, GET_STR, REQUIRED_ARG,
{"defaults-extra-file", required_argument, 0, 'e'}, 0, 0, 0, 0, 0, 0},
{"extra-file", required_argument, 0, 'e'}, {"defaults-file", 'c', "Synonym for --config-file",
{"no-defaults", no_argument, 0, 'n'}, (gptr*) &config_file, (gptr*) &config_file, 0, GET_STR, REQUIRED_ARG,
{"help", no_argument, 0, '?'}, 0, 0, 0, 0, 0, 0},
{"version", no_argument, 0, 'V'}, {"defaults-extra-file", 'e',
{0, 0, 0, 0} "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) 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); MACHINE_TYPE);
if (version) if (version)
return; 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("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"); puts("Prints all arguments that is give to some program using the default files");
printf("Usage: %s [OPTIONS] groups\n",my_progname); printf("Usage: %s [OPTIONS] groups\n", my_progname);
printf("\n\ my_print_help(my_long_options);
-c, --config-file=#, --defaults-file=#\n\ my_print_variables(my_long_options);
The config file to use (default '%s')\n\ printf("\nExample usage:\n%s --config-file=my client mysql\n", my_progname);
-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);
} }
static int get_options(int *argc,char ***argv)
{
int c,option_index;
while ((c=getopt_long(*argc,*argv,"nc:e:V?I", static my_bool
long_options, &option_index)) != EOF) get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
{ char *argument __attribute__((unused)))
switch (c) { {
case 'c': switch (optid) {
config_file=optarg;
break;
case 'e':
defaults_extra_file=optarg; /* Used by the load_defaults */
break;
case 'n': case 'n':
exit(0); exit(0);
case 'I': case 'I':
...@@ -85,9 +83,20 @@ static int get_options(int *argc,char ***argv) ...@@ -85,9 +83,20 @@ static int get_options(int *argc,char ***argv)
usage(1); usage(1);
exit(0); 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) if (*argc < 1)
{ {
usage(0); usage(0);
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
/* Install or upgrade MySQL server. By Sasha Pachev <sasha@mysql.com> /* 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 #define DONT_USE_RAID
#include <my_global.h> #include <my_global.h>
...@@ -27,17 +27,19 @@ ...@@ -27,17 +27,19 @@
#include <m_string.h> #include <m_string.h>
#include <mysql_version.h> #include <mysql_version.h>
#include <errno.h> #include <errno.h>
#include <getopt.h> #include <my_getopt.h>
#define ANSWERS_CHUNCK 32 #define ANSWERS_CHUNCK 32
int have_gui=0; int have_gui=0;
struct option long_options[] = static struct my_option my_long_options[] =
{ {
{"help", no_argument, 0, '?'}, {"help", '?', "Display this help and exit.",
{"version", no_argument, 0, 'V'}, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 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 /* For now, not much exciting here, but we'll add more once
...@@ -195,25 +197,32 @@ static int ask_user(const char* question,int default_ind, ...) ...@@ -195,25 +197,32 @@ static int ask_user(const char* question,int default_ind, ...)
return ans; return ans;
} }
static int parse_args(int argc, char **argv)
{
int c, option_index = 0;
while((c = getopt_long(argc, argv, "?V", static my_bool
long_options, &option_index)) != EOF) get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
{ char *argument __attribute__((unused)))
switch(c) {
{ switch(optid) {
case 'V': case 'V':
print_version(); print_version();
exit(0); exit(0);
case '?': case '?':
usage(); usage();
exit(0); exit(0);
default:
usage();
exit(1);
} }
return 0;
}
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);
} }
return 0; return 0;
} }
...@@ -231,10 +240,8 @@ static void usage() ...@@ -231,10 +240,8 @@ static void usage()
printf("This software comes with ABSOLUTELY NO WARRANTY\n\n"); printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
printf("Install or upgrade MySQL server.\n\n"); printf("Install or upgrade MySQL server.\n\n");
printf("Usage: %s [OPTIONS] \n", my_progname); printf("Usage: %s [OPTIONS] \n", my_progname);
printf("\n\ my_print_help(my_long_options);
-?, --help Display this help and exit.\n\ my_print_variables(my_long_options);
-h, --host=... Connect to host.\n\
-V, --version Output version information and exit.\n");
} }
int main(int argc, char** argv) int main(int argc, char** argv)
......
...@@ -16,32 +16,42 @@ ...@@ -16,32 +16,42 @@
/* Return error-text for system error messages and nisam messages */ /* 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_global.h>
#include <my_sys.h> #include <my_sys.h>
#include <m_string.h> #include <m_string.h>
#include <errno.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, '?'}, {"help", '?', "Displays this help and exits.", 0, 0, 0, GET_NO_ARG,
{"info", no_argument, 0, 'I'}, NO_ARG, 0, 0, 0, 0, 0, 0},
{"all", no_argument, 0, 'a'}, {"info", 'I', "Synonym for --help", 0, 0, 0, GET_NO_ARG,
{"silent", no_argument, 0, 's'}, NO_ARG, 0, 0, 0, 0, 0, 0},
{"verbose", no_argument, 0, 'v'}, #ifdef HAVE_SYS_ERRLIST
{"version", no_argument, 0, 'V'}, {"all", 'a', "Print all the error messages and the number.",
{0, 0, 0, 0} (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 { typedef struct ha_errors {
int errcode; int errcode;
const char *msg; const char *msg;
} HA_ERRORS; } HA_ERRORS;
static int verbose=1,print_all_codes=0;
static HA_ERRORS ha_errlist[]= static HA_ERRORS ha_errlist[]=
{ {
...@@ -99,36 +109,16 @@ static void usage(void) ...@@ -99,36 +109,16 @@ 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("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("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("Usage: %s [OPTIONS] [ERRORCODE [ERRORCODE...]]\n",my_progname);
printf("\n\ my_print_help(my_long_options);
-?, --help Displays this help and exits.\n\ my_print_variables(my_long_options);
-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");
} }
static int get_options(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; switch (optid) {
while ((c=getopt_long(*argc,*argv,"asvVI?",long_options,
&option_index)) != EOF)
{
switch (c) {
#ifdef HAVE_SYS_ERRLIST
case 'a':
print_all_codes=1;
break;
#endif
case 'v':
verbose=1;
break;
case 's': case 's':
verbose=0; verbose=0;
break; break;
...@@ -141,15 +131,21 @@ static int get_options(int *argc,char ***argv) ...@@ -141,15 +131,21 @@ static int get_options(int *argc,char ***argv)
usage(); usage();
exit(0); exit(0);
break; break;
default:
fprintf(stderr,"%s: Illegal option character '%c'\n",
my_progname,opterr);
return(1);
break;
} }
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 && !print_all_codes) if (!*argc && !print_all_codes)
{ {
usage(); usage();
......
...@@ -25,12 +25,12 @@ ...@@ -25,12 +25,12 @@
#include <m_string.h> #include <m_string.h>
#include <mysql_version.h> #include <mysql_version.h>
#include <errno.h> #include <errno.h>
#include <getopt.h> #include <my_getopt.h>
#define INIT_SYM_TABLE 4096 #define INIT_SYM_TABLE 4096
#define INC_SYM_TABLE 4096 #define INC_SYM_TABLE 4096
#define MAX_SYM_SIZE 128 #define MAX_SYM_SIZE 128
#define DUMP_VERSION "1.2" #define DUMP_VERSION "1.3"
#define HEX_INVALID (uchar)255 #define HEX_INVALID (uchar)255
typedef ulong my_long_addr_t ; /* at some point, we need to fix configure 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; ...@@ -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 DYNAMIC_ARRAY sym_table; /* how do you like this , static DYNAMIC ? */
static FILE* fp_dump, *fp_sym = 0, *fp_out; 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'}, {"help", 'h', "Display this help and exit.",
{"version", no_argument, 0, 'V'}, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"symbols-file", required_argument, 0, 's'}, {"version", 'V', "Output version information and exit.",
{"numeric-dump-file", required_argument, 0, 'n'}, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 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 verify_sort();
static void print_version(void) static void print_version(void)
...@@ -72,11 +78,8 @@ static void usage() ...@@ -72,11 +78,8 @@ static void usage()
printf("This software comes with ABSOLUTELY NO WARRANTY\n\n"); printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
printf("Resolve numeric stack strace dump into symbols.\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("Usage: %s [OPTIONS] symbols-file [numeric-dump-file]\n", my_progname);
printf("\n\ my_print_help(my_long_options);
-?, --help Display this help and exit.\n\ my_print_variables(my_long_options);
-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");
printf("\n\ printf("\n\
The symbols-file should include the output from: 'nm --numeric-sort mysqld'.\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\ The numeric-dump-file should contain a numeric stack trace from mysqld.\n\
...@@ -97,36 +100,32 @@ static void die(const char* fmt, ...) ...@@ -97,36 +100,32 @@ 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) {
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': case 'V':
print_version(); print_version();
exit(0); exit(0);
case '?': case '?':
usage(); usage();
exit(0); exit(0);
default:
usage();
exit(1);
}
} }
return 0;
}
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 The following code is to make the command compatible with the old
version that required one to use the -n and -s options version that required one to use the -n and -s options
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
/* Resolves IP's to hostname and hostnames to IP's */ /* 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 <my_global.h>
#include <m_ctype.h> #include <m_ctype.h>
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#endif #endif
#include <arpa/inet.h> #include <arpa/inet.h>
#include <netdb.h> #include <netdb.h>
#include <getopt.h> #include <my_getopt.h>
#ifdef SCO #ifdef SCO
#undef h_errno #undef h_errno
...@@ -42,15 +42,19 @@ extern int h_errno; ...@@ -42,15 +42,19 @@ extern int h_errno;
#endif #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, '?'}, {"help", '?', "Displays this help and exits.",
{"info", no_argument, 0, 'I'}, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"silent", no_argument, 0, 's'}, {"info", 'I', "Synonym for --help",
{"version", no_argument, 0, 'V'}, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 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) ...@@ -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("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"); 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("Usage: %s [OPTIONS] hostname or IP-address\n",my_progname);
printf("\n\ my_print_help(my_long_options);
-?, --help Displays this help and exits.\n\ my_print_variables(my_long_options);
-I, --info Synonym for the above.\n\
-s, --silent Be more silent.\n\
-V, --version Displays version information and exits.\n");
} }
/*static my_string load_default_groups[]= { "resolveip","client",0 }; */
static int get_options(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; switch (optid) {
/* load_defaults("my",load_default_groups,argc,argv); */
while ((c=getopt_long(*argc,*argv,"?IsV",
long_options, &option_index)) != EOF)
{
switch (c) {
case 's':
silent=1;
break;
case 'V': print_version(); exit(0); case 'V': print_version(); exit(0);
case 'I': case 'I':
case '?': case '?':
usage(); usage();
exit(0); exit(0);
default:
fprintf(stderr,"%s: Illegal option character '%c'\n",
my_progname,opterr);
return(1);
break;
} }
return 0;
}
/*static my_string load_default_groups[]= { "resolveip","client",0 }; */
static int get_options(int *argc,char ***argv)
{
int ho_error;
/* load_defaults("my",load_default_groups,argc,argv); */
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 == 0) if (*argc == 0)
{ {
usage(); usage();
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include "libmysqlfs.h" #include "libmysqlfs.h"
#include "mysqlcorbafs.h" #include "mysqlcorbafs.h"
#include <getopt.h> #include <my_getopt.h>
#define MAXPATHLEN 256 #define MAXPATHLEN 256
#include <sys/types.h> #include <sys/types.h>
...@@ -62,6 +62,10 @@ static char *default_charset, *current_host, *current_user, *opt_password, ...@@ -62,6 +62,10 @@ static char *default_charset, *current_host, *current_user, *opt_password,
*path,*fields_terminated=0, *lines_terminated=0, *enclosed=0, *path,*fields_terminated=0, *lines_terminated=0, *enclosed=0,
*opt_enclosed=0, *escaped=0; *opt_enclosed=0, *escaped=0;
/* This should be fixed to use my_getopt when the program is ready
static struct option long_options[] = static struct option long_options[] =
{ {
{"add-locks", no_argument, 0,OPT_LOCKS}, {"add-locks", no_argument, 0,OPT_LOCKS},
...@@ -99,6 +103,7 @@ static struct option long_options[] = ...@@ -99,6 +103,7 @@ static struct option long_options[] =
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
*/
/* /*
void void
...@@ -428,6 +433,8 @@ static int get_options(int *argc,char ***argv) ...@@ -428,6 +433,8 @@ static int get_options(int *argc,char ***argv)
my_bool tty_password=0; my_bool tty_password=0;
DBUG_ENTER("get_options"); DBUG_ENTER("get_options");
load_defaults("my",load_default_groups,argc,argv); load_defaults("my",load_default_groups,argc,argv);
/* change this to use my_getopt when program is ready */
set_all_changeable_vars(changeable_vars); set_all_changeable_vars(changeable_vars);
while ((c=getopt_long(*argc,*argv,"#::p::h:u:O:P:S:T:EBaAcCdefFlnqtvVw:?Ix", while ((c=getopt_long(*argc,*argv,"#::p::h:u:O:P:S:T:EBaAcCdefFlnqtvVw:?Ix",
long_options, &option_index)) != EOF) long_options, &option_index)) != EOF)
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#ifndef __GNU_LIBRARY__ #ifndef __GNU_LIBRARY__
#define __GNU_LIBRARY__ /* Skipp warnings in getopt.h */ #define __GNU_LIBRARY__ /* Skipp warnings in getopt.h */
#endif #endif
#include <getopt.h> #include <my_getopt.h>
#if INT_MAX > 32767 #if INT_MAX > 32767
#define BITS_SAVED 32 #define BITS_SAVED 32
...@@ -182,8 +182,9 @@ static int mrg_rrnd(MRG_INFO *info,byte *buf); ...@@ -182,8 +182,9 @@ static int mrg_rrnd(MRG_INFO *info,byte *buf);
static void mrg_reset(MRG_INFO *mrg); static void mrg_reset(MRG_INFO *mrg);
static int backup=0,error_on_write=0,test_only=0,verbose=0,silent=0, static int error_on_write=0,test_only=0,verbose=0,silent=0,
write_loop=0,force_pack=0,opt_wait=0,isamchk_neaded=0; write_loop=0,force_pack=0,isamchk_neaded=0;
static my_bool backup, opt_wait;
static int tmpfile_createflag=O_RDWR | O_TRUNC | O_EXCL; static int tmpfile_createflag=O_RDWR | O_TRUNC | O_EXCL;
static uint tree_buff_length=8196-MALLOC_OVERHEAD,force_pack_ref_length; static uint tree_buff_length=8196-MALLOC_OVERHEAD,force_pack_ref_length;
static char tmp_dir[FN_REFLEN]={0},*join_table; static char tmp_dir[FN_REFLEN]={0},*join_table;
...@@ -240,26 +241,44 @@ int main(int argc, char **argv) ...@@ -240,26 +241,44 @@ int main(int argc, char **argv)
} }
static struct option long_options[] = static struct my_option my_long_options[] =
{ {
{"backup", no_argument, 0, 'b'}, {"backup", 'b', "Make a backup of the table as table_name.OLD",
{"debug", optional_argument, 0, '#'}, (gptr*) &backup, (gptr*) &backup, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"force", no_argument, 0, 'f'}, {"debug", '#', "Output debug log. Often this is 'd:t:o,filename'",
{"join", required_argument, 0, 'j'}, 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"help", no_argument, 0, '?'}, {"force", 'f',
{"packlength",required_argument, 0, 'p'}, "Force packing of table even if it's gets bigger or tempfile exists.",
{"silent", no_argument, 0, 's'}, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"tmpdir", required_argument, 0, 'T'}, {"join", 'j',
{"test", no_argument, 0, 't'}, "Join all given tables into 'new_table_name'. All tables MUST have the identical layout.",
{"verbose", no_argument, 0, 'v'}, (gptr*) &join_table, (gptr*) &join_table, 0, GET_STR, REQUIRED_ARG, 0, 0,
{"version", no_argument, 0, 'V'}, 0, 0, 0, 0},
{"wait", no_argument, 0, 'w'}, {"help", '?', "Display this help and exit.",
{0, 0, 0, 0} 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"packlength", 'p', "Force storage size of recordlength (1, 2 or 3)",
(gptr*) &force_pack_ref_length, (gptr*) &force_pack_ref_length, 0,
GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"silent", 's', "Be more silent.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0 ,0},
{"tmpdir", 'T', "Use temporary directory to store temporary table",
(gptr*) &tmp_dir, (gptr*) &tmp_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0,
0, 0},
{"test", 't', "Don't pack table, only test packing it",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0 ,0},
{"verbose", 'v', "Write info about progress and packing result",
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},
{"wait", 'w', "Wait and retry if table is in use", (gptr*) &opt_wait,
(gptr*) &opt_wait, 0, GET_BOOL, 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 print_version(void) static void print_version(void)
{ {
printf("%s Ver 5.8 for %s on %s\n",my_progname,SYSTEM_TYPE,MACHINE_TYPE); printf("%s Ver 5.9 for %s on %s\n", my_progname, SYSTEM_TYPE, MACHINE_TYPE);
} }
static void usage(void) static void usage(void)
...@@ -274,92 +293,75 @@ static void usage(void) ...@@ -274,92 +293,75 @@ static void usage(void)
puts("You should give the .ISM file as the filename argument"); puts("You should give the .ISM file as the filename argument");
printf("\nUsage: %s [OPTIONS] filename...\n", my_progname); printf("\nUsage: %s [OPTIONS] filename...\n", my_progname);
puts("\n\ my_print_help(my_long_options);
-b, --backup Make a backup of the table as table_name.OLD\n\ print_defaults("my", load_default_groups);
-f, --force Force packing of table even if it's gets bigger or\n\ my_print_variables(my_long_options);
tempfile exists.\n\
-j, --join='new_table_name'\n\
Join all given tables into 'new_table_name'.\n\
All tables MUST have the identical layout.\n\
-p, --packlength=# Force storage size of recordlength (1,2 or 3)\n\
-s, --silent Be more silent.\n\
-t, --test Don't pack table, only test packing it\n\
-v, --verbose Write info about progress and packing result\n\
-w, --wait Wait and retry if table is in use\n\
-T, --tmpdir=# Use temporary directory to store temporary table\n\
-#, --debug=... output debug log. Often this is 'd:t:o,filename`\n\
-?, --help display this help and exit\n\
-V, --version output version information and exit\n");
print_defaults("my",load_default_groups);
} }
/* reads options */
/* Initiates DEBUG - but no debugging here ! */
static void get_options(int *argc,char ***argv) static my_bool
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
char *argument)
{ {
int c,option_index=0;
uint length; uint length;
my_progname= argv[0][0]; switch(optid) {
if (isatty(fileno(stdout)))
write_loop=1;
while ((c=getopt_long(*argc,*argv,"bfj:p:stvwT:#::?V",long_options,
&option_index)) != EOF)
{
switch(c) {
case 'b':
backup=1;
break;
case 'f': case 'f':
force_pack=1; force_pack= 1;
tmpfile_createflag=O_RDWR | O_TRUNC; tmpfile_createflag= O_RDWR | O_TRUNC;
break;
case 'j':
join_table=optarg;
break; break;
case 'p': case 'p':
force_pack_ref_length=(uint) atoi(optarg);
if (force_pack_ref_length > 3) if (force_pack_ref_length > 3)
force_pack_ref_length=0; force_pack_ref_length= 0;
break; break;
case 's': case 's':
write_loop=verbose=0; silent=1; write_loop= verbose= 0;
silent= 1;
break; break;
case 't': case 't':
test_only=verbose=1; test_only= verbose= 1;
break; break;
case 'T': case 'T':
length=(uint) (strmov(tmp_dir,optarg)-tmp_dir); length=(uint) (strmov(tmp_dir, argument) - tmp_dir);
if (length != dirname_length(tmp_dir)) if (length != dirname_length(tmp_dir))
{ {
tmp_dir[length]=FN_LIBCHAR; tmp_dir[length]= FN_LIBCHAR;
tmp_dir[length+1]=0; tmp_dir[length + 1]= 0;
} }
break; break;
case 'v': case 'v':
verbose=1; silent=0; verbose= 1;
break; silent= 0;
case 'w':
opt_wait=1;
break; break;
case '#': case '#':
DBUG_PUSH(optarg ? optarg : "d:t:o"); DBUG_PUSH(argument ? argument : "d:t:o");
break; break;
case 'V': print_version(); exit(0); case 'V': print_version(); exit(0);
case 'I': case 'I':
case '?': case '?':
usage(); usage();
exit(0); exit(0);
default:
fprintf(stderr,"%s: Illegal option: -%c\n",my_progname,opterr);
usage();
exit(1);
} }
return 0;
}
/* reads options */
/* Initiates DEBUG - but no debugging here ! */
static void 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; my_progname= argv[0][0];
(*argv)+=optind; if (isatty(fileno(stdout)))
write_loop=1;
if (!*argc) if (!*argc)
{ {
usage(); usage();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment