diff options
author | Egbert Eich <eich@freedesktop.org> | 2004-04-23 18:42:09 +0000 |
---|---|---|
committer | Egbert Eich <eich@freedesktop.org> | 2004-04-23 18:42:09 +0000 |
commit | c6349f43193b74a3c09945f3093a871b0157ba47 (patch) | |
tree | aea173c19da6fa57e24eb4633ff815feb7ae3fa0 /modules/lc/xlocale | |
parent | c3c4ddc682950a01b80825021f3e2503ab01ea7f (diff) |
Merging XORG-CURRENT into trunk
Diffstat (limited to 'modules/lc/xlocale')
-rw-r--r-- | modules/lc/xlocale/lcEuc.c | 493 | ||||
-rw-r--r-- | modules/lc/xlocale/lcJis.c | 375 | ||||
-rw-r--r-- | modules/lc/xlocale/lcSjis.c | 475 |
3 files changed, 676 insertions, 667 deletions
diff --git a/modules/lc/xlocale/lcEuc.c b/modules/lc/xlocale/lcEuc.c index 2027302..023db40 100644 --- a/modules/lc/xlocale/lcEuc.c +++ b/modules/lc/xlocale/lcEuc.c @@ -30,6 +30,14 @@ OF THIS SOFTWARE. Yoshiyuki Segawa (segawa@ossi.com) *****************************************************************/ +/* $XFree86: xc/lib/X11/lcEuc.c,v 3.12 2003/01/20 04:05:30 dawes Exp $ */ + +/* + * An EUC locale. + * Supports: all locales with codeset eucJP, eucKR, eucCN, eucTW. + * How: Provides converters for euc*. + * Platforms: Only those defining X_LOCALE (only Lynx, Linux-libc5, OS/2). + */ #ifdef X_LOCALE @@ -68,8 +76,8 @@ typedef unsigned char Uchar; typedef unsigned long Ulong; typedef unsigned int Uint; -static CodeSet GetCodeSetFromCharSet(); -static CodeSet wc_codeset(); +static CodeSet GetCodeSetFromCharSet (XLCd lcd, XlcCharSet charset); +static CodeSet wc_codeset (XLCd lcd, wchar_t wch); #define BADCHAR(min_ch, c) (BIT8OFF(c) < (char)min_ch && BIT8OFF(c) != 0x0 && \ BIT8OFF(c) != '\t' && BIT8OFF(c) != '\n' && \ @@ -84,48 +92,41 @@ static CodeSet wc_codeset(); */ static int -euc_mbstowcs(conv, from, from_left, to, to_left, args, num_args) - XlcConv conv; - XPointer *from; - int *from_left; - XPointer *to; - int *to_left; - XPointer *args; - int num_args; +euc_mbstowcs( + XlcConv conv, + XPointer *from, + int *from_left, + XPointer *to, + int *to_left, + XPointer *args, + int num_args) { - XLCd lcd = (XLCd)conv->state; - register Uchar ch; - register int chr_len = 0; - register int sshift = False; - register int shift_mult = 0; - register Uint chrcode; + Uchar ch; + int chr_len = 0; + int sshift = False; + int shift_mult = 0; + Uint chrcode; Uint wc_encode = 0; Uint wc_tmp = 0; int cs0flg = False; int cs1flg = False; - int length; - int num_conv; + int length = 0; int unconv_num = 0; Bool new_char; - XPointer inbufptr = *from; + const char *inbufptr = *from; wchar_t *outbufptr = (wchar_t *) *to; - wchar_t *outbuf_base = outbufptr; CodeSet *codesets = XLC_GENERIC(lcd, codeset_list); int codeset_num = XLC_GENERIC(lcd, codeset_num); Ulong wc_shift = XLC_GENERIC(lcd, wc_shift_bits); - - if (*from_left > *to_left) - *from_left = *to_left; - - for (new_char = True; *from_left > 0;) { + for (new_char = True; *from_left > 0 && *to_left > 0;) { ch = *inbufptr++; @@ -142,6 +143,7 @@ euc_mbstowcs(conv, from, from_left, to, to_left, args, num_args) length = CS0->length; *outbufptr++ = (wchar_t)ch; (*from_left)--; + (*to_left)--; continue; } else if (ch == SS2) { /* CS2 */ @@ -215,6 +217,7 @@ euc_mbstowcs(conv, from, from_left, to, to_left, args, num_args) if (--chr_len == 0) { wc_tmp |= wc_encode; *outbufptr++ = wc_tmp; + (*to_left)--; new_char = True; sshift = False; @@ -230,41 +233,32 @@ euc_mbstowcs(conv, from, from_left, to, to_left, args, num_args) if (cs0flg == True || cs1flg == True) /* error check on last char */ unconv_num++; - if ((num_conv = (int)(outbufptr - outbuf_base)) > 0) - *to_left = (*to_left) - num_conv; - return unconv_num; } static int -euc_wcstombs(conv, from, from_left, to, to_left, args, num_args) - XlcConv conv; - XPointer *from; - int *from_left; - XPointer *to; - int *to_left; - XPointer *args; - int num_args; +euc_wcstombs( + XlcConv conv, + XPointer *from, + int *from_left, + XPointer *to, + int *to_left, + XPointer *args, + int num_args) { - wchar_t *inbufptr = (wchar_t *) *from; - register XPointer outbufptr = *to; - XPointer outbuf_base = outbufptr; + const wchar_t *inbufptr = (const wchar_t *) *from; + XPointer outbufptr = *to; wchar_t wch; - register int length; + int length; Uchar tmp; - int num_conv; int unconv_num = 0; XLCd lcd = (XLCd)conv->state; CodeSet codeset; Ulong wc_shift = XLC_GENERIC(lcd, wc_shift_bits); - - if (*from_left > *to_left) - *from_left = *to_left; - - for (; *from_left > 0 ; (*from_left)-- ) { + for (; *from_left > 0 && *to_left > 0; (*from_left)-- ) { wch = *inbufptr++; @@ -277,8 +271,19 @@ euc_wcstombs(conv, from, from_left, to, to_left, args, num_args) length = codeset->length; wch ^= (wchar_t)codeset->wc_encoding; - if (codeset->parse_info) /* put out SS2 or SS3 */ + if (codeset->parse_info) { /* put out SS2 or SS3 */ + if (*to_left < length + 1) { + unconv_num++; + break; + } *outbufptr++ = *codeset->parse_info->encoding; + (*to_left)--; + } else { + if (*to_left < length) { + unconv_num++; + break; + } + } do { length--; @@ -288,27 +293,25 @@ euc_wcstombs(conv, from, from_left, to, to_left, args, num_args) tmp = BIT8ON(tmp); *outbufptr++ = (Uchar)tmp; + (*to_left)--; } while (length); } *to = (XPointer)outbufptr; - if ((num_conv = (int)(outbufptr - outbuf_base)) > 0) - *to_left -= num_conv; - return unconv_num; } static int -euc_mbtocs(conv, from, from_left, to, to_left, args, num_args) - XlcConv conv; - XPointer *from; - int *from_left; - XPointer *to; - int *to_left; - XPointer *args; - int num_args; +euc_mbtocs( + XlcConv conv, + XPointer *from, + int *from_left, + XPointer *to, + int *to_left, + XPointer *args, + int num_args) { XLCd lcd = (XLCd)conv->state; XlcCharSet charset; @@ -317,8 +320,8 @@ euc_mbtocs(conv, from, from_left, to, to_left, args, num_args) int length; int unconv_num = 0; int min_ch = 0; - register char *src = *from, *dst = *to; - + const char *src = *from; + char *dst = *to; if (isleftside(*src)) { /* 7-bit (CS0) */ if (ASCII_CODESET >= codeset_num) @@ -374,7 +377,7 @@ euc_mbtocs(conv, from, from_left, to, to_left, args, num_args) } while (--length); *to = dst; - *from = src; + *from = (XPointer) src; *from_left -= charset->char_size; *to_left -= charset->char_size - length; @@ -386,22 +389,22 @@ euc_mbtocs(conv, from, from_left, to, to_left, args, num_args) static int -euc_mbstocs(conv, from, from_left, to, to_left, args, num_args) - XlcConv conv; - XPointer *from; - int *from_left; - XPointer *to; - int *to_left; - XPointer *args; - int num_args; +euc_mbstocs( + XlcConv conv, + XPointer *from, + int *from_left, + XPointer *to, + int *to_left, + XPointer *args, + int num_args) { - char *tmp_from, *tmp_to; + const char *tmp_from; + char *tmp_to; int tmp_from_left, tmp_to_left; XlcCharSet charset, tmp_charset; XPointer tmp_args[1]; int unconv_num = 0, ret; - /* Determine the charset of the segment and convert one characater: */ tmp_args[0] = (XPointer) &charset; /* charset from euc_mbtocs() */ @@ -416,12 +419,11 @@ euc_mbstocs(conv, from, from_left, to, to_left, args, num_args) tmp_to_left = *to_left; tmp_to = *to; - /* Convert remainder of the segment: */ tmp_args[0] = (XPointer) &tmp_charset; - while( (ret = euc_mbtocs(conv, &tmp_from, &tmp_from_left, &tmp_to, - &tmp_to_left, tmp_args, 1)) >= 0 ) { + while( (ret = euc_mbtocs(conv, (XPointer *) &tmp_from, &tmp_from_left, + (XPointer *) &tmp_to, &tmp_to_left, tmp_args, 1)) >= 0 ) { if (ret > 0) { unconv_num += ret; @@ -431,9 +433,9 @@ euc_mbstocs(conv, from, from_left, to, to_left, args, num_args) if (tmp_charset != charset) /* quit on end of segment */ break; - *from = tmp_from; + *from = (XPointer) tmp_from; *from_left = tmp_from_left; - *to = tmp_to; + *to = (XPointer) tmp_to; *to_left = tmp_to_left; } @@ -445,26 +447,25 @@ euc_mbstocs(conv, from, from_left, to, to_left, args, num_args) static int -euc_wcstocs(conv, from, from_left, to, to_left, args, num_args) - XlcConv conv; - XPointer *from; - int *from_left; - XPointer *to; - int *to_left; - XPointer *args; - int num_args; +euc_wcstocs( + XlcConv conv, + XPointer *from, + int *from_left, + XPointer *to, + int *to_left, + XPointer *args, + int num_args) { XLCd lcd = (XLCd)conv->state; - wchar_t *wcptr = (wchar_t *) *from; - register char *bufptr = (char *) *to; + const wchar_t *wcptr = (const wchar_t *) *from; + char *bufptr = (char *) *to; wchar_t wch; char *tmpptr; - register int length; + int length; CodeSet codeset; Ulong wc_encoding; int wcstr_len = *from_left, buf_len = *to_left; - if (!(codeset = wc_codeset(lcd, *wcptr))) return -1; @@ -506,25 +507,24 @@ euc_wcstocs(conv, from, from_left, to, to_left, args, num_args) static int -euc_cstombs(conv, from, from_left, to, to_left, args, num_args) - XlcConv conv; - XPointer *from; - int *from_left; - XPointer *to; - int *to_left; - XPointer *args; - int num_args; +euc_cstombs( + XlcConv conv, + XPointer *from, + int *from_left, + XPointer *to, + int *to_left, + XPointer *args, + int num_args) { XLCd lcd = (XLCd)conv->state; - register char *csptr = *from; - register char *bufptr = *to; + const char *csptr = *from; + char *bufptr = *to; int csstr_len = *from_left; - register int buf_len = *to_left; + int buf_len = *to_left; int length; CodeSet codeset; int cvt_length; - if (num_args < 1) return -1; @@ -556,7 +556,7 @@ euc_cstombs(conv, from, from_left, to, to_left, args, num_args) } *from_left -= csptr - *from; - *from = csptr; + *from = (XPointer) csptr; if (bufptr) *to += cvt_length; *to_left -= cvt_length; @@ -566,26 +566,25 @@ euc_cstombs(conv, from, from_left, to, to_left, args, num_args) static int -euc_cstowcs(conv, from, from_left, to, to_left, args, num_args) - XlcConv conv; - XPointer *from; - int *from_left; - XPointer *to; - int *to_left; - XPointer *args; - int num_args; +euc_cstowcs( + XlcConv conv, + XPointer *from, + int *from_left, + XPointer *to, + int *to_left, + XPointer *args, + int num_args) { XLCd lcd = (XLCd)conv->state; - register char *csptr = *from; + const char *csptr = *from; wchar_t *bufptr = (wchar_t *) *to; wchar_t *toptr = (wchar_t *) *to; int csstr_len = *from_left; - register int buf_len = *to_left; + int buf_len = *to_left; wchar_t wch; int length; Ulong wc_shift_bits = XLC_GENERIC(lcd, wc_shift_bits); CodeSet codeset; - if (num_args < 1) return -1; @@ -617,21 +616,20 @@ euc_cstowcs(conv, from, from_left, to, to_left, args, num_args) } } *from_left -= csptr - *from; - *from = csptr; + *from = (XPointer) csptr; return 0; } static CodeSet -wc_codeset(lcd, wch) - XLCd lcd; - wchar_t wch; +wc_codeset( + XLCd lcd, + wchar_t wch) { - - register CodeSet *codesets = XLC_GENERIC(lcd, codeset_list); - register int end = XLC_GENERIC(lcd, codeset_num); - register Ulong widech = (Ulong)(wch & XLC_GENERIC(lcd, wc_encode_mask)); + CodeSet *codesets = XLC_GENERIC(lcd, codeset_list); + int end = XLC_GENERIC(lcd, codeset_num); + Ulong widech = (Ulong)(wch & XLC_GENERIC(lcd, wc_encode_mask)); for (; --end >= 0; codesets++) if ( widech == (*codesets)->wc_encoding ) @@ -642,13 +640,13 @@ wc_codeset(lcd, wch) static CodeSet -GetCodeSetFromCharSet(lcd, charset) - XLCd lcd; - XlcCharSet charset; +GetCodeSetFromCharSet( + XLCd lcd, + XlcCharSet charset) { - register CodeSet *codeset = XLC_GENERIC(lcd, codeset_list); - register XlcCharSet *charset_list; - register int codeset_num, num_charsets; + CodeSet *codeset = XLC_GENERIC(lcd, codeset_list); + XlcCharSet *charset_list; + int codeset_num, num_charsets; codeset_num = XLC_GENERIC(lcd, codeset_num); @@ -666,9 +664,9 @@ GetCodeSetFromCharSet(lcd, charset) static XlcConv -create_conv(lcd, methods) - XLCd lcd; - XlcConvMethods methods; +create_conv( + XLCd lcd, + XlcConvMethods methods) { XlcConv conv; @@ -756,8 +754,8 @@ static CTData ctdptr[sizeof(ctdata) / sizeof(CTDataRec)]; * initCTptr(): Set ctdptr[] to point at ctdata[], indexed by codeset_num. */ static void -initCTptr(lcd) - XLCd lcd; +initCTptr( + XLCd lcd) { int num_codesets = XLC_GENERIC(lcd, codeset_num); int num_charsets; @@ -810,27 +808,26 @@ initCTptr(lcd) #define SKIP_P(str) while (*(str) >= 0x30 && *(str) <= 0x3f) (str)++; static int -euc_ctstowcs(conv, from, from_left, to, to_left, args, num_args) - XlcConv conv; - XPointer *from; - int *from_left; - XPointer *to; - int *to_left; - XPointer *args; - int num_args; +euc_ctstowcs( + XlcConv conv, + XPointer *from, + int *from_left, + XPointer *to, + int *to_left, + XPointer *args, + int num_args) { XLCd lcd = (XLCd)conv->state; Ulong wc_shift_bits = XLC_GENERIC(lcd, wc_shift_bits); - register XPointer inbufptr = *from; - XPointer inbuf_base; - register wchar_t *outbufptr = (wchar_t *) *to; + const char *inbufptr = *from; + const char *inbuf_base; + wchar_t *outbufptr = (wchar_t *) *to; wchar_t *outbuf_base = outbufptr; - register int clen, length; - int num_conv; + int clen, length; int unconv_num = 0; unsigned int ct_seglen = 0; Uchar ct_type = 0; - register int shift_mult; + int shift_mult; wchar_t wc_tmp; wchar_t wch; Ulong wc_encoding; @@ -939,22 +936,22 @@ euc_ctstowcs(conv, from, from_left, to, to_left, args, num_args) #define userdef (codeset->cs_num == 3) static int -euc_wcstocts(conv, from, from_left, to, to_left, args, num_args) - XlcConv conv; - XPointer *from; - int *from_left; - XPointer *to; - int *to_left; - XPointer *args; - int num_args; +euc_wcstocts( + XlcConv conv, + XPointer *from, + int *from_left, + XPointer *to, + int *to_left, + XPointer *args, + int num_args) { - register int ct_len = *to_left; - register wchar_t *inbufptr = (wchar_t *) *from; - register char *ctptr = *to; + int ct_len = *to_left; + const wchar_t *inbufptr = (const wchar_t *) *from; + char *ctptr = *to; XPointer ct_base = ctptr; wchar_t wch; - register int length; - register int unconv_num = 0; + int length; + int unconv_num = 0; Uchar tmp; Uchar t1 = 0; int num_conv; @@ -965,7 +962,6 @@ euc_wcstocts(conv, from, from_left, to, to_left, args, num_args) CodeSet codeset; Ulong wc_shift = XLC_GENERIC(lcd, wc_shift_bits); - /* Initial State: */ ct_state.GL_charset = ctdptr[0]; /* Codeset 0 */ ct_state.GR_charset = NULL; @@ -1077,22 +1073,21 @@ euc_wcstocts(conv, from, from_left, to, to_left, args, num_args) #define userdef (ctdp == ctdptr[Userdef]) static int -euc_ctstombs(conv, from, from_left, to, to_left, args, num_args) - XlcConv conv; - XPointer *from; - int *from_left; - XPointer *to; - int *to_left; - XPointer *args; - int num_args; +euc_ctstombs( + XlcConv conv, + XPointer *from, + int *from_left, + XPointer *to, + int *to_left, + XPointer *args, + int num_args) { - register XPointer inbufptr = *from; - register XPointer outbufptr = *to; - XPointer inbuf_base; + char *inbufptr = *from; + XPointer outbufptr = *to; + const char *inbuf_base; XPointer outbuf_base = outbufptr; - register int clen, length; + int clen, length; int unconv_num = 0; - int num_conv; unsigned int ct_seglen = 0; Uchar ct_type = 0; CTData ctdp = &ctdata[0]; /* default */ @@ -1168,8 +1163,9 @@ euc_ctstombs(conv, from, from_left, to, to_left, args, num_args) clen = length; do { - if (byte1) + if (byte1) { if (kanji) { + /* FIXME: assignment of read-only location */ *inbufptr = BIT8ON(*inbufptr); *(inbufptr+1) = BIT8ON(*(inbufptr+1)); } @@ -1179,6 +1175,7 @@ euc_ctstombs(conv, from, from_left, to, to_left, args, num_args) } (*to_left)--; } + } if (save_outbuf == True) { *outbufptr++ = *inbufptr; } @@ -1205,22 +1202,22 @@ euc_ctstombs(conv, from, from_left, to, to_left, args, num_args) static int -euc_mbstocts(conv, from, from_left, to, to_left, args, num_args) - XlcConv conv; - XPointer *from; - int *from_left; - XPointer *to; - int *to_left; - XPointer *args; - int num_args; +euc_mbstocts( + XlcConv conv, + XPointer *from, + int *from_left, + XPointer *to, + int *to_left, + XPointer *args, + int num_args) { - register int ct_len = *to_left; + int ct_len = *to_left; int cs_num; - int clen, length; + int clen, length = 0; int unconv_num = 0; int num_conv; - XPointer inbufptr = *from; - register char *ctptr = *to; + const char *inbufptr = *from; + char *ctptr = *to; XPointer ct_base = ctptr; StateRec ct_state; @@ -1228,7 +1225,6 @@ euc_mbstocts(conv, from, from_left, to, to_left, args, num_args) XLCd lcd = (XLCd) conv->state; int codeset_num = XLC_GENERIC(lcd, codeset_num); - /* Initial State: */ ct_state.GL_charset = NULL; ct_state.GR_charset = NULL; @@ -1325,8 +1321,8 @@ euc_mbstocts(conv, from, from_left, to, to_left, args, num_args) static void -close_converter(conv) - XlcConv conv; +close_converter( + XlcConv conv) { Xfree((char *) conv); } @@ -1350,122 +1346,118 @@ static XlcConvMethodsRec conv_methods[] = { static XlcConv -open_mbstocs(from_lcd, from_type, to_lcd, to_type) - XLCd from_lcd; - char *from_type; - XLCd to_lcd; - char *to_type; +open_mbstocs( + XLCd from_lcd, + const char *from_type, + XLCd to_lcd, + const char *to_type) { return create_conv(from_lcd, &conv_methods[MBSTOCS]); } static XlcConv -open_wcstocs(from_lcd, from_type, to_lcd, to_type) - XLCd from_lcd; - char *from_type; - XLCd to_lcd; - char *to_type; +open_wcstocs( + XLCd from_lcd, + const char *from_type, + XLCd to_lcd, + const char *to_type) { return create_conv(from_lcd, &conv_methods[WCSTOCS]); } static XlcConv -open_mbtocs(from_lcd, from_type, to_lcd, to_type) - XLCd from_lcd; - char *from_type; - XLCd to_lcd; - char *to_type; +open_mbtocs( + XLCd from_lcd, + const char *from_type, + XLCd to_lcd, + const char *to_type) { return create_conv(from_lcd, &conv_methods[MBTOCS]); } static XlcConv -open_cstombs(from_lcd, from_type, to_lcd, to_type) - XLCd from_lcd; - char *from_type; - XLCd to_lcd; - char *to_type; +open_cstombs( + XLCd from_lcd, + const char *from_type, + XLCd to_lcd, + const char *to_type) { return create_conv(from_lcd, &conv_methods[CSTOMBS]); } static XlcConv -open_cstowcs(from_lcd, from_type, to_lcd, to_type) - XLCd from_lcd; - char *from_type; - XLCd to_lcd; - char *to_type; +open_cstowcs( + XLCd from_lcd, + const char *from_type, + XLCd to_lcd, + const char *to_type) { return create_conv(from_lcd, &conv_methods[CSTOWCS]); } static XlcConv -open_mbstowcs(from_lcd, from_type, to_lcd, to_type) - XLCd from_lcd; - char *from_type; - XLCd to_lcd; - char *to_type; +open_mbstowcs( + XLCd from_lcd, + const char *from_type, + XLCd to_lcd, + const char *to_type) { return create_conv(from_lcd, &conv_methods[MBSTOWCS]); } static XlcConv -open_wcstombs(from_lcd, from_type, to_lcd, to_type) - XLCd from_lcd; - char *from_type; - XLCd to_lcd; - char *to_type; +open_wcstombs( + XLCd from_lcd, + const char *from_type, + XLCd to_lcd, + const char *to_type) { return create_conv(from_lcd, &conv_methods[WCSTOMBS]); } static XlcConv -open_ctstowcs(from_lcd, from_type, to_lcd, to_type) - XLCd from_lcd; - char *from_type; - XLCd to_lcd; - char *to_type; +open_ctstowcs( + XLCd from_lcd, + const char *from_type, + XLCd to_lcd, + const char *to_type) { return create_conv(from_lcd, &conv_methods[CTSTOWCS]); } static XlcConv -open_ctstombs(from_lcd, from_type, to_lcd, to_type) - XLCd from_lcd; - char *from_type; - XLCd to_lcd; - char *to_type; +open_ctstombs( + XLCd from_lcd, + const char *from_type, + XLCd to_lcd, + const char *to_type) { return create_conv(from_lcd, &conv_methods[CTSTOMBS]); } static XlcConv -open_wcstocts(from_lcd, from_type, to_lcd, to_type) - XLCd from_lcd; - char *from_type; - XLCd to_lcd; - char *to_type; +open_wcstocts( + XLCd from_lcd, + const char *from_type, + XLCd to_lcd, + const char *to_type) { return create_conv(from_lcd, &conv_methods[WCSTOCTS]); } static XlcConv -open_mbstocts(from_lcd, from_type, to_lcd, to_type) - XLCd from_lcd; - char *from_type; - XLCd to_lcd; - char *to_type; +open_mbstocts( + XLCd from_lcd, + const char *from_type, + XLCd to_lcd, + const char *to_type) { return create_conv(from_lcd, &conv_methods[MBSTOCTS]); } XLCd -#ifdef DYNAMIC_LOAD -_XlcGenericLoader(name) -#else -_XlcEucLoader(name) -#endif - char *name; +_XlcEucLoader( + const char *name) { XLCd lcd; @@ -1473,7 +1465,6 @@ _XlcEucLoader(name) if (lcd == NULL) return lcd; - if (!XLC_PUBLIC_PART(lcd)->codeset || (_XlcNCompareISOLatin1(XLC_PUBLIC_PART(lcd)->codeset, "euc", 3))) { _XlcDestroyLC(lcd); @@ -1497,6 +1488,8 @@ _XlcEucLoader(name) _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNMultiByte, open_wcstombs); #endif + _XlcAddUtf8Converters(lcd); + return lcd; } diff --git a/modules/lc/xlocale/lcJis.c b/modules/lc/xlocale/lcJis.c index eae9ee9..9f93773 100644 --- a/modules/lc/xlocale/lcJis.c +++ b/modules/lc/xlocale/lcJis.c @@ -23,6 +23,14 @@ * Author: Katsuhisa Yano TOSHIBA Corp. * mopi@osa.ilab.toshiba.co.jp */ +/* $XFree86: xc/lib/X11/lcJis.c,v 1.9 2002/04/10 16:20:06 tsi Exp $ */ + +/* + * A Japanese JIS locale. + * Supports: all locales with codeset JIS7. + * How: Provides converters for JIS. + * Platforms: Only those defining X_LOCALE (only Lynx, Linux-libc5, OS/2). + */ #ifdef X_LOCALE @@ -30,7 +38,7 @@ #include "XlcGeneric.h" #include <stdio.h> -#if !defined(X_NOT_STDC_ENV) && !defined(macII) && !defined(X_LOCALE) +#if !defined(macII) && !defined(X_LOCALE) #define STDCVT #endif @@ -42,12 +50,12 @@ typedef struct _StateRec { } StateRec, *State; static void -init_state(conv) - XlcConv conv; +init_state( + XlcConv conv) { - register State state = (State) conv->state; - register XLCdGenericPart *gen = XLC_GENERIC_PART(state->lcd); - register CodeSet codeset; + State state = (State) conv->state; + XLCdGenericPart *gen = XLC_GENERIC_PART(state->lcd); + CodeSet codeset; codeset = gen->initial_state_GL; if (codeset && codeset->charset_list) @@ -57,17 +65,17 @@ init_state(conv) state->GR_charset = *codeset->charset_list; if (state->GL_charset == NULL) - if (codeset = *gen->codeset_list) + if ((codeset = *gen->codeset_list) != NULL) state->GL_charset = *codeset->charset_list; } static int -compare(src, encoding, length) - register char *src; - register char *encoding; - register int length; +compare( + const char *src, + const char *encoding, + int length) { - char *start = src; + const char *start = src; while (length-- > 0) { if (*src++ != *encoding++) @@ -80,32 +88,34 @@ compare(src, encoding, length) } static int -mbtocs(conv, from, from_left, to, to_left, args, num_args) - XlcConv conv; - XPointer *from; - int *from_left; - XPointer *to; - int *to_left; - XPointer *args; - int num_args; +mbtocs( + XlcConv conv, + XPointer *from, + int *from_left, + XPointer *to, + int *to_left, + XPointer *args, + int num_args) { State state = (State) conv->state; XLCd lcd = state->lcd; - register char *src, *dst; - unsigned char ch, *mb_parse_table; + const char *src; + char *dst; + unsigned char *mb_parse_table; ParseInfo *parse_list, parse_info; XlcCharSet charset; int length, number, encoding_len = 0; - register int i; + int i; - src = *((char **) from); + src = *((const char **) from); dst = *((char **) to); - if (mb_parse_table = XLC_GENERIC(lcd, mb_parse_table)) { + mb_parse_table = XLC_GENERIC(lcd, mb_parse_table); + if (mb_parse_table != NULL) { number = mb_parse_table[(unsigned char) *src]; if (number > 0) { parse_list = XLC_GENERIC(lcd, mb_parse_list) + number - 1; - for ( ; parse_info = *parse_list; parse_list++) { + for ( ; (parse_info = *parse_list) != NULL; parse_list++) { encoding_len = compare(src, parse_info->encoding, *from_left); if (encoding_len > 0) { switch (parse_info->type) { @@ -129,6 +139,8 @@ mbtocs(conv, from, from_left, to, to_left, args, num_args) case E_GR: charset = state->GR_charset; goto found; + default: + break; } } } @@ -176,14 +188,14 @@ end: } static int -mbstocs(conv, from, from_left, to, to_left, args, num_args) - XlcConv conv; - XPointer *from; - int *from_left; - XPointer *to; - int *to_left; - XPointer *args; - int num_args; +mbstocs( + XlcConv conv, + XPointer *from, + int *from_left, + XPointer *to, + int *to_left, + XPointer *args, + int num_args) { XlcCharSet charset = NULL; XPointer tmp_args[2], save_from = *from; @@ -212,13 +224,13 @@ mbstocs(conv, from, from_left, to, to_left, args, num_args) } static CodeSet -wc_parse_codeset(lcd, wcstr) - XLCd lcd; - wchar_t *wcstr; +wc_parse_codeset( + XLCd lcd, + const wchar_t *wcstr) { - register CodeSet *codeset; + CodeSet *codeset; unsigned long wc_encoding; - register int num; + int num; wc_encoding = *wcstr & XLC_GENERIC(lcd, wc_encode_mask); num = XLC_GENERIC(lcd, codeset_num); @@ -233,22 +245,22 @@ wc_parse_codeset(lcd, wcstr) } static int -wcstocs(conv, from, from_left, to, to_left, args, num_args) - XlcConv conv; - XPointer *from; - int *from_left; - XPointer *to; - int *to_left; - XPointer *args; - int num_args; +wcstocs( + XlcConv conv, + XPointer *from, + int *from_left, + XPointer *to, + int *to_left, + XPointer *args, + int num_args) { State state = (State) conv->state; XLCd lcd = state->lcd; - wchar_t *wcptr; - register char *bufptr; - register wchar_t wch; + const wchar_t *wcptr; + char *bufptr; + wchar_t wch; char *tmpptr; - register int length; + int length; CodeSet codeset; unsigned long wc_encoding; int wcstr_len, buf_len; @@ -256,7 +268,7 @@ wcstocs(conv, from, from_left, to, to_left, args, num_args) if (from == NULL || *from == NULL) return 0; - wcptr = *((wchar_t **) from); + wcptr = *((const wchar_t **) from); bufptr = *((char **) to); wcstr_len = *from_left; buf_len = *to_left; @@ -309,13 +321,13 @@ wcstocs(conv, from, from_left, to, to_left, args, num_args) } static CodeSet -GetCodeSetFromCharSet(lcd, charset) - XLCd lcd; - XlcCharSet charset; +GetCodeSetFromCharSet( + XLCd lcd, + XlcCharSet charset) { - register CodeSet *codeset = XLC_GENERIC(lcd, codeset_list); - register XlcCharSet *charset_list; - register int codeset_num, num_charsets; + CodeSet *codeset = XLC_GENERIC(lcd, codeset_list); + XlcCharSet *charset_list; + int codeset_num, num_charsets; codeset_num = XLC_GENERIC(lcd, codeset_num); @@ -332,27 +344,27 @@ GetCodeSetFromCharSet(lcd, charset) } static int -cstombs(conv, from, from_left, to, to_left, args, num_args) - XlcConv conv; - XPointer *from; - int *from_left; - XPointer *to; - int *to_left; - XPointer *args; - int num_args; +cstombs( + XlcConv conv, + XPointer *from, + int *from_left, + XPointer *to, + int *to_left, + XPointer *args, + int num_args) { State state = (State) conv->state; - register char *csptr; - register char *bufptr; + const char *csptr; + char *bufptr; int csstr_len; - register int buf_len; + int buf_len; int num, encoding_len = 0; CodeSet codeset; XlcCharSet charset; EncodingType type; int cvt_length; - csptr = *((char **) from); + csptr = *((const char **) from); bufptr = *((char **) to); csstr_len = *from_left; buf_len = *to_left; @@ -396,6 +408,8 @@ cstombs(conv, from, from_left, to, to_left, args, num_args) else state->GR_charset = charset; break; + default: + break; } } @@ -436,27 +450,27 @@ cstombs(conv, from, from_left, to, to_left, args, num_args) } static int -cstowcs(conv, from, from_left, to, to_left, args, num_args) - XlcConv conv; - XPointer *from; - int *from_left; - XPointer *to; - int *to_left; - XPointer *args; - int num_args; +cstowcs( + XlcConv conv, + XPointer *from, + int *from_left, + XPointer *to, + int *to_left, + XPointer *args, + int num_args) { State state = (State) conv->state; XLCd lcd = state->lcd; - register char *csptr; + const char *csptr; wchar_t *bufptr; int csstr_len; - register int buf_len; - register wchar_t wch; + int buf_len; + wchar_t wch; unsigned long code_mask, wc_encoding; int num, length, wc_shift_bits; CodeSet codeset; - csptr = *((char **) from); + csptr = *((const char **) from); bufptr = *((wchar_t **) to); csstr_len = *from_left; buf_len = *to_left; @@ -501,8 +515,8 @@ cstowcs(conv, from, from_left, to, to_left, args, num_args) static void -close_converter(conv) - XlcConv conv; +close_converter( + XlcConv conv) { if (conv->state) { Xfree((char *) conv->state); @@ -512,9 +526,9 @@ close_converter(conv) } static XlcConv -create_conv(lcd, methods) - XLCd lcd; - XlcConvMethods methods; +create_conv( + XLCd lcd, + XlcConvMethods methods) { XlcConv conv; State state; @@ -551,14 +565,14 @@ static XlcConvMethodsRec mbstocs_methods = { close_converter, mbstocs, NULL -} ; +}; static XlcConv -open_mbstocs(from_lcd, from_type, to_lcd, to_type) - XLCd from_lcd; - char *from_type; - XLCd to_lcd; - char *to_type; +open_mbstocs( + XLCd from_lcd, + const char *from_type, + XLCd to_lcd, + const char *to_type) { return create_conv(from_lcd, &mbstocs_methods); } @@ -567,14 +581,14 @@ static XlcConvMethodsRec wcstocs_methods = { close_converter, wcstocs, NULL -} ; +}; static XlcConv -open_wcstocs(from_lcd, from_type, to_lcd, to_type) - XLCd from_lcd; - char *from_type; - XLCd to_lcd; - char *to_type; +open_wcstocs( + XLCd from_lcd, + const char *from_type, + XLCd to_lcd, + const char *to_type) { return create_conv(from_lcd, &wcstocs_methods); } @@ -583,14 +597,14 @@ static XlcConvMethodsRec mbtocs_methods = { close_converter, mbtocs, NULL -} ; +}; static XlcConv -open_mbtocs(from_lcd, from_type, to_lcd, to_type) - XLCd from_lcd; - char *from_type; - XLCd to_lcd; - char *to_type; +open_mbtocs( + XLCd from_lcd, + const char *from_type, + XLCd to_lcd, + const char *to_type) { return create_conv(from_lcd, &mbtocs_methods); } @@ -599,14 +613,14 @@ static XlcConvMethodsRec cstombs_methods = { close_converter, cstombs, NULL -} ; +}; static XlcConv -open_cstombs(from_lcd, from_type, to_lcd, to_type) - XLCd from_lcd; - char *from_type; - XLCd to_lcd; - char *to_type; +open_cstombs( + XLCd from_lcd, + const char *from_type, + XLCd to_lcd, + const char *to_type) { return create_conv(from_lcd, &cstombs_methods); } @@ -615,30 +629,30 @@ static XlcConvMethodsRec cstowcs_methods = { close_converter, cstowcs, NULL -} ; +}; static XlcConv -open_cstowcs(from_lcd, from_type, to_lcd, to_type) - XLCd from_lcd; - char *from_type; - XLCd to_lcd; - char *to_type; +open_cstowcs( + XLCd from_lcd, + const char *from_type, + XLCd to_lcd, + const char *to_type) { return create_conv(from_lcd, &cstowcs_methods); } #ifdef STDCVT static int -stdc_mbstowcs(conv, from, from_left, to, to_left, args, num_args) - XlcConv conv; - XPointer *from; - int *from_left; - XPointer *to; - int *to_left; - XPointer *args; - int num_args; +stdc_mbstowcs( + XlcConv conv, + XPointer *from, + int *from_left, + XPointer *to, + int *to_left, + XPointer *args, + int num_args) { - char *src = *((char **) from); + const char *src = *((const char **) from); wchar_t *dst = *((wchar_t **) to); int src_left = *from_left; int dst_left = *to_left; @@ -675,16 +689,16 @@ stdc_mbstowcs(conv, from, from_left, to, to_left, args, num_args) } static int -stdc_wcstombs(conv, from, from_left, to, to_left, args, num_args) - XlcConv conv; - XPointer *from; - int *from_left; - XPointer *to; - int *to_left; - XPointer *args; - int num_args; +stdc_wcstombs( + XlcConv conv, + XPointer *from, + int *from_left, + XPointer *to, + int *to_left, + XPointer *args, + int num_args) { - wchar_t *src = *((wchar_t **) from); + const wchar_t *src = *((const wchar_t **) from); char *dst = *((char **) to); int src_left = *from_left; int dst_left = *to_left; @@ -719,16 +733,17 @@ stdc_wcstombs(conv, from, from_left, to, to_left, args, num_args) } static int -stdc_wcstocs(conv, from, from_left, to, to_left, args, num_args) - XlcConv conv; - XPointer *from; - int *from_left; - XPointer *to; - int *to_left; - XPointer *args; - int num_args; +stdc_wcstocs( + XlcConv conv, + XPointer *from, + int *from_left, + XPointer *to, + int *to_left, + XPointer *args, + int num_args) { - wchar_t wch, *src = *((wchar_t **) from); + const wchar_t *src = *((const wchar_t **) from); + wchar_t wch; XlcCharSet charset = NULL; XPointer tmp_args[2], tmp_from, save_from = *from; char tmp[32]; @@ -779,14 +794,14 @@ stdc_wcstocs(conv, from, from_left, to, to_left, args, num_args) #define FreeLocalBuf(ptr) if (ptr != local_buf) Xfree(ptr) static int -stdc_cstowcs(conv, from, from_left, to, to_left, args, num_args) - XlcConv conv; - XPointer *from; - int *from_left; - XPointer *to; - int *to_left; - XPointer *args; - int num_args; +stdc_cstowcs( + XlcConv conv, + XPointer *from, + int *from_left, + XPointer *to, + int *to_left, + XPointer *args, + int num_args) { XLCd lcd = ((State) conv->state)->lcd; DefineLocalBuf; @@ -817,14 +832,14 @@ static XlcConvMethodsRec stdc_mbstowcs_methods = { close_converter, stdc_mbstowcs, NULL -} ; +}; static XlcConv -open_stdc_mbstowcs(from_lcd, from_type, to_lcd, to_type) - XLCd from_lcd; - char *from_type; - XLCd to_lcd; - char *to_type; +open_stdc_mbstowcs( + XLCd from_lcd, + const char *from_type, + XLCd to_lcd, + const char *to_type) { return create_conv(from_lcd, &stdc_mbstowcs_methods); } @@ -833,14 +848,14 @@ static XlcConvMethodsRec stdc_wcstombs_methods = { close_converter, stdc_wcstombs, NULL -} ; +}; static XlcConv -open_stdc_wcstombs(from_lcd, from_type, to_lcd, to_type) - XLCd from_lcd; - char *from_type; - XLCd to_lcd; - char *to_type; +open_stdc_wcstombs( + XLCd from_lcd, + const char *from_type, + XLCd to_lcd, + const char *to_type) { return create_conv(from_lcd, &stdc_wcstombs_methods); } @@ -849,14 +864,14 @@ static XlcConvMethodsRec stdc_wcstocs_methods = { close_converter, stdc_wcstocs, NULL -} ; +}; static XlcConv -open_stdc_wcstocs(from_lcd, from_type, to_lcd, to_type) - XLCd from_lcd; - char *from_type; - XLCd to_lcd; - char *to_type; +open_stdc_wcstocs( + XLCd from_lcd, + const char *from_type, + XLCd to_lcd, + const char *to_type) { return create_conv(from_lcd, &stdc_wcstocs_methods); } @@ -865,25 +880,27 @@ static XlcConvMethodsRec stdc_cstowcs_methods = { close_converter, stdc_cstowcs, NULL -} ; +}; static XlcConv -open_stdc_cstowcs(from_lcd, from_type, to_lcd, to_type) - XLCd from_lcd; - char *from_type; - XLCd to_lcd; - char *to_type; +open_stdc_cstowcs( + XLCd from_lcd, + const char *from_type, + XLCd to_lcd, + const char *to_type) { return create_conv(from_lcd, &stdc_cstowcs_methods); } #endif /* STDCVT */ XLCd -_XlcJisLoader(name) - char *name; +_XlcJisLoader( + const char *name) { XLCd lcd; +#ifdef STDCVT XLCdGenericPart *gen; +#endif lcd = _XlcCreateLC(name, _XlcGenericMethods); if (lcd == NULL) @@ -917,6 +934,8 @@ _XlcJisLoader(name) } #endif + _XlcAddUtf8Converters(lcd); + return lcd; } diff --git a/modules/lc/xlocale/lcSjis.c b/modules/lc/xlocale/lcSjis.c index 95d9ed8..1bbed86 100644 --- a/modules/lc/xlocale/lcSjis.c +++ b/modules/lc/xlocale/lcSjis.c @@ -35,6 +35,14 @@ OR PERFORMANCE OF THIS SOFTWARE. makoto@sm.sony.co.jp *****************************************************************/ +/* $XFree86: xc/lib/X11/lcSjis.c,v 3.9 2002/04/10 16:20:06 tsi Exp $ */ + +/* + * A Japanese SJIS locale. + * Supports: all locales with codeset SJIS. + * How: Provides converters for SJIS. + * Platforms: Only those defining X_LOCALE (only Lynx, Linux-libc5, OS/2). + */ #ifdef X_LOCALE @@ -92,9 +100,9 @@ typedef unsigned int Uint; #define BIT8ON(c) ((c) | GR) -static void jis_to_sjis(); -static void sjis_to_jis(); -static CodeSet wc_codeset(); +static void jis_to_sjis (Uchar *p1, Uchar *p2); +static void sjis_to_jis (Uchar *p1, Uchar *p2); +static CodeSet wc_codeset (XLCd lcd, wchar_t wch); /* @@ -114,21 +122,21 @@ static CodeSet wc_codeset(); static int -sjis_mbstowcs(conv, from, from_left, to, to_left, args, num_args) - XlcConv conv; - XPointer *from; - int *from_left; - XPointer *to; - int *to_left; - XPointer *args; - int num_args; +sjis_mbstowcs( + XlcConv conv, + XPointer *from, + int *from_left, + XPointer *to, + int *to_left, + XPointer *args, + int num_args) { XLCd lcd = (XLCd)conv->state; - register int chr_len = 0; - register int shift_mult = 0; - register Uint chrcode = 0; + int chr_len = 0; + int shift_mult = 0; + Uint chrcode = 0; Uchar ch, ch2; Uint wc_encode = 0; @@ -137,11 +145,11 @@ sjis_mbstowcs(conv, from, from_left, to, to_left, args, num_args) Bool new_char; int firstbyte; - int length; + int length = 0; int num_conv; int unconv_num = 0; - XPointer inbufptr = *from; + const char *inbufptr = *from; wchar_t *outbufptr = (wchar_t *) *to; wchar_t *outbuf_base = outbufptr; @@ -149,7 +157,6 @@ sjis_mbstowcs(conv, from, from_left, to, to_left, args, num_args) int codeset_num = XLC_GENERIC(lcd, codeset_num); Ulong wc_shift = XLC_GENERIC(lcd, wc_shift_bits); - if (*from_left > *to_left) *from_left = *to_left; @@ -254,20 +261,20 @@ sjis_mbstowcs(conv, from, from_left, to, to_left, args, num_args) #define byte2 (byte1 == 0) static int -sjis_wcstombs(conv, from, from_left, to, to_left, args, num_args) - XlcConv conv; - XPointer *from; - int *from_left; - XPointer *to; - int *to_left; - XPointer *args; - int num_args; +sjis_wcstombs( + XlcConv conv, + XPointer *from, + int *from_left, + XPointer *to, + int *to_left, + XPointer *args, + int num_args) { - register wchar_t *inbufptr = (wchar_t *) *from; - register XPointer outbufptr = *to; + const wchar_t *inbufptr = (const wchar_t *) *from; + XPointer outbufptr = *to; XPointer outbuf_base = outbufptr; wchar_t wch; - register int length; + int length; Uchar tmp; Uchar t1, t2; int num_conv; @@ -277,8 +284,6 @@ sjis_wcstombs(conv, from, from_left, to, to_left, args, num_args) CodeSet codeset; Ulong wc_shift = XLC_GENERIC(lcd, wc_shift_bits); - - if (*from_left > *to_left) *from_left = *to_left; @@ -333,43 +338,43 @@ sjis_wcstombs(conv, from, from_left, to, to_left, args, num_args) * sjis<->jis conversion for widechar kanji (See Note at top of file) */ static void -sjis_to_jis(p1, p2) - Uchar *p1; - Uchar *p2; +sjis_to_jis( + Uchar *p1, + Uchar *p2) { - register Uchar c1 = *p1; - register Uchar c2 = *p2; - register Uchar adjust = c2 < 0x9f; - register Uchar rowOffset = c1 < 0xa0 ? 0x70 : 0xb0; - register Uchar cellOffset = adjust ? (0x1f + (c2 > 0x7f)) : 0x7e; + Uchar c1 = *p1; + Uchar c2 = *p2; + Uchar adjust = c2 < 0x9f; + Uchar rowOffset = c1 < 0xa0 ? 0x70 : 0xb0; + Uchar cellOffset = adjust ? (0x1f + (c2 > 0x7f)) : 0x7e; *p1 = ((c1 - rowOffset) << 1) - adjust; *p2 -= cellOffset; } static void -jis_to_sjis(p1, p2) - Uchar *p1; - Uchar *p2; +jis_to_sjis( + Uchar *p1, + Uchar *p2) { - register Uchar c1 = *p1; - register Uchar c2 = *p2; - register Uchar rowOffset = c1 < 0x5f ? 0x70 : 0xb0; - register Uchar cellOffset = c1 % 2 ? 0x1f + (c2 > 0x5f) : 0x7e; + Uchar c1 = *p1; + Uchar c2 = *p2; + Uchar rowOffset = c1 < 0x5f ? 0x70 : 0xb0; + Uchar cellOffset = c1 % 2 ? 0x1f + (c2 > 0x5f) : 0x7e; *p1 = ((Uchar)(c1 + 1) >> 1) + rowOffset; *p2 = c2 + cellOffset; } static CodeSet -wc_codeset(lcd, wch) - XLCd lcd; - wchar_t wch; +wc_codeset( + XLCd lcd, + wchar_t wch) { - register CodeSet *codesets = XLC_GENERIC(lcd, codeset_list); + CodeSet *codesets = XLC_GENERIC(lcd, codeset_list); #if !defined(__sony_news) || defined(SVR4) - register int end = XLC_GENERIC(lcd, codeset_num); - register Ulong widech = (Ulong)(wch & XLC_GENERIC(lcd, wc_encode_mask)); + int end = XLC_GENERIC(lcd, codeset_num); + Ulong widech = (Ulong)(wch & XLC_GENERIC(lcd, wc_encode_mask)); for (; --end >= 0; codesets++) if ( widech == (*codesets)->wc_encoding ) @@ -387,24 +392,24 @@ wc_codeset(lcd, wch) static int -sjis_mbtocs(conv, from, from_left, to, to_left, args, num_args) - XlcConv conv; - XPointer *from; - int *from_left; - XPointer *to; - int *to_left; - XPointer *args; - int num_args; +sjis_mbtocs( + XlcConv conv, + XPointer *from, + int *from_left, + XPointer *to, + int *to_left, + XPointer *args, + int num_args) { XLCd lcd = (XLCd)conv->state; XlcCharSet charset = NULL; int char_size = 0; int unconv_num = 0; - register char *src = *from, *dst = *to; + const char *src = *from; + char *dst = *to; CodeSet *codesets = XLC_GENERIC(lcd, codeset_list); int codeset_num = XLC_GENERIC(lcd, codeset_num); - if (iskanji(*src)) { if (KANJI_CODESET >= codeset_num) return -1; @@ -463,8 +468,8 @@ sjis_mbtocs(conv, from, from_left, to, to_left, args, num_args) *from_left -= char_size; *to_left -= char_size; - *to = dst; - *from = src; + *to = (XPointer) dst; + *from = (XPointer) src; if (num_args > 0) *((XlcCharSet *) args[0]) = charset; @@ -474,23 +479,22 @@ sjis_mbtocs(conv, from, from_left, to, to_left, args, num_args) static int -sjis_mbstocs(conv, from, from_left, to, to_left, args, num_args) - XlcConv conv; - XPointer *from; - int *from_left; - XPointer *to; - int *to_left; - XPointer *args; - int num_args; +sjis_mbstocs( + XlcConv conv, + XPointer *from, + int *from_left, + XPointer *to, + int *to_left, + XPointer *args, + int num_args) { - char *tmp_from, *tmp_to; + const char *tmp_from; + char *tmp_to; int tmp_from_left, tmp_to_left; XlcCharSet charset, tmp_charset; XPointer tmp_args[1]; int unconv_num = 0, ret; - - /* Determine the charset of the segment and convert one character: */ tmp_args[0] = (XPointer) &charset; /* charset from sjis_mbtocs() */ @@ -508,8 +512,8 @@ sjis_mbstocs(conv, from, from_left, to, to_left, args, num_args) /* Convert remainder of the segment: */ tmp_args[0] = (XPointer) &tmp_charset; - while( (ret = sjis_mbtocs(conv, &tmp_from, &tmp_from_left, &tmp_to, - &tmp_to_left, tmp_args, 1)) >= 0 ) { + while( (ret = sjis_mbtocs(conv, (XPointer *) &tmp_from, &tmp_from_left, + (XPointer *) &tmp_to, &tmp_to_left, tmp_args, 1)) >= 0 ) { if (ret > 0) { unconv_num += ret; @@ -519,9 +523,9 @@ sjis_mbstocs(conv, from, from_left, to, to_left, args, num_args) if (tmp_charset != charset) /* quit on end of segment */ break; - *from = tmp_from; + *from = (XPointer) tmp_from; *from_left = tmp_from_left; - *to = tmp_to; + *to = (XPointer) tmp_to; *to_left = tmp_to_left; } @@ -532,27 +536,26 @@ sjis_mbstocs(conv, from, from_left, to, to_left, args, num_args) } static int -sjis_wcstocs(conv, from, from_left, to, to_left, args, num_args) - XlcConv conv; - XPointer *from; - int *from_left; - XPointer *to; - int *to_left; - XPointer *args; - int num_args; +sjis_wcstocs( + XlcConv conv, + XPointer *from, + int *from_left, + XPointer *to, + int *to_left, + XPointer *args, + int num_args) { XLCd lcd = (XLCd) conv->state; - wchar_t *wcptr = *((wchar_t **)from); - register char *bufptr = *((char **) to); + const wchar_t *wcptr = *((const wchar_t **)from); + char *bufptr = *((char **) to); wchar_t wch; char *tmpptr; - register int length; + int length; CodeSet codeset; Ulong wc_encoding; int buf_len = *to_left; int wcstr_len = *from_left; - if (!(codeset = wc_codeset(lcd, *wcptr))) return -1; @@ -612,13 +615,13 @@ sjis_wcstocs(conv, from, from_left, to, to_left, args, num_args) } static CodeSet -GetCodeSetFromCharSet(lcd, charset) - XLCd lcd; - XlcCharSet charset; +GetCodeSetFromCharSet( + XLCd lcd, + XlcCharSet charset) { - register CodeSet *codeset = XLC_GENERIC(lcd, codeset_list); - register XlcCharSet *charset_list; - register int codeset_num, num_charsets; + CodeSet *codeset = XLC_GENERIC(lcd, codeset_list); + XlcCharSet *charset_list; + int codeset_num, num_charsets; codeset_num = XLC_GENERIC(lcd, codeset_num); @@ -636,26 +639,24 @@ GetCodeSetFromCharSet(lcd, charset) static int -sjis_cstombs(conv, from, from_left, to, to_left, args, num_args) - XlcConv conv; - char **from; - int *from_left; - char **to; - int *to_left; - XPointer *args; - int num_args; +sjis_cstombs( + XlcConv conv, + char **from, + int *from_left, + char **to, + int *to_left, + XPointer *args, + int num_args) { XLCd lcd = (XLCd) conv->state; - register char *csptr = *from; - register char *bufptr = *to; + const char *csptr = *from; + char *bufptr = *to; int csstr_len = *from_left; - register int buf_len = *to_left; + int buf_len = *to_left; int length; CodeSet codeset; - EncodingType type; int cvt_length = 0; - if (num_args < 1) return -1; @@ -682,7 +683,7 @@ sjis_cstombs(conv, from, from_left, to, to_left, args, num_args) } *from_left -= csptr - *from; - *from = csptr; + *from = (XPointer) csptr; if (bufptr) *to += cvt_length; @@ -693,27 +694,26 @@ sjis_cstombs(conv, from, from_left, to, to_left, args, num_args) } static int -sjis_cstowcs(conv, from, from_left, to, to_left, args, num_args) - XlcConv conv; - XPointer *from; - int *from_left; - XPointer *to; - int *to_left; - XPointer *args; - int num_args; +sjis_cstowcs( + XlcConv conv, + XPointer *from, + int *from_left, + XPointer *to, + int *to_left, + XPointer *args, + int num_args) { XLCd lcd = (XLCd) conv->state; - register char *csptr = (char *) *from; + const char *csptr = (const char *) *from; wchar_t *bufptr = (wchar_t *) *to; wchar_t *toptr = (wchar_t *) *to; int csstr_len = *from_left; - register int buf_len = *to_left; + int buf_len = *to_left; wchar_t wch; int length; Ulong wc_shift_bits = (int)XLC_GENERIC(lcd, wc_shift_bits); CodeSet codeset; - if (num_args < 1) return -1; @@ -745,7 +745,7 @@ sjis_cstowcs(conv, from, from_left, to, to_left, args, num_args) } *from_left -= csptr - *from; - *from = csptr; + *from = (XPointer) csptr; return 0; } @@ -828,8 +828,8 @@ static CTData ctd_endp = ctdata + ((sizeof(ctdata) / sizeof(CTDataRec))) - 1; * initCTptr(): Set ctptr[] to point at ctdata[], indexed by codeset_num. */ static void -initCTptr(lcd) - XLCd lcd; +initCTptr( + XLCd lcd) { int num_codesets = XLC_GENERIC(lcd, codeset_num); int num_charsets; @@ -874,36 +874,34 @@ initCTptr(lcd) static int -sjis_mbstocts(conv, from, from_left, to, to_left, args, num_args) - XlcConv conv; - XPointer *from; - int *from_left; - XPointer *to; - int *to_left; - XPointer *args; - int num_args; +sjis_mbstocts( + XlcConv conv, + XPointer *from, + int *from_left, + XPointer *to, + int *to_left, + XPointer *args, + int num_args) { - register int ct_len = *to_left; + int ct_len = *to_left; int cs_num; int clen; int unconv_num = 0; int num_conv; - XPointer inbufptr = *from; - register char *ctptr = *to; + const char *inbufptr = *from; + char *ctptr = *to; XPointer ct_base = ctptr; StateRec ct_state; - CTData charset; + CTData charset = NULL; XLCd lcd = (XLCd) conv->state; int codeset_num = XLC_GENERIC(lcd, codeset_num); - /* Initial State: */ ct_state.GL_charset = ctdptr[Ascii]; ct_state.GR_charset = NULL; - if (*from_left > *to_left) *from_left = *to_left; @@ -1009,21 +1007,21 @@ sjis_mbstocts(conv, from, from_left, to, to_left, args, num_args) #define byte2 (byte1 == 0) static int -sjis_wcstocts(conv, from, from_left, to, to_left, args, num_args) - XlcConv conv; - XPointer *from; - int *from_left; - XPointer *to; - int *to_left; - XPointer *args; - int num_args; +sjis_wcstocts( + XlcConv conv, + XPointer *from, + int *from_left, + XPointer *to, + int *to_left, + XPointer *args, + int num_args) { - register int ct_len = *to_left; - register wchar_t *inbufptr = (wchar_t *) *from; - register char *ctptr = *to; + int ct_len = *to_left; + const wchar_t *inbufptr = (const wchar_t *) *from; + char *ctptr = *to; XPointer ct_base = ctptr; wchar_t wch; - register int length; + int length; Uchar tmp; Uchar t1 = 0; int num_conv; @@ -1130,27 +1128,26 @@ sjis_wcstocts(conv, from, from_left, to, to_left, args, num_args) #define SKIP_P(str) while (*(str) >= 0x30 && *(str) <= 0x3f) (str)++; static int -sjis_ctstombs(conv, from, from_left, to, to_left, args, num_args) - XlcConv conv; - XPointer *from; - int *from_left; - XPointer *to; - int *to_left; - XPointer *args; - int num_args; +sjis_ctstombs( + XlcConv conv, + XPointer *from, + int *from_left, + XPointer *to, + int *to_left, + XPointer *args, + int num_args) { - register XPointer inbufptr = *from; - register XPointer outbufptr = *to; - XPointer inbuf_base; + const char *inbufptr = *from; + XPointer outbufptr = *to; + const char *inbuf_base; XPointer outbuf_base = outbufptr; - register int clen, length; + int clen, length; int unconv_num = 0; int num_conv; unsigned int ct_seglen = 0; Uchar ct_type; CTData ctdp = ctdata; /* default */ - if (*from_left > *to_left) *from_left = *to_left; @@ -1243,33 +1240,32 @@ sjis_ctstombs(conv, from, from_left, to, to_left, args, num_args) static int -sjis_ctstowcs(conv, from, from_left, to, to_left, args, num_args) - XlcConv conv; - XPointer *from; - int *from_left; - XPointer *to; - int *to_left; - XPointer *args; - int num_args; +sjis_ctstowcs( + XlcConv conv, + XPointer *from, + int *from_left, + XPointer *to, + int *to_left, + XPointer *args, + int num_args) { XLCd lcd = (XLCd)conv->state; Ulong wc_shift_bits = XLC_GENERIC(lcd, wc_shift_bits); - register XPointer inbufptr = *from; - XPointer inbuf_base; - register wchar_t *outbufptr = (wchar_t *) *to; + const char *inbufptr = *from; + const char *inbuf_base; + wchar_t *outbufptr = (wchar_t *) *to; wchar_t *outbuf_base = outbufptr; - register int clen, length; + int clen, length; int num_conv; int unconv_num = 0; unsigned int ct_seglen = 0; Uchar ct_type = 0; - register int shift_mult; + int shift_mult; wchar_t wc_tmp; wchar_t wch; Ulong wc_encoding; CTData ctdp = ctdata; - if (*from_left > *to_left) *from_left = *to_left; @@ -1375,17 +1371,17 @@ sjis_ctstowcs(conv, from, from_left, to, to_left, args, num_args) #undef BADCHAR static void -close_converter(conv) - XlcConv conv; +close_converter( + XlcConv conv) { Xfree((char *) conv); } static XlcConv -create_conv(lcd, methods) - XLCd lcd; - XlcConvMethods methods; +create_conv( + XLCd lcd, + XlcConvMethods methods) { XlcConv conv; @@ -1418,118 +1414,118 @@ static XlcConvMethodsRec conv_methods[] = { static XlcConv -open_mbstocs(from_lcd, from_type, to_lcd, to_type) - XLCd from_lcd; - char *from_type; - XLCd to_lcd; - char *to_type; +open_mbstocs( + XLCd from_lcd, + const char *from_type, + XLCd to_lcd, + const char *to_type) { return create_conv(from_lcd, &conv_methods[MBSTOCS]); } static XlcConv -open_wcstocs(from_lcd, from_type, to_lcd, to_type) - XLCd from_lcd; - char *from_type; - XLCd to_lcd; - char *to_type; +open_wcstocs( + XLCd from_lcd, + const char *from_type, + XLCd to_lcd, + const char *to_type) { return create_conv(from_lcd, &conv_methods[WCSTOCS]); } static XlcConv -open_mbtocs(from_lcd, from_type, to_lcd, to_type) - XLCd from_lcd; - char *from_type; - XLCd to_lcd; - char *to_type; +open_mbtocs( + XLCd from_lcd, + const char *from_type, + XLCd to_lcd, + const char *to_type) { return create_conv(from_lcd, &conv_methods[MBTOCS]); } static XlcConv -open_cstombs(from_lcd, from_type, to_lcd, to_type) - XLCd from_lcd; - char *from_type; - XLCd to_lcd; - char *to_type; +open_cstombs( + XLCd from_lcd, + const char *from_type, + XLCd to_lcd, + const char *to_type) { return create_conv(from_lcd, &conv_methods[CSTOMBS]); } static XlcConv -open_cstowcs(from_lcd, from_type, to_lcd, to_type) - XLCd from_lcd; - char *from_type; - XLCd to_lcd; - char *to_type; +open_cstowcs( + XLCd from_lcd, + const char *from_type, + XLCd to_lcd, + const char *to_type) { return create_conv(from_lcd, &conv_methods[CSTOWCS]); } static XlcConv -open_mbstowcs(from_lcd, from_type, to_lcd, to_type) - XLCd from_lcd; - char *from_type; - XLCd to_lcd; - char *to_type; +open_mbstowcs( + XLCd from_lcd, + const char *from_type, + XLCd to_lcd, + const char *to_type) { return create_conv(from_lcd, &conv_methods[MBSTOWCS]); } static XlcConv -open_wcstombs(from_lcd, from_type, to_lcd, to_type) - XLCd from_lcd; - char *from_type; - XLCd to_lcd; - char *to_type; +open_wcstombs( + XLCd from_lcd, + const char *from_type, + XLCd to_lcd, + const char *to_type) { return create_conv(from_lcd, &conv_methods[WCSTOMBS]); } static XlcConv -open_wcstocts(from_lcd, from_type, to_lcd, to_type) - XLCd from_lcd; - char *from_type; - XLCd to_lcd; - char *to_type; +open_wcstocts( + XLCd from_lcd, + const char *from_type, + XLCd to_lcd, + const char *to_type) { return create_conv(from_lcd, &conv_methods[WCSTOCTS]); } static XlcConv -open_mbstocts(from_lcd, from_type, to_lcd, to_type) - XLCd from_lcd; - char *from_type; - XLCd to_lcd; - char *to_type; +open_mbstocts( + XLCd from_lcd, + const char *from_type, + XLCd to_lcd, + const char *to_type) { return create_conv(from_lcd, &conv_methods[MBSTOCTS]); } static XlcConv -open_ctstombs(from_lcd, from_type, to_lcd, to_type) - XLCd from_lcd; - char *from_type; - XLCd to_lcd; - char *to_type; +open_ctstombs( + XLCd from_lcd, + const char *from_type, + XLCd to_lcd, + const char *to_type) { return create_conv(from_lcd, &conv_methods[CTSTOMBS]); } static XlcConv -open_ctstowcs(from_lcd, from_type, to_lcd, to_type) - XLCd from_lcd; - char *from_type; - XLCd to_lcd; - char *to_type; +open_ctstowcs( + XLCd from_lcd, + const char *from_type, + XLCd to_lcd, + const char *to_type) { return create_conv(from_lcd, &conv_methods[CTSTOWCS]); } XLCd -_XlcSjisLoader(name) - char *name; +_XlcSjisLoader( + const char *name) { XLCd lcd; @@ -1560,6 +1556,7 @@ _XlcSjisLoader(name) _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNMultiByte, open_wcstombs); #endif + _XlcAddUtf8Converters(lcd); return lcd; } |