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);
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 :
'_'))
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) &&
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));
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 &&
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));
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++)
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);