13
13
along with this program; if not, write to the Free Software
14
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#include "mysys_priv.h"
17
#include "mysys_err.h"
16
#include "mysys/mysys_priv.h"
17
#include "mysys/mysys_err.h"
18
18
#include <mystrings/m_ctype.h>
19
19
#include <mystrings/m_string.h>
20
#include <drizzled/configmake.h>
24
24
The code below implements this functionality:
26
26
- Initializing charset related structures
27
27
- Loading dynamic charsets
28
- Searching for a proper CHARSET_INFO
28
- Searching for a proper CHARSET_INFO
29
29
using charset name, collation name or collation ID
30
30
- Setting server default character set
44
44
cs < all_charsets+array_elements(all_charsets)-1 ;
47
if ( cs[0] && cs[0]->name &&
47
if ( cs[0] && cs[0]->name &&
48
48
!my_strcasecmp(&my_charset_utf8_general_ci, cs[0]->name, name))
49
49
return cs[0]->number;
58
58
unsigned char *state_map;
59
59
unsigned char *ident_map;
61
if (!(cs->state_map= (unsigned char*) my_once_alloc(256, MYF(MY_WME))))
61
if (!(cs->state_map= (unsigned char*) malloc(256)))
64
if (!(cs->ident_map= (unsigned char*) my_once_alloc(256, MYF(MY_WME))))
64
if (!(cs->ident_map= (unsigned char*) malloc(256)))
67
67
state_map= cs->state_map;
68
68
ident_map= cs->ident_map;
70
70
/* Fill state_map with states to get a faster parser */
71
71
for (i=0; i < 256 ; i++)
119
#define MY_MAX_ALLOWED_BUF 1024*1024
120
#define MY_CHARSET_INDEX "Index.xml"
122
const char *charsets_dir= NULL;
123
static int charset_initialized=0;
126
char *get_charsets_dir(char *buf)
128
const char *sharedir= SHAREDIR;
131
if (charsets_dir != NULL)
132
strmake(buf, charsets_dir, FN_REFLEN-1);
135
if (test_if_hard_path(sharedir) ||
136
is_prefix(sharedir, DEFAULT_CHARSET_HOME))
137
strxmov(buf, sharedir, "/", CHARSET_DIR, NULL);
139
strxmov(buf, DEFAULT_CHARSET_HOME, "/", sharedir, "/", CHARSET_DIR,
142
res= convert_dirname(buf,buf,NULL);
119
static bool charset_initialized= false;
146
121
CHARSET_INFO *all_charsets[256];
147
122
const CHARSET_INFO *default_charset_info = &my_charset_utf8_general_ci;
152
127
cs->state|= MY_CS_AVAILABLE;
155
static void *cs_alloc(size_t size)
130
void *cs_alloc(size_t size)
157
return my_once_alloc(size, MYF(MY_WME));
161
136
static bool init_available_charsets(myf myflags)
163
char fname[FN_REFLEN + sizeof(MY_CHARSET_INDEX)];
166
140
We have to use charset_initialized to not lock on THR_LOCK_charset
167
141
inside get_internal_charset...
169
if (!charset_initialized)
143
if (charset_initialized == false)
171
145
CHARSET_INFO **cs;
173
To make things thread safe we are not allowing other threads to interfere
174
while we may changing the cs_info_table
176
pthread_mutex_lock(&THR_LOCK_charset);
177
if (!charset_initialized)
146
memset(&all_charsets, 0, sizeof(all_charsets));
147
init_compiled_charsets(myflags);
149
/* Copy compiled charsets */
150
for (cs=all_charsets;
151
cs < all_charsets+array_elements(all_charsets)-1 ;
179
memset(&all_charsets, 0, sizeof(all_charsets));
180
init_compiled_charsets(myflags);
182
/* Copy compiled charsets */
183
for (cs=all_charsets;
184
cs < all_charsets+array_elements(all_charsets)-1 ;
190
if (init_state_maps(*cs))
157
if (init_state_maps(*cs))
195
my_stpcpy(get_charsets_dir(fname), MY_CHARSET_INDEX);
196
charset_initialized=1;
198
pthread_mutex_unlock(&THR_LOCK_charset);
162
charset_initialized= true;
164
assert(charset_initialized);
204
170
void free_charsets(void)
206
charset_initialized=0;
172
charset_initialized= true;
251
217
To make things thread safe we are not allowing other threads to interfere
252
218
while we may changing the cs_info_table
254
pthread_mutex_lock(&THR_LOCK_charset);
255
220
if ((cs= all_charsets[cs_number]))
257
222
if (!(cs->state & MY_CS_COMPILED) && !(cs->state & MY_CS_LOADED))
269
234
cs->state|= MY_CS_READY;
271
pthread_mutex_unlock(&THR_LOCK_charset);
276
const const CHARSET_INFO *get_charset(uint32_t cs_number, myf flags)
241
const CHARSET_INFO *get_charset(uint32_t cs_number)
278
243
const CHARSET_INFO *cs;
279
244
if (cs_number == default_charset_info->number)
280
245
return default_charset_info;
282
247
(void) init_available_charsets(MYF(0)); /* If it isn't initialized */
284
249
if (!cs_number || cs_number >= array_elements(all_charsets)-1)
287
252
cs= get_internal_charset(cs_number);
289
if (!cs && (flags & MY_WME))
291
char index_file[FN_REFLEN + sizeof(MY_CHARSET_INDEX)], cs_string[23];
292
my_stpcpy(get_charsets_dir(index_file),MY_CHARSET_INDEX);
294
int10_to_str(cs_number, cs_string+1, 10);
295
my_error(EE_UNKNOWN_CHARSET, MYF(ME_BELL), cs_string, index_file);
300
const CHARSET_INFO *get_charset_by_name(const char *cs_name, myf flags)
257
const CHARSET_INFO *get_charset_by_name(const char *cs_name)
302
259
uint32_t cs_number;
303
260
const CHARSET_INFO *cs;
306
263
cs_number=get_collation_number(cs_name);
307
264
cs= cs_number ? get_internal_charset(cs_number) : NULL;
309
if (!cs && (flags & MY_WME))
311
char index_file[FN_REFLEN + sizeof(MY_CHARSET_INDEX)];
312
my_stpcpy(get_charsets_dir(index_file),MY_CHARSET_INDEX);
313
my_error(EE_UNKNOWN_COLLATION, MYF(ME_BELL), cs_name, index_file);
320
const CHARSET_INFO *get_charset_by_csname(const char *cs_name,
270
const CHARSET_INFO *get_charset_by_csname(const char *cs_name, uint32_t cs_flags)
324
272
uint32_t cs_number;
325
273
const CHARSET_INFO *cs;
329
277
cs_number= get_charset_number(cs_name, cs_flags);
330
278
cs= cs_number ? get_internal_charset(cs_number) : NULL;
332
if (!cs && (flags & MY_WME))
334
char index_file[FN_REFLEN + sizeof(MY_CHARSET_INDEX)];
335
my_stpcpy(get_charsets_dir(index_file),MY_CHARSET_INDEX);
336
my_error(EE_UNKNOWN_CHARSET, MYF(ME_BELL), cs_name, index_file);
360
301
const CHARSET_INFO *default_cs,
361
302
const CHARSET_INFO **cs)
363
*cs= get_charset_by_csname(cs_name, MY_CS_PRIMARY, MYF(0));
304
*cs= get_charset_by_csname(cs_name, MY_CS_PRIMARY);