New field snprintf() in CHARSET_INFO structure

This commit is contained in:
bar@bar.mysql.r18.ru 2002-11-10 16:14:39 +04:00
commit abd3427150
16 changed files with 234 additions and 38 deletions

View file

@ -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
};

View file

@ -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 */
};

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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
};

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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
};

View file

@ -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
};

View file

@ -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
};

View file

@ -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
};

View file

@ -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
}
};