[KoCo-CVS] [Commit] cjkcodecs/src _big5.c _cp950.c _cp949.c _euc_kr.c _gb18030.c _gb2312.c _gbk.c
Brought to you by:
perky
From: Hye-Shik C. <pe...@us...> - 2003-05-20 11:20:57
|
perky 03/05/20 04:20:56 Modified: src _cp949.c _euc_kr.c _gb18030.c _gb2312.c _gbk.c Added: src _big5.c _cp950.c Log: Add big5 and cp950 codec and Fix programming error (UNIINV -> NOCHAR) Revision Changes Path 1.5 +2 -2 cjkcodecs/src/_cp949.c Index: _cp949.c =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/_cp949.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- _cp949.c 20 May 2003 10:08:47 -0000 1.4 +++ _cp949.c 20 May 2003 11:20:56 -0000 1.5 @@ -26,7 +26,7 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $Id: _cp949.c,v 1.4 2003/05/20 10:08:47 perky Exp $ + * $Id: _cp949.c,v 1.5 2003/05/20 11:20:56 perky Exp $ */ #include "codeccommon.h" @@ -57,7 +57,7 @@ map = &cp949encmap[c >> 8]; clow = c & 0xff; if (map->map == NULL || clow < map->bottom || clow > map->top || - (code = map->map[clow - map->bottom]) == UNIINV) + (code = map->map[clow - map->bottom]) == NOCHAR) return 1; (*outbuf)[0] = (code >> 8) | 0x80; 1.8 +2 -2 cjkcodecs/src/_euc_kr.c Index: _euc_kr.c =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/_euc_kr.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- _euc_kr.c 20 May 2003 10:08:47 -0000 1.7 +++ _euc_kr.c 20 May 2003 11:20:56 -0000 1.8 @@ -26,7 +26,7 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $Id: _euc_kr.c,v 1.7 2003/05/20 10:08:47 perky Exp $ + * $Id: _euc_kr.c,v 1.8 2003/05/20 11:20:56 perky Exp $ */ #include "codeccommon.h" @@ -56,7 +56,7 @@ map = &cp949encmap[c >> 8]; clow = c & 0xff; if (map->map == NULL || clow < map->bottom || clow > map->top || - (code = map->map[clow - map->bottom]) == UNIINV) + (code = map->map[clow - map->bottom]) == NOCHAR) return 1; if (code & 0x8000) /* MSB set: CP949 */ return 1; 1.2 +3 -3 cjkcodecs/src/_gb18030.c Index: _gb18030.c =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/_gb18030.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- _gb18030.c 20 May 2003 10:59:08 -0000 1.1 +++ _gb18030.c 20 May 2003 11:20:56 -0000 1.2 @@ -26,7 +26,7 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $Id: _gb18030.c,v 1.1 2003/05/20 10:59:08 perky Exp $ + * $Id: _gb18030.c,v 1.2 2003/05/20 11:20:56 perky Exp $ */ #include "codeccommon.h" @@ -85,11 +85,11 @@ map = &gbcommonencmap[c >> 8]; clow = c & 0xff; if (map->map == NULL || clow < map->bottom || clow > map->top || - (code = map->map[clow - map->bottom]) == UNIINV) { + (code = map->map[clow - map->bottom]) == NOCHAR) { map = &gb18030extencmap[c >> 8]; clow = c & 0xff; if (map->map == NULL || clow < map->bottom || clow > map->top || - (code = map->map[clow - map->bottom]) == UNIINV) { + (code = map->map[clow - map->bottom]) == NOCHAR) { const struct _gb18030_to_unibmp_ranges *utrrange; if (outleft < 4) 1.3 +2 -2 cjkcodecs/src/_gb2312.c Index: _gb2312.c =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/_gb2312.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- _gb2312.c 20 May 2003 10:08:47 -0000 1.2 +++ _gb2312.c 20 May 2003 11:20:56 -0000 1.3 @@ -26,7 +26,7 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $Id: _gb2312.c,v 1.2 2003/05/20 10:08:47 perky Exp $ + * $Id: _gb2312.c,v 1.3 2003/05/20 11:20:56 perky Exp $ */ #include "codeccommon.h" @@ -56,7 +56,7 @@ map = &gbcommonencmap[c >> 8]; clow = c & 0xff; if (map->map == NULL || clow < map->bottom || clow > map->top || - (code = map->map[clow - map->bottom]) == UNIINV) + (code = map->map[clow - map->bottom]) == NOCHAR) return 1; if (code & 0x8000) /* MSB set: GBK */ return 1; 1.2 +2 -2 cjkcodecs/src/_gbk.c Index: _gbk.c =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/_gbk.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- _gbk.c 20 May 2003 10:59:08 -0000 1.1 +++ _gbk.c 20 May 2003 11:20:56 -0000 1.2 @@ -26,7 +26,7 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $Id: _gbk.c,v 1.1 2003/05/20 10:59:08 perky Exp $ + * $Id: _gbk.c,v 1.2 2003/05/20 11:20:56 perky Exp $ */ #include "codeccommon.h" @@ -61,7 +61,7 @@ map = &gbcommonencmap[c >> 8]; clow = c & 0xff; if (map->map == NULL || clow < map->bottom || clow > map->top || - (code = map->map[clow - map->bottom]) == UNIINV) + (code = map->map[clow - map->bottom]) == NOCHAR) return 1; } 1.1 cjkcodecs/src/_big5.c Index: _big5.c =================================================================== /* * _big5.c: the Big5 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: _big5.c,v 1.1 2003/05/20 11:20:56 perky Exp $ */ #include "codeccommon.h" ENCMAP(big5) DECMAP(big5) ENCODER(big5) { while (inleft > 0) { const encode_map *map; Py_UNICODE c = **inbuf, clow; DBCHAR code; if (c < 0x80) { if (outleft < 1) return MBERR_TOOSMALL; **outbuf = c; (*inbuf)++; inleft--; (*outbuf)++; outleft--; continue; } UCS4INVALID(c) if (outleft < 2) return MBERR_TOOSMALL; map = &big5encmap[c >> 8]; clow = c & 0xff; if (map->map == NULL || clow < map->bottom || clow > map->top || (code = map->map[clow - map->bottom]) == NOCHAR) return 1; (*outbuf)[0] = (code >> 8) | 0x80; (*outbuf)[1] = (code & 0xFF) | 0x80; (*outbuf) += 2; outleft -= 2; (*inbuf)++; inleft--; } return 0; } DECODER(big5) { while (inleft > 0) { const decode_map *map; unsigned char c = **inbuf, c2; Py_UNICODE code; if (outleft < 1) return MBERR_TOOSMALL; if (c < 0x80) { **outbuf = c; (*inbuf)++; inleft--; (*outbuf)++; outleft--; continue; } if (inleft < 2) return MBERR_TOOFEW; c2 = (*inbuf)[1]; map = &big5decmap[c]; if (map->map == NULL || c2 < map->bottom || c2 > map->top || (code = map->map[c2 - map->bottom]) == UNIINV) return 2; **outbuf = code; (*outbuf)++; outleft--; (*inbuf) += 2; inleft -= 2; } return 0; } CODECDEF(big5) NOMETHODS(__methods) void init_big5(void) { PyObject *codec; PyObject *m = NULL, *mod = NULL, *o = NULL; m = Py_InitModule("_big5", __methods); /* Import mapdata */ MAPOPEN(mod, "zh_TW") if (IMPORTMAP(mod, big5, &big5encmap, &big5decmap)) goto errorexit; MAPCLOSE(mod) /* Create Codec Instances */ MULTIBYTECODEC_OPEN(mod, o) REGISTERCODEC(m, o, codec) MULTIBYTECODEC_CLOSE(mod, o) if (PyErr_Occurred()) Py_FatalError("can't initialize the _big5 module"); return; errorexit: Py_XDECREF(m); Py_XDECREF(mod); Py_XDECREF(o); } /* * ex: ts=8 sts=4 et */ 1.1 cjkcodecs/src/_cp950.c Index: _cp950.c =================================================================== /* * _cp950.c: the CP950 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: _cp950.c,v 1.1 2003/05/20 11:20:56 perky Exp $ */ #include "codeccommon.h" ENCMAP(big5) ENCMAP(cp950ext) DECMAP(big5) DECMAP(cp950ext) ENCODER(cp950) { while (inleft > 0) { const encode_map *map; Py_UNICODE c = **inbuf, clow; DBCHAR code; if (c < 0x80) { if (outleft < 1) return MBERR_TOOSMALL; **outbuf = c; (*inbuf)++; inleft--; (*outbuf)++; outleft--; continue; } UCS4INVALID(c) if (outleft < 2) return MBERR_TOOSMALL; map = &cp950extencmap[c >> 8]; clow = c & 0xff; if (map->map == NULL || clow < map->bottom || clow > map->top || (code = map->map[clow - map->bottom]) == NOCHAR) { map = &big5encmap[c >> 8]; if (map->map == NULL || clow < map->bottom || clow > map->top || (code = map->map[clow - map->bottom]) == NOCHAR) return 1; } (*outbuf)[0] = (code >> 8) | 0x80; (*outbuf)[1] = (code & 0xFF); (*outbuf) += 2; outleft -= 2; (*inbuf)++; inleft--; } return 0; } DECODER(cp950) { while (inleft > 0) { const decode_map *map; unsigned char c = **inbuf, c2; Py_UNICODE code; if (outleft < 1) return MBERR_TOOSMALL; if (c < 0x80) { **outbuf = c; (*inbuf)++; inleft--; (*outbuf)++; outleft--; continue; } if (inleft < 2) return MBERR_TOOFEW; c2 = (*inbuf)[1]; map = &cp950extdecmap[c & 0x7f]; if (map->map == NULL || c2 < map->bottom || c2 > map->top || (code = map->map[c2 - map->bottom]) == UNIINV) { map = &big5decmap[c]; if (map->map == NULL || c2 < map->bottom || c2 > map->top || (code = map->map[c2 - map->bottom]) == UNIINV) return 2; } **outbuf = code; (*outbuf)++; outleft--; (*inbuf) += 2; inleft -= 2; } return 0; } CODECDEF(cp950) NOMETHODS(__methods) void init_cp950(void) { PyObject *codec; PyObject *m = NULL, *mod = NULL, *o = NULL; m = Py_InitModule("_cp950", __methods); /* Import mapdata */ MAPOPEN(mod, "zh_TW") if (IMPORTMAP(mod, big5, &big5encmap, &big5decmap) || IMPORTMAP(mod, cp950ext, &cp950extencmap, &cp950extdecmap)) goto errorexit; MAPCLOSE(mod) /* Create Codec Instances */ MULTIBYTECODEC_OPEN(mod, o) REGISTERCODEC(m, o, codec) MULTIBYTECODEC_CLOSE(mod, o) if (PyErr_Occurred()) Py_FatalError("can't initialize the _cp950 module"); return; errorexit: Py_XDECREF(m); Py_XDECREF(mod); Py_XDECREF(o); } /* * ex: ts=8 sts=4 et */ |