Commit 7eea2623 authored by unknown's avatar unknown

- Added missing documentation to some mysql.cc options.

- Fixed Bug#2346
- Fixed Bug#2378
- Fixed bug in pager (no Bug#ID (?))
- Added support for new special situations option type, GET_DISABLED.
  See handling of --debug in mysql.cc. compiled wihtout debugging, as an
  example.


client/mysql.cc:
  - Added missing documentation to some options.
  - Fixed a bug in pager (no Bug#ID found (?)), but reported on internals list
    with subject "[PATCH] Fix pager problems in mysql client"
  - Fixed Bug#2346, "unique prefix is enough" option behaviour can be confusing with --debug
include/my_getopt.h:
  Added new option type, GET_DISABLED.
include/mysys_err.h:
  New exit code for my_getopt.
mysys/my_getopt.c:
  - Added handling for GET_DISABLED option type (Fix for Bug#2346)
  - Fixed Bug#2378, "Problem with option abbreviation"
parent 38a87d0e
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
#include <locale.h> #include <locale.h>
#endif #endif
const char *VER= "14.3"; const char *VER= "14.4";
/* 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
...@@ -134,7 +134,8 @@ static my_bool info_flag=0,ignore_errors=0,wait_flag=0,quick=0, ...@@ -134,7 +134,8 @@ static my_bool info_flag=0,ignore_errors=0,wait_flag=0,quick=0,
vertical=0, line_numbers=1, column_names=1,opt_html=0, vertical=0, line_numbers=1, column_names=1,opt_html=0,
opt_xml=0,opt_nopager=1, opt_outfile=0, named_cmds= 0, opt_xml=0,opt_nopager=1, opt_outfile=0, named_cmds= 0,
tty_password= 0, opt_nobeep=0, opt_reconnect=1, tty_password= 0, opt_nobeep=0, opt_reconnect=1,
default_charset_used= 0, opt_secure_auth= 0; default_charset_used= 0, opt_secure_auth= 0,
default_pager_set= 0;
static uint verbose=0,opt_silent=0,opt_mysql_port=0, opt_local_infile=0; static uint verbose=0,opt_silent=0,opt_mysql_port=0, opt_local_infile=0;
static my_string opt_mysql_unix_port=0; static my_string opt_mysql_unix_port=0;
static int connect_flag=CLIENT_INTERACTIVE; static int connect_flag=CLIENT_INTERACTIVE;
...@@ -331,8 +332,11 @@ int main(int argc,char *argv[]) ...@@ -331,8 +332,11 @@ int main(int argc,char *argv[])
strmov(pager, "stdout"); // the default, if --pager wasn't given strmov(pager, "stdout"); // the default, if --pager wasn't given
{ {
char *tmp=getenv("PAGER"); char *tmp=getenv("PAGER");
if (tmp) if (tmp && strlen(tmp))
strmov(default_pager,tmp); {
default_pager_set= 1;
strmov(default_pager, tmp);
}
} }
if (!isatty(0) || !isatty(1)) if (!isatty(0) || !isatty(1))
{ {
...@@ -467,6 +471,8 @@ static struct my_option my_long_options[] = ...@@ -467,6 +471,8 @@ static struct my_option my_long_options[] =
{ {
{"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, {"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
0, 0, 0, 0, 0}, 0, 0, 0, 0, 0},
{"help", 'I', "Synonym for -?", 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
0, 0, 0, 0, 0},
{"auto-rehash", OPT_AUTO_REHASH, {"auto-rehash", OPT_AUTO_REHASH,
"Enable automatic rehashing. One doesn't need to use 'rehash' to get table and field completion, but startup and reconnecting may take a longer time. Disable with --disable-auto-rehash.", "Enable automatic rehashing. One doesn't need to use 'rehash' to get table and field completion, but startup and reconnecting may take a longer time. Disable with --disable-auto-rehash.",
(gptr*) &rehash, (gptr*) &rehash, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0}, (gptr*) &rehash, (gptr*) &rehash, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
...@@ -484,8 +490,12 @@ static struct my_option my_long_options[] = ...@@ -484,8 +490,12 @@ static struct my_option my_long_options[] =
{"compress", 'C', "Use compression in server/client protocol.", {"compress", 'C', "Use compression in server/client protocol.",
(gptr*) &opt_compress, (gptr*) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0, (gptr*) &opt_compress, (gptr*) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
0, 0, 0}, 0, 0, 0},
#ifndef DBUG_OFF #ifdef DBUG_OFF
{"debug", '#', "Output debug log.", (gptr*) &default_dbug_option, {"debug", '#', "This is a non-debug version. Catch this and exit",
(gptr*) &default_dbug_option,
(gptr*) &default_dbug_option, 0, GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
#else
{"debug", '#', "Output debug log", (gptr*) &default_dbug_option,
(gptr*) &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, (gptr*) &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
#endif #endif
{"database", 'D', "Database to use.", (gptr*) &current_db, {"database", 'D', "Database to use.", (gptr*) &current_db,
...@@ -608,19 +618,27 @@ static struct my_option my_long_options[] = ...@@ -608,19 +618,27 @@ static struct my_option my_long_options[] =
GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"wait", 'w', "Wait and retry if connection is down.", 0, 0, 0, GET_NO_ARG, {"wait", 'w', "Wait and retry if connection is down.", 0, 0, 0, GET_NO_ARG,
NO_ARG, 0, 0, 0, 0, 0, 0}, NO_ARG, 0, 0, 0, 0, 0, 0},
{"connect_timeout", OPT_CONNECT_TIMEOUT, "", (gptr*) &opt_connect_timeout, {"connect_timeout", OPT_CONNECT_TIMEOUT,
"Number of seconds before connection timeout.",
(gptr*) &opt_connect_timeout,
(gptr*) &opt_connect_timeout, 0, GET_ULONG, REQUIRED_ARG, 0, 0, 3600*12, 0, (gptr*) &opt_connect_timeout, 0, GET_ULONG, REQUIRED_ARG, 0, 0, 3600*12, 0,
0, 1}, 0, 1},
{"max_allowed_packet", OPT_MAX_ALLOWED_PACKET, "", {"max_allowed_packet", OPT_MAX_ALLOWED_PACKET,
"Max packet length to send to, or receive from server",
(gptr*) &max_allowed_packet, (gptr*) &max_allowed_packet, 0, GET_ULONG, (gptr*) &max_allowed_packet, (gptr*) &max_allowed_packet, 0, GET_ULONG,
REQUIRED_ARG, 16 *1024L*1024L, 4096, (longlong) 2*1024L*1024L*1024L, REQUIRED_ARG, 16 *1024L*1024L, 4096, (longlong) 2*1024L*1024L*1024L,
MALLOC_OVERHEAD, 1024, 0}, MALLOC_OVERHEAD, 1024, 0},
{"net_buffer_length", OPT_NET_BUFFER_LENGTH, "", {"net_buffer_length", OPT_NET_BUFFER_LENGTH,
"Buffer for TCP/IP and socket communication",
(gptr*) &net_buffer_length, (gptr*) &net_buffer_length, 0, GET_ULONG, (gptr*) &net_buffer_length, (gptr*) &net_buffer_length, 0, GET_ULONG,
REQUIRED_ARG, 16384, 1024, 512*1024*1024L, MALLOC_OVERHEAD, 1024, 0}, REQUIRED_ARG, 16384, 1024, 512*1024*1024L, MALLOC_OVERHEAD, 1024, 0},
{"select_limit", OPT_SELECT_LIMIT, "", (gptr*) &select_limit, {"select_limit", OPT_SELECT_LIMIT,
"Automatic limit for SELECT when using --safe-updates",
(gptr*) &select_limit,
(gptr*) &select_limit, 0, GET_ULONG, REQUIRED_ARG, 1000L, 1, ~0L, 0, 1, 0}, (gptr*) &select_limit, 0, GET_ULONG, REQUIRED_ARG, 1000L, 1, ~0L, 0, 1, 0},
{"max_join_size", OPT_MAX_JOIN_SIZE, "", (gptr*) &max_join_size, {"max_join_size", OPT_MAX_JOIN_SIZE,
"Automatic limit for rows in a join when using --safe-updates",
(gptr*) &max_join_size,
(gptr*) &max_join_size, 0, GET_ULONG, REQUIRED_ARG, 1000000L, 1, ~0L, 0, 1, (gptr*) &max_join_size, 0, GET_ULONG, REQUIRED_ARG, 1000000L, 1, ~0L, 0, 1,
0}, 0},
{"secure-auth", OPT_SECURE_AUTH, "Refuse client connecting to server if it" {"secure-auth", OPT_SECURE_AUTH, "Refuse client connecting to server if it"
...@@ -689,11 +707,16 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), ...@@ -689,11 +707,16 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
else else
{ {
opt_nopager= 0; opt_nopager= 0;
if (argument) if (argument && strlen(argument))
{
default_pager_set= 1;
strmov(pager, argument); strmov(pager, argument);
else strmov(default_pager, pager);
}
else if (default_pager_set)
strmov(pager, default_pager); strmov(pager, default_pager);
strmov(default_pager, pager); else
opt_nopager= 1;
} }
break; break;
case OPT_NOPAGER: case OPT_NOPAGER:
...@@ -814,6 +837,7 @@ static int get_options(int argc, char **argv) ...@@ -814,6 +837,7 @@ static int get_options(int argc, char **argv)
strmov(default_pager, "stdout"); strmov(default_pager, "stdout");
strmov(pager, "stdout"); strmov(pager, "stdout");
opt_nopager= 1; opt_nopager= 1;
default_pager_set= 0;
opt_outfile= 0; opt_outfile= 0;
opt_reconnect= 0; opt_reconnect= 0;
connect_flag= 0; /* Not in interactive mode */ connect_flag= 0; /* Not in interactive mode */
...@@ -2163,12 +2187,17 @@ com_pager(String *buffer, char *line __attribute__((unused))) ...@@ -2163,12 +2187,17 @@ com_pager(String *buffer, char *line __attribute__((unused)))
if (status.batch) if (status.batch)
return 0; return 0;
/* Skip space from file name */ /* Skip spaces in front of the pager command */
while (my_isspace(charset_info,*line)) while (my_isspace(charset_info, *line))
line++; line++;
if (!(param= strchr(line, ' '))) // if pager was not given, use the default /* Skip the pager command */
param= strchr(line, ' ');
/* Skip the spaces between the command and the argument */
while (param && my_isspace(charset_info, *param))
param++;
if (!param || !strlen(param)) // if pager was not given, use the default
{ {
if (!default_pager[0]) if (!default_pager_set)
{ {
tee_fprintf(stdout, "Default pager wasn't set, using stdout.\n"); tee_fprintf(stdout, "Default pager wasn't set, using stdout.\n");
opt_nopager=1; opt_nopager=1;
...@@ -2180,9 +2209,7 @@ com_pager(String *buffer, char *line __attribute__((unused))) ...@@ -2180,9 +2209,7 @@ com_pager(String *buffer, char *line __attribute__((unused)))
} }
else else
{ {
while (my_isspace(charset_info,*param)) end= strmake(pager_name, param, sizeof(pager_name)-1);
param++;
end=strmake(pager_name, param, sizeof(pager_name)-1);
while (end > pager_name && (my_isspace(charset_info,end[-1]) || while (end > pager_name && (my_isspace(charset_info,end[-1]) ||
my_iscntrl(charset_info,end[-1]))) my_iscntrl(charset_info,end[-1])))
end--; end--;
...@@ -2191,7 +2218,7 @@ com_pager(String *buffer, char *line __attribute__((unused))) ...@@ -2191,7 +2218,7 @@ com_pager(String *buffer, char *line __attribute__((unused)))
strmov(default_pager, pager_name); strmov(default_pager, pager_name);
} }
opt_nopager=0; opt_nopager=0;
tee_fprintf(stdout, "PAGER set to %s\n", pager); tee_fprintf(stdout, "PAGER set to '%s'\n", pager);
return 0; return 0;
} }
...@@ -2202,6 +2229,7 @@ com_nopager(String *buffer __attribute__((unused)), ...@@ -2202,6 +2229,7 @@ com_nopager(String *buffer __attribute__((unused)),
{ {
strmov(pager, "stdout"); strmov(pager, "stdout");
opt_nopager=1; opt_nopager=1;
PAGER= stdout;
tee_fprintf(stdout, "PAGER set to stdout\n"); tee_fprintf(stdout, "PAGER set to stdout\n");
return 0; return 0;
} }
......
...@@ -17,11 +17,12 @@ ...@@ -17,11 +17,12 @@
C_MODE_START C_MODE_START
enum get_opt_var_type { GET_NO_ARG, GET_BOOL, GET_INT, GET_UINT, GET_LONG, enum get_opt_var_type { GET_NO_ARG, GET_BOOL, GET_INT, GET_UINT, GET_LONG,
GET_ULONG, GET_LL, GET_ULL, GET_STR, GET_STR_ALLOC GET_ULONG, GET_LL, GET_ULL, GET_STR, GET_STR_ALLOC,
GET_DISABLED
}; };
#define GET_ASK_ADDR 128 #define GET_ASK_ADDR 128
#define GET_TYPE_MASK 127 #define GET_TYPE_MASK 127
enum get_opt_arg_type { NO_ARG, OPT_ARG, REQUIRED_ARG }; enum get_opt_arg_type { NO_ARG, OPT_ARG, REQUIRED_ARG };
......
...@@ -68,6 +68,7 @@ extern const char * NEAR globerrs[]; /* my_error_messages is here */ ...@@ -68,6 +68,7 @@ extern const char * NEAR globerrs[]; /* my_error_messages is here */
#define EXIT_UNKNOWN_SUFFIX 9 #define EXIT_UNKNOWN_SUFFIX 9
#define EXIT_NO_PTR_TO_VARIABLE 10 #define EXIT_NO_PTR_TO_VARIABLE 10
#define EXIT_CANNOT_CONNECT_TO_SERVICE 11 #define EXIT_CANNOT_CONNECT_TO_SERVICE 11
#define EXIT_OPTION_DISABLED 12
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -285,6 +285,19 @@ int handle_options(int *argc, char ***argv, ...@@ -285,6 +285,19 @@ int handle_options(int *argc, char ***argv,
return EXIT_AMBIGUOUS_OPTION; return EXIT_AMBIGUOUS_OPTION;
} }
} }
if ((optp->var_type & GET_TYPE_MASK) == GET_DISABLED)
{
if (my_getopt_print_errors)
fprintf(stderr,
"%s: %s: Option '%s' used, but is disabled\n", my_progname,
option_is_loose ? "WARNING" : "ERROR", opt_str);
if (option_is_loose)
{
(*argc)--;
continue;
}
return EXIT_OPTION_DISABLED;
}
if (must_be_var && (optp->var_type & GET_TYPE_MASK) == GET_NO_ARG) if (must_be_var && (optp->var_type & GET_TYPE_MASK) == GET_NO_ARG)
{ {
if (my_getopt_print_errors) if (my_getopt_print_errors)
...@@ -358,6 +371,14 @@ int handle_options(int *argc, char ***argv, ...@@ -358,6 +371,14 @@ int handle_options(int *argc, char ***argv,
{ {
/* Option recognized. Find next what to do with it */ /* Option recognized. Find next what to do with it */
opt_found= 1; opt_found= 1;
if ((optp->var_type & GET_TYPE_MASK) == GET_DISABLED)
{
if (my_getopt_print_errors)
fprintf(stderr,
"%s: ERROR: Option '-%c' used, but is disabled\n",
my_progname, optp->id);
return EXIT_OPTION_DISABLED;
}
if ((optp->var_type & GET_TYPE_MASK) == GET_BOOL && if ((optp->var_type & GET_TYPE_MASK) == GET_BOOL &&
optp->arg_type == NO_ARG) optp->arg_type == NO_ARG)
{ {
...@@ -550,7 +571,7 @@ static int findopt(char *optpat, uint length, ...@@ -550,7 +571,7 @@ static int findopt(char *optpat, uint length,
const struct my_option **opt_res, const struct my_option **opt_res,
char **ffname) char **ffname)
{ {
int count; uint count;
struct my_option *opt= (struct my_option *) *opt_res; struct my_option *opt= (struct my_option *) *opt_res;
for (count= 0; opt->name; opt++) for (count= 0; opt->name; opt++)
...@@ -562,7 +583,8 @@ static int findopt(char *optpat, uint length, ...@@ -562,7 +583,8 @@ static int findopt(char *optpat, uint length,
*ffname= (char *) opt->name; /* We only need to know one prev */ *ffname= (char *) opt->name; /* We only need to know one prev */
if (!opt->name[length]) /* Exact match */ if (!opt->name[length]) /* Exact match */
return 1; return 1;
count++; if (!count || strcmp(*ffname, opt->name)) /* Don't count synonyms */
count++;
} }
} }
return count; return count;
...@@ -882,7 +904,8 @@ void my_print_variables(const struct my_option *options) ...@@ -882,7 +904,8 @@ void my_print_variables(const struct my_option *options)
longlong2str(*((ulonglong*) value), buff, 10); longlong2str(*((ulonglong*) value), buff, 10);
printf("%s\n", buff); printf("%s\n", buff);
break; break;
default: /* dummy default to avoid compiler warnings */ default:
printf("(Disabled)\n");
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