91
static const char *on_off_default_names[]=
93
"off","on","default", NullS
96
static const unsigned int on_off_default_names_len[]=
100
sizeof("default") - 1
103
static TYPELIB on_off_default_typelib= {array_elements(on_off_default_names)-1,
104
"", on_off_default_names,
105
(unsigned int *)on_off_default_names_len};
109
Parse a TYPELIB name from the buffer
113
lib Set of names to scan for.
114
strpos INOUT Start of the buffer (updated to point to the next
115
character after the name)
116
end End of the buffer
117
cs Charset used in the buffer
120
Parse a TYPELIB name from the buffer. The buffer is assumed to contain
121
one of the names specified in the TYPELIB, followed by comma, '=', or
126
>0 Offset+1 in typelib for matched name
129
static uint parse_name(TYPELIB *lib, const char **strpos, const char *end,
132
const char *pos= *strpos;
133
const char *start= pos;
135
/* Find the length */
136
if (cs && cs->mbminlen > 1)
139
for ( ; pos < end; pos+= mblen)
142
if ((mblen= cs->cset->mb_wc(cs, &wc, (const uchar *) pos,
143
(const uchar *) end)) < 1)
144
mblen= 1; // Not to hang on a wrong multibyte sequence
145
if (wc == (my_wc_t) '=' || wc == (my_wc_t) ',')
150
for (; pos != end && *pos != '=' && *pos !=',' ; pos++);
152
uint var_len= (uint) (pos - start);
153
/* Determine which flag it is */
154
uint find= cs ? find_type2(lib, start, var_len, cs) :
155
find_type(lib, start, var_len, (bool) 0);
161
/* Read next character from the buffer in a charset-aware way */
163
static my_wc_t get_next_char(const char **pos, const char *end, CHARSET_INFO *cs)
169
if (cs && cs->mbminlen > 1)
172
if ((mblen= cs->cset->mb_wc(cs, &wc, (const uchar *) *pos,
173
(const uchar *) end)) < 1)
174
mblen= 1; // Not to hang on a wrong multibyte sequence
184
Parse and apply a set of flag assingments
187
find_set_from_flags()
189
default_name Number of "default" in the typelib
190
cur_set Current set of flags (start from this state)
191
default_set Default set of flags (use this for assign-default
192
keyword and flag=default assignments)
193
str String to be parsed
194
length Length of the string
196
err_pos OUT If error, set to point to start of wrong set string
198
err_len OUT If error, set to the length of wrong set string
199
set_warning OUT TRUE <=> Some string in set couldn't be used
202
Parse a set of flag assignments, that is, parse a string in form:
204
param_name1=value1,param_name2=value2,...
206
where the names are specified in the TYPELIB, and each value can be
207
either 'on','off', or 'default'. Setting the same name twice is not
210
Besides param=val assignments, we support the "default" keyword (keyword
211
#default_name in the typelib). It can be used one time, if specified it
212
causes us to build the new set over the default_set rather than cur_set
216
Parsed set value if (*errpos == NULL)
220
ulonglong find_set_from_flags(TYPELIB *lib, uint default_name,
221
ulonglong cur_set, ulonglong default_set,
222
const char *str, uint length, CHARSET_INFO *cs,
223
char **err_pos, uint *err_len, bool *set_warning)
225
CHARSET_INFO *strip= cs ? cs : &my_charset_latin1;
226
const char *end= str + strip->cset->lengthsp(strip, str, length);
227
ulonglong flags_to_set= 0, flags_to_clear= 0;
228
bool set_defaults= 0;
229
*err_pos= 0; // No error yet
232
const char *start= str;
235
const char *pos= start;
238
if (!(flag_no= parse_name(lib, &pos, end, cs)))
241
if (flag_no == default_name)
243
/* Using 'default' twice isn't allowed. */
250
ulonglong bit= ((longlong) 1 << (flag_no - 1));
251
/* parse the '=on|off|default' */
252
if ((flags_to_clear | flags_to_set) & bit ||
253
get_next_char(&pos, end, cs) != '=' ||
254
!(value= parse_name(&on_off_default_typelib, &pos, end, cs)))
259
if (value == 1) // this is '=off'
260
flags_to_clear|= bit;
261
else if (value == 2) // this is '=on'
263
else // this is '=default'
265
if (default_set & bit)
268
flags_to_clear|= bit;
274
if (get_next_char(&pos, end, cs) != ',')
280
*err_pos= (char*)start;
281
*err_len= end - start;
286
ulonglong res= set_defaults? default_set : cur_set;
288
res&= ~flags_to_clear;
92
294
Function to find a string in a TYPELIB
93
295
(Same format as mysys/typelib.c)