mirror of
https://github.com/MariaDB/server.git
synced 2026-05-16 11:57:38 +02:00
Merge mysql.com:/misc/mysql/31177/50-31177
into mysql.com:/misc/mysql/31177/51-31177 include/m_string.h: Auto merged include/my_getopt.h: Auto merged mysql-test/r/delayed.result: Auto merged mysql-test/r/innodb.result: Auto merged mysql-test/r/innodb_mysql.result: Auto merged mysql-test/r/key_cache.result: Auto merged mysql-test/r/ps.result: Auto merged mysql-test/r/type_bit.result: Auto merged mysql-test/r/type_bit_innodb.result: Auto merged mysql-test/t/variables.test: Auto merged sql/mysql_priv.h: Auto merged BitKeeper/deleted/.del-index_merge.result: Auto merged sql/set_var.cc: Auto merged mysql-test/r/variables.result: manual merge client/mysql.cc: manual merge client/mysqltest.c: manual merge mysql-test/r/subselect.result: manual merge mysys/my_getopt.c: manual merge sql/mysqld.cc: manual merge
This commit is contained in:
commit
54ad7d88d0
19 changed files with 245 additions and 95 deletions
|
|
@ -34,6 +34,7 @@ my_bool getopt_compare_strings(const char *s,
|
|||
const char *t,
|
||||
uint length);
|
||||
static longlong getopt_ll(char *arg, const struct my_option *optp, int *err);
|
||||
static longlong getopt_ll_limit_value(longlong, const struct my_option *);
|
||||
static ulonglong getopt_ull(char *arg, const struct my_option *optp,
|
||||
int *err);
|
||||
static double getopt_double(char *arg, const struct my_option *optp, int *err);
|
||||
|
|
@ -86,6 +87,7 @@ static void default_reporter(enum loglevel level,
|
|||
fprintf(stderr, "%s", "Info: ");
|
||||
vfprintf(stderr, format, args);
|
||||
va_end(args);
|
||||
fputs('\n', stderr);
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
|
|
@ -153,7 +155,7 @@ int handle_options(int *argc, char ***argv,
|
|||
{
|
||||
if (my_getopt_print_errors)
|
||||
my_getopt_error_reporter(ERROR_LEVEL,
|
||||
"%s: Option '-O' requires an argument\n",
|
||||
"%s: Option '-O' requires an argument",
|
||||
my_progname);
|
||||
return EXIT_ARGUMENT_REQUIRED;
|
||||
}
|
||||
|
|
@ -171,7 +173,7 @@ int handle_options(int *argc, char ***argv,
|
|||
{
|
||||
if (my_getopt_print_errors)
|
||||
my_getopt_error_reporter(ERROR_LEVEL,
|
||||
"%s: Option '--set-variable' requires an argument\n",
|
||||
"%s: Option '--set-variable' requires an argument",
|
||||
my_progname);
|
||||
return EXIT_ARGUMENT_REQUIRED;
|
||||
}
|
||||
|
|
@ -185,7 +187,7 @@ int handle_options(int *argc, char ***argv,
|
|||
{
|
||||
if (my_getopt_print_errors)
|
||||
my_getopt_error_reporter(ERROR_LEVEL,
|
||||
"%s: Option '--set-variable' requires an argument\n",
|
||||
"%s: Option '--set-variable' requires an argument",
|
||||
my_progname);
|
||||
return EXIT_ARGUMENT_REQUIRED;
|
||||
}
|
||||
|
|
@ -247,7 +249,7 @@ int handle_options(int *argc, char ***argv,
|
|||
{
|
||||
if (my_getopt_print_errors)
|
||||
my_getopt_error_reporter(ERROR_LEVEL,
|
||||
"%s: ambiguous option '--%s-%s' (--%s-%s)\n",
|
||||
"%s: ambiguous option '--%s-%s' (--%s-%s)",
|
||||
my_progname, special_opt_prefix[i],
|
||||
cur_arg, special_opt_prefix[i],
|
||||
prev_found);
|
||||
|
|
@ -298,7 +300,7 @@ int handle_options(int *argc, char ***argv,
|
|||
if (my_getopt_print_errors)
|
||||
my_getopt_error_reporter(option_is_loose ?
|
||||
WARNING_LEVEL : ERROR_LEVEL,
|
||||
"%s: unknown variable '%s'\n",
|
||||
"%s: unknown variable '%s'",
|
||||
my_progname, cur_arg);
|
||||
if (!option_is_loose)
|
||||
return EXIT_UNKNOWN_VARIABLE;
|
||||
|
|
@ -308,7 +310,7 @@ int handle_options(int *argc, char ***argv,
|
|||
if (my_getopt_print_errors)
|
||||
my_getopt_error_reporter(option_is_loose ?
|
||||
WARNING_LEVEL : ERROR_LEVEL,
|
||||
"%s: unknown option '--%s'\n",
|
||||
"%s: unknown option '--%s'",
|
||||
my_progname, cur_arg);
|
||||
if (!option_is_loose)
|
||||
return EXIT_UNKNOWN_OPTION;
|
||||
|
|
@ -326,7 +328,7 @@ int handle_options(int *argc, char ***argv,
|
|||
{
|
||||
if (my_getopt_print_errors)
|
||||
my_getopt_error_reporter(ERROR_LEVEL,
|
||||
"%s: variable prefix '%s' is not unique\n",
|
||||
"%s: variable prefix '%s' is not unique",
|
||||
my_progname, opt_str);
|
||||
return EXIT_VAR_PREFIX_NOT_UNIQUE;
|
||||
}
|
||||
|
|
@ -334,7 +336,7 @@ int handle_options(int *argc, char ***argv,
|
|||
{
|
||||
if (my_getopt_print_errors)
|
||||
my_getopt_error_reporter(ERROR_LEVEL,
|
||||
"%s: ambiguous option '--%s' (%s, %s)\n",
|
||||
"%s: ambiguous option '--%s' (%s, %s)",
|
||||
my_progname, opt_str, prev_found,
|
||||
optp->name);
|
||||
return EXIT_AMBIGUOUS_OPTION;
|
||||
|
|
@ -357,7 +359,7 @@ int handle_options(int *argc, char ***argv,
|
|||
{
|
||||
if (my_getopt_print_errors)
|
||||
my_getopt_error_reporter(ERROR_LEVEL,
|
||||
"%s: option '%s' cannot take an argument\n",
|
||||
"%s: option '%s' cannot take an argument",
|
||||
my_progname, optp->name);
|
||||
return EXIT_NO_ARGUMENT_ALLOWED;
|
||||
}
|
||||
|
|
@ -370,7 +372,7 @@ int handle_options(int *argc, char ***argv,
|
|||
{
|
||||
if (my_getopt_print_errors)
|
||||
my_getopt_error_reporter(ERROR_LEVEL,
|
||||
"%s: option '--%s' cannot take an argument\n",
|
||||
"%s: option '--%s' cannot take an argument",
|
||||
my_progname, optp->name);
|
||||
return EXIT_NO_ARGUMENT_ALLOWED;
|
||||
}
|
||||
|
|
@ -392,7 +394,7 @@ int handle_options(int *argc, char ***argv,
|
|||
{
|
||||
my_getopt_error_reporter(WARNING_LEVEL,
|
||||
"%s: ignoring option '--%s' due to \
|
||||
invalid value '%s'\n",
|
||||
invalid value '%s'",
|
||||
my_progname, optp->name, optend);
|
||||
continue;
|
||||
}
|
||||
|
|
@ -423,7 +425,7 @@ invalid value '%s'\n",
|
|||
{
|
||||
if (my_getopt_print_errors)
|
||||
my_getopt_error_reporter(ERROR_LEVEL,
|
||||
"%s: option '--%s' requires an argument\n",
|
||||
"%s: option '--%s' requires an argument",
|
||||
my_progname, optp->name);
|
||||
return EXIT_ARGUMENT_REQUIRED;
|
||||
}
|
||||
|
|
@ -483,7 +485,7 @@ invalid value '%s'\n",
|
|||
{
|
||||
if (my_getopt_print_errors)
|
||||
my_getopt_error_reporter(ERROR_LEVEL,
|
||||
"%s: option '-%c' requires an argument\n",
|
||||
"%s: option '-%c' requires an argument",
|
||||
my_progname, optp->id);
|
||||
return EXIT_ARGUMENT_REQUIRED;
|
||||
}
|
||||
|
|
@ -496,7 +498,7 @@ invalid value '%s'\n",
|
|||
set_maximum_value)))
|
||||
{
|
||||
my_getopt_error_reporter(ERROR_LEVEL,
|
||||
"%s: Error while setting value '%s' to '%s'\n",
|
||||
"%s: Error while setting value '%s' to '%s'",
|
||||
my_progname, argument, optp->name);
|
||||
return error;
|
||||
}
|
||||
|
|
@ -508,7 +510,7 @@ invalid value '%s'\n",
|
|||
{
|
||||
if (my_getopt_print_errors)
|
||||
my_getopt_error_reporter(ERROR_LEVEL,
|
||||
"%s: unknown option '-%c'\n",
|
||||
"%s: unknown option '-%c'",
|
||||
my_progname, *optend);
|
||||
return EXIT_UNKNOWN_OPTION;
|
||||
}
|
||||
|
|
@ -519,7 +521,7 @@ invalid value '%s'\n",
|
|||
if ((error= setval(optp, value, argument, set_maximum_value)))
|
||||
{
|
||||
my_getopt_error_reporter(ERROR_LEVEL,
|
||||
"%s: Error while setting value '%s' to '%s'\n",
|
||||
"%s: Error while setting value '%s' to '%s'",
|
||||
my_progname, argument, optp->name);
|
||||
return error;
|
||||
}
|
||||
|
|
@ -608,13 +610,17 @@ static int setval(const struct my_option *opts, uchar* *value, char *argument,
|
|||
*((my_bool*) result_pos)= (my_bool) atoi(argument) != 0;
|
||||
break;
|
||||
case GET_INT:
|
||||
case GET_UINT: /* fall through */
|
||||
*((int*) result_pos)= (int) getopt_ll(argument, opts, &err);
|
||||
break;
|
||||
case GET_UINT:
|
||||
*((uint*) result_pos)= (uint) getopt_ull(argument, opts, &err);
|
||||
break;
|
||||
case GET_LONG:
|
||||
case GET_ULONG: /* fall through */
|
||||
*((long*) result_pos)= (long) getopt_ll(argument, opts, &err);
|
||||
break;
|
||||
case GET_ULONG:
|
||||
*((long*) result_pos)= (long) getopt_ull(argument, opts, &err);
|
||||
break;
|
||||
case GET_LL:
|
||||
*((longlong*) result_pos)= getopt_ll(argument, opts, &err);
|
||||
break;
|
||||
|
|
@ -778,23 +784,46 @@ static longlong eval_num_suffix(char *argument, int *error, char *option_name)
|
|||
|
||||
static longlong getopt_ll(char *arg, const struct my_option *optp, int *err)
|
||||
{
|
||||
longlong num;
|
||||
longlong num=eval_num_suffix(arg, err, (char*) optp->name);
|
||||
return getopt_ll_limit_value(num, optp);
|
||||
}
|
||||
|
||||
/*
|
||||
function: getopt_ll_limit_value
|
||||
|
||||
Applies min/max/block_size to a numeric value of an option.
|
||||
Returns "fixed" value.
|
||||
*/
|
||||
|
||||
static longlong getopt_ll_limit_value(longlong num,
|
||||
const struct my_option *optp)
|
||||
{
|
||||
longlong old= num;
|
||||
bool trunc= FALSE;
|
||||
char buf1[255], buf2[255];
|
||||
ulonglong block_size= (optp->block_size ? (ulonglong) optp->block_size : 1L);
|
||||
|
||||
num= eval_num_suffix(arg, err, (char*) optp->name);
|
||||
if (num > 0 && (ulonglong) num > (ulonglong) optp->max_value &&
|
||||
|
||||
if (num > 0 && ((ulonglong) num > (ulonglong) optp->max_value) &&
|
||||
optp->max_value) /* if max value is not set -> no upper limit */
|
||||
{
|
||||
char buf[22];
|
||||
my_getopt_error_reporter(WARNING_LEVEL,
|
||||
"Truncated incorrect %s value: '%s'",
|
||||
optp->name, llstr(num, buf));
|
||||
|
||||
num= (ulonglong) optp->max_value;
|
||||
trunc= TRUE;
|
||||
}
|
||||
|
||||
num= ((num - optp->sub_size) / block_size);
|
||||
num= (longlong) (num * block_size);
|
||||
return max(num, optp->min_value);
|
||||
|
||||
if (num < optp->min_value)
|
||||
{
|
||||
num= optp->min_value;
|
||||
trunc= TRUE;
|
||||
}
|
||||
|
||||
if (trunc)
|
||||
my_getopt_error_reporter(WARNING_LEVEL,
|
||||
"option '%s': signed value %s adjusted to %s",
|
||||
optp->name, llstr(old, buf1), llstr(num, buf2));
|
||||
return num;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -806,25 +835,67 @@ static longlong getopt_ll(char *arg, const struct my_option *optp, int *err)
|
|||
|
||||
static ulonglong getopt_ull(char *arg, const struct my_option *optp, int *err)
|
||||
{
|
||||
ulonglong num;
|
||||
|
||||
num= eval_num_suffix(arg, err, (char*) optp->name);
|
||||
return getopt_ull_limit_value(num, optp);
|
||||
ulonglong num= eval_num_suffix(arg, err, (char*) optp->name);
|
||||
return getopt_ull_limit_value(num, optp, NULL);
|
||||
}
|
||||
|
||||
|
||||
ulonglong getopt_ull_limit_value(ulonglong num, const struct my_option *optp)
|
||||
ulonglong getopt_ull_limit_value(ulonglong num, const struct my_option *optp,
|
||||
bool *fix)
|
||||
{
|
||||
bool adjusted= FALSE;
|
||||
ulonglong old= num, mod;
|
||||
char buf1[255], buf2[255];
|
||||
|
||||
if ((ulonglong) num > (ulonglong) optp->max_value &&
|
||||
optp->max_value) /* if max value is not set -> no upper limit */
|
||||
{
|
||||
num= (ulonglong) optp->max_value;
|
||||
adjusted= TRUE;
|
||||
}
|
||||
|
||||
switch ((optp->var_type & GET_TYPE_MASK)) {
|
||||
case GET_UINT:
|
||||
if (num > (ulonglong) UINT_MAX)
|
||||
{
|
||||
num= ((ulonglong) UINT_MAX);
|
||||
adjusted= TRUE;
|
||||
}
|
||||
break;
|
||||
case GET_ULONG:
|
||||
#if SIZEOF_LONG < SIZEOF_LONG_LONG
|
||||
if (num > (ulonglong) ULONG_MAX)
|
||||
{
|
||||
num= ((ulonglong) ULONG_MAX);
|
||||
adjusted= TRUE;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
DBUG_ASSERT((optp->var_type & GET_TYPE_MASK) == GET_ULL);
|
||||
break;
|
||||
}
|
||||
|
||||
if (optp->block_size > 1)
|
||||
{
|
||||
num/= (ulonglong) optp->block_size;
|
||||
num*= (ulonglong) optp->block_size;
|
||||
}
|
||||
|
||||
if (num < (ulonglong) optp->min_value)
|
||||
{
|
||||
num= (ulonglong) optp->min_value;
|
||||
adjusted= TRUE;
|
||||
}
|
||||
|
||||
if (adjusted)
|
||||
my_getopt_error_reporter(WARNING_LEVEL,
|
||||
"option '%s': unsigned value %s adjusted to %s",
|
||||
optp->name, ullstr(old, buf1), ullstr(num, buf2));
|
||||
|
||||
if (fix)
|
||||
*fix= adjusted;
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue