~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/charset.cc

  • Committer: jay
  • Date: 2008-12-23 00:18:10 UTC
  • Revision ID: jay@piggy.tangent.org-20081223001810-026ibij22q2842k1
Had a --regex-replace by accident. Should have been --replace_column call.  Only showed up in make test, not running single test, because InnoDB key numbers were different with multiple test running.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
#include "mysys_err.h"
18
18
#include <mystrings/m_ctype.h>
19
19
#include <mystrings/m_string.h>
20
 
#include <my_dir.h>
 
20
#include <drizzled/configmake.h>
21
21
 
22
22
 
23
23
/*
24
24
  The code below implements this functionality:
25
 
  
 
25
 
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
31
31
*/
44
44
       cs < all_charsets+array_elements(all_charsets)-1 ;
45
45
       cs++)
46
46
  {
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;
50
 
  }  
 
50
  }
51
51
  return 0;
52
52
}
53
53
 
58
58
  unsigned char *state_map;
59
59
  unsigned char *ident_map;
60
60
 
61
 
  if (!(cs->state_map= (unsigned char*) my_once_alloc(256, MYF(MY_WME))))
 
61
  if (!(cs->state_map= (unsigned char*) malloc(256)))
62
62
    return 1;
63
63
    
64
 
  if (!(cs->ident_map= (unsigned char*) my_once_alloc(256, MYF(MY_WME))))
 
64
  if (!(cs->ident_map= (unsigned char*) malloc(256)))
65
65
    return 1;
66
66
 
67
67
  state_map= cs->state_map;
68
68
  ident_map= cs->ident_map;
69
 
  
 
69
 
70
70
  /* Fill state_map with states to get a faster parser */
71
71
  for (i=0; i < 256 ; i++)
72
72
  {
116
116
}
117
117
 
118
118
 
119
 
#define MY_MAX_ALLOWED_BUF 1024*1024
120
119
#define MY_CHARSET_INDEX "Index.xml"
121
120
 
122
121
const char *charsets_dir= NULL;
125
124
 
126
125
char *get_charsets_dir(char *buf)
127
126
{
128
 
  const char *sharedir= SHAREDIR;
129
127
  char *res;
130
128
 
131
129
  if (charsets_dir != NULL)
132
 
    strmake(buf, charsets_dir, FN_REFLEN-1);
 
130
    strncpy(buf, charsets_dir, FN_REFLEN-1);
133
131
  else
134
132
  {
135
 
    if (test_if_hard_path(sharedir) ||
136
 
        is_prefix(sharedir, DEFAULT_CHARSET_HOME))
137
 
      strxmov(buf, sharedir, "/", CHARSET_DIR, NULL);
 
133
    if (test_if_hard_path(PKGDATADIR) ||
 
134
        is_prefix(PKGDATADIR, PREFIX))
 
135
      sprintf(buf,"%s/%s",PKGDATADIR,CHARSET_DIR);
138
136
    else
139
 
      strxmov(buf, DEFAULT_CHARSET_HOME, "/", sharedir, "/", CHARSET_DIR,
140
 
              NULL);
 
137
      sprintf(buf,"%s/%s/%s",PREFIX,PKGDATADIR,CHARSET_DIR);
141
138
  }
142
139
  res= convert_dirname(buf,buf,NULL);
143
140
  return(res);
152
149
  cs->state|= MY_CS_AVAILABLE;
153
150
}
154
151
 
155
 
static void *cs_alloc(size_t size)
 
152
void *cs_alloc(size_t size)
156
153
{
157
 
  return my_once_alloc(size, MYF(MY_WME));
 
154
  return malloc(size);
158
155
}
159
156
 
160
157
 
178
175
    {
179
176
      memset(&all_charsets, 0, sizeof(all_charsets));
180
177
      init_compiled_charsets(myflags);
181
 
      
 
178
 
182
179
      /* Copy compiled charsets */
183
180
      for (cs=all_charsets;
184
181
           cs < all_charsets+array_elements(all_charsets)-1 ;
191
188
              *cs= NULL;
192
189
        }
193
190
      }
