charset.c 15.1 KB
Newer Older
unknown's avatar
unknown committed
1 2 3 4 5 6 7 8
/* Copyright (C) 2000 MySQL AB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
unknown's avatar
unknown committed
9
   but WITHOUT ANY WARRANTY; without even the implied warranty of
unknown's avatar
unknown committed
10 11 12 13 14 15
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
unknown's avatar
unknown committed
16 17 18 19 20 21 22

#include "mysys_priv.h"
#include "mysys_err.h"
#include <m_ctype.h>
#include <m_string.h>
#include <my_dir.h>

23

unknown's avatar
unknown committed
24 25 26 27 28 29 30 31 32
const char *charsets_dir = NULL;
static int charset_initialized=0;

#define MAX_LINE  1024

#define CTYPE_TABLE_SIZE      257
#define TO_LOWER_TABLE_SIZE   256
#define TO_UPPER_TABLE_SIZE   256
#define SORT_ORDER_TABLE_SIZE 256
33
#define TO_UNI_TABLE_SIZE     256
unknown's avatar
unknown committed
34 35 36 37 38 39 40

struct simpleconfig_buf_st {
  FILE *f;
  char  buf[MAX_LINE];
  char *p;
};

41

unknown's avatar
unknown committed
42 43 44 45 46 47
static my_bool get_word(struct simpleconfig_buf_st *fb, char *buf)
{
  char *endptr=fb->p;

  for (;;)
  {
48
    while (my_isspace(system_charset_info, *endptr))
unknown's avatar
unknown committed
49 50 51 52 53 54 55 56
      ++endptr;
    if (*endptr && *endptr != '#')		/* Not comment */
      break;					/* Found something */
    if ((fgets(fb->buf, sizeof(fb->buf), fb->f)) == NULL)
      return TRUE; /* end of file */
    endptr = fb->buf;
  }

57
  while (!my_isspace(system_charset_info, *endptr))
unknown's avatar
unknown committed
58 59 60 61 62 63 64 65
    *buf++= *endptr++;
  *buf=0;
  fb->p = endptr;

  return FALSE;
}


66
char *get_charsets_dir(char *buf)
unknown's avatar
unknown committed
67 68 69 70 71
{
  const char *sharedir = SHAREDIR;
  DBUG_ENTER("get_charsets_dir");

  if (charsets_dir != NULL)
72
    strmake(buf, charsets_dir, FN_REFLEN-1);
unknown's avatar
unknown committed
73 74 75 76 77 78 79 80 81
  else
  {
    if (test_if_hard_path(sharedir) ||
	is_prefix(sharedir, DEFAULT_CHARSET_HOME))
      strxmov(buf, sharedir, "/", CHARSET_DIR, NullS);
    else
      strxmov(buf, DEFAULT_CHARSET_HOME, "/", sharedir, "/", CHARSET_DIR,
	      NullS);
  }
82
  convert_dirname(buf,buf,NullS);
unknown's avatar
unknown committed
83 84 85 86 87
  DBUG_PRINT("info",("charsets dir='%s'", buf));
  DBUG_RETURN(strend(buf));
}


88
static my_bool read_charset_index(myf myflags)
unknown's avatar
unknown committed
89 90
{
  struct simpleconfig_buf_st fb;
91
  char buf[MAX_LINE], num_buf[MAX_LINE];
92
    
unknown's avatar
unknown committed
93 94 95 96 97 98 99
  strmov(get_charsets_dir(buf), "Index");

  if ((fb.f = my_fopen(buf, O_RDONLY, myflags)) == NULL)
    return TRUE;
  fb.buf[0] = '\0';
  fb.p = fb.buf;

100
  
101
  while (!get_word(&fb, buf) && !get_word(&fb, num_buf))
unknown's avatar
unknown committed
102
  {
103
    uint csnum;
unknown's avatar
unknown committed
104
    uint length;
105
    CHARSET_INFO *cs;
106 107

    if (!(csnum = atoi(num_buf)))
unknown's avatar
unknown committed
108
    {
109
      /* corrupt Index file */
unknown's avatar
unknown committed
110 111 112
      my_fclose(fb.f,myflags);
      return TRUE;
    }
113
    
114 115 116 117 118 119 120 121 122 123 124
    if (all_charsets[csnum])
      continue;
    
    if (!(cs=(CHARSET_INFO*) my_once_alloc(sizeof(cs[0]),myflags)))
    {
      my_fclose(fb.f,myflags);
      return TRUE;
    }
    bzero(cs,sizeof(cs[0]));
    
    if (!(cs->name= (char*)my_once_alloc(length=(uint)strlen(buf)+1,myflags)))
125 126 127 128
    {
      my_fclose(fb.f,myflags);
      return TRUE;
    }
129 130
    memcpy((char*)cs->name,buf,length);
    cs->number=csnum;
131
    all_charsets[csnum]=cs;
unknown's avatar
unknown committed
132 133 134 135 136 137
  }
  my_fclose(fb.f,myflags);

  return FALSE;
}

138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
static void set_max_sort_char(CHARSET_INFO *cs)
{
  uchar max_char;
  uint  i;
  
  if (!cs->sort_order)
    return;
  
  max_char=cs->sort_order[(uchar) cs->max_sort_char];
  for (i = 0; i < 256; i++)
  {
    if ((uchar) cs->sort_order[i] > max_char)
    {
      max_char=(uchar) cs->sort_order[i];
      cs->max_sort_char= (char) i;
    }
  }
}
unknown's avatar
unknown committed
156 157 158

static my_bool init_available_charsets(myf myflags)
{
159
  my_bool error=FALSE;
unknown's avatar
unknown committed
160 161 162 163 164 165
  /*
    We have to use charset_initialized to not lock on THR_LOCK_charset
    inside get_internal_charset...
   */
  if (!charset_initialized)
  {
166
    CHARSET_INFO **cs;
unknown's avatar
unknown committed
167 168 169 170 171
  /*
    To make things thread safe we are not allowing other threads to interfere
    while we may changing the cs_info_table
  */
    pthread_mutex_lock(&THR_LOCK_charset);
172 173

    bzero(&all_charsets,sizeof(all_charsets));
174
    init_compiled_charsets(myflags);
175 176
    
    /* Copy compiled charsets */
177
    for (cs=all_charsets; cs < all_charsets+255 ; cs++)
178
    {
179 180
      if (*cs)
        set_max_sort_char(*cs);
181
    }
182
    error = read_charset_index(myflags);
unknown's avatar
unknown committed
183 184 185
    charset_initialized=1;
    pthread_mutex_unlock(&THR_LOCK_charset);
  }
186
  return error;
unknown's avatar
unknown committed
187 188 189 190 191
}


void free_charsets(void)
{
unknown's avatar
unknown committed
192
  charset_initialized=0;
unknown's avatar
unknown committed
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
}


static my_bool fill_array(uchar *array, int sz, struct simpleconfig_buf_st *fb)
{
  char buf[MAX_LINE];
  while (sz--)
  {
    if (get_word(fb, buf))
    {
      DBUG_PRINT("error",("get_word failed, expecting %d more words", sz + 1));
      return 1;
    }
    *array++ = (uchar) strtol(buf, NULL, 16);
  }
  return 0;
}

211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
static my_bool fill_uint16_array(uint16 *array, int sz, struct simpleconfig_buf_st *fb)
{
  char buf[MAX_LINE];
  while (sz--)
  {
    if (get_word(fb, buf))
    {
      DBUG_PRINT("error",("get_word failed, expecting %d more words", sz + 1));
      return 1;
    }
    *array++ = (uint16) strtol(buf, NULL, 16);
  }
  return 0;
}

unknown's avatar
unknown committed
226

227
static void get_charset_conf_name(const char *cs_name, char *buf)
unknown's avatar
unknown committed
228
{
229
  strxmov(get_charsets_dir(buf), cs_name, ".conf", NullS);
unknown's avatar
unknown committed
230 231
}

232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
typedef struct {
	int		nchars;
	MY_UNI_IDX	uidx;
} uni_idx;

#define PLANE_SIZE	0x100
#define PLANE_NUM	0x100
#define PLANE_NUMBER(x)	(((x)>>8) % PLANE_NUM)

static int pcmp(const void * f, const void * s)
{
  const uni_idx *F=(const uni_idx*)f;
  const uni_idx *S=(const uni_idx*)s;
  int res;

  if(!(res=((S->nchars)-(F->nchars))))
    res=((F->uidx.from)-(S->uidx.to));
  return res;
}

