Commit bb07d5c0 authored by unknown's avatar unknown

Changed mysqlbinlog, mysqlmanager-pwgen, mysqlmanagerc, mysqltest,

thread_test and isamchk to use my_getopt.

Fixed a bug in my_getopt.


client/mysqlbinlog.cc:
  Changed mysqlbinlog.cc to use my_getopt.
client/mysqlmanager-pwgen.c:
  Changed mysqlmanager-pwgen to use my_getopt.
client/mysqlmanagerc.c:
  Changed mysqlmanagerc to use my_getopt.
client/mysqltest.c:
  Changed mysqltest to use my_getopt.
client/thread_test.c:
  Changed thread_test to use my_getopt.
isam/isamchk.c:
  Changed isamchk to use my_getopt.
mysys/my_getopt.c:
  Fixed a bug in printing options when option didn't have a comment.
  Added startup initializing and printing for 'GET_BOOL' type variables.
sql/mysql_priv.h:
  Changed type.
sql/mysqld.cc:
  Fixed a bug in --local-infile option.
BitKeeper/etc/logging_ok:
  Logging to logging@openlogging.org accepted
parent 3181a6af
...@@ -61,3 +61,4 @@ tonu@x3.internalnet ...@@ -61,3 +61,4 @@ tonu@x3.internalnet
venu@work.mysql.com venu@work.mysql.com
zak@balfor.local zak@balfor.local
zak@linux.local zak@linux.local
jani@hynda.(none)
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#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)
...@@ -38,26 +39,6 @@ static FILE *result_file; ...@@ -38,26 +39,6 @@ static FILE *result_file;
static const char* default_dbug_option = "d:t:o,/tmp/mysqlbinlog.trace"; static const char* default_dbug_option = "d:t:o,/tmp/mysqlbinlog.trace";
#endif #endif
static struct option long_options[] =
{
#ifndef DBUG_OFF
{"debug", optional_argument, 0, '#'},
#endif
{"database", required_argument, 0, 'd'},
{"help", no_argument, 0, '?'},
{"host", required_argument, 0, 'h'},
{"offset", required_argument, 0, 'o'},
{"password", required_argument, 0, 'p'},
{"port", required_argument, 0, 'P'},
{"position", required_argument, 0, 'j'},
{"result-file", required_argument, 0, 'r'},
{"short-form", no_argument, 0, 's'},
{"table", required_argument, 0, 't'},
{"user", required_argument, 0, 'u'},
{"version", no_argument, 0, 'V'},
{0,0,0,0}
};
void sql_print_error(const char *format,...); void sql_print_error(const char *format,...);
static bool one_database = 0; static bool one_database = 0;
...@@ -82,6 +63,44 @@ static void dump_remote_table(NET* net, const char* db, const char* table); ...@@ -82,6 +63,44 @@ static void dump_remote_table(NET* net, const char* db, const char* table);
static void die(const char* fmt, ...); static void die(const char* fmt, ...);
static MYSQL* safe_connect(); static MYSQL* safe_connect();
static struct my_option my_long_options[] =
{
#ifndef DBUG_OFF
{"debug", '#', "Output debug log.", (gptr*) &default_dbug_option,
(gptr*) &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
#endif
{"database", 'd', "List entries for just this database (local log only)",
(gptr*) &database, (gptr*) &database, 0, GET_STR_ALLOC, REQUIRED_ARG,
0, 0, 0, 0, 0, 0},
{"help", '?', "Display this help and exit",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"host", 'h', "Get the binlog from server", (gptr*) &host, (gptr*) &host,
0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"offset", 'o', "Skip the first N entries", (gptr*) &offset, (gptr*) &offset,
0, GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"password", 'p', "Password to connect to remote server",
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"port", 'P', "Use port to connect to the remote server",
(gptr*) &port, (gptr*) &port, 0, GET_INT, REQUIRED_ARG, MYSQL_PORT, 0, 0,
0, 0, 0},
{"position", 'j', "Start reading the binlog at position N",
(gptr*) &position, (gptr*) &position, 0, GET_ULL, REQUIRED_ARG, 0, 0, 0, 0,
0, 0},
{"result-file", 'r', "Direct output to a given file", 0, 0, 0, GET_STR,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"short-form", 's', "Just show the queries, no extra info",
(gptr*) &short_form, (gptr*) &short_form, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
0, 0},
{"table", 't', "Get raw table dump using COM_TABLE_DUMB", (gptr*) &table,
(gptr*) &table, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"user", 'u', "Connect to the remote server as username",
(gptr*) &user, (gptr*) &user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0,
0, 0},
{"version", 'V', "Print version 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}
};
void sql_print_error(const char *format,...) void sql_print_error(const char *format,...)
{ {
...@@ -106,7 +125,7 @@ static void die(const char* fmt, ...) ...@@ -106,7 +125,7 @@ static void die(const char* fmt, ...)
static void print_version() static void print_version()
{ {
printf("%s Ver 1.9 for %s at %s\n",my_progname,SYSTEM_TYPE, MACHINE_TYPE); printf("%s Ver 2.0 for %s at %s\n", my_progname, SYSTEM_TYPE, MACHINE_TYPE);
} }
...@@ -120,26 +139,10 @@ and you are welcome to modify and redistribute it under the GPL license\n"); ...@@ -120,26 +139,10 @@ and you are welcome to modify and redistribute it under the GPL license\n");
printf("\ printf("\
Dumps a MySQL binary log in a format usable for viewing or for pipeing to\n\ Dumps a MySQL binary log in a format usable for viewing or for pipeing to\n\
the mysql command line client\n\n"); the mysql command line client\n\n");
printf("Usage: %s [options] log-files\n",my_progname); printf("Usage: %s [options] log-files\n", my_progname);
puts("Options:"); my_print_help(my_long_options);
#ifndef DBUG_OFF putchar('\n');
printf("-#, --debug[=...] Output debug log. (%s)\n", my_print_variables(my_long_options);
default_dbug_option);
#endif
printf("\
-?, --help Display this help and exit\n\
-s, --short-form Just show the queries, no extra info\n\
-o, --offset=N Skip the first N entries\n\
-d, --database=database List entries for just this database (local log only)\n\
-h, --host=server Get the binlog from server\n\
-P, --port=port Use port to connect to the remote server\n\
-u, --user=username Connect to the remote server as username\n\
-p, --password=password Password to connect to remote server\n\
-r, --result-file=file Direct output to a given file\n\
-j, --position=N Start reading the binlog at position N\n\
-t, --table=name Get raw table dump using COM_TABLE_DUMB\n\
-V, --version Print version and exit.\n\
");
} }
static void dump_remote_file(NET* net, const char* fname) static void dump_remote_file(NET* net, const char* fname)
...@@ -172,82 +175,61 @@ static void dump_remote_file(NET* net, const char* fname) ...@@ -172,82 +175,61 @@ static void dump_remote_file(NET* net, const char* fname)
fflush(result_file); fflush(result_file);
} }
static int parse_args(int *argc, char*** argv)
{
int c, opt_index = 0;
result_file = stdout; static my_bool
while((c = getopt_long(*argc, *argv, "so:#::d:h:j:u:p:P:r:t:?V", long_options, get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
&opt_index)) != EOF) char *argument)
{ {
switch(c) switch(optid)
{ {
#ifndef DBUG_OFF #ifndef DBUG_OFF
case '#': case '#':
DBUG_PUSH(optarg ? optarg : default_dbug_option); DBUG_PUSH(argument ? argument : default_dbug_option);
break; break;
#endif #endif
case 'd': case 'd':
one_database = 1; one_database = 1;
database = my_strdup(optarg, MYF(0));
break;
case 's':
short_form = 1;
break;
case 'o':
offset = strtoull(optarg,(char**) 0, 10);
break; break;
case 'j':
position = strtoull(optarg,(char**) 0, 10);
break;
case 'h': case 'h':
use_remote = 1; use_remote = 1;
host = my_strdup(optarg, MYF(0));
break; break;
case 'P': case 'P':
use_remote = 1; use_remote = 1;
port = atoi(optarg);
break; break;
case 'p': case 'p':
use_remote = 1; use_remote = 1;
pass = my_strdup(optarg, MYF(0)); pass = my_strdup(argument, MYF(0));
break; break;
case 'r': case 'r':
if (!(result_file = my_fopen(optarg, O_WRONLY | O_BINARY, MYF(MY_WME)))) if (!(result_file = my_fopen(argument, O_WRONLY | O_BINARY, MYF(MY_WME))))
exit(1); exit(1);
break; break;
case 'u': case 'u':
use_remote = 1; use_remote = 1;
user = my_strdup(optarg, MYF(0));
break;
case 't':
table = my_strdup(optarg, MYF(0));
break; break;
case 'V': case 'V':
print_version(); print_version();
exit(0); exit(0);
case '?': case '?':
default: default:
usage(); usage();
exit(0); exit(0);
}
} }
return 0;
}
(*argc)-=optind;
(*argv)+=optind;
static int parse_args(int *argc, char*** argv)
{
int ho_error;
result_file = stdout;
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;
} }
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#define MANAGER_PWGEN_VERSION "1.0" #define MANAGER_PWGEN_VERSION "1.1"
#include <my_global.h> #include <my_global.h>
#include <m_ctype.h> #include <m_ctype.h>
...@@ -22,18 +22,23 @@ ...@@ -22,18 +22,23 @@
#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>
#include <md5.h> #include <md5.h>
const char* outfile=0,*user="root"; const char* outfile=0,*user="root";
struct option long_options[] = static struct my_option my_long_options[] =
{ {
{"output-file",required_argument,0,'o'}, {"output-file", 'o', "Write the output to the file with the given name",
{"user",required_argument,0,'u'}, (gptr*) &outfile, (gptr*) &outfile, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0,
{"help",no_argument,0,'?'}, 0, 0},
{"version",no_argument,0,'V'}, {"user", 'u', "Put given user in the password file", (gptr*) &user,
{0,0,0,0} (gptr*) &user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"help", '?', "Display this message and exit", 0, 0, 0, GET_NO_ARG, NO_ARG,
0, 0, 0, 0, 0, 0},
{"version", 'V', "Display version info", 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 die(const char* fmt, ...) static void die(const char* fmt, ...)
...@@ -66,26 +71,16 @@ void usage() ...@@ -66,26 +71,16 @@ void usage()
printf("This software comes with ABSOLUTELY NO WARRANTY\n\n"); printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
printf("Generates a password file to be used by mysqltest.\n\n"); printf("Generates a password file to be used by mysqltest.\n\n");
printf("Usage: %s [OPTIONS]\n", my_progname); printf("Usage: %s [OPTIONS]\n", my_progname);
printf("-?,--help Display this message and exit\n\ my_print_help(my_long_options);
-V,--version Display version info\n\ putchar('\n');
-u,--user= Put given user in the password file\n\ my_print_variables(my_long_options);
-o,--output-file= Write the output to the file with the given name\n");
} }
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,"?Vu:o:",long_options,&option_index))
!= EOF)
{
switch (c)
{
case 'o':
outfile=optarg;
break;
case 'u':
user=optarg;
break;
case '?': case '?':
usage(); usage();
exit(0); exit(0);
...@@ -96,6 +91,19 @@ int parse_args(int argc, char** argv) ...@@ -96,6 +91,19 @@ int parse_args(int argc, char** argv)
usage(); usage();
exit(1); exit(1);
} }
return 0;
}
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;
} }
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#define MANAGER_CLIENT_VERSION "1.1" #define MANAGER_CLIENT_VERSION "1.2"
#include <my_global.h> #include <my_global.h>
#include <mysql.h> #include <mysql.h>
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#include <mysqld_error.h> #include <mysqld_error.h>
#include <my_sys.h> #include <my_sys.h>
#include <m_string.h> #include <m_string.h>
#include <getopt.h> #include <my_getopt.h>
#include <stdarg.h> #include <stdarg.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
...@@ -35,23 +35,31 @@ static void die(const char* fmt, ...); ...@@ -35,23 +35,31 @@ static void die(const char* fmt, ...);
const char* user="root",*host="localhost"; const char* user="root",*host="localhost";
char* pass=0; char* pass=0;
int quiet=0; my_bool quiet=0;
uint port=MYSQL_MANAGER_PORT; uint port=MYSQL_MANAGER_PORT;
static const char *load_default_groups[]= { "mysqlmanagerc",0 }; static const char *load_default_groups[]= { "mysqlmanagerc",0 };
char** default_argv; char** default_argv;
MYSQL_MANAGER *manager; MYSQL_MANAGER *manager;
FILE* fp, *fp_out; FILE* fp, *fp_out;
struct option long_options[] = static struct my_option my_long_options[] =
{ {
{"host",required_argument,0,'h'}, {"host", 'h', "Connect to host.", (gptr*) &host, (gptr*) &host, 0,
{"user",required_argument,0,'u'}, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"password",optional_argument,0,'p',}, {"user", 'u', "User for login.", (gptr*) &user, (gptr*) &user, 0,
{"port",required_argument,0,'P'}, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"help",no_argument,0,'?'}, {"password", 'p', "Password to use when connecting to server.",
{"version",no_argument,0,'V'}, 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"quiet",no_argument,0,'q'}, {"port", 'P', "Port number to use for connection.", (gptr*) &port,
{0,0,0,0} (gptr*) &port, 0, GET_UINT, REQUIRED_ARG, MYSQL_MANAGER_PORT, 0, 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},
{"quiet", 'q', "Suppress all normal output.", (gptr*) &quiet, (gptr*) &quiet,
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 die(const char* fmt, ...) static void die(const char* fmt, ...)
...@@ -84,63 +92,51 @@ void usage() ...@@ -84,63 +92,51 @@ void usage()
printf("This software comes with ABSOLUTELY NO WARRANTY\n\n"); printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
printf("Command-line client for MySQL manager daemon.\n\n"); printf("Command-line client for MySQL manager daemon.\n\n");
printf("Usage: %s [OPTIONS] < command_file\n", my_progname); printf("Usage: %s [OPTIONS] < command_file\n", my_progname);
printf("\n\ my_print_help(my_long_options);
-?, --help Display this help and exit.\n"); printf(" --no-defaults Don't read default options from any options file.\n\n");
printf("\ my_print_variables(my_long_options);
-h, --host=... Connect to host.\n\
-u, --user=... User for login.\n\
-p[password], --password[=...]\n\
Password to use when connecting to server.\n\
-P, --port=... Port number to use for connection.\n\
-q, --quiet, --silent Suppress all normal output.\n\
-V, --version Output version information and exit.\n\
--no-defaults Don't read default options from any options file.\n\n");
} }
int parse_args(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;
my_bool tty_password=0; my_bool tty_password=0;
load_defaults("my",load_default_groups,&argc,&argv); switch (optid) {
default_argv= argv;
while ((c = getopt_long(argc, argv, "h:p::u:P:?Vq",
long_options, &option_index)) != EOF)
{
switch (c)
{
case 'h':
host=optarg;
break;
case 'u':
user=optarg;
break;
case 'p': case 'p':
if (optarg) if (argument)
{ {
my_free(pass,MYF(MY_ALLOW_ZERO_PTR)); my_free(pass, MYF(MY_ALLOW_ZERO_PTR));
pass=my_strdup(optarg,MYF(MY_FAE)); pass= my_strdup(argument, MYF(MY_FAE));
while (*optarg) *optarg++= 'x'; /* Destroy argument */ while (*argument) *argument++= 'x'; /* Destroy argument */
} }
else else
tty_password=1; tty_password=1;
break; break;
case 'P':
port=atoi(optarg);
break;
case 'q':
quiet=1;
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;
}
int parse_args(int argc, char **argv)
{
int ho_error;
load_defaults("my",load_default_groups,&argc,&argv);
default_argv= 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);
} }
return 0; return 0;
} }
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
* Sasha Pachev <sasha@mysql.com> * Sasha Pachev <sasha@mysql.com>
* Matt Wagner <matt@mysql.com> * Matt Wagner <matt@mysql.com>
* Monty * Monty
* Jani
**/ **/
/********************************************************************** /**********************************************************************
...@@ -41,7 +42,7 @@ ...@@ -41,7 +42,7 @@
**********************************************************************/ **********************************************************************/
#define MTEST_VERSION "1.14" #define MTEST_VERSION "1.20"
#include <my_global.h> #include <my_global.h>
#include <mysql_embed.h> #include <mysql_embed.h>
...@@ -55,7 +56,7 @@ ...@@ -55,7 +56,7 @@
#include <hash.h> #include <hash.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <getopt.h> #include <my_getopt.h>
#include <stdarg.h> #include <stdarg.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
...@@ -95,10 +96,12 @@ ...@@ -95,10 +96,12 @@
enum {OPT_MANAGER_USER=256,OPT_MANAGER_HOST,OPT_MANAGER_PASSWD, enum {OPT_MANAGER_USER=256,OPT_MANAGER_HOST,OPT_MANAGER_PASSWD,
OPT_MANAGER_PORT,OPT_MANAGER_WAIT_TIMEOUT}; OPT_MANAGER_PORT,OPT_MANAGER_WAIT_TIMEOUT};
static int record = 0, verbose = 0, silent = 0, opt_sleep=0; static int record = 0, opt_sleep=0;
static char *db = 0, *pass=0; static char *db = 0, *pass=0;
const char* user = 0, *host = 0, *unix_sock = 0, *opt_basedir="./"; const char* user = 0, *host = 0, *unix_sock = 0, *opt_basedir="./";
static int port = 0, opt_big_test=0, opt_compress=0; static int port = 0;
static my_bool opt_big_test= 0, opt_compress= 0, silent= 0, verbose = 0,
tty_password= 0;
static uint start_lineno, *lineno; static uint start_lineno, *lineno;
const char* manager_user="root",*manager_host=0; const char* manager_user="root",*manager_host=0;
char *manager_pass=0; char *manager_pass=0;
...@@ -1785,36 +1788,74 @@ int read_query(struct st_query** q_ptr) ...@@ -1785,36 +1788,74 @@ int read_query(struct st_query** q_ptr)
return 0; return 0;
} }
struct option long_options[] =
{ static struct my_option my_long_options[] =
{"debug", optional_argument, 0, '#'}, {
{"database", required_argument, 0, 'D'}, #ifndef DBUG_OFF
{"basedir", required_argument, 0, 'b'}, {"debug", '#', "Output debug log. Often this is 'd:t:o,filename'",
{"big-test", no_argument, 0, 'B'}, 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"compress", no_argument, 0, 'C'}, #endif
{"help", no_argument, 0, '?'}, {"database", 'D', "Database to use.", (gptr*) &db, (gptr*) &db, 0,
{"host", required_argument, 0, 'h'}, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"manager-user",required_argument, 0, OPT_MANAGER_USER}, {"basedir", 'b', "Basedir for tests", (gptr*) &opt_basedir,
{"manager-host",required_argument, 0, OPT_MANAGER_HOST}, (gptr*) &opt_basedir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"manager-password",required_argument,0,OPT_MANAGER_PASSWD}, {"big-test", 'B', "Define BIG_TEST to 1", (gptr*) &opt_big_test,
{"manager-port",required_argument,0,OPT_MANAGER_PORT}, (gptr*) &opt_big_test, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"manager-wait-timeout",required_argument,0,OPT_MANAGER_WAIT_TIMEOUT}, {"compress", 'C', "Use the compressed server/client protocol",
{"password", optional_argument, 0, 'p'}, (gptr*) &opt_compress, (gptr*) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
{"port", required_argument, 0, 'P'}, 0, 0, 0},
{"quiet", no_argument, 0, 's'}, {"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG,
{"record", no_argument, 0, 'r'}, 0, 0, 0, 0, 0, 0},
{"result-file", required_argument, 0, 'R'}, {"host", 'h', "Connect to host.", (gptr*) &host, (gptr*) &host, 0,
{"server-arg", required_argument, 0, 'A'}, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"server-file", required_argument, 0, 'F'}, {"manager-user", OPT_MANAGER_USER, "Undocumented: Used for debugging",
{"silent", no_argument, 0, 's'}, (gptr*) &manager_user, (gptr*) &manager_user, 0, GET_STR, REQUIRED_ARG, 0,
{"sleep", required_argument, 0, 'T'}, 0, 0, 0, 0, 0},
{"socket", required_argument, 0, 'S'}, {"manager-host", OPT_MANAGER_HOST, "Undocumented: Used for debugging",
{"test-file", required_argument, 0, 'x'}, (gptr*) &manager_host, (gptr*) &manager_host, 0, GET_STR, REQUIRED_ARG,
{"tmpdir", required_argument, 0, 't'}, 0, 0, 0, 0, 0, 0},
{"user", required_argument, 0, 'u'}, {"manager-password", OPT_MANAGER_PASSWD, "Undocumented: Used for debugging",
{"verbose", no_argument, 0, 'v'}, 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"version", no_argument, 0, 'V'}, {"manager-port", OPT_MANAGER_PORT, "Undocumented: Used for debugging",
{0, 0, 0, 0} (gptr*) &manager_port, (gptr*) &manager_port, 0, GET_INT, REQUIRED_ARG,
MYSQL_MANAGER_PORT, 0, 0, 0, 0, 0},
{"manager-wait-timeout", OPT_MANAGER_WAIT_TIMEOUT,
"Undocumented: Used for debugging", (gptr*) &manager_wait_timeout,
(gptr*) &manager_wait_timeout, 0, GET_INT, REQUIRED_ARG, 3, 0, 0, 0, 0, 0},
{"password", 'p', "Password to use when connecting to server.",
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"port", 'P', "Port number to use for connection.", (gptr*) &port,
(gptr*) &port, 0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"quiet", 's', "Suppress all normal output.", (gptr*) &silent,
(gptr*) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"record", 'r', "Record output of test_file into result file.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"result-file", 'R', "Read/Store result from/in this file.",
(gptr*) &result_file, (gptr*) &result_file, 0, GET_STR, REQUIRED_ARG,
0, 0, 0, 0, 0, 0},
{"server-arg", 'A', "Send enbedded server this as a paramenter",
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"server-file", 'F', "Read embedded server arguments from file",
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"silent", 's', "Suppress all normal output. Synonym for --quiet.",
(gptr*) &silent, (gptr*) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"sleep", 'T', "Sleep always this many seconds on sleep commands",
(gptr*) &opt_sleep, (gptr*) &opt_sleep, 0, GET_INT, REQUIRED_ARG, 0, 0, 0,
0, 0, 0},
{"socket", 'S', "Socket file to use for connection.",
(gptr*) &unix_sock, (gptr*) &unix_sock, 0, GET_STR, REQUIRED_ARG, 0, 0, 0,
0, 0, 0},
{"test-file", 'x', "Read test from/in this file (default stdin).",
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"tmpdir", 't', "Temporary directory where sockets are put",
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"user", 'u', "User for login.", (gptr*) &user, (gptr*) &user, 0, GET_STR,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"verbose", 'v', "Write more.", (gptr*) &verbose, (gptr*) &verbose, 0,
GET_BOOL, 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}
}; };
...@@ -1827,136 +1868,57 @@ static void print_version(void) ...@@ -1827,136 +1868,57 @@ static void print_version(void)
void usage() void usage()
{ {
print_version(); print_version();
printf("MySQL AB, by Sasha, Matt & Monty\n"); printf("MySQL AB, by Sasha, Matt, Monty & Jani\n");
printf("This software comes with ABSOLUTELY NO WARRANTY\n\n"); printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
printf("Runs a test against the mysql server and compares output with a results file.\n\n"); printf("Runs a test against the mysql server and compares output with a results file.\n\n");
printf("Usage: %s [OPTIONS] [database] < test_file\n", my_progname); printf("Usage: %s [OPTIONS] [database] < test_file\n", my_progname);
printf("\n\ my_print_help(my_long_options);
-?, --help Display this help and exit.\n"); printf(" --no-defaults Don't read default options from any options file.\n\n");
#ifndef DBUG_OFF my_print_variables(my_long_options);
puts("\
-#, --debug=[...] Output debug log. Often this is 'd:t:o,filename`");
#endif
printf("\
-h, --host=... Connect to host.\n\
-u, --user=... User for login.\n\
-p[password], --password[=...]\n\
Password to use when connecting to server.\n\
-b, --basedir=... Basedir for tests\n\
-B, --big-test Define BIG_TEST to 1\n\
-C, --compress Use the compressed server/client protocol\n\
-D, --database=... Database to use.\n\
-P, --port=... Port number to use for connection.\n\
--server-arg=... Send enbedded server this as a paramenter\n\
--server-file=... Read embedded server arguments from file\n\
-s, --silent, --quiet Suppress all normal output.\n\
-S, --socket=... Socket file to use for connection.\n\
-t, --tmpdir=... Temporary directory where sockets are put\n\
-T, --sleep=# Sleep always this many seconds on sleep commands\n\
-r, --record Record output of test_file into result file.\n\
-R, --result-file=... Read/Store result from/in this file.\n\
-x, --test-file=... Read test from/in this file (default stdin).\n\
-v, --verbose Write more.\n\
-V, --version Output version information and exit.\n\
--no-defaults Don't read default options from any options file.\n\n");
} }
int parse_args(int argc, char **argv)
{
int c, option_index = 0;
my_bool tty_password=0;
load_defaults("my",load_default_groups,&argc,&argv);
default_argv= argv;
while ((c = getopt_long(argc, argv, "A:h:p::u:b:BCF:P:D:S:R:x:t:T:#:?rvVs", static my_bool
long_options, &option_index)) != EOF) get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
{ char *argument)
switch(c) { {
switch(optid) {
case '#': case '#':
DBUG_PUSH(optarg ? optarg : "d:t:S:i:O,/tmp/mysqltest.trace"); DBUG_PUSH(argument ? argument : "d:t:S:i:O,/tmp/mysqltest.trace");
break;
case 'v':
verbose = 1;
break; break;
case 'r': case 'r':
record = 1; record = 1;
break; break;
case (int)OPT_MANAGER_WAIT_TIMEOUT:
manager_wait_timeout=atoi(optarg);
break;
case (int)OPT_MANAGER_PORT:
manager_port=atoi(optarg);
break;
case (int)OPT_MANAGER_HOST:
manager_host=optarg;
break;
case (int)OPT_MANAGER_USER:
manager_user=optarg;
break;
case (int)OPT_MANAGER_PASSWD: case (int)OPT_MANAGER_PASSWD:
my_free(manager_pass,MYF(MY_ALLOW_ZERO_PTR)); my_free(manager_pass,MYF(MY_ALLOW_ZERO_PTR));
manager_pass=my_strdup(optarg,MYF(MY_FAE)); manager_pass=my_strdup(argument, MYF(MY_FAE));
while (*optarg) *optarg++= 'x'; /* Destroy argument */ while (*argument) *argument++= 'x'; /* Destroy argument */
break;
case 'u':
user = optarg;
break;
case 'R':
result_file = optarg;
break; break;
case 'x': case 'x':
{ {
char buff[FN_REFLEN]; char buff[FN_REFLEN];
if (!test_if_hard_path(optarg)) if (!test_if_hard_path(argument))
{ {
strxmov(buff, opt_basedir, optarg, NullS); strxmov(buff, opt_basedir, argument, NullS);
optarg=buff; argument= buff;
} }
fn_format(buff,optarg,"","",4); fn_format(buff, argument, "", "", 4);
if (!(*++cur_file = my_fopen(buff, O_RDONLY, MYF(MY_WME)))) if (!(*++cur_file = my_fopen(buff, O_RDONLY, MYF(MY_WME))))
die("Could not open %s: errno = %d", optarg, errno); die("Could not open %s: errno = %d", argument, errno);
break; break;
} }
case 'p': case 'p':
if (optarg) if (argument)
{ {
my_free(pass,MYF(MY_ALLOW_ZERO_PTR)); my_free(pass, MYF(MY_ALLOW_ZERO_PTR));
pass=my_strdup(optarg,MYF(MY_FAE)); pass= my_strdup(argument, MYF(MY_FAE));
while (*optarg) *optarg++= 'x'; /* Destroy argument */ while (*argument) *argument++= 'x'; /* Destroy argument */
} }
else else
tty_password=1; tty_password= 1;
break;
case 'b':
opt_basedir= optarg;
break;
case 'B':
opt_big_test=1;
break;
case 'C':
opt_compress=1;
break;
case 'P':
port = atoi(optarg);
break;
case 'S':
unix_sock = optarg;
break;
case 'D':
db = optarg;
break;
case 'h':
host = optarg;
break;
case 's':
silent = 1;
break; break;
case 't': case 't':
strnmov(TMPDIR,optarg,sizeof(TMPDIR)); strnmov(TMPDIR, argument, sizeof(TMPDIR));
break;
case 'T':
opt_sleep=atoi(optarg);
break; break;
case 'A': case 'A':
if (!embedded_server_arg_count) if (!embedded_server_arg_count)
...@@ -1965,7 +1927,7 @@ int parse_args(int argc, char **argv) ...@@ -1965,7 +1927,7 @@ int parse_args(int argc, char **argv)
embedded_server_args[0]= (char*) ""; embedded_server_args[0]= (char*) "";
} }
embedded_server_args[embedded_server_arg_count++]= embedded_server_args[embedded_server_arg_count++]=
my_strdup(optarg,MYF(MY_FAE)); my_strdup(argument, MYF(MY_FAE));
if (embedded_server_arg_count == MAX_SERVER_ARGS || if (embedded_server_arg_count == MAX_SERVER_ARGS ||
!embedded_server_args[embedded_server_arg_count-1]) !embedded_server_args[embedded_server_arg_count-1])
{ {
...@@ -1973,24 +1935,34 @@ int parse_args(int argc, char **argv) ...@@ -1973,24 +1935,34 @@ int parse_args(int argc, char **argv)
} }
break; break;
case 'F': case 'F':
if (read_server_arguments(optarg)) if (read_server_arguments(argument))
die(NullS); die(NullS);
break; break;
case 'V': case 'V':
print_version(); print_version();
exit(0); exit(0);
case '?': case '?':
usage();
exit(1); /* Unknown option */
default:
fprintf(stderr,"Unknown option '%c'\n",c);
usage(); usage();
exit(1); exit(1);
} }
return 0;
}
int parse_args(int argc, char **argv)
{
int ho_error;
load_defaults("my",load_default_groups,&argc,&argv);
default_argv= 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 > 1) if (argc > 1)
{ {
usage(); usage();
......
...@@ -28,9 +28,9 @@ int main(int argc __attribute__((unused)), char **argv __attribute__((unused))) ...@@ -28,9 +28,9 @@ int main(int argc __attribute__((unused)), char **argv __attribute__((unused)))
#include <my_sys.h> #include <my_sys.h>
#include <my_pthread.h> #include <my_pthread.h>
#include "mysql.h" #include "mysql.h"
#include <getopt.h> #include <my_getopt.h>
static my_bool version,verbose; static my_bool version, verbose, tty_password= 0;
static uint thread_count,number_of_tests=1000,number_of_threads=2; static uint thread_count,number_of_tests=1000,number_of_threads=2;
static pthread_cond_t COND_thread_count; static pthread_cond_t COND_thread_count;
static pthread_mutex_t LOCK_thread_count; static pthread_mutex_t LOCK_thread_count;
...@@ -84,23 +84,39 @@ end: ...@@ -84,23 +84,39 @@ end:
} }
static struct option long_options[] = static struct my_option my_long_options[] =
{ {
{"help", no_argument, 0, '?'}, {"help", '?', "Display this help and exit", 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
{"database", required_argument, 0, 'D'}, 0, 0, 0, 0, 0},
{"host", required_argument, 0, 'h'}, {"database", 'D', "Database to use", (gptr*) &database, (gptr*) &database,
{"password", optional_argument, 0, 'p'}, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"user", required_argument, 0, 'u'}, {"host", 'h', "Connect to host", (gptr*) &host, (gptr*) &host, 0, GET_STR,
{"version", no_argument, 0, 'V'}, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"verbose", no_argument, 0, 'v'}, {"password", 'p',
{"query", required_argument, 0, 'Q'}, "Password to use when connecting to server. If password is not given it's asked from the tty.",
{"port", required_argument, 0, 'P'}, 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"socket", required_argument, 0, 'S'}, {"user", 'u', "User for login if not current user", (gptr*) &user,
{"test-count",required_argument, 0, 'c'}, (gptr*) &user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"thread-count",required_argument, 0, 't'}, {"version", 'V', "Output version information and exit",
{0, 0, 0, 0} 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"verbose", 'v', "Write some progress indicators", (gptr*) &verbose,
(gptr*) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"query", 'Q', "Query to execute in each threads", (gptr*) &query,
(gptr*) &query, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"port", 'P', "Port number to use for connection", (gptr*) &tcp_port,
(gptr*) &tcp_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"socket", 'S', "Socket file to use for connection", (gptr*) &unix_socket,
(gptr*) &unix_socket, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"test-count", 'c', "Run test count times (default %d)",
(gptr*) &number_of_tests, (gptr*) &number_of_tests, 0, GET_UINT,
REQUIRED_ARG, 1000, 0, 0, 0, 0, 0},
{"thread-count", 't', "Number of threads to start",
(gptr*) &number_of_threads, (gptr*) &number_of_threads, 0, GET_UINT,
REQUIRED_ARG, 2, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
}; };
static const char *load_default_groups[]= { "client",0 }; static const char *load_default_groups[]= { "client",0 };
static void usage() static void usage()
...@@ -110,103 +126,59 @@ static void usage() ...@@ -110,103 +126,59 @@ static void usage()
return; return;
puts("This software comes with ABSOLUTELY NO WARRANTY.\n"); puts("This software comes with ABSOLUTELY NO WARRANTY.\n");
printf("Usage: %s [OPTIONS] [database]\n", my_progname); printf("Usage: %s [OPTIONS] [database]\n", my_progname);
printf("\n\
-?, --help Display this help and exit\n\
-c #, --test-count=# Run test count times (default %d)\n",number_of_tests);
printf("\
-D, --database=.. Database to use\n\
-h, --host=... Connect to host\n\
-p[password], --password[=...]\n\
Password to use when connecting to server\n\
If password is not given it's asked from the tty.\n");
printf("\n\
-P --port=... Port number to use for connection\n\
-Q, --query=... Query to execute in each threads\n\
-S --socket=... Socket file to use for connection\n");
printf("\
-t --thread-count=# Number of threads to start (default: %d) \n\
-u, --user=# User for login if not current user\n\
-v, --verbose Write some progress indicators\n\
-V, --version Output version information and exit\n",
number_of_threads);
my_print_help(my_long_options);
print_defaults("my",load_default_groups); print_defaults("my",load_default_groups);
my_print_variables(my_long_options);
printf("\nExample usage:\n\n\ printf("\nExample usage:\n\n\
%s -Q 'select * from mysql.user' -c %d -t %d\n", %s -Q 'select * from mysql.user' -c %d -t %d\n",
my_progname, number_of_tests, number_of_threads); my_progname, number_of_tests, number_of_threads);
} }
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,error=0; switch (optid) {
bool tty_password=0;
load_defaults("my",load_default_groups,&argc,&argv);
while ((c=getopt_long(argc,argv, "c:D:h:p::VQ:P:S:t:?I",
long_options, &option_index)) != EOF)
{
switch (c) {
case 'c':
number_of_tests=atoi(optarg);
break;
case 'D':
my_free(database,MYF(MY_ALLOW_ZERO_PTR));
database=my_strdup(optarg,MYF(MY_WME));
break;
case 'h':
host = optarg;
break;
case 'Q': /* Allow old 'q' option */
query= optarg;
break;
case 'p': case 'p':
if (optarg) if (argument)
{ {
my_free(password,MYF(MY_ALLOW_ZERO_PTR)); my_free(password, MYF(MY_ALLOW_ZERO_PTR));
password=my_strdup(optarg,MYF(MY_FAE)); password= my_strdup(argument, MYF(MY_FAE));
while (*optarg) *optarg++= 'x'; /* Destroy argument */ while (*argument) *argument++= 'x'; /* Destroy argument */
} }
else else
tty_password=1; tty_password= 1;
break;
case 'u':
my_free(user,MYF(MY_ALLOW_ZERO_PTR));
user= my_strdup(optarg,MYF(0));
break;
case 'P':
tcp_port= (unsigned int) atoi(optarg);
break;
case 'S':
my_free(unix_socket,MYF(MY_ALLOW_ZERO_PTR));
unix_socket= my_strdup(optarg,MYF(0));
break;
case 't':
number_of_threads=atoi(optarg);
break;
case 'v':
verbose=1;
break; break;
case 'V': case 'V':
version=1; version= 1;
usage(); usage();
exit(0); exit(0);
break; break;
default:
fprintf(stderr,"Illegal option character '%c'\n",opterr);
/* Fall through */
case '?': case '?':
case 'I': /* Info */ case 'I': /* Info */
error++; usage();
exit(1);
break; break;
} }
} return 0;
if (error || argc != optind) }
static void 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)))
{ {
usage(); printf("%s: handle_options() failed with error %d\n", my_progname,
ho_error);
exit(1); exit(1);
} }
free_defaults(argv); free_defaults(argv);
if (tty_password) if (tty_password)
password=get_tty_password(NullS); password=get_tty_password(NullS);
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#include <m_ctype.h> #include <m_ctype.h>
#include <stdarg.h> #include <stdarg.h>
#include <getopt.h> #include <my_getopt.h>
#ifdef HAVE_SYS_VADVICE_H #ifdef HAVE_SYS_VADVICE_H
#include <sys/vadvise.h> #include <sys/vadvise.h>
#endif #endif
...@@ -94,12 +94,16 @@ typedef struct st_isam_sort_info { ...@@ -94,12 +94,16 @@ typedef struct st_isam_sort_info {
N_KEYSEG *keyseg; N_KEYSEG *keyseg;
} ISAM_SORT_INFO; } ISAM_SORT_INFO;
enum ic_options {OPT_CHARSETS_DIR_IC=256}; enum ic_options {OPT_CHARSETS_DIR_IC=256, OPT_KEY_BUFFER_SIZE,
OPT_READ_BUFFER_SIZE, OPT_WRITE_BUFFER_SIZE,
OPT_SORT_BUFFER_SIZE, OPT_SORT_KEY_BLOCKS,
OPT_DECODE_BITS};
static ulong use_buffers=0,read_buffer_length=0,write_buffer_length=0, static ulong use_buffers=0,read_buffer_length=0,write_buffer_length=0,
sort_buffer_length=0,sort_key_blocks=0,crc=0,unique_count=0; sort_buffer_length=0,sort_key_blocks=0,crc=0,unique_count=0;
static uint testflag=0,out_flag=0,warning_printed=0,error_printed=0, static uint testflag=0,out_flag=0,warning_printed=0,error_printed=0,
rep_quick=0,verbose=0,opt_follow_links=1; verbose=0,opt_follow_links=1;
static my_bool rep_quick= 0;
static uint opt_sort_key=0,total_files=0,max_level=0,max_key=N_MAXKEY; static uint opt_sort_key=0,total_files=0,max_level=0,max_key=N_MAXKEY;
static ulong keydata=0,totaldata=0,key_blocks=0; static ulong keydata=0,totaldata=0,key_blocks=0;
static ulong new_file_pos=0,record_checksum=0,key_file_blocks=0,decode_bits; static ulong new_file_pos=0,record_checksum=0,key_file_blocks=0,decode_bits;
...@@ -234,118 +238,118 @@ int main( int argc, char **argv) ...@@ -234,118 +238,118 @@ int main( int argc, char **argv)
} /* main */ } /* main */
static CHANGEABLE_VAR changeable_vars[] = { static struct my_option my_long_options[] =
{ "key_buffer_size",(long*) &use_buffers,(long) USE_BUFFER_INIT,
(long) MALLOC_OVERHEAD, (long) ~0L,(long) MALLOC_OVERHEAD,(long) IO_SIZE },
{ "read_buffer_size", (long*) &read_buffer_length,(long) READ_BUFFER_INIT,
(long) MALLOC_OVERHEAD,(long) ~0L,(long) MALLOC_OVERHEAD,(long) 1L },
{ "write_buffer_size", (long*) &write_buffer_length,(long) READ_BUFFER_INIT,
(long) MALLOC_OVERHEAD,(long) ~0L,(long) MALLOC_OVERHEAD,(long) 1L },
{ "sort_buffer_size",(long*) &sort_buffer_length,(long) SORT_BUFFER_INIT,
(long) (MIN_SORT_BUFFER+MALLOC_OVERHEAD),(long) ~0L,
(long) MALLOC_OVERHEAD,(long) 1L },
{ "sort_key_blocks",(long*) &sort_key_blocks,BUFFERS_WHEN_SORTING,4L,100L,0L,
1L },
{ "decode_bits",(long*) &decode_bits,9L,4L,17L,0L,1L },
{ NullS,(long*) 0,0L,0L,0L,0L,0L,} };
static struct option long_options[] =
{ {
{"analyze", no_argument, 0, 'a'}, {"analyze", 'a',
{"character-sets-dir", required_argument, 0, OPT_CHARSETS_DIR_IC}, "Analyze distribution of keys. Will make some joins in MySQL faster.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"character-sets-dir", OPT_CHARSETS_DIR_IC,
"Directory where character sets are", (gptr*) &charsets_dir,
(gptr*) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
#ifndef DBUG_OFF #ifndef DBUG_OFF
{"debug", required_argument, 0, '#'}, {"debug", '#', "Output debug log. Often this is 'd:t:o,filename'",
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
#endif #endif
{"default-character-set", required_argument, 0, 'C'}, {"default-character-set", 'C', "Set the default character set",
{"description", no_argument, 0, 'd'}, (gptr*) &default_charset, (gptr*) &default_charset, 0, GET_STR,
{"extend-check", no_argument, 0, 'e'}, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"information", no_argument, 0, 'i'}, {"description", 'd', "Prints some information about table.",
{"force", no_argument, 0, 'f'}, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"help", no_argument, 0, '?'}, {"extend-check", 'e',
{"keys-used", required_argument, 0, 'k'}, "Check the table VERY thoroughly. One need to use this only in extreme cases, because isamchk should normally find all errors even without this switch.",
{"no-symlinks", no_argument, 0, 'l'}, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"quick", no_argument, 0, 'q'}, {"information", 'i', "Print statistics information about the table",
{"recover", no_argument, 0, 'r'}, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"safe-recover", no_argument, 0, 'o'}, {"force", 'f',
{"block-search", required_argument, 0, 'b'}, "Overwrite old temporary files. If one uses -f when checking tables (running isamchk without -r), isamchk will automatically restart with -r on any wrong table.",
{"set-variable", required_argument, 0, 'O'}, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"silent", no_argument, 0, 's'}, {"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
{"sort-index", no_argument, 0, 'S'}, 0, 0, 0, 0, 0},
{"sort-records", required_argument, 0, 'R'}, {"keys-used", 'k',
{"unpack", no_argument, 0, 'u'}, "Used with '-r'. Tell ISAM to update only the first # keys. This can be used to get faster inserts!",
{"verbose", no_argument, 0, 'v'}, (gptr*) &max_key, (gptr*) &max_key, 0, GET_UINT, REQUIRED_ARG, N_MAXKEY, 0,
{"version", no_argument, 0, 'V'}, 0, 0, 0, 0},
{"wait", no_argument, 0, 'w'}, {"no-symlinks", 'l',
{0, 0, 0, 0} "Do not follow symbolic links when repairing. Normally isamchk repairs the table a symlink points at.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"quick", 'q',
"Used with -r to get a faster repair. (The data file isn't touched.) One can give a second '-q' to force isamchk to modify the original datafile.",
(gptr*) &rep_quick, (gptr*) &rep_quick, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
0},
{"recover", 'r',
"Can fix almost anything except unique keys that aren't unique.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"safe-recover", 'o',
"Uses old recovery method; slower than '-r' but can handle a couple of cases that '-r' cannot handle.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"set-variable", 'O',
"Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.",
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"block-search", 'b', "For debugging.", (gptr*) &search_after_block,
(gptr*) &search_after_block, 0, GET_ULONG, REQUIRED_ARG, NI_POS_ERROR, 0,
0, 0, 0, 0},
{"silent", 's',
"Only print errors. One can use two -s to make isamchk very silent.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"sort-index", 'S',
"Sort index blocks. This speeds up 'read-next' in applications.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"sort-records", 'R',
"Sort records according to an index. This makes your data much more localized and may speed up things (It may be VERY slow to do a sort the first time!)",
(gptr*) &opt_sort_key, (gptr*) &opt_sort_key, 0, GET_UINT, REQUIRED_ARG,
0, 0, (N_MAXKEY - 1), 1, 0, 0},
{"unpack", 'u', "Unpack file packed with pack_isam.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"verbose", 'v',
"Print more information. This can be used with -d and -e. Use many -v for more verbosity!",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"version", 'V', "Print version and exit.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"wait", 'w', "Wait if table is locked.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"key_buffer_size", OPT_KEY_BUFFER_SIZE, "", (gptr*) &use_buffers,
(gptr*) &use_buffers, 0, GET_ULONG, REQUIRED_ARG, (long) USE_BUFFER_INIT,
(long) MALLOC_OVERHEAD, (long) ~0L, (long) MALLOC_OVERHEAD, (long) IO_SIZE,
0},
{"read_buffer_size", OPT_READ_BUFFER_SIZE, "",
(gptr*) &read_buffer_length, (gptr*) &read_buffer_length, 0, GET_ULONG,
REQUIRED_ARG, (long) READ_BUFFER_INIT, (long) MALLOC_OVERHEAD,
(long) ~0L, (long) MALLOC_OVERHEAD, (long) 1L, 0},
{"write_buffer_size", OPT_WRITE_BUFFER_SIZE, "",
(gptr*) &write_buffer_length, (gptr*) &write_buffer_length, 0, GET_ULONG,
REQUIRED_ARG, (long) READ_BUFFER_INIT, (long) MALLOC_OVERHEAD, (long) ~0L,
(long) MALLOC_OVERHEAD, (long) 1L, 0},
{"sort_buffer_size", OPT_SORT_BUFFER_SIZE, "",
(gptr*) &sort_buffer_length, (gptr*) &sort_buffer_length, 0, GET_ULONG,
REQUIRED_ARG, (long) SORT_BUFFER_INIT,
(long) (MIN_SORT_BUFFER + MALLOC_OVERHEAD), (long) ~0L,
(long) MALLOC_OVERHEAD, (long) 1L, 0},
{"sort_key_blocks", OPT_SORT_KEY_BLOCKS, "",
(gptr*) &sort_key_blocks, (gptr*) &sort_key_blocks, 0, GET_ULONG,
REQUIRED_ARG, BUFFERS_WHEN_SORTING, 4L, 100L, 0L, 1L, 0},
{"decode_bits", OPT_DECODE_BITS, "",
(gptr*) &decode_bits, (gptr*) &decode_bits, 0, GET_ULONG, REQUIRED_ARG,
9L, 4L, 17L, 0L, 1L, 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.17 for %s at %s\n",my_progname,SYSTEM_TYPE, printf("%s Ver 6.00 for %s at %s\n", my_progname, SYSTEM_TYPE,
MACHINE_TYPE); MACHINE_TYPE);
} }
static void usage(void) static void usage(void)
{ {
uint i;
print_version(); print_version();
puts("TCX Datakonsult AB, by Monty, for your professional use"); puts("MySQL AB, by Monty, for your professional use");
puts("This software comes with NO WARRANTY: see the PUBLIC for details.\n"); puts("This software comes with NO WARRANTY: see the PUBLIC for details.\n");
puts("Description, check and repair of ISAM tables."); puts("Description, check and repair of ISAM tables.");
puts("Used without options all tables on the command will be checked for errors"); puts("Used without options all tables on the command will be checked for errors");
printf("Usage: %s [OPTIONS] tables[.ISM]\n", my_progname); printf("Usage: %s [OPTIONS] tables[.ISM]\n", my_progname);
puts("\n\ my_print_help(my_long_options);
-a, --analyze Analyze distribution of keys. Will make some joins in\n\ print_defaults("my", load_default_groups);
MySQL faster.\n\ my_print_variables(my_long_options);
-#, --debug=... Output debug log. Often this is 'd:t:o,filename`\n\
--character-sets-dir=...\n\
Directory where character sets are\n\
-C, --default-character-set=...\n\
Set the default character set\n\
-d, --description Prints some information about table.\n\
-e, --extend-check Check the table VERY thoroughly. One need use this\n\
only in extreme cases as isamchk should normally find\n\
all errors even without this switch\n\
-f, --force Overwrite old temporary files.\n\
If one uses -f when checking tables (running isamchk\n\
without -r), isamchk will automatically restart with\n\
-r on any wrong table.\n\
-?, --help Display this help and exit.\n\
-i, --information Print statistics information about the table\n\
-k, --keys-used=# Used with '-r'. Tell ISAM to update only the first\n\
# keys. This can be used to get faster inserts!\n\
-l, --no-symlinks Do not follow symbolic links when repairing. Normally\n\
isamchk repairs the table a symlink points at.\n\
-q, --quick Used with -r to get a faster repair. (The data file\n\
isn't touched.) One can give a second '-q' to force\n\
isamchk to modify the original datafile.");
puts("\
-r, --recover Can fix almost anything except unique keys that aren't\n\
unique.\n\
-o, --safe-recover Uses old recovery method; slower than '-r' but can\n\
handle a couple of cases that '-r' cannot handle.\n\
-O, --set-variable var=option\n\
Change the value of a variable.\n\
-s, --silent Only print errors. One can use two -s to make isamchk\n\
very silent\n\
-S, --sort-index Sort index blocks. This speeds up 'read-next' in\n\
applications\n\
-R, --sort-records=#\n\
Sort records according to an index. This makes your\n\
data much more localized and may speed up things\n\
(It may be VERY slow to do a sort the first time!)\n\
-u, --unpack Unpack file packed with pack_isam.\n\
-v, --verbose Print more information. This can be used with\n\
-d and -e. Use many -v for more verbosity!\n\
-V, --version Print version and exit.\n\
-w, --wait Wait if table is locked.");
print_defaults("my",load_default_groups);
printf("\nPossible variables for option --set-variable (-O) are:\n");
for (i=0; changeable_vars[i].name ; i++)
printf("%-20s current value: %lu\n",
changeable_vars[i].name,
*changeable_vars[i].varptr);
} }
/* Check table */ /* Check table */
...@@ -575,33 +579,15 @@ end2: ...@@ -575,33 +579,15 @@ end2:
} /* nisamchk */ } /* nisamchk */
/* Read options */ static my_bool
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
char *argument)
static void get_options(register int *argc,register char ***argv)
{ {
int c,option_index=0; switch(optid) {
load_defaults("my",load_default_groups,argc,argv);
defaults_alloc= *argv;
set_all_changeable_vars(changeable_vars);
if (isatty(fileno(stdout)))
testflag|=T_WRITE_LOOP;
while ((c=getopt_long(*argc,*argv,"adeif?lqrosSuvVw#:b:k:O:R:C:",
long_options, &option_index)) != EOF)
{
switch(c) {
case 'a': case 'a':
testflag|= T_STATISTICS; testflag|= T_STATISTICS;
break; break;
case 'C':
default_charset=optarg;
break;
case OPT_CHARSETS_DIR_IC:
charsets_dir = optarg;
break;
case 'b':
search_after_block=strtoul(optarg,NULL,10);
break;
case 's': /* silent */ case 's': /* silent */
if (testflag & T_SILENT) if (testflag & T_SILENT)
testflag|=T_VERY_SILENT; testflag|=T_VERY_SILENT;
...@@ -624,9 +610,6 @@ static void get_options(register int *argc,register char ***argv) ...@@ -624,9 +610,6 @@ static void get_options(register int *argc,register char ***argv)
tmpfile_createflag= O_RDWR | O_TRUNC; tmpfile_createflag= O_RDWR | O_TRUNC;
testflag|=T_FORCE_CREATE; testflag|=T_FORCE_CREATE;
break; break;
case 'k':
max_key= (uint) atoi(optarg);
break;
case 'l': case 'l':
opt_follow_links=0; opt_follow_links=0;
break; break;
...@@ -637,9 +620,6 @@ static void get_options(register int *argc,register char ***argv) ...@@ -637,9 +620,6 @@ static void get_options(register int *argc,register char ***argv)
testflag= (testflag & ~T_REP_BY_SORT) | T_REP; testflag= (testflag & ~T_REP_BY_SORT) | T_REP;
my_disable_async_io=1; /* More safety */ my_disable_async_io=1; /* More safety */
break; break;
case 'q':
rep_quick++;
break;
case 'u': case 'u':
testflag|= T_UNPACK | T_REP_BY_SORT; testflag|= T_UNPACK | T_REP_BY_SORT;
break; break;
...@@ -647,16 +627,8 @@ static void get_options(register int *argc,register char ***argv) ...@@ -647,16 +627,8 @@ static void get_options(register int *argc,register char ***argv)
testflag|= T_VERBOSE; testflag|= T_VERBOSE;
verbose++; verbose++;
break; break;
case 'O':
if (set_changeable_var(optarg, changeable_vars))
{
usage();
exit(1);
}
break;
case 'R': /* Sort records */ case 'R': /* Sort records */
testflag|= T_SORT_RECORDS; testflag|= T_SORT_RECORDS;
opt_sort_key=(uint) atoi(optarg)-1;
if (opt_sort_key >= N_MAXKEY) if (opt_sort_key >= N_MAXKEY)
{ {
fprintf(stderr, fprintf(stderr,
...@@ -669,7 +641,7 @@ static void get_options(register int *argc,register char ***argv) ...@@ -669,7 +641,7 @@ static void get_options(register int *argc,register char ***argv)
testflag|= T_SORT_INDEX; testflag|= T_SORT_INDEX;
break; break;
case '#': case '#':
DBUG_PUSH(optarg ? optarg : "d:t:o,/tmp/isamchk.trace"); DBUG_PUSH(argument ? argument : "d:t:o,/tmp/isamchk.trace");
break; break;
case 'V': case 'V':
print_version(); print_version();
...@@ -678,9 +650,27 @@ static void get_options(register int *argc,register char ***argv) ...@@ -678,9 +650,27 @@ static void get_options(register int *argc,register char ***argv)
usage(); usage();
exit(0); exit(0);
} }
return 0;
}
/* Read options */
static void get_options(register int *argc, register char ***argv)
{
int ho_error;
load_defaults("my",load_default_groups,argc,argv);
defaults_alloc= *argv;
if (isatty(fileno(stdout)))
testflag|=T_WRITE_LOOP;
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();
......
...@@ -593,6 +593,9 @@ static void init_variables(const struct my_option *options) ...@@ -593,6 +593,9 @@ static void init_variables(const struct my_option *options)
else if (options->var_type == GET_UINT) else if (options->var_type == GET_UINT)
*((uint*) options->u_max_value)= *((uint*) options->value)= *((uint*) options->u_max_value)= *((uint*) options->value)=
(uint) options->def_value; (uint) options->def_value;
else if (options->var_type == GET_BOOL)
*((my_bool*) options->u_max_value)= *((my_bool*) options->value)=
(my_bool) options->def_value;
else if (options->var_type == GET_LONG) else if (options->var_type == GET_LONG)
*((long*) options->u_max_value)= *((long*) options->value)= *((long*) options->u_max_value)= *((long*) options->value)=
(long) options->def_value; (long) options->def_value;
...@@ -653,7 +656,7 @@ void my_print_help(const struct my_option *options) ...@@ -653,7 +656,7 @@ void my_print_help(const struct my_option *options)
optp->arg_type == OPT_ARG ? "]" : ""); optp->arg_type == OPT_ARG ? "]" : "");
col+= (optp->arg_type == OPT_ARG) ? 5 : 3; col+= (optp->arg_type == OPT_ARG) ? 5 : 3;
} }
if (col > name_space) if (col > name_space && optp->comment && *optp->comment)
{ {
putchar('\n'); putchar('\n');
col= 0; col= 0;
...@@ -697,7 +700,7 @@ void my_print_variables(const struct my_option *options) ...@@ -697,7 +700,7 @@ void my_print_variables(const struct my_option *options)
printf("--------------------------------- -------------\n"); printf("--------------------------------- -------------\n");
for (optp= options; optp->id; optp++) for (optp= options; optp->id; optp++)
{ {
if (optp->value && optp->var_type != GET_BOOL) if (optp->value)
{ {
printf("%s", optp->name); printf("%s", optp->name);
length= strlen(optp->name); length= strlen(optp->name);
...@@ -710,6 +713,13 @@ void my_print_variables(const struct my_option *options) ...@@ -710,6 +713,13 @@ void my_print_variables(const struct my_option *options)
else else
printf("(No default value)\n"); printf("(No default value)\n");
} }
else if (optp->var_type == GET_BOOL)
{
if (!optp->def_value && !*((my_bool*) optp->value))
printf("(No default value)\n");
else
printf("%d\n", *((my_bool*) optp->value));
}
else if (optp->var_type == GET_INT) else if (optp->var_type == GET_INT)
{ {
if (!optp->def_value && !*((int*) optp->value)) if (!optp->def_value && !*((int*) optp->value))
......
...@@ -617,7 +617,7 @@ extern pthread_cond_t COND_refresh,COND_thread_count; ...@@ -617,7 +617,7 @@ extern pthread_cond_t COND_refresh,COND_thread_count;
extern pthread_attr_t connection_attrib; extern pthread_attr_t connection_attrib;
extern bool opt_endinfo, using_udf_functions, locked_in_memory, extern bool opt_endinfo, using_udf_functions, locked_in_memory,
opt_using_transactions, use_temp_pool, mysql_embedded; opt_using_transactions, use_temp_pool, mysql_embedded;
extern bool opt_local_infile; extern my_bool opt_local_infile;
extern char f_fyllchar; extern char f_fyllchar;
extern ulong ha_read_count, ha_write_count, ha_delete_count, ha_update_count, extern ulong ha_read_count, ha_write_count, ha_delete_count, ha_update_count,
ha_read_key_count, ha_read_next_count, ha_read_prev_count, ha_read_key_count, ha_read_next_count, ha_read_prev_count,
......
...@@ -334,7 +334,7 @@ ulong bytes_sent = 0L, bytes_received = 0L; ...@@ -334,7 +334,7 @@ ulong bytes_sent = 0L, bytes_received = 0L;
bool opt_endinfo,using_udf_functions,low_priority_updates, locked_in_memory; bool opt_endinfo,using_udf_functions,low_priority_updates, locked_in_memory;
bool opt_using_transactions, using_update_log, opt_warnings=0; bool opt_using_transactions, using_update_log, opt_warnings=0;
bool opt_local_infile=1; my_bool opt_local_infile=1;
bool volatile abort_loop,select_thread_in_use,grant_option; bool volatile abort_loop,select_thread_in_use,grant_option;
bool volatile ready_to_exit,shutdown_in_progress; bool volatile ready_to_exit,shutdown_in_progress;
ulong refresh_version=1L,flush_version=1L; /* Increments on each reload */ ulong refresh_version=1L,flush_version=1L; /* Increments on each reload */
...@@ -2974,7 +2974,7 @@ static struct my_option my_long_options[] = ...@@ -2974,7 +2974,7 @@ static struct my_option my_long_options[] =
{"local-infile", OPT_LOCAL_INFILE, {"local-infile", OPT_LOCAL_INFILE,
"Enable/disable LOAD DATA LOCAL INFILE (takes values 1|0)", "Enable/disable LOAD DATA LOCAL INFILE (takes values 1|0)",
(gptr*) &opt_local_infile, (gptr*) &opt_local_infile, 0, GET_BOOL, OPT_ARG, (gptr*) &opt_local_infile, (gptr*) &opt_local_infile, 0, GET_BOOL, OPT_ARG,
0, 0, 0, 0, 0, 0}, 1, 0, 0, 0, 0, 0},
{"log-bin", OPT_BIN_LOG, {"log-bin", OPT_BIN_LOG,
"Log queries in new binary format (for replication)", "Log queries in new binary format (for replication)",
(gptr*) &opt_bin_logname, (gptr*) &opt_bin_logname, 0, GET_STR_ALLOC, (gptr*) &opt_bin_logname, (gptr*) &opt_bin_logname, 0, GET_STR_ALLOC,
...@@ -3987,9 +3987,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), ...@@ -3987,9 +3987,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
case 'o': case 'o':
protocol_version=PROTOCOL_VERSION-1; protocol_version=PROTOCOL_VERSION-1;
break; break;
case OPT_LOCAL_INFILE:
opt_local_infile= test(!argument || atoi(argument) != 0);
break;
case OPT_SLAVE_SKIP_ERRORS: case OPT_SLAVE_SKIP_ERRORS:
init_slave_skip_errors(argument); init_slave_skip_errors(argument);
break; break;
......
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