[KoCo-CVS] [Commit] KoreanCodecs/src hangul.c
Brought to you by:
perky
From: Hye-Shik C. <pe...@us...> - 2003-01-02 03:44:42
|
perky 03/01/01 19:44:41 Modified: src hangul.c Log: Minor style fixes Revision Changes Path 1.16 +48 -44 KoreanCodecs/src/hangul.c Index: hangul.c =================================================================== RCS file: /cvsroot/koco/KoreanCodecs/src/hangul.c,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- hangul.c 14 Oct 2002 10:27:13 -0000 1.15 +++ hangul.c 2 Jan 2003 03:44:41 -0000 1.16 @@ -1,10 +1,10 @@ /* - * hangul.c - $Revision: 1.15 $ + * hangul.c - $Revision: 1.16 $ * * KoreanCodecs Hangul Module C Implementation * * Author : Hye-Shik Chang <pe...@Fr...> - * Date : $Date: 2002/10/14 10:27:13 $ + * Date : $Date: 2003/01/02 03:44:41 $ * Created : 25 April 2002 * * This file is part of KoreanCodecs. @@ -24,7 +24,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -static char *version = "$Revision: 1.15 $"; +static char *version = "$Revision: 1.16 $"; #include "Python.h" @@ -377,11 +377,9 @@ if (codelen > i+1 && JUNGSUNG_FILLER <= code[i+1] && code[i+1] <= 0x1175) { - if (c == CHOSUNG_FILLER) cho = -1; - else cho = c - JBASE_CHOSUNG; - - if (code[i+1] == JUNGSUNG_FILLER) jung = -1; - else jung = code[i+1] - JBASE_JUNGSUNG; + cho = (c == CHOSUNG_FILLER) ? -1 : c - JBASE_CHOSUNG; + jung = (code[i+1] == JUNGSUNG_FILLER) ? -1 : + code[i+1] - JBASE_JUNGSUNG; if (codelen > i+2 && JBASE_JONGSUNG <= code[i+2] && code[i+2] <= 0x11c2) { @@ -393,8 +391,10 @@ if (jong && (cho == -1 || jung == -1)) { /* can't trans to syllable */ - if (cho >= 0) *(dst++) = jamo_chosung[cho]->code; - if (jung >= 0) *(dst++) = jamo_jungsung[jung]->code; + if (cho >= 0) + *(dst++) = jamo_chosung[cho]->code; + if (jung >= 0) + *(dst++) = jamo_jungsung[jung]->code; *(dst++) = jamo_jongsung[jong]->code; } else if (cho == -1) /* jungsung only */ @@ -558,33 +558,33 @@ fmt = PyUnicode_AS_UNICODE(r); fmtsize = PyUnicode_GET_SIZE(r); -#define HAS_FINAL() ( \ - (past = *(fmt-1)), \ - isHangulSyllable(past) ? \ - ((past-HANGUL_BOTTOM) % NJONGSUNG > 0) \ - : (past < 0x80 ? pseudofinal[past] : 0) \ +#define HAS_FINAL() ( \ + (past = *(fmt-1)), \ + isHangulSyllable(past) ? \ + ((past-HANGUL_BOTTOM) % NJONGSUNG > 0) \ + : (past < 0x80 ? pseudofinal[past] : 0) \ ) -#define HAS_FINAL_OR_NOTSYL() ( \ - (past = *(fmt-1)), \ - isHangulSyllable(past) ? \ - ((past-HANGUL_BOTTOM) % NJONGSUNG > 0) \ - : 1 \ +#define HAS_FINAL_OR_NOTSYL() ( \ + (past = *(fmt-1)), \ + isHangulSyllable(past) ? \ + ((past-HANGUL_BOTTOM) % NJONGSUNG > 0) \ + : 1 \ ) -#define PROCESSSUFFIX(nofinal, existfinal) \ - if (next == nofinal || next == existfinal) { \ - *(fcur++) = HAS_FINAL() ? (existfinal) : (nofinal); \ - fmtsize--; fmt++; \ +#define PROCESSSUFFIX(nofinal, existfinal) \ + if (next == nofinal || next == existfinal) { \ + *(fcur++) = HAS_FINAL() ? (existfinal) : (nofinal); \ + fmtsize--; fmt++; \ } -#define PROCESSSUFFIX_IDA(jongsungadder, existfinal) \ - if (next == existfinal) { \ - if (HAS_FINAL_OR_NOTSYL()) \ - *(fcur++) = existfinal; \ - else \ - *(fcur-1) += jongsungadder; \ - fmtsize-=3; fmt+=3; \ +#define PROCESSSUFFIX_IDA(jongsungadder, existfinal) \ + if (next == existfinal) { \ + if (HAS_FINAL_OR_NOTSYL()) \ + *(fcur++) = existfinal; \ + else \ + *(fcur-1) += jongsungadder; \ + fmtsize-=3; fmt+=3; \ } for (fcur = fmtout; fmtsize--; fmt++) { @@ -611,7 +611,6 @@ *(fcur++) = *fmt; } -/* these were written separatedly for win32 compilers */ #undef PROCESSSUFFIX #undef PROCESSSUFFIX_IDA #undef HAS_FINAL @@ -663,6 +662,13 @@ PyDict_SetItemString(dict, #value, mp); \ Py_DECREF(mp); \ } +#define SET_UNICHARCONSTANT(dict, value) { \ + PyObject *mp; \ + Py_UNICODE tmpuni = value; \ + mp = PyUnicode_FromUnicode(&tmpuni, 1); \ + PyDict_SetItemString(dict, #value, mp); \ + Py_DECREF(mp); \ +} void inithangul(void) @@ -801,20 +807,18 @@ PyDict_SetItemString(d, "ZONE", tmp); Py_DECREF(tmp); - tuni[0] = JBASE_CHOSUNG; - PyDict_SetItemString(d, "JBASE_CHOSUNG", PyUnicode_FromUnicode(tuni, 1)); - tuni[0] = JBASE_JUNGSUNG; - PyDict_SetItemString(d, "JBASE_JUNGSUNG", PyUnicode_FromUnicode(tuni, 1)); - tuni[0] = JBASE_JONGSUNG; - PyDict_SetItemString(d, "JBASE_JONGSUNG", PyUnicode_FromUnicode(tuni, 1)); - tuni[0] = CHOSUNG_FILLER; - PyDict_SetItemString(d, "CHOSUNG_FILLER", PyUnicode_FromUnicode(tuni, 1)); - tuni[0] = JUNGSUNG_FILLER; - PyDict_SetItemString(d, "JUNGSUNG_FILLER", PyUnicode_FromUnicode(tuni, 1)); + SET_UNICHARCONSTANT(d, JBASE_CHOSUNG); + SET_UNICHARCONSTANT(d, JBASE_JUNGSUNG); + SET_UNICHARCONSTANT(d, JBASE_JONGSUNG); + SET_UNICHARCONSTANT(d, CHOSUNG_FILLER); + SET_UNICHARCONSTANT(d, JUNGSUNG_FILLER); + PyDict_SetItemString(d, "Null", UniNull); PyDict_SetItemString(d, "Space", UniSpace); - PyDict_SetItemString(d, "version", PyString_FromString(version)); + tmp = PyString_FromString(version); + PyDict_SetItemString(d, "__version__", tmp); + Py_DECREF(tmp); ErrorObject = PyErr_NewException("hangul.UnicodeHangulError", NULL, NULL); PyDict_SetItemString(d, "UnicodeHangulError", ErrorObject); @@ -825,6 +829,6 @@ } /* - * $Id: hangul.c,v 1.15 2002/10/14 10:27:13 perky Exp $ + * $Id: hangul.c,v 1.16 2003/01/02 03:44:41 perky Exp $ * ex: ts=8 sts=4 et */ |