From 9cb8b57c2572718c285c251004532c132970a56d Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 5 Jan 2003 17:34:24 +0400 Subject: [PATCH] koi8_ru -> koi8_r charset.conf -> charset.xml bug fix mysql-test/r/ctype_many.result: koi8_ru -> koi8_r mysql-test/t/ctype_many.test: koi8_ru -> koi8_r mysys/charset.c: charset.conf -> charset.xml sql/share/Makefile.am: charset.conf -> charset.xml strings/ctype-simple.c: Bug fix --- mysql-test/r/ctype_many.result | 14 +- mysql-test/t/ctype_many.test | 4 +- mysys/charset.c | 384 ++++++++++++++++++--------------- sql/share/Makefile.am | 3 +- strings/ctype-simple.c | 2 +- 5 files changed, 216 insertions(+), 191 deletions(-) diff --git a/mysql-test/r/ctype_many.result b/mysql-test/r/ctype_many.result index a483145e33a..ec6e0b76772 100644 --- a/mysql-test/r/ctype_many.result +++ b/mysql-test/r/ctype_many.result @@ -1,27 +1,27 @@ DROP TABLE IF EXISTS t1; CREATE TABLE t1 ( comment CHAR(32) ASCII NOT NULL, -koi8_ru_f CHAR(32) CHARACTER SET koi8_ru NOT NULL +koi8_ru_f CHAR(32) CHARACTER SET koi8_r NOT NULL ) CHARSET=latin5; SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( `comment` char(32) character set latin1 NOT NULL default '', - `koi8_ru_f` char(32) character set koi8_ru NOT NULL default '' + `koi8_ru_f` char(32) character set koi8_r NOT NULL default '' ) TYPE=MyISAM CHARSET=latin5 ALTER TABLE t1 CHANGE comment comment CHAR(32) CHARACTER SET latin2 NOT NULL; SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( `comment` char(32) character set latin2 NOT NULL default '', - `koi8_ru_f` char(32) character set koi8_ru NOT NULL default '' + `koi8_ru_f` char(32) character set koi8_r NOT NULL default '' ) TYPE=MyISAM CHARSET=latin5 ALTER TABLE t1 ADD latin5_f CHAR(32) NOT NULL; SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( `comment` char(32) character set latin2 NOT NULL default '', - `koi8_ru_f` char(32) character set koi8_ru NOT NULL default '', + `koi8_ru_f` char(32) character set koi8_r NOT NULL default '', `latin5_f` char(32) character set latin5 NOT NULL default '' ) TYPE=MyISAM CHARSET=latin5 ALTER TABLE t1 CHARSET=latin2; @@ -30,7 +30,7 @@ SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( `comment` char(32) character set latin2 NOT NULL default '', - `koi8_ru_f` char(32) character set koi8_ru NOT NULL default '', + `koi8_ru_f` char(32) character set koi8_r NOT NULL default '', `latin5_f` char(32) character set latin5 NOT NULL default '', `latin2_f` char(32) character set latin2 NOT NULL default '' ) TYPE=MyISAM CHARSET=latin2 @@ -39,7 +39,7 @@ SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( `comment` char(32) character set latin2 NOT NULL default '', - `koi8_ru_f` char(32) character set koi8_ru NOT NULL default '' + `koi8_ru_f` char(32) character set koi8_r NOT NULL default '' ) TYPE=MyISAM CHARSET=latin2 INSERT INTO t1 (koi8_ru_f,comment) VALUES ('a','LAT SMALL A'); INSERT INTO t1 (koi8_ru_f,comment) VALUES ('b','LAT SMALL B'); @@ -1061,7 +1061,7 @@ CYR SMALL YA CYR CAPIT YA CYR SMALL YA CYR SMALL YA SELECT t11.comment,t12.comment FROM t1 t11,t1 t12 -WHERE t11.koi8_ru_f=CONVERT(t12.utf8_f USING koi8_ru) +WHERE t11.koi8_ru_f=CONVERT(t12.utf8_f USING koi8_r) ORDER BY t12.utf8_f,t11.comment,t12.comment; comment comment LAT CAPIT A LAT CAPIT A diff --git a/mysql-test/t/ctype_many.test b/mysql-test/t/ctype_many.test index b02684b2fb8..b5ca63507e8 100644 --- a/mysql-test/t/ctype_many.test +++ b/mysql-test/t/ctype_many.test @@ -2,7 +2,7 @@ DROP TABLE IF EXISTS t1; CREATE TABLE t1 ( comment CHAR(32) ASCII NOT NULL, - koi8_ru_f CHAR(32) CHARACTER SET koi8_ru NOT NULL + koi8_ru_f CHAR(32) CHARACTER SET koi8_r NOT NULL ) CHARSET=latin5; SHOW CREATE TABLE t1; @@ -156,7 +156,7 @@ ORDER BY t11.koi8_ru_f,t11.comment,t12.comment; SELECT t11.comment,t12.comment FROM t1 t11,t1 t12 -WHERE t11.koi8_ru_f=CONVERT(t12.utf8_f USING koi8_ru) +WHERE t11.koi8_ru_f=CONVERT(t12.utf8_f USING koi8_r) ORDER BY t12.utf8_f,t11.comment,t12.comment; ALTER TABLE t1 ADD ucs2_f CHAR(32) CHARACTER SET ucs2; diff --git a/mysys/charset.c b/mysys/charset.c index f590ee2a49e..c94f2e91817 100644 --- a/mysys/charset.c +++ b/mysys/charset.c @@ -21,6 +21,11 @@ #include #include + +static void set_max_sort_char(CHARSET_INFO *cs); +static my_bool create_fromuni(CHARSET_INFO *cs); + + #define MY_CHARSET_INDEX "Index.xml" const char *charsets_dir = NULL; @@ -34,37 +39,6 @@ static int charset_initialized=0; #define SORT_ORDER_TABLE_SIZE 256 #define TO_UNI_TABLE_SIZE 256 -struct simpleconfig_buf_st { - FILE *f; - char buf[MAX_LINE]; - char *p; -}; - - -static my_bool get_word(struct simpleconfig_buf_st *fb, char *buf) -{ - char *endptr=fb->p; - - for (;;) - { - while (my_isspace(system_charset_info, *endptr)) - ++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; - } - - while (!my_isspace(system_charset_info, *endptr)) - *buf++= *endptr++; - *buf=0; - fb->p = endptr; - - return FALSE; -} - - char *get_charsets_dir(char *buf) { const char *sharedir = SHAREDIR; @@ -89,13 +63,14 @@ char *get_charsets_dir(char *buf) #define MAX_BUF 1024*16 - +#ifndef DBUG_OFF static void mstr(char *str,const char *src,uint l1,uint l2) { l1 = l1like_range = my_like_range_simple; + cs->wildcmp = my_wildcmp_8bit; + cs->strnncoll = my_strnncoll_simple; + cs->caseup_str = my_caseup_str_8bit; + cs->casedn_str = my_casedn_str_8bit; + cs->caseup = my_caseup_8bit; + cs->casedn = my_casedn_8bit; + cs->tosort = my_tosort_8bit; + cs->strcasecmp = my_strcasecmp_8bit; + cs->strncasecmp = my_strncasecmp_8bit; + cs->mb_wc = my_mb_wc_8bit; + cs->wc_mb = my_wc_mb_8bit; + cs->hash_caseup = my_hash_caseup_simple; + cs->hash_sort = my_hash_sort_simple; + cs->snprintf = my_snprintf_8bit; + cs->strntol = my_strntol_8bit; + cs->strntoul = my_strntoul_8bit; + cs->strntoll = my_strntoll_8bit; + cs->strntoull = my_strntoull_8bit; + cs->strntod = my_strntod_8bit; + cs->mbmaxlen = 1; +} + +static void simple_cs_copy_data(CHARSET_INFO *to, CHARSET_INFO *from) +{ + to->number = from->number ? from->number : to->number; + to->state |= from->state; + + if (from->csname) + to->csname=my_strdup(from->csname,MYF(MY_WME)); + + if (from->name) + to->name=my_strdup(from->name,MYF(MY_WME)); + + if (from->ctype) + { + to->ctype = (uchar*) my_once_alloc(CTYPE_TABLE_SIZE,MYF(MY_WME)); + memcpy((char*)to->ctype,(char*)from->ctype,CTYPE_TABLE_SIZE); + } + if (from->to_lower) + { + to->to_lower = (uchar*) my_once_alloc(TO_LOWER_TABLE_SIZE,MYF(MY_WME)); + memcpy((char*)to->to_lower,(char*)from->to_lower,TO_LOWER_TABLE_SIZE); + } + if (from->to_upper) + { + to->to_upper = (uchar*) my_once_alloc(TO_UPPER_TABLE_SIZE,MYF(MY_WME)); + memcpy((char*)to->to_upper,(char*)from->to_upper,TO_UPPER_TABLE_SIZE); + } + if (from->sort_order) + { + to->sort_order=(uchar*) my_once_alloc(SORT_ORDER_TABLE_SIZE,MYF(MY_WME)); + memcpy((char*)to->sort_order,(char*)from->sort_order, SORT_ORDER_TABLE_SIZE); + set_max_sort_char(to); + } + if (from->tab_to_uni) + { + uint sz=TO_UNI_TABLE_SIZE*sizeof(uint16); + to->tab_to_uni=(uint16*)my_once_alloc(sz,MYF(MY_WME)); + memcpy((char*)to->tab_to_uni,(char*)from->tab_to_uni,sz); + create_fromuni(to); + } +} + +static my_bool simple_cs_is_full(CHARSET_INFO *cs) +{ + return + (cs->csname && cs->tab_to_uni && cs->ctype && cs->to_upper && cs->to_lower) + && + (cs->number && cs->name && cs->sort_order); +} + +static int fill_uchar(uchar *a,uint size,const char *str, uint len) +{ + uint i=0; + const char *s, *b, *e=str+len; + + for (s=str ; ssize) + break; + a[i]=my_strntoul(my_charset_latin1,b,s-b,NULL,16); + } + return 0; +} + +static int fill_uint16(uint16 *a,uint size,const char *str, uint len) +{ + uint i=0; + const char *s, *b, *e=str+len; + char buf[6]; + for (s=str ; ssize) + break; + mstr(buf,b,6,s-b); + a[i]=my_strntol(my_charset_latin1,b,s-b,NULL,16); + } + return 0; +} + static int cs_enter(MY_XML_PARSER *st,const char *attr, uint len) { struct my_cs_file_info *i = (struct my_cs_file_info *)st->user_data; @@ -169,21 +280,35 @@ static int cs_leave(MY_XML_PARSER *st,const char *attr, uint len) if (state == _CS_COLLATION) { - if (!all_charsets[i->cs.number]) + if (i->cs.name && (i->cs.number || (i->cs.number=get_charset_number(i->cs.name)))) { - if (!(all_charsets[i->cs.number]= - (CHARSET_INFO*) my_once_alloc(sizeof(CHARSET_INFO),i->myflags))) + if (!all_charsets[i->cs.number]) { - return MY_XML_ERROR; + if (!(all_charsets[i->cs.number]= + (CHARSET_INFO*) my_once_alloc(sizeof(CHARSET_INFO),i->myflags))) + { + return MY_XML_ERROR; + } + bzero((void*)all_charsets[i->cs.number],sizeof(CHARSET_INFO)); } - all_charsets[i->cs.number][0]=i->cs; + + if (!(all_charsets[i->cs.number]->state & MY_CS_COMPILED)) + { + simple_cs_copy_data(all_charsets[i->cs.number],&i->cs); + if (simple_cs_is_full(all_charsets[i->cs.number])) + { + simple_cs_init_functions(all_charsets[i->cs.number]); + all_charsets[i->cs.number]->state |= MY_CS_LOADED; + } + } + i->cs.number=0; + i->cs.name=NULL; + i->cs.state=0; + i->cs.sort_order=NULL; + i->cs.state=0; } - else - { - all_charsets[i->cs.number]->state |= i->cs.state; - } - i->cs.state=0; } + return MY_XML_OK; } @@ -193,12 +318,13 @@ static int cs_value(MY_XML_PARSER *st,const char *attr, uint len) struct my_cs_file_section_st *s; int state = (s=cs_file_sec(st->attr,strlen(st->attr))) ? s->state : 0; - if(0) - { - char str[256]; +#ifndef DBUG_OFF + if(0){ + char str[1024]; mstr(str,attr,len,sizeof(str)-1); printf("VALUE %d %s='%s'\n",state,st->attr,str); } +#endif switch (state) { @@ -206,22 +332,39 @@ static int cs_value(MY_XML_PARSER *st,const char *attr, uint len) i->cs.number = my_strntoul(my_charset_latin1,attr,len,(char**)NULL,0); break; case _CS_COLNAME: - if ((i->cs.name = (char*) my_once_alloc(len+1,i->myflags))) - { - memcpy((char*)i->cs.name,attr,len); - ((char*)(i->cs.name))[len]='\0'; - } + memcpy(i->name,attr,len=min(len,CS_MAX_NM_LEN-1)); + i->name[len]='\0'; + i->cs.name=i->name; break; case _CS_NAME: - if ((i->cs.csname = (char*) my_once_alloc(len+1,i->myflags))) - { - memcpy((char*)i->cs.csname,attr,len); - ((char*)(i->cs.csname))[len]='\0'; - } + memcpy(i->csname,attr,len=min(len,CS_MAX_NM_LEN-1)); + i->csname[len]='\0'; + i->cs.csname=i->csname; break; case _CS_FLAG: if (!strncmp("primary",attr,len)) i->cs.state |= MY_CS_PRIMARY; + break; + case _CS_UPPERMAP: + fill_uchar(i->to_upper,TO_UPPER_TABLE_SIZE,attr,len); + i->cs.to_upper=i->to_upper; + break; + case _CS_LOWERMAP: + fill_uchar(i->to_lower,TO_LOWER_TABLE_SIZE,attr,len); + i->cs.to_lower=i->to_lower; + break; + case _CS_UNIMAP: + fill_uint16(i->tab_to_uni,TO_UNI_TABLE_SIZE,attr,len); + i->cs.tab_to_uni=i->tab_to_uni; + break; + case _CS_COLLMAP: + fill_uchar(i->sort_order,SORT_ORDER_TABLE_SIZE,attr,len); + i->cs.sort_order=i->sort_order; + break; + case _CS_CTYPEMAP: + fill_uchar(i->ctype,CTYPE_TABLE_SIZE,attr,len); + i->cs.ctype=i->ctype; + break; } return MY_XML_OK; } @@ -326,38 +469,6 @@ void free_charsets(void) charset_initialized=0; } - -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; -} - -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; -} - - static void get_charset_conf_name(const char *cs_name, char *buf) { strxmov(get_charsets_dir(buf), cs_name, ".conf", NullS); @@ -449,96 +560,6 @@ static my_bool create_fromuni(CHARSET_INFO *cs){ } -static my_bool read_charset_file(const char *cs_name, CHARSET_INFO *set, - myf myflags) -{ - struct simpleconfig_buf_st fb; - char buf[FN_REFLEN]; - my_bool result; - DBUG_ENTER("read_charset_file"); - DBUG_PRINT("enter",("cs_name: %s", cs_name)); - - get_charset_conf_name(cs_name, buf); - 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) || - fill_array(set->sort_order, SORT_ORDER_TABLE_SIZE, &fb) || - fill_uint16_array(set->tab_to_uni,TO_UNI_TABLE_SIZE,&fb)) - result=TRUE; - - my_fclose(fb.f, MYF(0)); - DBUG_RETURN(result); -} - - -static CHARSET_INFO *add_charset(CHARSET_INFO *cs, myf flags) -{ - 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]; - - /* Note: cs->name and cs->number are already initialized */ - - cs->ctype=tmp_ctype; - cs->to_lower=tmp_to_lower; - cs->to_upper=tmp_to_upper; - cs->sort_order=tmp_sort_order; - cs->tab_to_uni=tmp_to_uni; - if (read_charset_file(cs->name, cs, flags)) - 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)); - cs->tab_to_uni=(uint16*)my_once_alloc(TO_UNI_TABLE_SIZE*sizeof(uint16), MYF(MY_WME)); - 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)); - memcpy((char*) cs->tab_to_uni, (char*) tmp_to_uni, sizeof(tmp_to_uni)); - - cs->like_range = my_like_range_simple; - cs->wildcmp = my_wildcmp_8bit; - cs->strnncoll = my_strnncoll_simple; - cs->caseup_str = my_caseup_str_8bit; - cs->casedn_str = my_casedn_str_8bit; - cs->caseup = my_caseup_8bit; - cs->casedn = my_casedn_8bit; - cs->tosort = my_tosort_8bit; - cs->strcasecmp = my_strcasecmp_8bit; - cs->strncasecmp = my_strncasecmp_8bit; - cs->mb_wc = my_mb_wc_8bit; - cs->wc_mb = my_wc_mb_8bit; - cs->hash_caseup = my_hash_caseup_simple; - cs->hash_sort = my_hash_sort_simple; - cs->snprintf = my_snprintf_8bit; - cs->strntol = my_strntol_8bit; - cs->strntoul = my_strntoul_8bit; - cs->strntoll = my_strntoll_8bit; - cs->strntoull = my_strntoull_8bit; - cs->strntod = my_strntod_8bit; - cs->mbmaxlen = 1; - - set_max_sort_char(cs); - create_fromuni(cs); - - return cs; -} - - uint get_charset_number(const char *charset_name) { CHARSET_INFO **cs; @@ -569,6 +590,7 @@ const char *get_charset_name(uint charset_number) static CHARSET_INFO *get_internal_charset(uint cs_number, myf flags) { + char buf[FN_REFLEN]; CHARSET_INFO *cs; /* To make things thread safe we are not allowing other threads to interfere @@ -577,9 +599,13 @@ static CHARSET_INFO *get_internal_charset(uint cs_number, myf flags) pthread_mutex_lock(&THR_LOCK_charset); cs = all_charsets[cs_number]; - if (cs && !(cs->state & (MY_CS_COMPILED | MY_CS_LOADED))) - cs=add_charset(cs, flags); + if (cs && !(cs->state & (MY_CS_COMPILED | MY_CS_LOADED))) + { + strxmov(buf, cs->csname, ".xml", NullS); + read_charset_index(buf,flags); + cs = (cs->state & MY_CS_LOADED) ? cs : NULL; + } pthread_mutex_unlock(&THR_LOCK_charset); return cs; } diff --git a/sql/share/Makefile.am b/sql/share/Makefile.am index a1b506f1ff5..35202ff4722 100644 --- a/sql/share/Makefile.am +++ b/sql/share/Makefile.am @@ -25,8 +25,7 @@ install-data-local: done $(mkinstalldirs) $(DESTDIR)$(pkgdatadir)/charsets $(INSTALL_DATA) $(srcdir)/charsets/README $(DESTDIR)$(pkgdatadir)/charsets/README - $(INSTALL_DATA) $(srcdir)/charsets/Index.xml $(DESTDIR)$(pkgdatadir)/charsets/Index.xml - $(INSTALL_DATA) $(srcdir)/charsets/*.conf $(DESTDIR)$(pkgdatadir)/charsets + $(INSTALL_DATA) $(srcdir)/charsets/*.xml $(DESTDIR)$(pkgdatadir)/charsets fix_errors: for lang in @AVAILABLE_LANGUAGES@; \ diff --git a/strings/ctype-simple.c b/strings/ctype-simple.c index fa1ece20b3e..49801478504 100644 --- a/strings/ctype-simple.c +++ b/strings/ctype-simple.c @@ -432,7 +432,7 @@ ulong my_strntoul_8bit(CHARSET_INFO *cs, c -= '0'; else if (c>='A' && c<='F') c = c - 'A' + 10; - else if (c>='a' && c<='a') + else if (c>='a' && c<='f') c = c - 'a' + 10; else break;