00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <config.h>
00019
00020 #include <stdio.h>
00021
00022 #include <drizzled/internal/m_string.h>
00023 #include <drizzled/charset.h>
00024 #include <drizzled/memory/root.h>
00025 #include <drizzled/typelib.h>
00026
00027 namespace drizzled {
00028
00029 static const char field_separator=',';
00030
00031 int TYPELIB::find_type_or_exit(const char *x, const char *option) const
00032 {
00033 int res= find_type(x, e_dont_complete);
00034 if (res > 0)
00035 return res;
00036 if (!*x)
00037 fprintf(stderr, "No option given to %s\n", option);
00038 else
00039 fprintf(stderr, "Unknown option to %s: %s\n", option, x);
00040 const char **ptr= type_names;
00041 fprintf(stderr, "Alternatives are: '%s'", *ptr);
00042 while (*++ptr)
00043 fprintf(stderr, ",'%s'", *ptr);
00044 fprintf(stderr, "\n");
00045 exit(1);
00046 }
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 int TYPELIB::find_type(const char *x, e_find_options full_name) const
00074 {
00075 assert(full_name & e_dont_complete);
00076 if (!count)
00077 return 0;
00078 int find= 0;
00079 int findpos= 0;
00080 const char *j;
00081 for (int pos= 0; (j= type_names[pos]); pos++)
00082 {
00083 const char *i= x;
00084 for (; *i && *i != field_separator &&
00085 my_charset_utf8_general_ci.toupper(*i) == my_charset_utf8_general_ci.toupper(*j); i++, j++)
00086 {
00087 }
00088 if (not *j)
00089 {
00090 while (*i == ' ')
00091 i++;
00092 if (not *i)
00093 return pos + 1;
00094 }
00095 if (not *i && *i != field_separator && (not *j || not (full_name & e_match_full)))
00096 {
00097 find++;
00098 findpos= pos;
00099 }
00100 }
00101 if (find == 0 || not x[0])
00102 return 0;
00103 if (find != 1 || (full_name & e_match_full))
00104 return -1;
00105 return findpos + 1;
00106 }
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 TYPELIB *TYPELIB::copy_typelib(memory::Root& root) const
00122 {
00123 TYPELIB* to= new (root) TYPELIB;
00124 to->type_names= (const char**)root.alloc((sizeof(char *) + sizeof(int)) * (count + 1));
00125 to->type_lengths= (unsigned int*)(to->type_names + count + 1);
00126 to->count= count;
00127 to->name= name ? root.strdup(name) : NULL;
00128 for (uint32_t i= 0; i < count; i++)
00129 {
00130 to->type_names[i]= root.strdup(type_names[i], type_lengths[i]);
00131 to->type_lengths[i]= type_lengths[i];
00132 }
00133 to->type_names[to->count]= NULL;
00134 to->type_lengths[to->count]= 0;
00135 return to;
00136 }
00137
00138 }