~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/charset.cc

  • Committer: Monty Taylor
  • Date: 2009-02-09 20:45:49 UTC
  • mfrom: (864 drizzle)
  • mto: This revision was merged to the branch mainline in revision 865.
  • Revision ID: mordred@inaugust.com-20090209204549-hcaonir5zwelh0t9
MergedĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
116
116
}
117
117
 
118
118
 
119
 
#define MY_CHARSET_INDEX "Index.xml"
120
 
 
121
 
const char *charsets_dir= NULL;
122
 
static int charset_initialized=0;
123
 
 
124
 
 
125
 
char *get_charsets_dir(char *buf)
126
 
{
127
 
  char *res;
128
 
 
129
 
  if (charsets_dir != NULL)
130
 
    strncpy(buf, charsets_dir, FN_REFLEN-1);
131
 
  else
132
 
  {
133
 
    if (test_if_hard_path(PKGDATADIR) ||
134
 
        is_prefix(PKGDATADIR, PREFIX))
135
 
      sprintf(buf,"%s/%s",PKGDATADIR,CHARSET_DIR);
136
 
    else
137
 
      sprintf(buf,"%s/%s/%s",PREFIX,PKGDATADIR,CHARSET_DIR);
138
 
  }
139
 
  res= convert_dirname(buf,buf,NULL);
140
 
  return(res);
141
 
}
 
119
static bool charset_initialized= false;
142
120
 
143
121
CHARSET_INFO *all_charsets[256];
144
122
const CHARSET_INFO *default_charset_info = &my_charset_utf8_general_ci;
157
135
 
158
136
static bool init_available_charsets(myf myflags)
159
137
{
160
 
  char fname[FN_REFLEN + sizeof(MY_CHARSET_INDEX)];
161
 
  bool error=false;
 
138
  bool error= false;
162
139
  /*
163
140
    We have to use charset_initialized to not lock on THR_LOCK_charset
164
141
    inside get_internal_charset...
165
142
  */
166
 
  if (!charset_initialized)
 
143
  if (charset_initialized == false)
167
144
  {
168
145
    CHARSET_INFO **cs;
169
 
    /*
170
 
      To make things thread safe we are not allowing other threads to interfere
171
 
      while we may changing the cs_info_table
172
 
    */
173
 
    pthread_mutex_lock(&THR_LOCK_charset);
174
 
    if (!charset_initialized)
 
146
    memset(&all_charsets, 0, sizeof(all_charsets));
 
147
    init_compiled_charsets(myflags);
 
148
 
 
149
    /* Copy compiled charsets */
 
150
    for (cs=all_charsets;
 
151
         cs < all_charsets+array_elements(all_charsets)-1 ;
 
152
         cs++)
175
153
    {
176
 
      memset(&all_charsets, 0, sizeof(all_charsets));
177
 
      init_compiled_charsets(myflags);
178
 
 
179
 
      /* Copy compiled charsets */
180
 
      for (cs=all_charsets;
181
 
           cs < all_charsets+array_elements(all_charsets)-1 ;
182
 
           cs++)
 
154
      if (*cs)
183
155
      {
184
 
        if (*cs)
185
 
        {
186
 
          if (cs[0]->ctype)
187
 
            if (init_state_maps(*cs))
188
 
              *cs= NULL;
189
 
        }
 
156
        if (cs[0]->ctype)
 
157
          if (init_state_maps(*cs))
 
158
            *cs= NULL;
190
159
      }
191
 
 
192
 
      strcpy(get_charsets_dir(fname), MY_CHARSET_INDEX);
193
 
      charset_initialized=1;
194
160
    }
195
 
    pthread_mutex_unlock(&THR_LOCK_charset);
 
161
 
 
162
    charset_initialized= true;
196
163
  }
 
164
  assert(charset_initialized);
 
165
 
197
166
  return error;
198
167
}
199
168
 
200
169
 
201
170
void free_charsets(void)
202
171
{
203
 
  charset_initialized=0;
 
172
  charset_initialized= true;
204
173
}
205
174
 
206
175
 
248
217
    To make things thread safe we are not allowing other threads to interfere
249
218
    while we may changing the cs_info_table
250
219
  */
251
 
  pthread_mutex_lock(&THR_LOCK_charset);
252
220
  if ((cs= all_charsets[cs_number]))
253
221
  {
254
222
    if (!(cs->state & MY_CS_COMPILED) && !(cs->state & MY_CS_LOADED))
265
233
    else
266
234
      cs->state|= MY_CS_READY;
267
235
  }
268
 
  pthread_mutex_unlock(&THR_LOCK_charset);
 
236
 
269
237
  return cs;
270
238
}
271
239
 
272
240
 
273
 
const CHARSET_INFO *get_charset(uint32_t cs_number, myf flags)
 
241
const CHARSET_INFO *get_charset(uint32_t cs_number)
274
242
{
275
243
  const CHARSET_INFO *cs;
276
244
  if (cs_number == default_charset_info->number)
283
251
 
284
252
  cs= get_internal_charset(cs_number);
285
253
 
286
 
  if (!cs && (flags & MY_WME))
287
 
  {
288
 
    char index_file[FN_REFLEN + sizeof(MY_CHARSET_INDEX)], cs_string[23];
289
 
    strcpy(get_charsets_dir(index_file),MY_CHARSET_INDEX);
290
 
    cs_string[0]='#';
291
 
    int10_to_str(cs_number, cs_string+1, 10);
292
 
    my_error(EE_UNKNOWN_CHARSET, MYF(ME_BELL), cs_string, index_file);
293
 
  }
294
254
  return cs;
295
255
}
296
256
 
297
 
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)
298
258
{
299
259
  uint32_t cs_number;
300
260
  const CHARSET_INFO *cs;
303
263
  cs_number=get_collation_number(cs_name);
304
264
  cs= cs_number ? get_internal_charset(cs_number) : NULL;
305
265
 
306
 
  if (!cs && (flags & MY_WME))
307
 
  {
308
 
    char index_file[FN_REFLEN + sizeof(MY_CHARSET_INDEX)];
309
 
    strcpy(get_charsets_dir(index_file),MY_CHARSET_INDEX);
310
 
    my_error(EE_UNKNOWN_COLLATION, MYF(ME_BELL), cs_name, index_file);
311
 
  }
312
 
 
313
266
  return cs;
314
267
}
315
268
 
316
269
 
317
 
const CHARSET_INFO *get_charset_by_csname(const char *cs_name,
318
 
                                    uint32_t cs_flags,
319
 
                                    myf flags)
 
270
const CHARSET_INFO *get_charset_by_csname(const char *cs_name, uint32_t cs_flags)
320
271
{
321
272
  uint32_t cs_number;
322
273
  const CHARSET_INFO *cs;
326
277
  cs_number= get_charset_number(cs_name, cs_flags);
327
278
  cs= cs_number ? get_internal_charset(cs_number) : NULL;
328
279
 
329
 
  if (!cs && (flags & MY_WME))
330
 
  {
331
 
    char index_file[FN_REFLEN + sizeof(MY_CHARSET_INDEX)];
332
 
    strcpy(get_charsets_dir(index_file),MY_CHARSET_INDEX);
333
 
    my_error(EE_UNKNOWN_CHARSET, MYF(ME_BELL), cs_name, index_file);
334
 
  }
335
 
 
336
280
  return(cs);
337
281
}
338
282
 
357
301
                     const CHARSET_INFO *default_cs,
358
302
                     const CHARSET_INFO **cs)
359
303
{
360
 
  *cs= get_charset_by_csname(cs_name, MY_CS_PRIMARY, MYF(0));
 
304
  *cs= get_charset_by_csname(cs_name, MY_CS_PRIMARY);
361
305
 
362
306
  if (*cs == NULL)
363
307
  {
389
333
                       const CHARSET_INFO *default_cl,
390
334
                       const CHARSET_INFO **cl)
391
335
{
392
 
  *cl= get_charset_by_name(cl_name, MYF(0));
 
336
  *cl= get_charset_by_name(cl_name);
393
337
 
394
338
  if (*cl == NULL)
395
339
  {