static my_bool create_fromuni(CHARSET_INFO *cs){
  uni_idx	idx[PLANE_NUM];
  int		i,n;
  
  /* Clear plane statistics */
  bzero(idx,sizeof(idx));
  
  /* Count number of characters in each plane */
  for(i=0;i<0x100;i++)
  {
    uint16 wc=cs->tab_to_uni[i];
    int pl= PLANE_NUMBER(wc);
    
    if(wc || !i)
    {
      if(!idx[pl].nchars)
      {
        idx[pl].uidx.from=wc;
        idx[pl].uidx.to=wc;
      }else
      {
        idx[pl].uidx.from=wc<idx[pl].uidx.from?wc:idx[pl].uidx.from;
        idx[pl].uidx.to=wc>idx[pl].uidx.to?wc:idx[pl].uidx.to;
      }
      idx[pl].nchars++;
    }
  }
  
  /* Sort planes in descending order */
  qsort(&idx,PLANE_NUM,sizeof(uni_idx),&pcmp);
  
  for(i=0;i<PLANE_NUM;i++)
  {
    int ch,numchars;
    
    /* Skip empty plane */
    if(!idx[i].nchars)
      break;
    
    numchars=idx[i].uidx.to-idx[i].uidx.from+1;
    idx[i].uidx.tab=(unsigned char*)my_once_alloc(numchars*sizeof(*idx[i].uidx.tab),MYF(MY_WME));
    bzero(idx[i].uidx.tab,numchars*sizeof(*idx[i].uidx.tab));
    
    for(ch=1;ch<PLANE_SIZE;ch++)
    {
      uint16 wc=cs->tab_to_uni[ch];
      if(wc>=idx[i].uidx.from && wc<=idx[i].uidx.to && wc)
      {
        int ofs=wc-idx[i].uidx.from;
        idx[i].uidx.tab[ofs]=ch;
      }
    }
  }
  
  /* Allocate and fill reverse table for each plane */
  n=i;
  cs->tab_from_uni=(MY_UNI_IDX*)my_once_alloc(sizeof(MY_UNI_IDX)*(n+1),MYF(MY_WME));
  for(i=0;i<n;i++)
    cs->tab_from_uni[i]=idx[i].uidx;
  
  /* Set end-of-list marker */
  bzero(&cs->tab_from_uni[i],sizeof(MY_UNI_IDX));
  return FALSE;
}

unknown's avatar
unknown committed
317

318
static my_bool read_charset_file(const char *cs_name, CHARSET_INFO *set,
unknown's avatar
unknown committed
319 320 321 322 323 324
				 myf myflags)
{
  struct simpleconfig_buf_st fb;
  char buf[FN_REFLEN];
  my_bool result;
  DBUG_ENTER("read_charset_file");
325
  DBUG_PRINT("enter",("cs_name: %s", cs_name));
unknown's avatar
unknown committed
326

327
  get_charset_conf_name(cs_name, buf);
unknown's avatar
unknown committed
328 329 330 331 332 333 334 335 336 337 338 339
  DBUG_PRINT("info",("file name: %s", buf));

  if ((fb.f = my_fopen(buf, O_RDONLY, myflags)) == NULL)
    DBUG_RETURN(TRUE);

  fb.buf[0] = '\0';				/* Init for get_word */
  fb.p = fb.buf;

  result=FALSE;
  if (fill_array(set->ctype,      CTYPE_TABLE_SIZE,      &fb) ||
      fill_array(set->to_lower,   TO_LOWER_TABLE_SIZE,   &fb) ||
      fill_array(set->to_upper,   TO_UPPER_TABLE_SIZE,   &fb) ||
340 341
      fill_array(set->sort_order, SORT_ORDER_TABLE_SIZE, &fb) ||
      fill_uint16_array(set->tab_to_uni,TO_UNI_TABLE_SIZE,&fb))
unknown's avatar
unknown committed
342 343 344 345 346 347 348
    result=TRUE;

  my_fclose(fb.f, MYF(0));
  DBUG_RETURN(result);
}


