[KoCo-CVS] [Commit] cjkcodecs/src _euc_kr.c codeccommon.h
Brought to you by:
perky
From: Hye-Shik C. <pe...@us...> - 2003-05-19 08:12:25
|
perky 03/05/19 01:12:24 Modified: src _euc_kr.c codeccommon.h Log: Make more concise! Revision Changes Path 1.3 +13 -31 cjkcodecs/src/_euc_kr.c Index: _euc_kr.c =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/_euc_kr.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- _euc_kr.c 19 May 2003 06:32:17 -0000 1.2 +++ _euc_kr.c 19 May 2003 08:12:23 -0000 1.3 @@ -26,21 +26,16 @@ * 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.2 2003/05/19 06:32:17 perky Exp $ + * $Id: _euc_kr.c,v 1.3 2003/05/19 08:12:23 perky Exp $ */ -#include "Python.h" -#include "multibytecodec.h" -#include "cjkcommon.h" #include "codeccommon.h" -const static struct unim_index *cp949encmap; -const static struct dbcs_index *ksx1001decmap, *cp949decmap; +ENCMAP(cp949) +DECMAP(ksx1001) +DECMAP(cp949ext) -static int -euc_kr_encode(PyMultibyteCodec_State *state, - const Py_UNICODE **inbuf, size_t inleft, - unsigned char **outbuf, size_t outleft) +ENCODER(euc_kr) { while (inleft > 0) { const struct unim_index *map; @@ -75,23 +70,13 @@ return 0; } -static int -euc_kr_decode(PyMultibyteCodec_State *state, - const unsigned char **inbuf, size_t inleft, - Py_UNICODE **outbuf, size_t outleft) +DECODER(euc_kr) { return 0; } -static PyMultibyteCodec __codec = { - "euc_kr", - euc_kr_encode, - euc_kr_decode, -}; - -static struct PyMethodDef __methods[] = { - {NULL, NULL}, -}; +CODECDEF(euc_kr) +NOMETHODS(__methods) void init_euc_kr(void) @@ -103,18 +88,15 @@ /* Import mapdata */ MAPOPEN(mod, "ko_KR") - if (importmap(mod, "__map_ksx1001", NULL, &ksx1001decmap) || - importmap(mod, "__map_cp949ext", NULL, &cp949decmap) || - importmap(mod, "__map_cp949", &cp949encmap, NULL)) - goto errorexit; + if (IMPORTMAP(mod, ksx1001, NULL, &ksx1001decmap) || + IMPORTMAP(mod, cp949ext, NULL, &cp949extdecmap) || + IMPORTMAP(mod, cp949, &cp949encmap, NULL)) + goto errorexit; MAPCLOSE(mod) /* Create Codec Instances */ MULTIBYTECODEC_OPEN(mod, o) - codec = createcodec(o, &__codec); - if (codec == NULL) - goto errorexit; - PyModule_AddObject(m, "codec", codec); + REGISTERCODEC(m, o, codec) MULTIBYTECODEC_CLOSE(mod, o) if (PyErr_Occurred()) 1.2 +37 -1 cjkcodecs/src/codeccommon.h Index: codeccommon.h =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/codeccommon.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- codeccommon.h 19 May 2003 06:06:38 -0000 1.1 +++ codeccommon.h 19 May 2003 08:12:24 -0000 1.2 @@ -26,9 +26,37 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $Id: codeccommon.h,v 1.1 2003/05/19 06:06:38 perky Exp $ + * $Id: codeccommon.h,v 1.2 2003/05/19 08:12:24 perky Exp $ */ +#include "Python.h" +#include "multibytecodec.h" +#include "cjkcommon.h" + +#define ENCMAP(encoding) \ + const static struct unim_index *encoding##encmap; +#define DECMAP(encoding) \ + const static struct dbcs_index *encoding##decmap; + +#define ENCODER(encoding) \ + static int encoding##_encode( \ + PyMultibyteCodec_State *state, \ + const Py_UNICODE **inbuf, size_t inleft, \ + unsigned char **outbuf, size_t outleft) +#define DECODER(encoding) \ + static int encoding##_decode( \ + PyMultibyteCodec_State *state, \ + const unsigned char **inbuf, size_t inleft, \ + Py_UNICODE **outbuf, size_t outleft) +#define CODECDEF(encoding) \ + static PyMultibyteCodec __codec = { \ + #encoding, encoding##_encode, encoding##_decode \ + }; +#define NOMETHODS(name) \ + static struct PyMethodDef name[] = { \ + {NULL, NULL}, \ + }; + #define MAPOPEN(mod, locale) \ mod = PyImport_ImportModule("mapdata_" locale); \ if (mod == NULL) goto errorexit; @@ -43,6 +71,14 @@ goto errorexit; #define MULTIBYTECODEC_CLOSE(mod, o) \ Py_DECREF(o); Py_DECREF(mod); + +#define IMPORTMAP(mod, encoding, em, dm) \ + importmap(mod, "__map_" #encoding, em, dm) +#define REGISTERCODEC(m, o, codec) \ + codec = createcodec(o, &__codec); \ + if (codec == NULL) \ + goto errorexit; \ + PyModule_AddObject(m, "codec", codec); static int importmap(PyObject *mod, const char *symbol, |