summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbar@bar.mysql.r18.ru <>2002-11-10 16:14:39 +0400
committerbar@bar.mysql.r18.ru <>2002-11-10 16:14:39 +0400
commitabd3427150a0d52a26c48523de02c871662daccc (patch)
tree7f3c8b67fd349318c5c99fce4630ea3f1fc76ac0
parent95676115779a2c0e19769b0c09a5a1edf2ad116e (diff)
downloadmariadb-git-abd3427150a0d52a26c48523de02c871662daccc.tar.gz
New field snprintf() in CHARSET_INFO structure
-rw-r--r--include/m_ctype.h8
-rw-r--r--mysys/charset.c1
-rw-r--r--strings/ctype-big5.c3
-rw-r--r--strings/ctype-bin.c3
-rw-r--r--strings/ctype-czech.c3
-rw-r--r--strings/ctype-euc_kr.c3
-rw-r--r--strings/ctype-gb2312.c3
-rw-r--r--strings/ctype-gbk.c3
-rw-r--r--strings/ctype-latin1_de.c3
-rw-r--r--strings/ctype-simple.c64
-rw-r--r--strings/ctype-sjis.c3
-rw-r--r--strings/ctype-tis620.c3
-rw-r--r--strings/ctype-ujis.c3
-rw-r--r--strings/ctype-utf8.c94
-rw-r--r--strings/ctype-win1250ch.c3
-rw-r--r--strings/ctype.c72
16 files changed, 234 insertions, 38 deletions
diff --git a/include/m_ctype.h b/include/m_ctype.h
index 029a1a5db39..6a964bf3b97 100644
--- a/include/m_ctype.h
+++ b/include/m_ctype.h
@@ -112,8 +112,12 @@ typedef struct charset_info_st
uint (*hash_caseup)(struct charset_info_st *cs, const byte *key, uint len);
void (*hash_sort)(struct charset_info_st *cs, const uchar *key, uint len,
ulong *nr1, ulong *nr2);
-
+
char max_sort_char; /* For LIKE optimization */
+
+ /* Charset dependant snprintf() */
+ int (*snprintf)(struct charset_info_st *, char *to, uint n, const char *fmt, ...);
+
} CHARSET_INFO;
@@ -150,6 +154,8 @@ extern int my_strncasecmp_8bit(CHARSET_INFO * cs, const char *, const char *, ui
int my_mb_wc_8bit(CHARSET_INFO *cs,my_wc_t *wc, const uchar *s,const uchar *e);
int my_wc_mb_8bit(CHARSET_INFO *cs,my_wc_t wc, uchar *s, uchar *e);
+int my_snprintf_8bit(struct charset_info_st *, char *to, uint n, const char *fmt, ...);
+
#ifdef USE_MB
/* Functions for multibyte charsets */
diff --git a/mysys/charset.c b/mysys/charset.c
index 9c977c7d145..3ad4b4e8faa 100644
--- a/mysys/charset.c
+++ b/mysys/charset.c
@@ -388,6 +388,7 @@ static CHARSET_INFO *add_charset(CHARSET_INFO *cs, myf flags)
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;
set_max_sort_char(cs);
create_fromuni(cs);
diff --git a/strings/ctype-big5.c b/strings/ctype-big5.c
index b9011ac12aa..8dff0d860a0 100644
--- a/strings/ctype-big5.c
+++ b/strings/ctype-big5.c
@@ -6247,7 +6247,8 @@ CHARSET_INFO my_charset_big5 =
my_strncasecmp_mb,
my_hash_caseup_simple,
my_hash_sort_simple,
- 0
+ 0,
+ my_snprintf_8bit
};
diff --git a/strings/ctype-bin.c b/strings/ctype-bin.c
index 0a90a1e26e5..e479053071b 100644
--- a/strings/ctype-bin.c
+++ b/strings/ctype-bin.c
@@ -177,7 +177,8 @@ static CHARSET_INFO my_charset_bin_st =
my_strncasecmp_bin, /* strncasecmp */
my_hash_caseup_bin, /* hash_caseup */
my_hash_sort_bin, /* hash_sort */
- 255 /* max_sort_char */
+ 255, /* max_sort_char */
+ my_snprintf_8bit /* snprintf */
};
diff --git a/strings/ctype-czech.c b/strings/ctype-czech.c
index e6cab722a8e..6ce2bf13fce 100644
--- a/strings/ctype-czech.c
+++ b/strings/ctype-czech.c
@@ -625,7 +625,8 @@ CHARSET_INFO my_charset_czech =
my_strncasecmp_8bit,
my_hash_caseup_simple,
my_hash_sort_simple,
- 0
+ 0,
+ my_snprintf_8bit
};
#endif
diff --git a/strings/ctype-euc_kr.c b/strings/ctype-euc_kr.c
index a7d6044b378..154fada271e 100644
--- a/strings/ctype-euc_kr.c
+++ b/strings/ctype-euc_kr.c
@@ -8664,7 +8664,8 @@ CHARSET_INFO my_charset_euc_kr =
my_strncasecmp_mb,
my_hash_caseup_simple,
my_hash_sort_simple,
- 0
+ 0,
+ my_snprintf_8bit
};
#endif
diff --git a/strings/ctype-gb2312.c b/strings/ctype-gb2312.c
index e931c7c1f31..ecd15830b3f 100644
--- a/strings/ctype-gb2312.c
+++ b/strings/ctype-gb2312.c
@@ -5714,7 +5714,8 @@ CHARSET_INFO my_charset_gb2312 =
my_strncasecmp_mb,
my_hash_caseup_simple,
my_hash_sort_simple,
- 0
+ 0,
+ my_snprintf_8bit
};
#endif
diff --git a/strings/ctype-gbk.c b/strings/ctype-gbk.c
index 0f2de81ccb6..bdfdfb9b256 100644
--- a/strings/ctype-gbk.c
+++ b/strings/ctype-gbk.c
@@ -9902,7 +9902,8 @@ CHARSET_INFO my_charset_gbk =
my_strncasecmp_mb,
my_hash_caseup_simple,
my_hash_sort_simple,
- 0
+ 0,
+ my_snprintf_8bit
};
diff --git a/strings/ctype-latin1_de.c b/strings/ctype-latin1_de.c
index 040bd11b5e9..574fbf41da3 100644
--- a/strings/ctype-latin1_de.c
+++ b/strings/ctype-latin1_de.c
@@ -443,7 +443,8 @@ CHARSET_INFO my_charset_latin1_de =
my_strncasecmp_8bit,
my_hash_caseup_simple,
my_hash_sort_simple,
- 0
+ 0,
+ my_snprintf_8bit
};
#endif
diff --git a/strings/ctype-simple.c b/strings/ctype-simple.c
index f27b113376b..9fef27cad10 100644
--- a/strings/ctype-simple.c
+++ b/strings/ctype-simple.c
@@ -15,8 +15,11 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include <my_global.h>
+#include "my_sys.h"
#include "m_ctype.h"
+#include "m_string.h"
#include "dbug.h"
+#include "stdarg.h"
#include "assert.h"
int my_strnxfrm_simple(CHARSET_INFO * cs,
@@ -120,6 +123,67 @@ int my_wc_mb_8bit(CHARSET_INFO *cs,my_wc_t wc,
}
+static int my_vsnprintf_8bit(char *to, size_t n, const char* fmt, va_list ap)
+{
+ char *start=to, *end=to+n-1;
+ for (; *fmt ; fmt++)
+ {
+ if (fmt[0] != '%')
+ {
+ if (to == end) /* End of buffer */
+ break;
+ *to++= *fmt; /* Copy ordinary char */
+ continue;
+ }
+ /* Skip if max size is used (to be compatible with printf) */
+ fmt++;
+ while (my_isdigit(system_charset_info,*fmt) || *fmt == '.' || *fmt == '-')
+ fmt++;
+ if (*fmt == 'l')
+ fmt++;
+ if (*fmt == 's') /* String parameter */
+ {
+ reg2 char *par = va_arg(ap, char *);
+ uint plen,left_len = (uint)(end-to);
+ if (!par) par = (char*)"(null)";
+ plen = (uint) strlen(par);
+ if (left_len <= plen)
+ plen = left_len - 1;
+ to=strnmov(to,par,plen);
+ continue;
+ }
+ else if (*fmt == 'd' || *fmt == 'u') /* Integer parameter */
+ {
+ register int iarg;
+ if ((uint) (end-to) < 16)
+ break;
+ iarg = va_arg(ap, int);
+ if (*fmt == 'd')
+ to=int10_to_str((long) iarg,to, -10);
+ else
+ to=int10_to_str((long) (uint) iarg,to,10);
+ continue;
+ }
+ /* We come here on '%%', unknown code or too long parameter */
+ if (to == end)
+ break;
+ *to++='%'; /* % used as % or unknown code */
+ }
+ DBUG_ASSERT(to <= end);
+ *to='\0'; /* End of errmessage */
+ return (uint) (to - start);
+}
+
+
+int my_snprintf_8bit(CHARSET_INFO *cs __attribute__((unused)),
+ char* to, uint n, const char* fmt, ...)
+{
+ va_list args;
+ va_start(args,fmt);
+ return my_vsnprintf_8bit(to, n, fmt, args);
+}
+
+
#ifndef NEW_HASH_FUNCTION
diff --git a/strings/ctype-sjis.c b/strings/ctype-sjis.c
index 9c8ac8d0c16..d657405137e 100644
--- a/strings/ctype-sjis.c
+++ b/strings/ctype-sjis.c
@@ -4489,7 +4489,8 @@ CHARSET_INFO my_charset_sjis =
my_strncasecmp_8bit,
my_hash_caseup_simple,
my_hash_sort_simple,
- 0
+ 0,
+ my_snprintf_8bit
};
#endif
diff --git a/strings/ctype-tis620.c b/strings/ctype-tis620.c
index 88549e7ee69..de1a0e170fb 100644
--- a/strings/ctype-tis620.c
+++ b/strings/ctype-tis620.c
@@ -717,7 +717,8 @@ CHARSET_INFO my_charset_tis620 =
my_strncasecmp_8bit,
my_hash_caseup_simple,
my_hash_sort_simple,
- 0
+ 0,
+ my_snprintf_8bit
};
diff --git a/strings/ctype-ujis.c b/strings/ctype-ujis.c
index cb1da080951..85b51b0469c 100644
--- a/strings/ctype-ujis.c
+++ b/strings/ctype-ujis.c
@@ -8458,7 +8458,8 @@ CHARSET_INFO my_charset_ujis =
my_strncasecmp_mb,
my_hash_caseup_simple,
my_hash_sort_simple,
- 0
+ 0,
+ my_snprintf_8bit
};
diff --git a/strings/ctype-utf8.c b/strings/ctype-utf8.c
index 81671e28c3f..707ca8f5c77 100644
--- a/strings/ctype-utf8.c
+++ b/strings/ctype-utf8.c
@@ -1983,7 +1983,8 @@ CHARSET_INFO my_charset_utf8 =
my_strncasecmp_utf8,
my_hash_caseup_utf8,/* hash_caseup */
my_hash_sort_utf8, /* hash_sort */
- 0
+ 0,
+ my_snprintf_8bit
};
@@ -2345,6 +2346,94 @@ static int my_mbcharlen_ucs2(CHARSET_INFO *cs __attribute__((unused)) ,
}
+#include <m_string.h>
+#include <stdarg.h>
+#include <assert.h>
+
+static int my_vsnprintf_ucs2(char *dst, uint n, const char* fmt, va_list ap)
+{
+ char *start=dst, *end=dst+n-1;
+ for (; *fmt ; fmt++)
+ {
+ if (fmt[0] != '%')
+ {
+ if (dst == end) /* End of buffer */
+ break;
+
+ *dst++='\0'; *dst++= *fmt; /* Copy ordinary char */
+ continue;
+ }
+
+ fmt++;
+
+ /* Skip if max size is used (to be compatible with printf) */
+ while (my_isdigit(system_charset_info,*fmt) || *fmt == '.' || *fmt == '-')
+ fmt++;
+
+ if (*fmt == 'l')
+ fmt++;
+
+ if (*fmt == 's') /* String parameter */
+ {
+ reg2 char *par = va_arg(ap, char *);
+ uint plen;
+ uint left_len = (uint)(end-dst);
+ if (!par) par = (char*)"(null)";
+ plen = (uint) strlen(par);
+ if (left_len <= plen*2)
+ plen = left_len/2 - 1;
+ dst=strnmov(dst,par,plen);
+ for ( ; plen ; plen--, dst++, par++)
+ {
+ dst[0]='\0';
+ dst[1]=par[0];
+ }
+ continue;
+ }
+ else if (*fmt == 'd' || *fmt == 'u') /* Integer parameter */
+ {
+ register int iarg;
+ char nbuf[16];
+ char *pbuf=nbuf;
+
+ if ((uint) (end-dst) < 32)
+ break;
+ iarg = va_arg(ap, int);
+ if (*fmt == 'd')
+ dst=int10_to_str((long) iarg, nbuf, -10);
+ else
+ dst=int10_to_str((long) (uint) iarg,nbuf,10);
+
+ for (; pbuf[0]; pbuf++)
+ {
+ *dst++='\0';
+ *dst++=*pbuf;
+ }
+ continue;
+ }
+
+ /* We come here on '%%', unknown code or too long parameter */
+ if (dst == end)
+ break;
+ *dst++='\0';
+ *dst++='%'; /* % used as % or unknown code */
+ }
+
+ DBUG_ASSERT(dst <= end);
+ *dst='\0'; /* End of errmessage */
+ return (uint) (dst - start);
+}
+
+static int my_snprintf_ucs2(CHARSET_INFO *cs __attribute__((unused))
+ ,char* to, uint n, const char* fmt, ...)
+{
+ va_list args;
+ va_start(args,fmt);
+ return my_vsnprintf_ucs2(to, n, fmt, args);
+}
+
+
+
CHARSET_INFO my_charset_ucs2 =
{
35, /* number */
@@ -2376,7 +2465,8 @@ CHARSET_INFO my_charset_ucs2 =
my_strncasecmp_ucs2,
my_hash_caseup_ucs2,/* hash_caseup */
my_hash_sort_ucs2, /* hash_sort */
- 0
+ 0,
+ my_snprintf_ucs2
};
diff --git a/strings/ctype-win1250ch.c b/strings/ctype-win1250ch.c
index f64eddd2c2b..64697ce08f3 100644
--- a/strings/ctype-win1250ch.c
+++ b/strings/ctype-win1250ch.c
@@ -651,7 +651,8 @@ CHARSET_INFO my_charset_win1250ch =
my_strncasecmp_8bit,
my_hash_caseup_simple,
my_hash_sort_simple,
- 0
+ 0,
+ my_snprintf_8bit
};
diff --git a/strings/ctype.c b/strings/ctype.c
index 1358fced15c..8fc189f4b7f 100644
--- a/strings/ctype.c
+++ b/strings/ctype.c
@@ -2838,7 +2838,8 @@ static CHARSET_INFO compiled_charsets[] = {
my_strncasecmp_8bit,
my_hash_caseup_simple,
my_hash_sort_simple,
- 0
+ 0,
+ my_snprintf_8bit
},
#endif
@@ -2874,7 +2875,8 @@ static CHARSET_INFO compiled_charsets[] = {
my_strncasecmp_8bit,
my_hash_caseup_simple,
my_hash_sort_simple,
- 0
+ 0,
+ my_snprintf_8bit
},
#endif
@@ -2909,7 +2911,8 @@ static CHARSET_INFO compiled_charsets[] = {
my_strncasecmp_8bit,
my_hash_caseup_simple,
my_hash_sort_simple,
- 0
+ 0,
+ my_snprintf_8bit
},
#endif
@@ -2944,7 +2947,8 @@ static CHARSET_INFO compiled_charsets[] = {
my_strncasecmp_8bit,
my_hash_caseup_simple,
my_hash_sort_simple,
- 0
+ 0,
+ my_snprintf_8bit
},
#endif
@@ -2980,7 +2984,8 @@ static CHARSET_INFO compiled_charsets[] = {
my_strncasecmp_8bit,
my_hash_caseup_simple,
my_hash_sort_simple,
- 0
+ 0,
+ my_snprintf_8bit
},
#endif
@@ -3015,7 +3020,8 @@ static CHARSET_INFO compiled_charsets[] = {
my_strncasecmp_8bit,
my_hash_caseup_simple,
my_hash_sort_simple,
- 0
+ 0,
+ my_snprintf_8bit
},
#endif
@@ -3050,7 +3056,8 @@ static CHARSET_INFO compiled_charsets[] = {
my_strncasecmp_8bit,
my_hash_caseup_simple,
my_hash_sort_simple,
- 0
+ 0,
+ my_snprintf_8bit
},
#endif
@@ -3085,7 +3092,8 @@ static CHARSET_INFO compiled_charsets[] = {
my_strncasecmp_8bit,
my_hash_caseup_simple,
my_hash_sort_simple,
- 0
+ 0,
+ my_snprintf_8bit
},
#endif
@@ -3121,7 +3129,8 @@ static CHARSET_INFO compiled_charsets[] = {
my_strncasecmp_8bit,
my_hash_caseup_simple,
my_hash_sort_simple,
- 0
+ 0,
+ my_snprintf_8bit
},
#endif
@@ -3156,7 +3165,8 @@ static CHARSET_INFO compiled_charsets[] = {
my_strncasecmp_8bit,
my_hash_caseup_simple,
my_hash_sort_simple,
- 0
+ 0,
+ my_snprintf_8bit
},
#endif
@@ -3191,7 +3201,8 @@ static CHARSET_INFO compiled_charsets[] = {
my_strncasecmp_8bit,
my_hash_caseup_simple,
my_hash_sort_simple,
- 0
+ 0,
+ my_snprintf_8bit
},
#endif
@@ -3226,7 +3237,8 @@ static CHARSET_INFO compiled_charsets[] = {
my_strncasecmp_8bit,
my_hash_caseup_simple,
my_hash_sort_simple,
- 0
+ 0,
+ my_snprintf_8bit
},
#endif
@@ -3261,7 +3273,8 @@ static CHARSET_INFO compiled_charsets[] = {
my_strncasecmp_8bit,
my_hash_caseup_simple,
my_hash_sort_simple,
- 0
+ 0,
+ my_snprintf_8bit
},
#endif
@@ -3296,7 +3309,8 @@ static CHARSET_INFO compiled_charsets[] = {
my_strncasecmp_8bit,
my_hash_caseup_simple,
my_hash_sort_simple,
- 0
+ 0,
+ my_snprintf_8bit
},
#endif
@@ -3331,7 +3345,8 @@ static CHARSET_INFO compiled_charsets[] = {
my_strncasecmp_8bit,
my_hash_caseup_simple,
my_hash_sort_simple,
- 0
+ 0,
+ my_snprintf_8bit
},
#endif
@@ -3367,7 +3382,8 @@ static CHARSET_INFO compiled_charsets[] = {
my_strncasecmp_8bit,
my_hash_caseup_simple,
my_hash_sort_simple,
- 0
+ 0,
+ my_snprintf_8bit
},
#endif
@@ -3402,7 +3418,8 @@ static CHARSET_INFO compiled_charsets[] = {
my_strncasecmp_8bit,
my_hash_caseup_simple,
my_hash_sort_simple,
- 0
+ 0,
+ my_snprintf_8bit
},
#endif
@@ -3438,7 +3455,8 @@ static CHARSET_INFO compiled_charsets[] = {
my_strncasecmp_8bit,
my_hash_caseup_simple,
my_hash_sort_simple,
- 0
+ 0,
+ my_snprintf_8bit
},
#endif
@@ -3474,7 +3492,8 @@ static CHARSET_INFO compiled_charsets[] = {
my_strncasecmp_8bit,
my_hash_caseup_simple,
my_hash_sort_simple,
- 0
+ 0,
+ my_snprintf_8bit
},
#endif
@@ -3509,7 +3528,8 @@ static CHARSET_INFO compiled_charsets[] = {
my_strncasecmp_8bit,
my_hash_caseup_simple,
my_hash_sort_simple,
- 0
+ 0,
+ my_snprintf_8bit
},
#endif
@@ -3544,7 +3564,8 @@ static CHARSET_INFO compiled_charsets[] = {
my_strncasecmp_8bit,
my_hash_caseup_simple,
my_hash_sort_simple,
- 0
+ 0,
+ my_snprintf_8bit
},
#endif
@@ -3579,7 +3600,8 @@ static CHARSET_INFO compiled_charsets[] = {
my_strncasecmp_8bit,
my_hash_caseup_simple,
my_hash_sort_simple,
- 0
+ 0,
+ my_snprintf_8bit
},
#endif
@@ -3614,7 +3636,8 @@ static CHARSET_INFO compiled_charsets[] = {
my_strncasecmp_8bit,
my_hash_caseup_simple,
my_hash_sort_simple,
- 0
+ 0,
+ my_snprintf_8bit
},
#endif
@@ -3650,7 +3673,8 @@ static CHARSET_INFO compiled_charsets[] = {
NULL,
NULL, /* hash_caseup */
NULL, /* hash_sort */
- 0
+ 0,
+ NULL
}
};