349
static CHARSET_INFO *add_charset(CHARSET_INFO *cs, myf flags)
unknown's avatar
unknown committed
350
{
351 352 353 354 355
  uchar  tmp_ctype[CTYPE_TABLE_SIZE];
  uchar  tmp_to_lower[TO_LOWER_TABLE_SIZE];
  uchar  tmp_to_upper[TO_UPPER_TABLE_SIZE];
  uchar  tmp_sort_order[SORT_ORDER_TABLE_SIZE];
  uint16 tmp_to_uni[TO_UNI_TABLE_SIZE];
unknown's avatar
unknown committed
356

357
  /* Note: cs->name and cs->number are already initialized */
unknown's avatar
unknown committed
358
  
unknown's avatar
unknown committed
359 360 361 362
  cs->ctype=tmp_ctype;
  cs->to_lower=tmp_to_lower;
  cs->to_upper=tmp_to_upper;
  cs->sort_order=tmp_sort_order;
363
  cs->tab_to_uni=tmp_to_uni;
unknown's avatar
unknown committed
364
  if (read_charset_file(cs->name, cs, flags))
unknown's avatar
unknown committed
365 366 367 368 369 370
    return NULL;

  cs->ctype    = (uchar*) my_once_alloc(CTYPE_TABLE_SIZE,      MYF(MY_WME));
  cs->to_lower = (uchar*) my_once_alloc(TO_LOWER_TABLE_SIZE,   MYF(MY_WME));
  cs->to_upper = (uchar*) my_once_alloc(TO_UPPER_TABLE_SIZE,   MYF(MY_WME));
  cs->sort_order=(uchar*) my_once_alloc(SORT_ORDER_TABLE_SIZE, MYF(MY_WME));
371
  cs->tab_to_uni=(uint16*)my_once_alloc(TO_UNI_TABLE_SIZE*sizeof(uint16), MYF(MY_WME));
unknown's avatar
unknown committed
372 373 374 375 376
  memcpy((char*) cs->ctype,	 (char*) tmp_ctype,	sizeof(tmp_ctype));
  memcpy((char*) cs->to_lower, (char*) tmp_to_lower,	sizeof(tmp_to_lower));
  memcpy((char*) cs->to_upper, (char*) tmp_to_upper,	sizeof(tmp_to_upper));
  memcpy((char*) cs->sort_order, (char*) tmp_sort_order,
	 sizeof(tmp_sort_order));
377
  memcpy((char*) cs->tab_to_uni, (char*) tmp_to_uni, sizeof(tmp_to_uni));
378

379
  cs->like_range  = my_like_range_simple;
unknown's avatar
unknown committed
380
  cs->wildcmp     = my_wildcmp_8bit;
unknown's avatar
unknown committed
381
  cs->strnncoll   = my_strnncoll_simple;
382 383 384 385
  cs->caseup_str  = my_caseup_str_8bit;
  cs->casedn_str  = my_casedn_str_8bit;
  cs->caseup      = my_caseup_8bit;
  cs->casedn      = my_casedn_8bit;
386
  cs->tosort      = my_tosort_8bit;
387 388
  cs->strcasecmp  = my_strcasecmp_8bit;
  cs->strncasecmp = my_strncasecmp_8bit;
389 390
  cs->mb_wc       = my_mb_wc_8bit;
  cs->wc_mb       = my_wc_mb_8bit;
391 392
  cs->hash_caseup = my_hash_caseup_simple;
  cs->hash_sort   = my_hash_sort_simple;
393
  cs->snprintf	  = my_snprintf_8bit;
394 395 396 397
  cs->strtol      = my_strtol_8bit;
  cs->strtoul     = my_strtoul_8bit;
  cs->strtoll     = my_strtoll_8bit;
  cs->strtoull     = my_strtoull_8bit;
398
  cs->mbmaxlen    = 1;
399
  
400
  set_max_sort_char(cs);
401
  create_fromuni(cs);
402
  
unknown's avatar
unknown committed
403 404 405
  return cs;
}

406 407 408

uint get_charset_number(const char *charset_name)
{
409
  CHARSET_INFO **cs;
410 411 412 413
  if (init_available_charsets(MYF(0)))	/* If it isn't initialized */
    return 0;
  
  for (cs = all_charsets; cs < all_charsets+255; ++cs)
414 415
    if ( cs[0] && cs[0]->name && !strcmp(cs[0]->name, charset_name))
      return cs[0]->number;
416 417 418 419 420 421 422 423 424 425 426
  
  return 0;   /* this mimics find_type() */
}


const char *get_charset_name(uint charset_number)
{
  CHARSET_INFO *cs;
  if (init_available_charsets(MYF(0)))	/* If it isn't initialized */
    return "?";

427 428
  cs=all_charsets[charset_number];
  if ( cs && (cs->number==charset_number) && cs->name )
unknown's avatar
unknown committed
429 430
    return (char*) cs->name;
  
431 432 433 434
  return (char*) "?";   /* this mimics find_type() */
}


435
static CHARSET_INFO *get_internal_charset(uint cs_number, myf flags)
unknown's avatar
unknown committed
436 437 438 439 440 441 442
{
  CHARSET_INFO *cs;
  /*
    To make things thread safe we are not allowing other threads to interfere
    while we may changing the cs_info_table
  */
  pthread_mutex_lock(&THR_LOCK_charset);
443

444 445 446
  cs = all_charsets[cs_number];
  if (cs && !(cs->state & (MY_CS_COMPILED | MY_CS_LOADED)))
    cs=add_charset(cs, flags);
447

unknown's avatar
unknown committed
448 449 450 451 452
  pthread_mutex_unlock(&THR_LOCK_charset);
  return cs;
}


453
static CHARSET_INFO *get_internal_charset_by_name(const char *name, myf flags)
unknown's avatar
unknown committed
454
{
unknown's avatar
unknown committed
455 456
  uint cs_number=get_charset_number(name);
  return cs_number ? get_internal_charset(cs_number,flags) : NULL;
unknown's avatar
unknown committed
457 458 459
}


unknown's avatar
unknown committed
460

unknown's avatar
unknown committed
461 462 463 464
CHARSET_INFO *get_charset(uint cs_number, myf flags)
{
  CHARSET_INFO *cs;
  (void) init_available_charsets(MYF(0));	/* If it isn't initialized */
unknown's avatar
unknown committed
465 466 467 468
  
  if (!cs_number)
    return NULL;
  
469
  cs=get_internal_charset(cs_number, flags);
unknown's avatar
unknown committed
470

unknown's avatar
unknown committed
471
  if (!cs && (flags & MY_WME))
unknown's avatar
unknown committed
472 473 474 475 476 477 478 479 480 481 482 483
  {
    char index_file[FN_REFLEN], cs_string[23];
    strmov(get_charsets_dir(index_file), "Index");
    cs_string[0]='#';
    int10_to_str(cs_number, cs_string+1, 10);
    my_error(EE_UNKNOWN_CHARSET, MYF(ME_BELL), cs_string, index_file);
  }
  return cs;
}

my_bool set_default_charset(uint cs, myf flags)
{
unknown's avatar
unknown committed
484
  CHARSET_INFO *new_charset;
unknown's avatar
unknown committed
485 486
  DBUG_ENTER("set_default_charset");
  DBUG_PRINT("enter",("character set: %d",(int) cs));
unknown's avatar
unknown committed
487 488
  new_charset = get_charset(cs, flags);
  if (!new_charset)
unknown's avatar
unknown committed
489 490 491 492
  {
    DBUG_PRINT("error",("Couldn't set default character set"));
    DBUG_RETURN(TRUE);   /* error */
  }
unknown's avatar
unknown committed
493
  default_charset_info = new_charset;
494
  system_charset_info = new_charset;
unknown's avatar
unknown committed
495 496 497 498 499 500 501
  DBUG_RETURN(FALSE);
}

CHARSET_INFO *get_charset_by_name(const char *cs_name, myf flags)
{
  CHARSET_INFO *cs;
  (void) init_available_charsets(MYF(0));	/* If it isn't initialized */
502
  cs=get_internal_charset_by_name(cs_name, flags);
unknown's avatar
unknown committed
503 504 505 506 507 508 509 510 511 512 513 514 515

  if (!cs && (flags & MY_WME))
  {
    char index_file[FN_REFLEN];
    strmov(get_charsets_dir(index_file), "Index");
    my_error(EE_UNKNOWN_CHARSET, MYF(ME_BELL), cs_name, index_file);
  }

  return cs;
}

