[ Avaa Bypassed ]




Upload:

Command:

hmhc3928@3.145.109.231: ~ $
/*
 * "streamable kanji code filter and converter"
 * Copyright (c) 1998-2002 HappySize, Inc. All rights reserved.
 *
 * LICENSE NOTICES
 *
 * This file is part of "streamable kanji code filter and converter",
 * which is distributed under the terms of GNU Lesser General Public 
 * License (version 2) as published by the Free Software Foundation.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with "streamable kanji code filter and converter";
 * if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 * Suite 330, Boston, MA  02111-1307  USA
 *
 * The author of this file:
 *
 */
/*
 * The source code included in this files was separated from mbfilter_ja.c
 * by moriyoshi koizumi <moriyoshi@php.net> on 4 dec 2002.
 * 
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "mbfilter.h"
#include "mbfilter_cp51932.h"

#include "unicode_table_cp932_ext.h"
#include "unicode_table_jis.h"
#include "cp932_table.h"

static int mbfl_filt_ident_cp51932(int c, mbfl_identify_filter *filter);

static const unsigned char mblen_table_eucjp[] = { /* 0xA1-0xFE */
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1
};


static const char *mbfl_encoding_cp51932_aliases[] = {"cp51932", NULL};

const struct mbfl_identify_vtbl vtbl_identify_cp51932 = {
	mbfl_no_encoding_cp51932,
	mbfl_filt_ident_common_ctor,
	mbfl_filt_ident_common_dtor,
	mbfl_filt_ident_cp51932
};

const mbfl_encoding mbfl_encoding_cp51932 = {
	mbfl_no_encoding_cp51932,
	"CP51932",
	"CP51932",
	(const char *(*)[])&mbfl_encoding_cp51932_aliases,
	mblen_table_eucjp,
	MBFL_ENCTYPE_MBCS
};

const struct mbfl_convert_vtbl vtbl_cp51932_wchar = {
	mbfl_no_encoding_cp51932,
	mbfl_no_encoding_wchar,
	mbfl_filt_conv_common_ctor,
	mbfl_filt_conv_common_dtor,
	mbfl_filt_conv_cp51932_wchar,
	mbfl_filt_conv_common_flush
};

const struct mbfl_convert_vtbl vtbl_wchar_cp51932 = {
	mbfl_no_encoding_wchar,
	mbfl_no_encoding_cp51932,
	mbfl_filt_conv_common_ctor,
	mbfl_filt_conv_common_dtor,
	mbfl_filt_conv_wchar_cp51932,
	mbfl_filt_conv_common_flush
};

#define CK(statement)	do { if ((statement) < 0) return (-1); } while (0)

#define sjistoidx(c1, c2) \
        (((c1) > 0x9f) \
        ? (((c1) - 0xc1) * 188 + (c2) - (((c2) > 0x7e) ? 0x41 : 0x40)) \
        : (((c1) - 0x81) * 188 + (c2) - (((c2) > 0x7e) ? 0x41 : 0x40)))
#define idxtoeuc1(c) (((c) / 94) + 0xa1)
#define idxtoeuc2(c) (((c) % 94) + 0xa1)

/*
 * cp51932 => wchar
 */
