summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
Diffstat (limited to 'mysys')
-rw-r--r--mysys/default.c4
-rw-r--r--mysys/my_getopt.c4
-rw-r--r--mysys/typelib.c49
3 files changed, 28 insertions, 29 deletions
diff --git a/mysys/default.c b/mysys/default.c
index 805dc5f3f58..fe070f42748 100644
--- a/mysys/default.c
+++ b/mysys/default.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
+/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -376,7 +376,7 @@ static int handle_default_option(void *in_ctx, const char *group_name,
if (!option)
return 0;
- if (find_type((char *)group_name, ctx->group, 3))
+ if (find_type((char *)group_name, ctx->group, FIND_TYPE_NO_PREFIX))
{
if (!(tmp= alloc_root(ctx->alloc, strlen(option) + 1)))
return 1;
diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c
index 6f7ed070ccf..ac4ae46eab5 100644
--- a/mysys/my_getopt.c
+++ b/mysys/my_getopt.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
+/* Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -695,7 +695,7 @@ static int setval(const struct my_option *opts, void *value, char *argument,
break;
case GET_ENUM:
{
- int type= find_type(argument, opts->typelib, 2);
+ int type= find_type(argument, opts->typelib, FIND_TYPE_BASIC);
if (type == 0)
{
/*
diff --git a/mysys/typelib.c b/mysys/typelib.c
index 7681ff581ac..c0d37e26ecf 100644
--- a/mysys/typelib.c
+++ b/mysys/typelib.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB
+/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -27,7 +27,7 @@ int find_type_or_exit(const char *x, TYPELIB *typelib, const char *option)
int res;
const char **ptr;
- if ((res= find_type((char *) x, typelib, 2)) <= 0)
+ if ((res= find_type((char *) x, typelib, FIND_TYPE_BASIC)) <= 0)
{
ptr= typelib->type_names;
if (!*x)
@@ -48,16 +48,13 @@ int find_type_or_exit(const char *x, TYPELIB *typelib, const char *option)
Search after a string in a list of strings. Endspace in x is not compared.
@param x String to find
- @param lib TYPELIB (struct of pointer to values + count)
- @param full_name bitmap of what to do
- If & 1 accept only whole names
- If & 2 don't expand if half field
- If & 4 allow #number# as type
- If & 8 use ',' as string terminator
-
- @note
- If part, uniq field is found and full_name == 0 then x is expanded
- to full field.
+ @param typelib TYPELIB (struct of pointer to values + count)
+ @param flags flags to tune behaviour: a combination of
+ FIND_TYPE_NO_PREFIX
+ FIND_TYPE_ALLOW_NUMBER
+ FIND_TYPE_COMMA_TERM.
+ FIND_TYPE_NO_OVERWRITE can be passed but is
+ superfluous (is always implicitely on).
@retval
-1 Too many matching values
@@ -68,15 +65,17 @@ int find_type_or_exit(const char *x, TYPELIB *typelib, const char *option)
*/
-int find_type(char *x, const TYPELIB *typelib, uint full_name)
+int find_type(const char *x, const TYPELIB *typelib, uint flags)
{
int find,pos;
int UNINIT_VAR(findpos); /* guarded by find */
- reg1 char * i;
- reg2 const char *j;
+ const char *i;
+ const char *j;
DBUG_ENTER("find_type");
DBUG_PRINT("enter",("x: '%s' lib: 0x%lx", x, (long) typelib));
+ DBUG_ASSERT(!(flags & ~(FIND_TYPE_NO_PREFIX | FIND_TYPE_ALLOW_NUMBER |
+ FIND_TYPE_NO_OVERWRITE | FIND_TYPE_COMMA_TERM)));
if (!typelib->count)
{
DBUG_PRINT("exit",("no count"));
@@ -86,24 +85,26 @@ int find_type(char *x, const TYPELIB *typelib, uint full_name)
for (pos=0 ; (j=typelib->type_names[pos]) ; pos++)
{
for (i=x ;
- *i && (!(full_name & 8) || !is_field_separator(*i)) &&
+ *i && (!(flags & FIND_TYPE_COMMA_TERM) || !is_field_separator(*i)) &&
my_toupper(&my_charset_latin1,*i) ==
my_toupper(&my_charset_latin1,*j) ; i++, j++) ;
if (! *j)
{
while (*i == ' ')
i++; /* skip_end_space */
- if (! *i || ((full_name & 8) && is_field_separator(*i)))
+ if (! *i || ((flags & FIND_TYPE_COMMA_TERM) && is_field_separator(*i)))
DBUG_RETURN(pos+1);
}
- if ((!*i && (!(full_name & 8) || !is_field_separator(*i))) &&
- (!*j || !(full_name & 1)))
+ if ((!*i &&
+ (!(flags & FIND_TYPE_COMMA_TERM) || !is_field_separator(*i))) &&
+ (!*j || !(flags & FIND_TYPE_NO_PREFIX)))
{
find++;
findpos=pos;
}
}
- if (find == 0 && (full_name & 4) && x[0] == '#' && strend(x)[-1] == '#' &&
+ if (find == 0 && (flags & FIND_TYPE_ALLOW_NUMBER) && x[0] == '#' &&
+ strend(x)[-1] == '#' &&
(findpos=atoi(x+1)-1) >= 0 && (uint) findpos < typelib->count)
find=1;
else if (find == 0 || ! x[0])
@@ -111,13 +112,11 @@ int find_type(char *x, const TYPELIB *typelib, uint full_name)
DBUG_PRINT("exit",("Couldn't find type"));
DBUG_RETURN(0);
}
- else if (find != 1 || (full_name & 1))
+ else if (find != 1 || (flags & FIND_TYPE_NO_PREFIX))
{
DBUG_PRINT("exit",("Too many possybilities"));
DBUG_RETURN(-1);
}
- if (!(full_name & 2))
- (void) strmov(x,typelib->type_names[findpos]);
DBUG_RETURN(findpos+1);
} /* find_type */
@@ -192,7 +191,7 @@ my_ulonglong find_typeset(char *x, TYPELIB *lib, int *err)
x++;
if (x[0] && x[1]) /* skip separator if found */
x++;
- if ((find= find_type(i, lib, 2 | 8) - 1) < 0)
+ if ((find= find_type(i, lib, FIND_TYPE_COMMA_TERM) - 1) < 0)
DBUG_RETURN(0);
result|= (ULL(1) << find);
}
@@ -276,7 +275,7 @@ static TYPELIB on_off_default_typelib= {array_elements(on_off_default_names)-1,
static uint parse_name(const TYPELIB *lib, const char **strpos, const char *end)
{
const char *pos= *strpos;
- uint find= find_type((char*)pos, lib, 8);
+ uint find= find_type(pos, lib, FIND_TYPE_COMMA_TERM);
for (; pos != end && *pos != '=' && *pos !=',' ; pos++);
*strpos= pos;
return find;