1
by brian
clean slate |
1 |
/* Copyright (C) 2000 MySQL AB
|
2 |
||
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.
|
|
6 |
||
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.
|
|
11 |
||
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
|
|
1802.10.2
by Monty Taylor
Update all of the copyright headers to include the correct address. |
14 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
1
by brian
clean slate |
15 |
|
16 |
/* Functions to handle typelib */
|
|
17 |
||
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
18 |
#include <config.h> |
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
19 |
|
20 |
#include <stdio.h> |
|
21 |
||
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
22 |
#include <drizzled/internal/m_string.h> |
2281.5.1
by Muhammad Umair
Merged charset declarations of global_charset_info.h and charset_info.h into charset.h header file. |
23 |
#include <drizzled/charset.h> |
2252.1.3
by Olaf van der Spek
Common fwd |
24 |
#include <drizzled/memory/root.h> |
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
25 |
#include <drizzled/typelib.h> |
1
by brian
clean slate |
26 |
|
2252.1.3
by Olaf van der Spek
Common fwd |
27 |
namespace drizzled { |
1
by brian
clean slate |
28 |
|
29 |
static const char field_separator=','; |
|
30 |
||
2252.1.3
by Olaf van der Spek
Common fwd |
31 |
int TYPELIB::find_type_or_exit(const char *x, const char *option) const |
1
by brian
clean slate |
32 |
{
|
2275.2.20
by Olaf van der Spek
Typelib Options |
33 |
int res= find_type(x, e_dont_complete); |
2151.5.2
by Olaf van der Spek
Make class of TYPELIB |
34 |
if (res > 0) |
35 |
return res; |
|
36 |
if (!*x) |
|
37 |
fprintf(stderr, "No option given to %s\n", option); |
|
38 |
else
|
|
39 |
fprintf(stderr, "Unknown option to %s: %s\n", option, x); |
|
40 |
const char **ptr= type_names; |
|
41 |
fprintf(stderr, "Alternatives are: '%s'", *ptr); |
|
42 |
while (*++ptr) |
|
43 |
fprintf(stderr, ",'%s'", *ptr); |
|
44 |
fprintf(stderr, "\n"); |
|
45 |
exit(1); |
|
1
by brian
clean slate |
46 |
}
|
47 |
||
48 |
||
49 |
/*
|
|
50 |
Search after a string in a list of strings. Endspace in x is not compared.
|
|
51 |
||
52 |
SYNOPSIS
|
|
53 |
find_type()
|
|
54 |
x String to find
|
|
55 |
lib TYPELIB (struct of pointer to values + count)
|
|
56 |
full_name bitmap of what to do
|
|
2275.2.21
by Olaf van der Spek
Typelib Options |
57 |
If & 1 accept only whole names - e_match_full
|
58 |
If & 2 don't expand if half field - e_dont_complete
|
|
59 |
If & 4 allow #number# as type - e_allow_int
|
|
60 |
If & 8 use ',' as string terminator - e_use_comma
|
|
1
by brian
clean slate |
61 |
|
62 |
NOTES
|
|
63 |
If part, uniq field is found and full_name == 0 then x is expanded
|
|
64 |
to full field.
|
|
65 |
||
66 |
RETURN
|
|
67 |
-1 Too many matching values
|
|
68 |
0 No matching value
|
|
69 |
>0 Offset+1 in typelib for matched string
|
|
70 |
*/
|
|
71 |
||
72 |
||
2275.2.20
by Olaf van der Spek
Typelib Options |
73 |
int TYPELIB::find_type(const char *x, e_find_options full_name) const |
2151.5.3
by Olaf van der Spek
Make class of TYPELIB |
74 |
{
|
2281.4.16
by Olaf van der Spek
Return void |
75 |
assert(full_name & e_dont_complete); |
2151.5.2
by Olaf van der Spek
Make class of TYPELIB |
76 |
if (!count) |
77 |
return 0; |
|
78 |
int find= 0; |
|
79 |
int findpos= 0; |
|
80 |
const char *j; |
|
81 |
for (int pos= 0; (j= type_names[pos]); pos++) |
|
82 |
{
|
|
2318.2.1
by Olaf van der Spek
Refactor |
83 |
const char *i= x; |
84 |
for (; *i && *i != field_separator && |
|
2445.1.4
by Olaf van der Spek
Refactor |
85 |
my_charset_utf8_general_ci.toupper(*i) == my_charset_utf8_general_ci.toupper(*j); i++, j++) |
2318.2.1
by Olaf van der Spek
Refactor |
86 |
{
|
87 |
}
|
|
88 |
if (not *j) |
|
1
by brian
clean slate |
89 |
{
|
90 |
while (*i == ' ') |
|
2318.2.1
by Olaf van der Spek
Refactor |
91 |
i++; /* skip_end_space */ |
2297.1.3
by Olaf van der Spek
Refactor |
92 |
if (not *i) |
2318.2.1
by Olaf van der Spek
Refactor |
93 |
return pos + 1; |
1
by brian
clean slate |
94 |
}
|
2318.2.1
by Olaf van der Spek
Refactor |
95 |
if (not *i && *i != field_separator && (not *j || not (full_name & e_match_full))) |
1
by brian
clean slate |
96 |
{
|
97 |
find++; |
|
2318.2.1
by Olaf van der Spek
Refactor |
98 |
findpos= pos; |
1
by brian
clean slate |
99 |
}
|
100 |
}
|
|
2297.1.2
by Olaf van der Spek
Remove unused typelib options |
101 |
if (find == 0 || not x[0]) |
2297.1.3
by Olaf van der Spek
Refactor |
102 |
return 0; |
103 |
if (find != 1 || (full_name & e_match_full)) |
|
104 |
return -1; |
|
2151.5.2
by Olaf van der Spek
Make class of TYPELIB |
105 |
return findpos + 1; |
1
by brian
clean slate |
106 |
} /* find_type */ |
107 |
||
108 |
/*
|
|
109 |
Create a copy of a specified TYPELIB structure.
|
|
110 |
||
111 |
SYNOPSIS
|
|
112 |
copy_typelib()
|
|
1253.1.3
by Monty Taylor
MEM_ROOT == memory::Root |
113 |
root pointer to a memory::Root object for allocations
|
1
by brian
clean slate |
114 |
from pointer to a source TYPELIB structure
|
115 |
||
116 |
RETURN
|
|
117 |
pointer to the new TYPELIB structure on successful copy, or
|
|
118 |
NULL otherwise
|
|
119 |
*/
|
|
120 |
||
2275.2.20
by Olaf van der Spek
Typelib Options |
121 |
TYPELIB *TYPELIB::copy_typelib(memory::Root& root) const |
1
by brian
clean slate |
122 |
{
|
2318.6.58
by Olaf van der Spek
Refactor |
123 |
TYPELIB* to= new (root) TYPELIB; |
2318.6.40
by Olaf van der Spek
Refactor |
124 |
to->type_names= (const char**)root.alloc((sizeof(char *) + sizeof(int)) * (count + 1)); |
2275.2.1
by Olaf van der Spek
Refactor Typelib |
125 |
to->type_lengths= (unsigned int*)(to->type_names + count + 1); |
2151.5.3
by Olaf van der Spek
Make class of TYPELIB |
126 |
to->count= count; |
2318.6.24
by Olaf van der Spek
Refactor |
127 |
to->name= name ? root.strdup(name) : NULL; |
2275.2.1
by Olaf van der Spek
Refactor Typelib |
128 |
for (uint32_t i= 0; i < count; i++) |
129 |
{
|
|
2318.9.10
by Olaf van der Spek
Rename strmake to strdup (standard name) |
130 |
to->type_names[i]= root.strdup(type_names[i], type_lengths[i]); |
2151.5.3
by Olaf van der Spek
Make class of TYPELIB |
131 |
to->type_lengths[i]= type_lengths[i]; |
1
by brian
clean slate |
132 |
}
|
133 |
to->type_names[to->count]= NULL; |
|
134 |
to->type_lengths[to->count]= 0; |
|
135 |
return to; |
|
136 |
}
|
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
137 |
|
138 |
} /* namespace drizzled */ |