int
mbfl_filt_conv_cp51932_wchar(int c, mbfl_convert_filter *filter)
{
	int c1, s, w;

	switch (filter->status) {
	case 0:
		if (c >= 0 && c < 0x80) {	/* latin */
			CK((*filter->output_function)(c, filter->data));
		} else if (c > 0xa0 && c < 0xff) {	/* CP932 first char */
			filter->status = 1;
			filter->cache = c;
		} else if (c == 0x8e) {	/* kana first char */
			filter->status = 2;
		} else {
			w = c & MBFL_WCSGROUP_MASK;
			w |= MBFL_WCSGROUP_THROUGH;
			CK((*filter->output_function)(w, filter->data));
		}
		break;

	case 1:	/* got first half */
		filter->status = 0;
		c1 = filter->cache;
		if (c > 0xa0 && c < 0xff) {
			w = 0;
			s = (c1 - 0xa1)*94 + c - 0xa1;
			if (s <= 137) {
				if (s == 31) {
					w = 0xff3c;			/* FULLWIDTH REVERSE SOLIDUS */
				} else if (s == 32) {
					w = 0xff5e;			/* FULLWIDTH TILDE */
				} else if (s == 33) {
					w = 0x2225;			/* PARALLEL TO */
				} else if (s == 60) {
					w = 0xff0d;			/* FULLWIDTH HYPHEN-MINUS */
				} else if (s == 80) {
					w = 0xffe0;			/* FULLWIDTH CENT SIGN */
				} else if (s == 81) {
					w = 0xffe1;			/* FULLWIDTH POUND SIGN */
				} else if (s == 137) {
					w = 0xffe2;			/* FULLWIDTH NOT SIGN */
				}
			}
			if (w == 0) {
				if (s >= cp932ext1_ucs_table_min && s < cp932ext1_ucs_table_max) {		/* vendor ext1 (13ku) */
					w = cp932ext1_ucs_table[s - cp932ext1_ucs_table_min];
				} else if (s >= 0 && s < jisx0208_ucs_table_size) {		/* X 0208 */
					w = jisx0208_ucs_table[s];
				} else if (s >= cp932ext2_ucs_table_min && s < cp932ext2_ucs_table_max) {		/* vendor ext2 (89ku - 92ku) */
					w = cp932ext2_ucs_table[s - cp932ext2_ucs_table_min];
				}
			}
			if (w <= 0) {
				w = ((c1 & 0x7f) << 8) | (c & 0x7f);
				w &= MBFL_WCSPLANE_MASK;
				w |= MBFL_WCSPLANE_WINCP932;
			}
			CK((*filter->output_function)(w, filter->data));
		} else if ((c >= 0 && c < 0x21) || c == 0x7f) {		/* CTLs */
			CK((*filter->output_function)(c, filter->data));
		} else {
			w = (c1 << 8) | c;
			w &= MBFL_WCSGROUP_MASK;
			w |= MBFL_WCSGROUP_THROUGH;
			CK((*filter->output_function)(w, filter->data));
		}
		break;

	case 2:	/* got 0x8e, X0201 kana */
		filter->status = 0;
		if (c > 0xa0 && c < 0xe0) {
			w = 0xfec0 + c;
			CK((*filter->output_function)(w, filter->data));
		} else if ((c >= 0 && c < 0x21) || c == 0x7f) {		/* CTLs */
			CK((*filter->output_function)(c, filter->data));
		} else {
			w = 0x8e00 | c;
			w &= MBFL_WCSGROUP_MASK;
			w |= MBFL_WCSGROUP_THROUGH;
			CK((*filter->output_function)(w, filter->data));
		}
		break;

	default:
		filter->status = 0;
		break;
	}

	return c;
}

/*
 * wchar => cp51932
 */
int
mbfl_filt_conv_wchar_cp51932(int c, mbfl_convert_filter *filter)
{
	int c1, c2, s1;

	s1 = 0;
	if (c >= ucs_a1_jis_table_min && c < ucs_a1_jis_table_max) {
		s1 = ucs_a1_jis_table[c - ucs_a1_jis_table_min];
	} else if (c >= ucs_a2_jis_table_min && c < ucs_a2_jis_table_max) {
		s1 = ucs_a2_jis_table[c - ucs_a2_jis_table_min];
	} else if (c >= ucs_i_jis_table_min && c < ucs_i_jis_table_max) {
		s1 = ucs_i_jis_table[c - ucs_i_jis_table_min];
	} else if (c >= ucs_r_jis_table_min && c < ucs_r_jis_table_max) {
		s1 = ucs_r_jis_table[c - ucs_r_jis_table_min];
	}
	if (s1 >= 0x8080) s1 = -1; /* we don't support JIS X0213 */
	if (s1 <= 0) {
		c1 = c & ~MBFL_WCSPLANE_MASK;
		if (c1 == MBFL_WCSPLANE_WINCP932) {
			s1 = c & MBFL_WCSPLANE_MASK;
			if (s1 >= ((85 + 0x20) << 8)) {	/* 85ku - 120ku */
				s1 = -1;
			}
		} else if (c1 == MBFL_WCSPLANE_JIS0208) {
			s1 = c & MBFL_WCSPLANE_MASK;
			if ((s1 >= ((85 + 0x20) << 8) &&  /* 85ku - 94ku */
                             s1 <= ((88 + 0x20) << 8)) ||/* IBM extension */
			    (s1 >= ((93 + 0x20) << 8) && /* 89ku - 92ku */
                             s1 <= ((94 + 0x20) << 8))) {
				s1 = -1;
			}
		} else if (c == 0xa5) {		/* YEN SIGN */
			s1 = 0x005c;			/* YEN SIGN */
		} else if (c == 0x203e) {	/* OVER LINE */
			s1 = 0x007e;			/* FULLWIDTH MACRON */
		} else if (c == 0xff3c) {	/* FULLWIDTH REVERSE SOLIDUS */
			s1 = 0x2140;
		} else if (c == 0xff5e) {	/* FULLWIDTH TILDE */
			s1 = 0x2141;
		} else if (c == 0x2225) {	/* PARALLEL TO */
			s1 = 0x2142;
		} else if (c == 0xff0d) {	/* FULLWIDTH HYPHEN-MINUS */
			s1 = 0x215d;
		} else if (c == 0xffe0) {	/* FULLWIDTH CENT SIGN */
			s1 = 0x2171;
		} else if (c == 0xffe1) {	/* FULLWIDTH POUND SIGN */
			s1 = 0x2172;
		} else if (c == 0xffe2) {	/* FULLWIDTH NOT SIGN */
			s1 = 0x224c;
		} else {
			s1 = -1;
			c1 = 0;
			c2 = cp932ext1_ucs_table_max - cp932ext1_ucs_table_min;
			while (c1 < c2) {		/* CP932 vendor ext1 (13ku) */
				if (c == cp932ext1_ucs_table[c1]) {
					s1 = ((c1/94 + 0x2d) << 8) + (c1%94 + 0x21);
					break;
				}
				c1++;
			}
			if (s1 < 0) {
				c1 = 0;
				c2 = cp932ext2_ucs_table_max - cp932ext2_ucs_table_min;
				while (c1 < c2) {		/* CP932 vendor ext3 (115ku - 119ku) */
					if (c == cp932ext2_ucs_table[c1]) {
					  s1 = ((c1/94 + 0x79) << 8) +(c1%94 + 0x21);
					  break;
					}
					c1++;
				}
			}
		}
		if (c == 0) {
			s1 = 0;
		} else if (s1 <= 0) {
			s1 = -1;
		}
	}

	if (s1 >= 0) {
		if (s1 < 0x80) {	/* latin */
			CK((*filter->output_function)(s1, filter->data));
		} else if (s1 < 0x100) {	/* kana */
			CK((*filter->output_function)(0x8e, filter->data));
			CK((*filter->output_function)(s1, filter->data));
		} else if (s1 < 0x8080)  {	/* X 0208 */
			CK((*filter->output_function)(((s1 >> 8) & 0xff) | 0x80, filter->data));
			CK((*filter->output_function)((s1 & 0xff) | 0x80, filter->data));
		} else {
		  if (filter->illegal_mode != MBFL_OUTPUTFILTER_ILLEGAL_MODE_NONE) {
		    CK(mbfl_filt_conv_illegal_output(c, filter));
		  }
		}
	} else {
		if (filter->illegal_mode != MBFL_OUTPUTFILTER_ILLEGAL_MODE_NONE) {
			CK(mbfl_filt_conv_illegal_output(c, filter));
		}
	}

	return c;
}

static int mbfl_filt_ident_cp51932(int c, mbfl_identify_filter *filter)
{
	switch (filter->status) {
	case  0:	/* latin */
		if (c >= 0 && c < 0x80) {	/* ok */
			;
		} else if (c > 0xa0 && c < 0xff) {	/* kanji first char */
			filter->status = 1;
		} else if (c == 0x8e) {				/* kana first char */
			filter->status = 2;
		} else {							/* bad */
			filter->flag = 1;
		}
		break;

	case  1:	/* got first half */
		if (c < 0xa1 || c > 0xfe) {		/* bad */
			filter->flag = 1;
		}
		filter->status = 0;
		break;

	case  2:	/* got 0x8e */
		if (c < 0xa1 || c > 0xdf) {		/* bad */
			filter->flag = 1;
		}
		filter->status = 0;
		break;

	default:
		filter->status = 0;
		break;
	}

	return c;
}



Filemanager

