[KoCo-CVS] [Commit] cjkcodecs/src _shift_jis.c codeccommon.h
Brought to you by:
perky
From: Hye-Shik C. <pe...@us...> - 2003-05-22 04:18:21
|
perky 03/05/21 21:18:21 Modified: src codeccommon.h Added: src _shift_jis.c Log: Add shift-jis codec. Revision Changes Path 1.7 +3 -2 cjkcodecs/src/codeccommon.h Index: codeccommon.h =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/codeccommon.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- codeccommon.h 21 May 2003 23:52:12 -0000 1.6 +++ codeccommon.h 22 May 2003 04:18:21 -0000 1.7 @@ -26,7 +26,7 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $Id: codeccommon.h,v 1.6 2003/05/21 23:52:12 perky Exp $ + * $Id: codeccommon.h,v 1.7 2003/05/22 04:18:21 perky Exp $ */ #include "Python.h" @@ -54,7 +54,8 @@ if ((code) > 0xFFFF) \ return 1; #else -#define UCS4INVALID(code) +#define UCS4INVALID(code) \ + if (0) ; #endif #define BEGIN_CODEC_REGISTRY(encoding) \ 1.1 cjkcodecs/src/_shift_jis.c Index: _shift_jis.c =================================================================== /* * _shift_jis.c: the SHIFT-JIS 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: _shift_jis.c,v 1.1 2003/05/22 04:18:21 perky Exp $ */ #include "codeccommon.h" #include "maps/alg_jisx0201.h" ENCMAP(jisxcommon) DECMAP(jisx0208) ENCODER(shift_jis) { while (inleft > 0) { Py_UNICODE c = **inbuf; DBCHAR code; unsigned char c1, c2; JISX0201_ENCODE(c, code) else UCS4INVALID(c) else code = NOCHAR; if (code < 0x80 || (code >= 0xa1 && code <= 0xdf)) { RESERVE_OUTBUF(1) **outbuf = (unsigned char)code; NEXT(1, 1) continue; } RESERVE_OUTBUF(2) if (code == NOCHAR) { TRYMAP_ENC(&jisxcommonencmap[c >> 8], code, c & 0xff) else if (c >= 0xe000 && c < 0xe758) { /* user-defined area */ c1 = (Py_UNICODE)(c - 0xe000) / 188; c2 = (Py_UNICODE)(c - 0xe000) % 188; (*outbuf)[0] = c1 + 0xf0; (*outbuf)[1] = (c2 < 0x3f ? c2 + 0x40 : c2 + 0x41); NEXT(1, 2) continue; } else return 1; if (code & 0x8000) /* MSB set: JIS X 0212 */ return 1; } c1 = code >> 8; c2 = code & 0xff; c2 = (((c1 - 0x21) & 1) ? 0x5e : 0) + (c2 - 0x21); c1 = (c1 - 0x21) >> 1; (*outbuf)[0] = c1 < 0x1f ? c1 + 0x81 : c1 + 0xc1; (*outbuf)[1] = c2 < 0x3f ? c2 + 0x40 : c2 + 0x41; NEXT(1, 2) } return 0; } DECODER(shift_jis) { while (inleft > 0) { unsigned char c = **inbuf; Py_UNICODE code; RESERVE_OUTBUF(1) JISX0201_DECODE(c, code) else if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xea)) { unsigned char c1, c2; RESERVE_INBUF(2) c2 = (*inbuf)[1]; if (c2 < 0x40 || (c2 > 0x7e && c2 < 0x80) || c2 > 0xfc) return 2; c1 = (c < 0xe0 ? c - 0x81 : c - 0xc1); c2 = (c2 < 0x80 ? c2 - 0x40 : c2 - 0x41); c1 = (2 * c1 + (c2 < 0x5e ? 0 : 1) + 0x21); c2 = (c2 < 0x5e ? c2 : c2 - 0x5e) + 0x21; TRYMAP_DEC(&jisx0208decmap[c1], code, c2) else return 2; } else if (c >= 0xf0 && c <= 0xf9) { unsigned char c2; RESERVE_INBUF(2) c2 = (*inbuf)[1]; if ((c2 >= 0x40 && c2 <= 0x7e) || (c2 >= 0x80 && c2 <= 0xfc)) code = 0xe000 + 188 * (c - 0xf0) + (c2 < 0x80 ? c2 - 0x40 : c2 - 0x41); else return 2; } else return 2; **outbuf = code; NEXT(2, 1) } return 0; } BEGIN_CODEC_REGISTRY(shift_jis) MAPOPEN(ja_JP) IMPORTMAP_DEC(jisx0208) IMPORTMAP_ENC(jisxcommon) MAPCLOSE() END_CODEC_REGISTRY(shift_jis) /* * ex: ts=8 sts=4 et */ |