36
36
namespace drizzled {
38
static void default_reporter(enum loglevel level, const char *format, ...)
41
va_start(args, format);
42
if (level == WARNING_LEVEL)
43
fprintf(stderr, "%s", _("Warning: "));
44
else if (level == INFORMATION_LEVEL)
45
fprintf(stderr, "%s", _("Info: "));
46
vfprintf(stderr, format, args);
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);
53
55
function: compare_strings
55
57
Works like strncmp, other than 1.) considers '-' and '_' the same.
56
58
2.) Returns -1 if strings differ, 0 if they are equal
59
bool getopt_compare_strings(const char *s, const char *t,
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++)
62
char const *end= s + length;
63
for (;s != end ; s++, t++)
66
if ((*s != '-' ? *s : '_') != (*t != '-' ? *t : '_'))
65
if ((*s != '-' ? *s : '_') != (*t != '-' ? *t : '_'))
72
76
function: getopt_ll_limit_value
74
78
Applies min/max/block_size to a numeric value of an option.
75
79
Returns "fixed" value.
78
int64_t getopt_ll_limit_value(int64_t num, const option& optp, bool *fix)
82
char buf1[255], buf2[255];
83
uint64_t block_size= optp.block_size ? optp.block_size : 1;
85
if (num > 0 && ((uint64_t) num > (uint64_t) optp.max_value) &&
86
optp.max_value) /* if max value is not set -> no upper limit */
88
num= (uint64_t) optp.max_value;
92
switch ((optp.var_type & GET_TYPE_MASK)) {
94
if (num > (int64_t) INT_MAX)
96
num= ((int64_t) INT_MAX);
101
if (num > (int64_t) INT32_MAX)
103
num= ((int64_t) INT32_MAX);
108
assert((optp.var_type & GET_TYPE_MASK) == GET_LL);
112
num= ((num - optp.sub_size) / block_size);
113
num= (int64_t) (num * block_size);
115
if (num < optp.min_value)
124
default_reporter(WARNING_LEVEL,
125
"option '%s': signed value %s adjusted to %s",
126
optp.name, internal::llstr(old, buf1), internal::llstr(num, buf2));
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));
131
139
function: getopt_ull
133
141
This is the same as getopt_ll, but is meant for uint64_t
137
uint64_t getopt_ull_limit_value(uint64_t num, const option& optp, bool *fix)
139
bool adjusted= false;
141
char buf1[255], buf2[255];
143
if ((uint64_t) num > (uint64_t) optp.max_value &&
144
optp.max_value) /* if max value is not set -> no upper limit */
146
num= (uint64_t) optp.max_value;
150
switch (optp.var_type & GET_TYPE_MASK)
160
case GET_ULONG_IS_FAIL:
161
if (num > UINT32_MAX)
175
assert((optp.var_type & GET_TYPE_MASK) == GET_ULL || (optp.var_type & GET_TYPE_MASK) == GET_UINT64);
178
if (optp.block_size > 1)
180
num/= optp.block_size;
181
num*= optp.block_size;
184
if (num < (uint64_t) optp.min_value)
186
num= (uint64_t) optp.min_value;
193
default_reporter(WARNING_LEVEL, "option '%s': unsigned value %s adjusted to %s",
194
optp.name, internal::ullstr(old, buf1), internal::ullstr(num, buf2));
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));
201
209
function: my_print_options
203
211
Print help for all options and variables.
206
void my_print_help(const option* options)
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++)
208
uint32_t col, name_space= 22, comment_space= 57;
209
const char *line_end;
210
const struct option *optp;
212
for (optp= options; optp->id; optp++)
216
printf(" -%c%s", optp->id, strlen(optp->name) ? ", " : " ");
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)
224
if (strlen(optp->name))
226
printf("--%s", optp->name);
227
col+= 2 + (uint32_t) strlen(optp->name);
228
if ((optp->var_type & GET_TYPE_MASK) == GET_STR ||
229
(optp->var_type & GET_TYPE_MASK) == GET_STR_ALLOC)
231
printf("%s=name%s ", optp->arg_type == OPT_ARG ? "[" : "",
232
optp->arg_type == OPT_ARG ? "]" : "");
233
col+= (optp->arg_type == OPT_ARG) ? 8 : 6;
235
else if ((optp->var_type & GET_TYPE_MASK) == GET_NO_ARG ||
236
(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++)
243
printf("%s=#%s ", optp->arg_type == OPT_ARG ? "[" : "",
244
optp->arg_type == OPT_ARG ? "]" : "");
245
col+= (optp->arg_type == OPT_ARG) ? 5 : 3;
247
if (col > name_space && optp->comment && *optp->comment)
253
for (; col < name_space; col++)
255
if (optp->comment && *optp->comment)
257
const char *comment= _(optp->comment), *end= strchr(comment, '\0');
259
while ((uint32_t) (end - comment) > comment_space)
261
for (line_end= comment + comment_space; *line_end != ' '; line_end--)
263
for (; comment != line_end; comment++)
265
comment++; /* skip the space, as a newline will take it's place now */
267
for (col= 0; col < name_space; col++)
270
printf("%s", comment);
273
if ((optp->var_type & GET_TYPE_MASK) == GET_NO_ARG ||
274
(optp->var_type & GET_TYPE_MASK) == GET_BOOL)
276
if (optp->def_value != 0)
278
printf(_("%*s(Defaults to on; use --skip-%s to disable.)\n"), name_space, "", optp->name);
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);
285
293
} /* namespace drizzled */