Name Type Size Permission Actions
cp932_table.h File 3.96 KB 0644
emoji2uni.h File 41.06 KB 0644
html_entities.c File 6.73 KB 0644
html_entities.h File 1.29 KB 0644
mbfilter_7bit.c File 2.06 KB 0644
mbfilter_7bit.h File 1.46 KB 0644
mbfilter_armscii8.c File 3.55 KB 0644
mbfilter_armscii8.h File 1.47 KB 0644
mbfilter_ascii.c File 3 KB 0644
mbfilter_ascii.h File 1.54 KB 0644
mbfilter_base64.c File 5.95 KB 0644
mbfilter_base64.h File 1.6 KB 0644
mbfilter_big5.c File 9.1 KB 0644
mbfilter_big5.h File 1.72 KB 0644
mbfilter_byte2.c File 3.38 KB 0644
mbfilter_byte2.h File 1.78 KB 0644
mbfilter_byte4.c File 4.04 KB 0644
mbfilter_byte4.h File 1.76 KB 0644
mbfilter_cp1251.c File 3.5 KB 0644
mbfilter_cp1251.h File 1.52 KB 0644
mbfilter_cp1252.c File 3.57 KB 0644
mbfilter_cp1252.h File 1.52 KB 0644
mbfilter_cp1254.c File 3.8 KB 0644
mbfilter_cp1254.h File 1.52 KB 0644
mbfilter_cp5022x.c File 33.99 KB 0644
mbfilter_cp5022x.h File 2.74 KB 0644
mbfilter_cp51932.c File 9.7 KB 0644
mbfilter_cp51932.h File 1.5 KB 0644
mbfilter_cp850.c File 3.34 KB 0644
mbfilter_cp850.h File 1.4 KB 0644
mbfilter_cp866.c File 3.43 KB 0644
mbfilter_cp866.h File 1.49 KB 0644
mbfilter_cp932.c File 9.59 KB 0644
mbfilter_cp932.h File 1.48 KB 0644
mbfilter_cp936.c File 8.74 KB 0644
mbfilter_cp936.h File 1.49 KB 0644
mbfilter_euc_cn.c File 6.31 KB 0644
mbfilter_euc_cn.h File 1.49 KB 0644
mbfilter_euc_jp.c File 8.83 KB 0644
mbfilter_euc_jp.h File 1.49 KB 0644
mbfilter_euc_jp_2004.c File 2.2 KB 0644
mbfilter_euc_jp_2004.h File 1.52 KB 0644
mbfilter_euc_jp_win.c File 11.94 KB 0644
mbfilter_euc_jp_win.h File 1.52 KB 0644
mbfilter_euc_kr.c File 6.71 KB 0644
mbfilter_euc_kr.h File 1.49 KB 0644
mbfilter_euc_tw.c File 8.79 KB 0644
mbfilter_euc_tw.h File 1.52 KB 0644
mbfilter_gb18030.c File 13.37 KB 0644
mbfilter_gb18030.h File 1.5 KB 0644
mbfilter_htmlent.c File 7.91 KB 0644
mbfilter_htmlent.h File 1.83 KB 0644
mbfilter_hz.c File 6.85 KB 0644
mbfilter_hz.h File 1.52 KB 0644
mbfilter_iso2022_jp_ms.c File 14.11 KB 0644
mbfilter_iso2022_jp_ms.h File 1.59 KB 0644
mbfilter_iso2022_kr.c File 8.67 KB 0644
mbfilter_iso2022_kr.h File 1.57 KB 0644
mbfilter_iso2022jp_2004.c File 3.86 KB 0644
mbfilter_iso2022jp_2004.h File 1.61 KB 0644
mbfilter_iso2022jp_mobile.c File 11.49 KB 0644
mbfilter_iso2022jp_mobile.h File 1.57 KB 0644
mbfilter_iso8859_1.c File 2.53 KB 0644
mbfilter_iso8859_1.h File 1.5 KB 0644
mbfilter_iso8859_10.c File 3.15 KB 0644
mbfilter_iso8859_10.h File 1.51 KB 0644
mbfilter_iso8859_13.c File 3.14 KB 0644
mbfilter_iso8859_13.h File 1.51 KB 0644
mbfilter_iso8859_14.c File 3.15 KB 0644
mbfilter_iso8859_14.h File 838 B 0644
mbfilter_iso8859_15.c File 3.14 KB 0644
mbfilter_iso8859_15.h File 838 B 0644
mbfilter_iso8859_16.c File 3.14 KB 0644
mbfilter_iso8859_16.h File 704 B 0644
mbfilter_iso8859_2.c File 3.13 KB 0644
mbfilter_iso8859_2.h File 1.5 KB 0644
mbfilter_iso8859_3.c File 3.13 KB 0644
mbfilter_iso8859_3.h File 1.5 KB 0644
mbfilter_iso8859_4.c File 3.13 KB 0644
mbfilter_iso8859_4.h File 1.48 KB 0644
mbfilter_iso8859_5.c File 3.13 KB 0644
mbfilter_iso8859_5.h File 1.5 KB 0644
mbfilter_iso8859_6.c File 3.13 KB 0644
mbfilter_iso8859_6.h File 1.5 KB 0644
mbfilter_iso8859_7.c File 3.13 KB 0644
mbfilter_iso8859_7.h File 1.5 KB 0644
mbfilter_iso8859_8.c File 3.13 KB 0644
mbfilter_iso8859_8.h File 1.5 KB 0644
mbfilter_iso8859_9.c File 3.13 KB 0644
mbfilter_iso8859_9.h File 1.5 KB 0644
mbfilter_jis.c File 17.03 KB 0644
mbfilter_jis.h File 1.82 KB 0644
mbfilter_koi8r.c File 3.41 KB 0644
mbfilter_koi8r.h File 1.59 KB 0644
mbfilter_koi8u.c File 3.31 KB 0644
mbfilter_koi8u.h File 1.48 KB 0644
mbfilter_qprint.c File 6.66 KB 0644
mbfilter_qprint.h File 1.55 KB 0644
mbfilter_sjis.c File 7.71 KB 0644
mbfilter_sjis.h File 1.5 KB 0644
mbfilter_sjis_2004.c File 19.5 KB 0644
mbfilter_sjis_2004.h File 1.6 KB 0644
mbfilter_sjis_mac.c File 16.3 KB 0644
mbfilter_sjis_mac.h File 1.51 KB 0644
mbfilter_sjis_mobile.c File 24.87 KB 0644
mbfilter_sjis_mobile.h File 2.84 KB 0644
mbfilter_sjis_open.c File 9.66 KB 0644
mbfilter_sjis_open.h File 1.52 KB 0644
mbfilter_tl_jisx0201_jisx0208.c File 9.5 KB 0644
mbfilter_tl_jisx0201_jisx0208.h File 2.89 KB 0644
mbfilter_ucs2.c File 5.2 KB 0644
mbfilter_ucs2.h File 1.94 KB 0644
mbfilter_ucs4.c File 6.17 KB 0644
mbfilter_ucs4.h File 1.92 KB 0644
mbfilter_uhc.c File 6.87 KB 0644
mbfilter_uhc.h File 1.47 KB 0644
mbfilter_utf16.c File 7.67 KB 0644
mbfilter_utf16.h File 1.93 KB 0644
mbfilter_utf32.c File 6.76 KB 0644
mbfilter_utf32.h File 1.93 KB 0644
mbfilter_utf7.c File 12.45 KB 0644
mbfilter_utf7.h File 1.54 KB 0644
mbfilter_utf7imap.c File 10.79 KB 0644
mbfilter_utf7imap.h File 1.52 KB 0644
mbfilter_utf8.c File 8.38 KB 0644
mbfilter_utf8.h File 1.52 KB 0644
mbfilter_utf8_mobile.c File 10.13 KB 0644
mbfilter_utf8_mobile.h File 2.21 KB 0644
mbfilter_uuencode.c File 3.97 KB 0644
mbfilter_uuencode.h File 1.29 KB 0644
sjis_mac2uni.h File 10.99 KB 0644
translit_kana_jisx0201_jisx0208.h File 2.89 KB 0644
unicode_prop.h File 5.84 KB 0644
unicode_table_armscii8.h File 2.33 KB 0644
unicode_table_big5.h File 281.68 KB 0644
unicode_table_cns11643.h File 364.48 KB 0644
unicode_table_cp1251.h File 2.4 KB 0644
unicode_table_cp1252.h File 1.59 KB 0644
unicode_table_cp1254.h File 2.4 KB 0644
unicode_table_cp850.h File 2.38 KB 0644
unicode_table_cp866.h File 2.37 KB 0644
unicode_table_cp932_ext.h File 8.29 KB 0644
unicode_table_cp936.h File 354.25 KB 0644
unicode_table_gb18030.h File 11.47 KB 0644
unicode_table_iso8859_10.h File 958 B 0644
unicode_table_iso8859_13.h File 958 B 0644
unicode_table_iso8859_14.h File 958 B 0644
unicode_table_iso8859_15.h File 958 B 0644
unicode_table_iso8859_16.h File 956 B 0644
unicode_table_iso8859_2.h File 955 B 0644
unicode_table_iso8859_3.h File 955 B 0644
unicode_table_iso8859_4.h File 955 B 0644
unicode_table_iso8859_5.h File 955 B 0644
unicode_table_iso8859_6.h File 955 B 0644
unicode_table_iso8859_7.h File 955 B 0644
unicode_table_iso8859_8.h File 955 B 0644
unicode_table_iso8859_9.h File 955 B 0644
unicode_table_jis.h File 301.96 KB 0644
unicode_table_jis2004.h File 263.02 KB 0644
unicode_table_koi8r.h File 2.36 KB 0644
unicode_table_koi8u.h File 7.29 KB 0644
unicode_table_uhc.h File 393.6 KB 0644