194
 
      
195
 
      my_stpcpy(get_charsets_dir(fname), MY_CHARSET_INDEX);
 
191
 
 
192
      strcpy(get_charsets_dir(fname), MY_CHARSET_INDEX);
196
193
      charset_initialized=1;
197
194
    }
198
195
    pthread_mutex_unlock(&THR_LOCK_charset);
218
215
{
219
216
  CHARSET_INFO **cs;
220
217
  init_available_charsets(MYF(0));
221
 
  
 
218
 
222
219
  for (cs= all_charsets;
223
220
       cs < all_charsets+array_elements(all_charsets)-1 ;
224
221
       cs++)
226
223
    if ( cs[0] && cs[0]->csname && (cs[0]->state & cs_flags) &&
227
224
         !my_strcasecmp(&my_charset_utf8_general_ci, cs[0]->csname, charset_name))
228
225
      return cs[0]->number;
229
 
  }  
 
226
  }
230
227
  return 0;
231
228
}
232
229
 
239
236
  cs=all_charsets[charset_number];
240
237
  if (cs && (cs->number == charset_number) && cs->name )
241
238
    return (char*) cs->name;
242
 
  
 
239
 
243
240
  return (char*) "?";   /* this mimics find_type() */
244
241
}
245
242
 
273
270
}
274
271
 
275
272
 
276
 
const const CHARSET_INFO *get_charset(uint32_t cs_number, myf flags)
 
273
const CHARSET_INFO *get_charset(uint32_t cs_number, myf flags)
277
274
{
278
275
  const CHARSET_INFO *cs;
279
276
  if (cs_number == default_charset_info->number)
280
277
    return default_charset_info;
281
278
 
282
279
  (void) init_available_charsets(MYF(0));       /* If it isn't initialized */
283
 
  
 
280
 
284
281
  if (!cs_number || cs_number >= array_elements(all_charsets)-1)
285
282
    return NULL;
286
 
  
 
283
 
287
284
  cs= get_internal_charset(cs_number);
288
285
 
289
286
  if (!cs && (flags & MY_WME))
290
287
  {
291
288
    char index_file[FN_REFLEN + sizeof(MY_CHARSET_INDEX)], cs_string[23];
292
 
    my_stpcpy(get_charsets_dir(index_file),MY_CHARSET_INDEX);
 
289
    strcpy(get_charsets_dir(index_file),MY_CHARSET_INDEX);
293
290
    cs_string[0]='#';
294
291
    int10_to_str(cs_number, cs_string+1, 10);
295
292
    my_error(EE_UNKNOWN_CHARSET, MYF(ME_BELL), cs_string, index_file);
309
306
  if (!cs && (flags & MY_WME))
310
307
  {
311
308
    char index_file[FN_REFLEN + sizeof(MY_CHARSET_INDEX)];
312
 
    my_stpcpy(get_charsets_dir(index_file),MY_CHARSET_INDEX);
 
309
    strcpy(get_charsets_dir(index_file),MY_CHARSET_INDEX);
313
310
    my_error(EE_UNKNOWN_COLLATION, MYF(ME_BELL), cs_name, index_file);
314
311
  }
315
312
 
332
329
  if (!cs && (flags & MY_WME))
333
330
  {
334
331
    char index_file[FN_REFLEN + sizeof(MY_CHARSET_INDEX)];
335
 
    my_stpcpy(get_charsets_dir(index_file),MY_CHARSET_INDEX);
 
332
    strcpy(get_charsets_dir(index_file),MY_CHARSET_INDEX);
336
333
    my_error(EE_UNKNOWN_CHARSET, MYF(ME_BELL), cs_name, index_file);
337
334
  }
338
335