1
/* Copyright (C) 2002-2006 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
17
#include <drizzled/definitions.h>
18
#include <drizzled/charset.h>
19
#include <drizzled/internal/my_sys.h>
20
#include <drizzled/gettext.h>
22
#include <drizzled/internal/m_string.h>
23
#include <drizzled/internal/my_sys.h>
24
#include <drizzled/error.h>
25
#include <drizzled/option.h>
26
#include <drizzled/typelib.h>
38
static void default_reporter(enum loglevel level, const char *format, ...)
41
va_start(args, format);
43
if (level == WARNING_LEVEL)
44
fprintf(stderr, "%s", _("Warning: "));
45
else if (level == INFORMATION_LEVEL)
46
fprintf(stderr, "%s", _("Info: "));
48
vfprintf(stderr, format, args);
55
function: compare_strings
57
Works like strncmp, other than 1.) considers '-' and '_' the same.
58
2.) Returns -1 if strings differ, 0 if they are equal
61
bool getopt_compare_strings(const char *s, const char *t, uint32_t length)
63
char const *end= s + length;
64
for (;s != end ; s++, t++)
66
if ((*s != '-' ? *s : '_') != (*t != '-' ? *t : '_'))
76
function: getopt_ll_limit_value
78
Applies min/max/block_size to a numeric value of an option.
79
Returns "fixed" value.
82
int64_t getopt_ll_limit_value(int64_t num, const option& optp, bool *fix)
86
char buf1[255], buf2[255];
87
uint64_t block_size= optp.block_size ? optp.block_size : 1;
89
if (num > 0 && ((uint64_t) num > (uint64_t) optp.max_value) &&
90
optp.max_value) /* if max value is not set -> no upper limit */
92
num= (uint64_t) optp.max_value;
96
switch ((optp.var_type & GET_TYPE_MASK)) {
98
if (num > (int64_t) INT_MAX)
100
num= ((int64_t) INT_MAX);
105
if (num > (int64_t) INT32_MAX)
107
num= ((int64_t) INT32_MAX);
112
assert((optp.var_type & GET_TYPE_MASK) == GET_LL);
116
num= ((num - optp.sub_size) / block_size);
117
num= (int64_t) (num * block_size);
119
if (num < optp.min_value)
131
default_reporter(WARNING_LEVEL,
132
"option '%s': signed value %s adjusted to %s",
133
optp.name, internal::llstr(old, buf1), internal::llstr(num, buf2));
141
This is the same as getopt_ll, but is meant for uint64_t
145
uint64_t getopt_ull_limit_value(uint64_t num, const option& optp, bool *fix)
147
bool adjusted= false;
149
char buf1[255], buf2[255];
151
if ((uint64_t) num > (uint64_t) optp.max_value &&
152
optp.max_value) /* if max value is not set -> no upper limit */
154
num= (uint64_t) optp.max_value;
158
switch (optp.var_type & GET_TYPE_MASK)
168
case GET_ULONG_IS_FAIL:
169
if (num > UINT32_MAX)
183
assert((optp.var_type & GET_TYPE_MASK) == GET_ULL || (optp.var_type & GET_TYPE_MASK) == GET_UINT64);
186
if (optp.block_size > 1)
188
num/= optp.block_size;
189
num*= optp.block_size;
192
if (num < (uint64_t) optp.min_value)
194
num= (uint64_t) optp.min_value;
201
default_reporter(WARNING_LEVEL, "option '%s': unsigned value %s adjusted to %s",
202
optp.name, internal::ullstr(old, buf1), internal::ullstr(num, buf2));
209
function: my_print_options
211
Print help for all options and variables.
214
void my_print_help(const option* options)
216
uint32_t col, name_space= 22, comment_space= 57;
217
const char *line_end;
218
const struct option *optp;
220
for (optp= options; optp->id; optp++)
224
printf(" -%c%s", optp->id, strlen(optp->name) ? ", " : " ");
232
if (strlen(optp->name))
234
printf("--%s", optp->name);
235
col+= 2 + (uint32_t) strlen(optp->name);
236
if ((optp->var_type & GET_TYPE_MASK) == GET_STR ||
237
(optp->var_type & GET_TYPE_MASK) == GET_STR_ALLOC)
239
printf("%s=name%s ", optp->arg_type == OPT_ARG ? "[" : "",
240
optp->arg_type == OPT_ARG ? "]" : "");
241
col+= (optp->arg_type == OPT_ARG) ? 8 : 6;
243
else if ((optp->var_type & GET_TYPE_MASK) == GET_NO_ARG ||
244
(optp->var_type & GET_TYPE_MASK) == GET_BOOL)
251
printf("%s=#%s ", optp->arg_type == OPT_ARG ? "[" : "",
252
optp->arg_type == OPT_ARG ? "]" : "");
253
col+= (optp->arg_type == OPT_ARG) ? 5 : 3;
255
if (col > name_space && optp->comment && *optp->comment)
261
for (; col < name_space; col++)
263
if (optp->comment && *optp->comment)
265
const char *comment= _(optp->comment), *end= strchr(comment, '\0');
267
while ((uint32_t) (end - comment) > comment_space)
269
for (line_end= comment + comment_space; *line_end != ' '; line_end--)
271
for (; comment != line_end; comment++)
273
comment++; /* skip the space, as a newline will take it's place now */
275
for (col= 0; col < name_space; col++)
278
printf("%s", comment);
281
if ((optp->var_type & GET_TYPE_MASK) == GET_NO_ARG ||
282
(optp->var_type & GET_TYPE_MASK) == GET_BOOL)
284
if (optp->def_value != 0)
286
printf(_("%*s(Defaults to on; use --skip-%s to disable.)\n"), name_space, "", optp->name);
293
} /* namespace drizzled */