The world's most popular open source database
#include "mysys_priv.h"#include "mysys_err.h"#include <m_ctype.h>#include <m_string.h>#include <my_dir.h>#include <my_xml.h>Include dependency graph for charset.c:

Go to the source code of this file.
| #define MY_CHARSET_INDEX "Index.xml" |
Definition at line 305 of file charset.c.
Referenced by get_charset(), get_charset_by_csname(), get_charset_by_name(), and init_available_charsets().
| #define MY_MAX_ALLOWED_BUF 1024*1024 |
| static int add_collation | ( | CHARSET_INFO * | cs | ) | [static] |
Definition at line 206 of file charset.c.
References all_charsets, charset_info_st::binary_number, bzero, charset_info_st::coll, charset_info_st::comment, cs_copy_data(), charset_info_st::cset, charset_info_st::csname, get_collation_number_internal(), charset_info_st::max_sort_char, charset_info_st::min_sort_char, my_charset_ucs2_general_uca, MY_CS_AVAILABLE, MY_CS_BINSORT, MY_CS_COMPILED, MY_CS_CSSORT, MY_CS_LOADED, MY_CS_PRIMARY, my_once_alloc(), my_once_strdup(), MY_WME, MY_XML_ERROR, MY_XML_OK, MYF, charset_info_st::name, NULL, charset_info_st::number, charset_info_st::primary_number, simple_cs_init_functions(), simple_cs_is_full(), charset_info_st::sort_order, sort_order, charset_info_st::state, strcmp(), and charset_info_st::strxfrm_multiply.
Referenced by my_read_charset_file().
00207 { 00208 if (cs->name && (cs->number || 00209 (cs->number=get_collation_number_internal(cs->name)))) 00210 { 00211 if (!all_charsets[cs->number]) 00212 { 00213 if (!(all_charsets[cs->number]= 00214 (CHARSET_INFO*) my_once_alloc(sizeof(CHARSET_INFO),MYF(0)))) 00215 return MY_XML_ERROR; 00216 bzero((void*)all_charsets[cs->number],sizeof(CHARSET_INFO)); 00217 } 00218 00219 if (cs->primary_number == cs->number) 00220 cs->state |= MY_CS_PRIMARY; 00221 00222 if (cs->binary_number == cs->number) 00223 cs->state |= MY_CS_BINSORT; 00224 00225 all_charsets[cs->number]->state|= cs->state; 00226 00227 if (!(all_charsets[cs->number]->state & MY_CS_COMPILED)) 00228 { 00229 CHARSET_INFO *new= all_charsets[cs->number]; 00230 if (cs_copy_data(all_charsets[cs->number],cs)) 00231 return MY_XML_ERROR; 00232 00233 if (!strcmp(cs->csname,"ucs2") ) 00234 { 00235 #if defined(HAVE_CHARSET_ucs2) && defined(HAVE_UCA_COLLATIONS) 00236 new->cset= my_charset_ucs2_general_uca.cset; 00237 new->coll= my_charset_ucs2_general_uca.coll; 00238 new->strxfrm_multiply= my_charset_ucs2_general_uca.strxfrm_multiply; 00239 new->min_sort_char= my_charset_ucs2_general_uca.min_sort_char; 00240 new->max_sort_char= my_charset_ucs2_general_uca.max_sort_char; 00241 new->mbminlen= 2; 00242 new->mbmaxlen= 2; 00243 new->state |= MY_CS_AVAILABLE | MY_CS_LOADED; 00244 #endif 00245 } 00246 else 00247 { 00248 uchar *sort_order= all_charsets[cs->number]->sort_order; 00249 simple_cs_init_functions(all_charsets[cs->number]); 00250 new->mbminlen= 1; 00251 new->mbmaxlen= 1; 00252 if (simple_cs_is_full(all_charsets[cs->number])) 00253 { 00254 all_charsets[cs->number]->state |= MY_CS_LOADED; 00255 } 00256 all_charsets[cs->number]->state|= MY_CS_AVAILABLE; 00257 00258 /* 00259 Check if case sensitive sort order: A < a < B. 00260 We need MY_CS_FLAG for regex library, and for 00261 case sensitivity flag for 5.0 client protocol, 00262 to support isCaseSensitive() method in JDBC driver 00263 */ 00264 if (sort_order && sort_order['A'] < sort_order['a'] && 00265 sort_order['a'] < sort_order['B']) 00266 all_charsets[cs->number]->state|= MY_CS_CSSORT; 00267 } 00268 } 00269 else 00270 { 00271 /* 00272 We need the below to make get_charset_name() 00273 and get_charset_number() working even if a 00274 character set has not been really incompiled. 00275 The above functions are used for example 00276 in error message compiler extra/comp_err.c. 00277 If a character set was compiled, this information 00278 will get lost and overwritten in add_compiled_collation(). 00279 */ 00280 CHARSET_INFO *dst= all_charsets[cs->number]; 00281 dst->number= cs->number; 00282 if (cs->comment) 00283 if (!(dst->comment= my_once_strdup(cs->comment,MYF(MY_WME)))) 00284 return MY_XML_ERROR; 00285 if (cs->csname) 00286 if (!(dst->csname= my_once_strdup(cs->csname,MYF(MY_WME)))) 00287 return MY_XML_ERROR; 00288 if (cs->name) 00289 if (!(dst->name= my_once_strdup(cs->name,MYF(MY_WME)))) 00290 return MY_XML_ERROR; 00291 } 00292 cs->number= 0; 00293 cs->primary_number= 0; 00294 cs->binary_number= 0; 00295 cs->name= NULL; 00296 cs->state= 0; 00297 cs->sort_order= NULL; 00298 cs->state= 0; 00299 } 00300 return MY_XML_OK; 00301 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void add_compiled_collation | ( | CHARSET_INFO * | cs | ) |
Definition at line 371 of file charset.c.
References all_charsets, MY_CS_AVAILABLE, charset_info_st::number, and charset_info_st::state.
00372 { 00373 all_charsets[cs->number]= cs; 00374 cs->state|= MY_CS_AVAILABLE; 00375 }
| static void* cs_alloc | ( | uint | size | ) | [static] |
Definition at line 377 of file charset.c.
References my_once_alloc(), MY_WME, and MYF.
Referenced by get_internal_charset().
00378 { 00379 return my_once_alloc(size, MYF(MY_WME)); 00380 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static int cs_copy_data | ( | CHARSET_INFO * | to, | |
| CHARSET_INFO * | from | |||
| ) | [static] |
Definition at line 134 of file charset.c.
References err, from, init_state_maps(), MY_CS_CTYPE_TABLE_SIZE, MY_CS_SORT_ORDER_TABLE_SIZE, MY_CS_TO_LOWER_TABLE_SIZE, MY_CS_TO_UNI_TABLE_SIZE, MY_CS_TO_UPPER_TABLE_SIZE, my_once_memdup(), my_once_strdup(), MY_WME, MYF, and to.
Referenced by add_collation().
00135 { 00136 to->number= from->number ? from->number : to->number; 00137 00138 if (from->csname) 00139 if (!(to->csname= my_once_strdup(from->csname,MYF(MY_WME)))) 00140 goto err; 00141 00142 if (from->name) 00143 if (!(to->name= my_once_strdup(from->name,MYF(MY_WME)))) 00144 goto err; 00145 00146 if (from->comment) 00147 if (!(to->comment= my_once_strdup(from->comment,MYF(MY_WME)))) 00148 goto err; 00149 00150 if (from->ctype) 00151 { 00152 if (!(to->ctype= (uchar*) my_once_memdup((char*) from->ctype, 00153 MY_CS_CTYPE_TABLE_SIZE, 00154 MYF(MY_WME)))) 00155 goto err; 00156 if (init_state_maps(to)) 00157 goto err; 00158 } 00159 if (from->to_lower) 00160 if (!(to->to_lower= (uchar*) my_once_memdup((char*) from->to_lower, 00161 MY_CS_TO_LOWER_TABLE_SIZE, 00162 MYF(MY_WME)))) 00163 goto err; 00164 00165 if (from->to_upper) 00166 if (!(to->to_upper= (uchar*) my_once_memdup((char*) from->to_upper, 00167 MY_CS_TO_UPPER_TABLE_SIZE, 00168 MYF(MY_WME)))) 00169 goto err; 00170 if (from->sort_order) 00171 { 00172 if (!(to->sort_order= (uchar*) my_once_memdup((char*) from->sort_order, 00173 MY_CS_SORT_ORDER_TABLE_SIZE, 00174 MYF(MY_WME)))) 00175 goto err; 00176 00177 } 00178 if (from->tab_to_uni) 00179 { 00180 uint sz= MY_CS_TO_UNI_TABLE_SIZE*sizeof(uint16); 00181 if (!(to->tab_to_uni= (uint16*) my_once_memdup((char*)from->tab_to_uni, 00182 sz, MYF(MY_WME)))) 00183 goto err; 00184 } 00185 if (from->tailoring) 00186 if (!(to->tailoring= my_once_strdup(from->tailoring,MYF(MY_WME)))) 00187 goto err; 00188 00189 return 0; 00190 00191 err: 00192 return 1; 00193 }
Here is the call graph for this function:

Here is the caller graph for this function:

| ulong escape_quotes_for_mysql | ( | CHARSET_INFO * | charset_info, | |
| char * | to, | |||
| ulong | to_length, | |||
| const char * | from, | |||
| ulong | length | |||
| ) |
Definition at line 739 of file charset.c.
References charset_info, FALSE, my_ismbchar, TRUE, USE_MB, and use_mb.
00742 { 00743 const char *to_start= to; 00744 const char *end, *to_end=to_start + (to_length ? to_length-1 : 2*length); 00745 my_bool overflow= FALSE; 00746 #ifdef USE_MB 00747 my_bool use_mb_flag= use_mb(charset_info); 00748 #endif 00749 for (end= from + length; from < end; from++) 00750 { 00751 #ifdef USE_MB 00752 int tmp_length; 00753 if (use_mb_flag && (tmp_length= my_ismbchar(charset_info, from, end))) 00754 { 00755 if (to + tmp_length > to_end) 00756 { 00757 overflow= TRUE; 00758 break; 00759 } 00760 while (tmp_length--) 00761 *to++= *from++; 00762 from--; 00763 continue; 00764 } 00765 /* 00766 We don't have the same issue here with a non-multi-byte character being 00767 turned into a multi-byte character by the addition of an escaping 00768 character, because we are only escaping the ' character with itself. 00769 */ 00770 #endif 00771 if (*from == '\'') 00772 { 00773 if (to + 2 > to_end) 00774 { 00775 overflow= TRUE; 00776 break; 00777 } 00778 *to++= '\''; 00779 *to++= '\''; 00780 } 00781 else 00782 { 00783 if (to + 1 > to_end) 00784 { 00785 overflow= TRUE; 00786 break; 00787 } 00788 *to++= *from; 00789 } 00790 } 00791 *to= 0; 00792 return overflow ? (ulong)~0 : (ulong) (to - to_start); 00793 }
| ulong escape_string_for_mysql | ( | CHARSET_INFO * | charset_info, | |
| char * | to, | |||
| ulong | to_length, | |||
| const char * | from, | |||
| ulong | length | |||
| ) |
Definition at line 599 of file charset.c.
References charset_info, FALSE, my_ismbchar, my_mbcharlen, TRUE, and use_mb.
00602 { 00603 const char *to_start= to; 00604 const char *end, *to_end=to_start + (to_length ? to_length-1 : 2*length); 00605 my_bool overflow= FALSE; 00606 #ifdef USE_MB 00607 my_bool use_mb_flag= use_mb(charset_info); 00608 #endif 00609 for (end= from + length; from < end; from++) 00610 { 00611 char escape= 0; 00612 #ifdef USE_MB 00613 int tmp_length; 00614 if (use_mb_flag && (tmp_length= my_ismbchar(charset_info, from, end))) 00615 { 00616 if (to + tmp_length > to_end) 00617 { 00618 overflow= TRUE; 00619 break; 00620 } 00621 while (tmp_length--) 00622 *to++= *from++; 00623 from--; 00624 continue; 00625 } 00626 /* 00627 If the next character appears to begin a multi-byte character, we 00628 escape that first byte of that apparent multi-byte character. (The 00629 character just looks like a multi-byte character -- if it were actually 00630 a multi-byte character, it would have been passed through in the test 00631 above.) 00632 00633 Without this check, we can create a problem by converting an invalid 00634 multi-byte character into a valid one. For example, 0xbf27 is not 00635 a valid GBK character, but 0xbf5c is. (0x27 = ', 0x5c = \) 00636 */ 00637 if (use_mb_flag && (tmp_length= my_mbcharlen(charset_info, *from)) > 1) 00638 escape= *from; 00639 else 00640 #endif 00641 switch (*from) { 00642 case 0: /* Must be escaped for 'mysql' */ 00643 escape= '0'; 00644 break; 00645 case '\n': /* Must be escaped for logs */ 00646 escape= 'n'; 00647 break; 00648 case '\r': 00649 escape= 'r'; 00650 break; 00651 case '\\': 00652 escape= '\\'; 00653 break; 00654 case '\'': 00655 escape= '\''; 00656 break; 00657 case '"': /* Better safe than sorry */ 00658 escape= '"'; 00659 break; 00660 case '\032': /* This gives problems on Win32 */ 00661 escape= 'Z'; 00662 break; 00663 } 00664 if (escape) 00665 { 00666 if (to + 2 > to_end) 00667 { 00668 overflow= TRUE; 00669 break; 00670 } 00671 *to++= '\\'; 00672 *to++= escape; 00673 } 00674 else 00675 { 00676 if (to + 1 > to_end) 00677 { 00678 overflow= TRUE; 00679 break; 00680 } 00681 *to++= *from; 00682 } 00683 } 00684 *to= 0; 00685 return overflow ? (ulong)~0 : (ulong) (to - to_start); 00686 }
| void free_charsets | ( | void | ) |
Definition at line 431 of file charset.c.
References charset_initialized.
00432 { 00433 charset_initialized=0; 00434 }
| CHARSET_INFO* get_charset | ( | uint | cs_number, | |
| myf | flags | |||
| ) |
Definition at line 505 of file charset.c.
References all_charsets, array_elements, default_charset_info, EE_UNKNOWN_CHARSET, FN_REFLEN, get_charsets_dir(), get_internal_charset(), init_available_charsets(), int10_to_str(), ME_BELL, MY_CHARSET_INDEX, my_error(), MY_WME, MYF, NULL, charset_info_st::number, and strmov().
00506 { 00507 CHARSET_INFO *cs; 00508 if (cs_number == default_charset_info->number) 00509 return default_charset_info; 00510 00511 (void) init_available_charsets(MYF(0)); /* If it isn't initialized */ 00512 00513 if (!cs_number || cs_number >= array_elements(all_charsets)-1) 00514 return NULL; 00515 00516 cs=get_internal_charset(cs_number, flags); 00517 00518 if (!cs && (flags & MY_WME)) 00519 { 00520 char index_file[FN_REFLEN], cs_string[23]; 00521 strmov(get_charsets_dir(index_file),MY_CHARSET_INDEX); 00522 cs_string[0]='#'; 00523 int10_to_str(cs_number, cs_string+1, 10); 00524 my_error(EE_UNKNOWN_CHARSET, MYF(ME_BELL), cs_string, index_file); 00525 } 00526 return cs; 00527 }
Here is the call graph for this function:

| CHARSET_INFO* get_charset_by_csname | ( | const char * | cs_name, | |
| uint | cs_flags, | |||
| myf | flags | |||
| ) |
Definition at line 549 of file charset.c.
References DBUG_ENTER, DBUG_PRINT, DBUG_RETURN, EE_UNKNOWN_CHARSET, FN_REFLEN, get_charset_number(), get_charsets_dir(), get_internal_charset(), init_available_charsets(), ME_BELL, MY_CHARSET_INDEX, my_error(), MY_WME, MYF, NULL, and strmov().
00552 { 00553 uint cs_number; 00554 CHARSET_INFO *cs; 00555 DBUG_ENTER("get_charset_by_csname"); 00556 DBUG_PRINT("enter",("name: '%s'", cs_name)); 00557 00558 (void) init_available_charsets(MYF(0)); /* If it isn't initialized */ 00559 00560 cs_number= get_charset_number(cs_name, cs_flags); 00561 cs= cs_number ? get_internal_charset(cs_number, flags) : NULL; 00562 00563 if (!cs && (flags & MY_WME)) 00564 { 00565 char index_file[FN_REFLEN]; 00566 strmov(get_charsets_dir(index_file),MY_CHARSET_INDEX); 00567 my_error(EE_UNKNOWN_CHARSET, MYF(ME_BELL), cs_name, index_file); 00568 } 00569 00570 DBUG_RETURN(cs); 00571 }
Here is the call graph for this function:

| CHARSET_INFO* get_charset_by_name | ( | const char * | cs_name, | |
| myf | flags | |||
| ) |
Definition at line 529 of file charset.c.
References EE_UNKNOWN_COLLATION, FN_REFLEN, get_charsets_dir(), get_collation_number(), get_internal_charset(), init_available_charsets(), ME_BELL, MY_CHARSET_INDEX, my_error(), MY_WME, MYF, NULL, and strmov().
00530 { 00531 uint cs_number; 00532 CHARSET_INFO *cs; 00533 (void) init_available_charsets(MYF(0)); /* If it isn't initialized */ 00534 00535 cs_number=get_collation_number(cs_name); 00536 cs= cs_number ? get_internal_charset(cs_number,flags) : NULL; 00537 00538 if (!cs && (flags & MY_WME)) 00539 { 00540 char index_file[FN_REFLEN]; 00541 strmov(get_charsets_dir(index_file),MY_CHARSET_INDEX); 00542 my_error(EE_UNKNOWN_COLLATION, MYF(ME_BELL), cs_name, index_file); 00543 } 00544 00545 return cs; 00546 }
Here is the call graph for this function:

| const char* get_charset_name | ( | uint | charset_number | ) |
Definition at line 461 of file charset.c.
References all_charsets, init_available_charsets(), MYF, charset_info_st::name, and charset_info_st::number.
00462 { 00463 CHARSET_INFO *cs; 00464 init_available_charsets(MYF(0)); 00465 00466 cs=all_charsets[charset_number]; 00467 if (cs && (cs->number == charset_number) && cs->name ) 00468 return (char*) cs->name; 00469 00470 return (char*) "?"; /* this mimics find_type() */ 00471 }
Here is the call graph for this function:

Definition at line 444 of file charset.c.
References all_charsets, array_elements, init_available_charsets(), my_charset_latin1, my_strcasecmp, MYF, and charset_info_st::number.
00445 { 00446 CHARSET_INFO **cs; 00447 init_available_charsets(MYF(0)); 00448 00449 for (cs= all_charsets; 00450 cs < all_charsets+array_elements(all_charsets)-1 ; 00451 cs++) 00452 { 00453 if ( cs[0] && cs[0]->csname && (cs[0]->state & cs_flags) && 00454 !my_strcasecmp(&my_charset_latin1, cs[0]->csname, charset_name)) 00455 return cs[0]->number; 00456 } 00457 return 0; 00458 }
Here is the call graph for this function:

| char* get_charsets_dir | ( | char * | buf | ) |
Definition at line 346 of file charset.c.
References CHARSET_DIR, charsets_dir, convert_dirname(), DBUG_ENTER, DBUG_PRINT, DBUG_RETURN, DEFAULT_CHARSET_HOME, FN_REFLEN, is_prefix(), NULL, NullS, SHAREDIR, strmake(), strxmov(), and test_if_hard_path().
00347 { 00348 const char *sharedir= SHAREDIR; 00349 char *res; 00350 DBUG_ENTER("get_charsets_dir"); 00351 00352 if (charsets_dir != NULL) 00353 strmake(buf, charsets_dir, FN_REFLEN-1); 00354 else 00355 { 00356 if (test_if_hard_path(sharedir) || 00357 is_prefix(sharedir, DEFAULT_CHARSET_HOME)) 00358 strxmov(buf, sharedir, "/", CHARSET_DIR, NullS); 00359 else 00360 strxmov(buf, DEFAULT_CHARSET_HOME, "/", sharedir, "/", CHARSET_DIR, 00361 NullS); 00362 } 00363 res= convert_dirname(buf,buf,NullS); 00364 DBUG_PRINT("info",("charsets dir: '%s'", buf)); 00365 DBUG_RETURN(res); 00366 }
Here is the call graph for this function:


