[KoCo-CVS] [Commit] cjkcodecs/src _euc_jp.c
Brought to you by:
perky
From: Hye-Shik C. <pe...@us...> - 2003-05-26 06:21:41
|
perky 03/05/25 23:21:40 Added: src _euc_jp.c Log: Add euc-jp codec. Revision Changes Path 1.1 cjkcodecs/src/_euc_jp.c Index: _euc_jp.c =================================================================== /* * _euc_jp.c: the EUC-JP codec * * Copyright (C) 2003 Hye-Shik Chang <pe...@Fr...>. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * $Id: _euc_jp.c,v 1.1 2003/05/26 06:21:40 perky Exp $ */ #include "codeccommon.h" ENCMAP(jisxcommon) DECMAP(jisx0208) DECMAP(jisx0212) ENCODER(euc_jp) { while (inleft > 0) { Py_UNICODE c = **inbuf; DBCHAR code; if (c < 0x80) { RESERVE_OUTBUF(1) **outbuf = c; NEXT(1, 1) continue; } UCS4INVALID(c) TRYMAP_ENC(jisxcommon, code, c) else if (c >= 0xff61 && c <= 0xff9f) { /* JIS X 0201 half-width katakana */ RESERVE_OUTBUF(2) (*outbuf)[0] = 0x8e; (*outbuf)[1] = (unsigned char)(c - 0xfec0); NEXT(1, 2) continue; } else if (c >= 0xe000 && c < 0xe3ac) { /* User-defined area 1 */ RESERVE_OUTBUF(2) (*outbuf)[0] = (Py_UNICODE)(c - 0xe000) / 94 + 0xf5; (*outbuf)[1] = (Py_UNICODE)(c - 0xe000) % 94 + 0xa1; NEXT(1, 2) continue; } else if (c >= 0xe3ac && c < 0xe758) { /* User-defined area 2 */ RESERVE_OUTBUF(3) (*outbuf)[0] = 0x8f; (*outbuf)[1] = (Py_UNICODE)(c - 0xe3ac) / 94 + 0xf5; (*outbuf)[2] = (Py_UNICODE)(c - 0xe3ac) % 94 + 0xa1; NEXT(1, 3) continue; } else return 1; if (code & 0x8000) { /* JIS X 0212 */ RESERVE_OUTBUF(3) (*outbuf)[0] = 0x8f; (*outbuf)[1] = code >> 8; (*outbuf)[2] = (code & 0xFF) | 0x80; NEXT(1, 3) } else { /* JIS X 0208 */ RESERVE_OUTBUF(2) (*outbuf)[0] = (code >> 8) | 0x80; (*outbuf)[1] = (code & 0xFF) | 0x80; NEXT(1, 2) } } return 0; } DECODER(euc_jp) { while (inleft > 0) { unsigned char c = **inbuf; RESERVE_OUTBUF(1) if (c < 0x80) { **outbuf = c; NEXT(1, 1) continue; } if (c == 0x8e) { /* JIS X 0201 half-width katakana */ unsigned char c2; RESERVE_INBUF(2) c2 = (*inbuf)[1]; if (c2 >= 0xa1 && c2 <= 0xdf) { **outbuf = 0xfec0 + c2; NEXT(2, 1) } else return 2; } else if (c == 0x8f) { unsigned char c2, c3; RESERVE_INBUF(3) c2 = (*inbuf)[1]; c3 = (*inbuf)[2]; if (c2 < 0xf5) { /* JIS X 0212 */ TRYMAP_DEC(jisx0212, **outbuf, c2 ^ 0x80, c3 ^ 0x80) else return 3; } else { /* User-defined area 2 */ if (c2 == 0xff || c3 < 0xa1 || c3 == 0xff) return 3; **outbuf = 0xe3ac + 94 * (c2 - 0xf5) + (c3 - 0xa1); } NEXT(3, 1) } else { unsigned char c2; RESERVE_INBUF(2) c2 = (*inbuf)[1]; if (c < 0xf5) { /* JIS X 0208 */ TRYMAP_DEC(jisx0208, **outbuf, c ^ 0x80, c2 ^ 0x80) else return 2; } else { /* User-defined area 1 */ if (c2 < 0xa1 || c2 == 0xff) return 2; **outbuf = 0xe000 + 94 * (c - 0xf5) + (c2 - 0xa1); } NEXT(2, 1) } } return 0; } BEGIN_CODEC_REGISTRY(euc_jp) MAPOPEN(ja_JP) IMPORTMAP_DEC(jisx0208) IMPORTMAP_DEC(jisx0212) IMPORTMAP_ENC(jisxcommon) MAPCLOSE() END_CODEC_REGISTRY(euc_jp) /* * ex: ts=8 sts=4 et */ |