my_bool set_default_charset_by_name(const char *cs_name, myf flags)
{
unknown's avatar
unknown committed
516
  CHARSET_INFO *new_charset;
unknown's avatar
unknown committed
517 518
  DBUG_ENTER("set_default_charset_by_name");
  DBUG_PRINT("enter",("character set: %s", cs_name));
unknown's avatar
unknown committed
519 520
  new_charset = get_charset_by_name(cs_name, flags);
  if (!new_charset)
unknown's avatar
unknown committed
521 522 523 524 525
  {
    DBUG_PRINT("error",("Couldn't set default character set"));
    DBUG_RETURN(TRUE);   /* error */
  }

unknown's avatar
unknown committed
526
  default_charset_info = new_charset;
527
  system_charset_info = new_charset;
unknown's avatar
unknown committed
528 529 530 531 532 533 534
  DBUG_RETURN(FALSE);
}

/* Only append name if it doesn't exist from before */

static my_bool charset_in_string(const char *name, DYNAMIC_STRING *s)
{
535
  uint length= (uint) strlen(name);
unknown's avatar
unknown committed
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562
  const char *pos;
  for (pos=s->str ; (pos=strstr(pos,name)) ; pos++)
  {
    if (! pos[length] || pos[length] == ' ')
      return TRUE;				/* Already existed */
  }

  return FALSE;
}

static void charset_append(DYNAMIC_STRING *s, const char *name)
{
  if (!charset_in_string(name, s)) {
    dynstr_append(s, name);
    dynstr_append(s, " ");
  }
}


/* Returns a dynamically-allocated string listing the character sets
   requested.  The caller is responsible for freeing the memory. */

char * list_charsets(myf want_flags)
{
  DYNAMIC_STRING s;
  char *p;

563
  (void)init_available_charsets(MYF(0));
unknown's avatar
unknown committed
564 565
  init_dynamic_string(&s, NullS, 256, 1024);

566
  if (want_flags & MY_CS_COMPILED)
unknown's avatar
unknown committed
567
  {
568 569
    CHARSET_INFO **cs;
    for (cs = all_charsets; cs < all_charsets+255; cs++)
unknown's avatar
unknown committed
570
    {
571 572 573 574 575
      if (cs[0])
      {
        dynstr_append(&s, cs[0]->name);
        dynstr_append(&s, " ");
      }
unknown's avatar
unknown committed
576 577 578
    }
  }

579
  if (want_flags & MY_CS_CONFIG)
unknown's avatar
unknown committed
580
  {
581
    CHARSET_INFO **cs;
unknown's avatar
unknown committed
582
    char buf[FN_REFLEN];
583
    MY_STAT status;
unknown's avatar
unknown committed
584

585 586
    for (cs=all_charsets; cs < all_charsets+255; cs++)
    {
587
      if (!cs[0] || !cs[0]->name || charset_in_string(cs[0]->name, &s))
588
	continue;
589
      get_charset_conf_name(cs[0]->name, buf);
590 591
      if (!my_stat(buf, &status, MYF(0)))
	continue;       /* conf file doesn't exist */
592
      dynstr_append(&s, cs[0]->name);
593 594
      dynstr_append(&s, " ");
    }
unknown's avatar
unknown committed
595 596
  }

unknown's avatar
unknown committed
597
  if (want_flags & (MY_CS_INDEX|MY_CS_LOADED))
unknown's avatar
unknown committed
598
  {
599
    CHARSET_INFO **cs;
600
    for (cs = all_charsets; cs < all_charsets + 255; cs++)
601 602
      if (cs[0] && cs[0]->name && (cs[0]->state & want_flags) )
        charset_append(&s, cs[0]->name);
unknown's avatar
unknown committed
603
  }
unknown's avatar
unknown committed
604 605
  
  if (s.length)
unknown's avatar
unknown committed
606
  {
unknown's avatar
unknown committed
607 608 609 610 611 612
    s.str[s.length - 1] = '\0';   /* chop trailing space */
    p = my_strdup(s.str, MYF(MY_WME));
  }
  else
  {
    p = my_strdup("", MYF(MY_WME));
unknown's avatar
unknown committed
613 614
  }
  dynstr_free(&s);
unknown's avatar
unknown committed
615
  
unknown's avatar
unknown committed
616 617
  return p;
}