summaryrefslogtreecommitdiffstats
path: root/Modules/cjkcodecs
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-10-28 23:19:27 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-10-28 23:19:27 (GMT)
commit14c9fea60aa6884586c0a87046b308c2af76d38d (patch)
tree81c61ca9de204a341e7b1e21b4ffa11bb4785e81 /Modules/cjkcodecs
parent146a2ed0f29a338abe7ea954604ee0f68b35c37f (diff)
downloadcpython-14c9fea60aa6884586c0a87046b308c2af76d38d.zip
cpython-14c9fea60aa6884586c0a87046b308c2af76d38d.tar.gz
cpython-14c9fea60aa6884586c0a87046b308c2af76d38d.tar.bz2
CJK codecs: less magic macros, require explicit semicolon
Diffstat (limited to 'Modules/cjkcodecs')
-rw-r--r--Modules/cjkcodecs/_codecs_cn.c93
-rw-r--r--Modules/cjkcodecs/_codecs_hk.c8
-rw-r--r--Modules/cjkcodecs/_codecs_iso2022.c57
-rw-r--r--Modules/cjkcodecs/_codecs_jp.c58
-rw-r--r--Modules/cjkcodecs/_codecs_kr.c48
-rw-r--r--Modules/cjkcodecs/_codecs_tw.c16
-rw-r--r--Modules/cjkcodecs/alg_jisx0201.h35
-rw-r--r--Modules/cjkcodecs/cjkcodecs.h64
-rw-r--r--Modules/cjkcodecs/emu_jisx0213_2000.h36
-rw-r--r--Modules/cjkcodecs/multibytecodec.h10
10 files changed, 234 insertions, 191 deletions
diff --git a/Modules/cjkcodecs/_codecs_cn.c b/Modules/cjkcodecs/_codecs_cn.c
index c5e5d25..5fbcfec 100644
--- a/Modules/cjkcodecs/_codecs_cn.c
+++ b/Modules/cjkcodecs/_codecs_cn.c
@@ -23,23 +23,32 @@
* A844 undefined U+2015 HORIZONTAL BAR
*/
-#define GBK_DECODE(dc1, dc2, writer) \
- if ((dc1) == 0xa1 && (dc2) == 0xaa) OUTCHAR(0x2014); \
- else if ((dc1) == 0xa8 && (dc2) == 0x44) OUTCHAR(0x2015); \
- else if ((dc1) == 0xa1 && (dc2) == 0xa4) OUTCHAR(0x00b7); \
- else if (TRYMAP_DEC(gb2312, decoded, dc1 ^ 0x80, dc2 ^ 0x80)) \
- OUTCHAR(decoded); \
- else if (TRYMAP_DEC(gbkext, decoded, dc1, dc2)) \
- OUTCHAR(decoded);
+#define GBK_DECODE(dc1, dc2, writer) \
+ if ((dc1) == 0xa1 && (dc2) == 0xaa) { \
+ OUTCHAR(0x2014); \
+ } \
+ else if ((dc1) == 0xa8 && (dc2) == 0x44) { \
+ OUTCHAR(0x2015); \
+ } \
+ else if ((dc1) == 0xa1 && (dc2) == 0xa4) { \
+ OUTCHAR(0x00b7); \
+ } \
+ else if (TRYMAP_DEC(gb2312, decoded, dc1 ^ 0x80, dc2 ^ 0x80)) { \
+ OUTCHAR(decoded); \
+ } \
+ else if (TRYMAP_DEC(gbkext, decoded, dc1, dc2)) { \
+ OUTCHAR(decoded); \
+ }
#define GBK_ENCODE(code, assi) \
- if ((code) == 0x2014) \
+ if ((code) == 0x2014) { \
(assi) = 0xa1aa; \
- else if ((code) == 0x2015) \
+ } else if ((code) == 0x2015) { \
(assi) = 0xa844; \
- else if ((code) == 0x00b7) \
+ } else if ((code) == 0x00b7) { \
(assi) = 0xa1a4; \
- else if ((code) != 0x30fb && TRYMAP_ENC(gbcommon, assi, code))
+ } else if ((code) != 0x30fb && TRYMAP_ENC(gbcommon, assi, code)) { \
+ }
/*
* GB2312 codec
@@ -52,7 +61,7 @@ ENCODER(gb2312)
DBCHAR code;
if (c < 0x80) {
- WRITEBYTE1((unsigned char)c)
+ WRITEBYTE1((unsigned char)c);
NEXT(1, 1);
continue;
}
@@ -60,7 +69,7 @@ ENCODER(gb2312)
if (c > 0xFFFF)
return 1;
- REQUIRE_OUTBUF(2)
+ REQUIRE_OUTBUF(2);
if (TRYMAP_ENC(gbcommon, code, c))
;
else
@@ -69,8 +78,8 @@ ENCODER(gb2312)
if (code & 0x8000) /* MSB set: GBK */
return 1;
- OUTBYTE1((code >> 8) | 0x80)
- OUTBYTE2((code & 0xFF) | 0x80)
+ OUTBYTE1((code >> 8) | 0x80);
+ OUTBYTE2((code & 0xFF) | 0x80);
NEXT(1, 2);
}
@@ -113,7 +122,7 @@ ENCODER(gbk)
DBCHAR code;
if (c < 0x80) {
- WRITEBYTE1((unsigned char)c)
+ WRITEBYTE1((unsigned char)c);
NEXT(1, 1);
continue;
}
@@ -121,18 +130,17 @@ ENCODER(gbk)
if (c > 0xFFFF)
return 1;
- REQUIRE_OUTBUF(2)
+ REQUIRE_OUTBUF(2);
GBK_ENCODE(c, code)
- ;
else
return 1;
- OUTBYTE1((code >> 8) | 0x80)
+ OUTBYTE1((code >> 8) | 0x80);
if (code & 0x8000)
- OUTBYTE2((code & 0xFF)) /* MSB set: GBK */
+ OUTBYTE2((code & 0xFF)); /* MSB set: GBK */
else
- OUTBYTE2((code & 0xFF) | 0x80) /* MSB unset: GB2312 */
+ OUTBYTE2((code & 0xFF) | 0x80); /* MSB unset: GB2312 */
NEXT(1, 2);
}
@@ -175,7 +183,7 @@ ENCODER(gb18030)
DBCHAR code;
if (c < 0x80) {
- WRITEBYTE1(c)
+ WRITEBYTE1(c);
NEXT(1, 1);
continue;
}
@@ -184,30 +192,29 @@ ENCODER(gb18030)
Py_UCS4 tc = c - 0x10000;
assert (c <= 0x10FFFF);
- REQUIRE_OUTBUF(4)
+ REQUIRE_OUTBUF(4);
- OUTBYTE4((unsigned char)(tc % 10) + 0x30)
+ OUTBYTE4((unsigned char)(tc % 10) + 0x30);
tc /= 10;
- OUTBYTE3((unsigned char)(tc % 126) + 0x81)
+ OUTBYTE3((unsigned char)(tc % 126) + 0x81);
tc /= 126;
- OUTBYTE2((unsigned char)(tc % 10) + 0x30)
+ OUTBYTE2((unsigned char)(tc % 10) + 0x30);
tc /= 10;
- OUTBYTE1((unsigned char)(tc + 0x90))
+ OUTBYTE1((unsigned char)(tc + 0x90));
NEXT(1, 4);
continue;
}
- REQUIRE_OUTBUF(2)
+ REQUIRE_OUTBUF(2);
GBK_ENCODE(c, code)
- ;
else if (TRYMAP_ENC(gb18030ext, code, c))
;
else {
const struct _gb18030_to_unibmp_ranges *utrrange;
- REQUIRE_OUTBUF(4)
+ REQUIRE_OUTBUF(4);
for (utrrange = gb18030_to_unibmp_ranges;
utrrange->first != 0;
@@ -219,13 +226,13 @@ ENCODER(gb18030)
tc = c - utrrange->first +
utrrange->base;
- OUTBYTE4((unsigned char)(tc % 10) + 0x30)
+ OUTBYTE4((unsigned char)(tc % 10) + 0x30);
tc /= 10;
- OUTBYTE3((unsigned char)(tc % 126) + 0x81)
+ OUTBYTE3((unsigned char)(tc % 126) + 0x81);
tc /= 126;
- OUTBYTE2((unsigned char)(tc % 10) + 0x30)
+ OUTBYTE2((unsigned char)(tc % 10) + 0x30);
tc /= 10;
- OUTBYTE1((unsigned char)tc + 0x81)
+ OUTBYTE1((unsigned char)tc + 0x81);
NEXT(1, 4);
break;
@@ -236,11 +243,11 @@ ENCODER(gb18030)
continue;
}
- OUTBYTE1((code >> 8) | 0x80)
+ OUTBYTE1((code >> 8) | 0x80);
if (code & 0x8000)
- OUTBYTE2((code & 0xFF)) /* MSB set: GBK or GB18030ext */
+ OUTBYTE2((code & 0xFF)); /* MSB set: GBK or GB18030ext */
else
- OUTBYTE2((code & 0xFF) | 0x80) /* MSB unset: GB2312 */
+ OUTBYTE2((code & 0xFF) | 0x80); /* MSB unset: GB2312 */
NEXT(1, 2);
}
@@ -326,7 +333,7 @@ ENCODER_INIT(hz)
ENCODER_RESET(hz)
{
if (state->i != 0) {
- WRITEBYTE2('~', '}')
+ WRITEBYTE2('~', '}');
state->i = 0;
NEXT_OUT(2);
}
@@ -341,11 +348,11 @@ ENCODER(hz)
if (c < 0x80) {
if (state->i == 0) {
- WRITEBYTE1((unsigned char)c)
+ WRITEBYTE1((unsigned char)c);
NEXT(1, 1);
}
else {
- WRITEBYTE3('~', '}', (unsigned char)c)
+ WRITEBYTE3('~', '}', (unsigned char)c);
NEXT(1, 3);
state->i = 0;
}
@@ -364,12 +371,12 @@ ENCODER(hz)
return 1;
if (state->i == 0) {
- WRITEBYTE4('~', '{', code >> 8, code & 0xff)
+ WRITEBYTE4('~', '{', code >> 8, code & 0xff);
NEXT(1, 4);
state->i = 1;
}
else {
- WRITEBYTE2(code >> 8, code & 0xff)
+ WRITEBYTE2(code >> 8, code & 0xff);
NEXT(1, 2);
}
}
diff --git a/Modules/cjkcodecs/_codecs_hk.c b/Modules/cjkcodecs/_codecs_hk.c
index a79b699..92c468a 100644
--- a/Modules/cjkcodecs/_codecs_hk.c
+++ b/Modules/cjkcodecs/_codecs_hk.c
@@ -44,14 +44,14 @@ ENCODER(big5hkscs)
Py_ssize_t insize;
if (c < 0x80) {
- REQUIRE_OUTBUF(1)
+ REQUIRE_OUTBUF(1);
**outbuf = (unsigned char)c;
NEXT(1, 1);
continue;
}
insize = 1;
- REQUIRE_OUTBUF(2)
+ REQUIRE_OUTBUF(2);
if (c < 0x10000) {
if (TRYMAP_ENC(big5hkscs_bmp, code, c)) {
@@ -97,8 +97,8 @@ ENCODER(big5hkscs)
else
return insize;
- OUTBYTE1(code >> 8)
- OUTBYTE2(code & 0xFF)
+ OUTBYTE1(code >> 8);
+ OUTBYTE2(code & 0xFF);
NEXT(insize, 2);
}
diff --git a/Modules/cjkcodecs/_codecs_iso2022.c b/Modules/cjkcodecs/_codecs_iso2022.c
index 0fd786a..3e5fb43 100644
--- a/Modules/cjkcodecs/_codecs_iso2022.c
+++ b/Modules/cjkcodecs/_codecs_iso2022.c
@@ -141,12 +141,12 @@ ENCODER_INIT(iso2022)
ENCODER_RESET(iso2022)
{
if (STATE_GETFLAG(F_SHIFTED)) {
- WRITEBYTE1(SI)
+ WRITEBYTE1(SI);
NEXT_OUT(1);
STATE_CLEARFLAG(F_SHIFTED)
}
if (STATE_G0 != CHARSET_ASCII) {
- WRITEBYTE3(ESC, '(', 'B')
+ WRITEBYTE3(ESC, '(', 'B');
NEXT_OUT(3);
STATE_SETG0(CHARSET_ASCII)
}
@@ -163,16 +163,16 @@ ENCODER(iso2022)
if (c < 0x80) {
if (STATE_G0 != CHARSET_ASCII) {
- WRITEBYTE3(ESC, '(', 'B')
+ WRITEBYTE3(ESC, '(', 'B');
STATE_SETG0(CHARSET_ASCII)
NEXT_OUT(3);
}
if (STATE_GETFLAG(F_SHIFTED)) {
- WRITEBYTE1(SI)
+ WRITEBYTE1(SI);
STATE_CLEARFLAG(F_SHIFTED)
NEXT_OUT(1);
}
- WRITEBYTE1((unsigned char)c)
+ WRITEBYTE1((unsigned char)c);
NEXT(1, 1);
continue;
}
@@ -210,24 +210,24 @@ ENCODER(iso2022)
switch (dsg->plane) {
case 0: /* G0 */
if (STATE_GETFLAG(F_SHIFTED)) {
- WRITEBYTE1(SI)
+ WRITEBYTE1(SI);
STATE_CLEARFLAG(F_SHIFTED)
NEXT_OUT(1);
}
if (STATE_G0 != dsg->mark) {
if (dsg->width == 1) {
- WRITEBYTE3(ESC, '(', ESCMARK(dsg->mark))
+ WRITEBYTE3(ESC, '(', ESCMARK(dsg->mark));
STATE_SETG0(dsg->mark)
NEXT_OUT(3);
}
else if (dsg->mark == CHARSET_JISX0208) {
- WRITEBYTE3(ESC, '$', ESCMARK(dsg->mark))
+ WRITEBYTE3(ESC, '$', ESCMARK(dsg->mark));
STATE_SETG0(dsg->mark)
NEXT_OUT(3);
}
else {
WRITEBYTE4(ESC, '$', '(',
- ESCMARK(dsg->mark))
+ ESCMARK(dsg->mark));
STATE_SETG0(dsg->mark)
NEXT_OUT(4);
}
@@ -236,19 +236,19 @@ ENCODER(iso2022)
case 1: /* G1 */
if (STATE_G1 != dsg->mark) {
if (dsg->width == 1) {
- WRITEBYTE3(ESC, ')', ESCMARK(dsg->mark))
+ WRITEBYTE3(ESC, ')', ESCMARK(dsg->mark));
STATE_SETG1(dsg->mark)
NEXT_OUT(3);
}
else {
WRITEBYTE4(ESC, '$', ')',
- ESCMARK(dsg->mark))
+ ESCMARK(dsg->mark));
STATE_SETG1(dsg->mark)
NEXT_OUT(4);
}
}
if (!STATE_GETFLAG(F_SHIFTED)) {
- WRITEBYTE1(SO)
+ WRITEBYTE1(SO);
STATE_SETFLAG(F_SHIFTED)
NEXT_OUT(1);
}
@@ -259,11 +259,11 @@ ENCODER(iso2022)
}
if (dsg->width == 1) {
- WRITEBYTE1((unsigned char)encoded)
+ WRITEBYTE1((unsigned char)encoded);
NEXT_OUT(1);
}
else {
- WRITEBYTE2(encoded >> 8, encoded & 0xff)
+ WRITEBYTE2(encoded >> 8, encoded & 0xff);
NEXT_OUT(2);
}
NEXT_INCHAR(insize);
@@ -371,20 +371,21 @@ iso2022processesc(const void *config, MultibyteCodec_State *state,
return 0;
}
-#define ISO8859_7_DECODE(c, writer) \
- if ((c) < 0xa0) \
- OUTCHAR(c); \
- else if ((c) < 0xc0 && (0x288f3bc9L & (1L << ((c)-0xa0)))) \
- OUTCHAR(c); \
- else if ((c) >= 0xb4 && (c) <= 0xfe && ((c) >= 0xd4 || \
- (0xbffffd77L & (1L << ((c)-0xb4))))) \
- OUTCHAR(0x02d0 + (c)); \
- else if ((c) == 0xa1) \
- OUTCHAR(0x2018); \
- else if ((c) == 0xa2) \
- OUTCHAR(0x2019); \
- else if ((c) == 0xaf) \
- OUTCHAR(0x2015);
+#define ISO8859_7_DECODE(c, writer) \
+ if ((c) < 0xa0) { \
+ OUTCHAR(c); \
+ } else if ((c) < 0xc0 && (0x288f3bc9L & (1L << ((c)-0xa0)))) { \
+ OUTCHAR(c); \
+ } else if ((c) >= 0xb4 && (c) <= 0xfe && ((c) >= 0xd4 || \
+ (0xbffffd77L & (1L << ((c)-0xb4))))) { \
+ OUTCHAR(0x02d0 + (c)); \
+ } else if ((c) == 0xa1) { \
+ OUTCHAR(0x2018); \
+ } else if ((c) == 0xa2) { \
+ OUTCHAR(0x2019); \
+ } else if ((c) == 0xaf) { \
+ OUTCHAR(0x2015); \
+ }
static Py_ssize_t
iso2022processg2(const void *config, MultibyteCodec_State *state,
diff --git a/Modules/cjkcodecs/_codecs_jp.c b/Modules/cjkcodecs/_codecs_jp.c
index bc34020..447bf77 100644
--- a/Modules/cjkcodecs/_codecs_jp.c
+++ b/Modules/cjkcodecs/_codecs_jp.c
@@ -25,33 +25,33 @@ ENCODER(cp932)
unsigned char c1, c2;
if (c <= 0x80) {
- WRITEBYTE1((unsigned char)c)
+ WRITEBYTE1((unsigned char)c);
NEXT(1, 1);
continue;
}
else if (c >= 0xff61 && c <= 0xff9f) {
- WRITEBYTE1(c - 0xfec0)
+ WRITEBYTE1(c - 0xfec0);
NEXT(1, 1);
continue;
}
else if (c >= 0xf8f0 && c <= 0xf8f3) {
/* Windows compatibility */
- REQUIRE_OUTBUF(1)
+ REQUIRE_OUTBUF(1);
if (c == 0xf8f0)
- OUTBYTE1(0xa0)
+ OUTBYTE1(0xa0);
else
- OUTBYTE1(c - 0xfef1 + 0xfd)
+ OUTBYTE1(c - 0xfef1 + 0xfd);
NEXT(1, 1);
continue;
}
if (c > 0xFFFF)
return 1;
- REQUIRE_OUTBUF(2)
+ REQUIRE_OUTBUF(2);
if (TRYMAP_ENC(cp932ext, code, c)) {
- OUTBYTE1(code >> 8)
- OUTBYTE2(code & 0xff)
+ OUTBYTE1(code >> 8);
+ OUTBYTE2(code & 0xff);
}
else if (TRYMAP_ENC(jisxcommon, code, c)) {
if (code & 0x8000) /* MSB set: JIS X 0212 */
@@ -62,15 +62,15 @@ ENCODER(cp932)
c2 = code & 0xff;
c2 = (((c1 - 0x21) & 1) ? 0x5e : 0) + (c2 - 0x21);
c1 = (c1 - 0x21) >> 1;
- OUTBYTE1(c1 < 0x1f ? c1 + 0x81 : c1 + 0xc1)
- OUTBYTE2(c2 < 0x3f ? c2 + 0x40 : c2 + 0x41)
+ OUTBYTE1(c1 < 0x1f ? c1 + 0x81 : c1 + 0xc1);
+ OUTBYTE2(c2 < 0x3f ? c2 + 0x40 : c2 + 0x41);
}
else if (c >= 0xe000 && c < 0xe758) {
/* User-defined area */
c1 = (Py_UCS4)(c - 0xe000) / 188;
c2 = (Py_UCS4)(c - 0xe000) % 188;
- OUTBYTE1(c1 + 0xf0)
- OUTBYTE2(c2 < 0x3f ? c2 + 0x40 : c2 + 0x41)
+ OUTBYTE1(c1 + 0xf0);
+ OUTBYTE2(c2 < 0x3f ? c2 + 0x40 : c2 + 0x41);
}
else
return 1;
@@ -156,7 +156,7 @@ ENCODER(euc_jis_2004)
Py_ssize_t insize;
if (c < 0x80) {
- WRITEBYTE1(c)
+ WRITEBYTE1(c);
NEXT(1, 1);
continue;
}
@@ -201,7 +201,7 @@ ENCODER(euc_jis_2004)
;
else if (c >= 0xff61 && c <= 0xff9f) {
/* JIS X 0201 half-width katakana */
- WRITEBYTE2(0x8e, c - 0xfec0)
+ WRITEBYTE2(0x8e, c - 0xfec0);
NEXT(1, 2);
continue;
}
@@ -226,11 +226,11 @@ ENCODER(euc_jis_2004)
if (code & 0x8000) {
/* Codeset 2 */
- WRITEBYTE3(0x8f, code >> 8, (code & 0xFF) | 0x80)
+ WRITEBYTE3(0x8f, code >> 8, (code & 0xFF) | 0x80);
NEXT(insize, 3);
} else {
/* Codeset 1 */
- WRITEBYTE2((code >> 8) | 0x80, (code & 0xFF) | 0x80)
+ WRITEBYTE2((code >> 8) | 0x80, (code & 0xFF) | 0x80);
NEXT(insize, 2);
}
}
@@ -333,7 +333,7 @@ ENCODER(euc_jp)
DBCHAR code;
if (c < 0x80) {
- WRITEBYTE1((unsigned char)c)
+ WRITEBYTE1((unsigned char)c);
NEXT(1, 1);
continue;
}
@@ -345,7 +345,7 @@ ENCODER(euc_jp)
;
else if (c >= 0xff61 && c <= 0xff9f) {
/* JIS X 0201 half-width katakana */
- WRITEBYTE2(0x8e, c - 0xfec0)
+ WRITEBYTE2(0x8e, c - 0xfec0);
NEXT(1, 2);
continue;
}
@@ -367,11 +367,11 @@ ENCODER(euc_jp)
if (code & 0x8000) {
/* JIS X 0212 */
- WRITEBYTE3(0x8f, code >> 8, (code & 0xFF) | 0x80)
+ WRITEBYTE3(0x8f, code >> 8, (code & 0xFF) | 0x80);
NEXT(1, 3);
} else {
/* JIS X 0208 */
- WRITEBYTE2((code >> 8) | 0x80, (code & 0xFF) | 0x80)
+ WRITEBYTE2((code >> 8) | 0x80, (code & 0xFF) | 0x80);
NEXT(1, 2);
}
}
@@ -470,14 +470,14 @@ ENCODER(shift_jis)
code = NOCHAR;
if (code < 0x80 || (code >= 0xa1 && code <= 0xdf)) {
- REQUIRE_OUTBUF(1)
+ REQUIRE_OUTBUF(1);
- OUTBYTE1((unsigned char)code)
+ OUTBYTE1((unsigned char)code);
NEXT(1, 1);
continue;
}
- REQUIRE_OUTBUF(2)
+ REQUIRE_OUTBUF(2);
if (code == NOCHAR) {
if (TRYMAP_ENC(jisxcommon, code, c))
@@ -497,8 +497,8 @@ ENCODER(shift_jis)
c2 = code & 0xff;
c2 = (((c1 - 0x21) & 1) ? 0x5e : 0) + (c2 - 0x21);
c1 = (c1 - 0x21) >> 1;
- OUTBYTE1(c1 < 0x1f ? c1 + 0x81 : c1 + 0xc1)
- OUTBYTE2(c2 < 0x3f ? c2 + 0x40 : c2 + 0x41)
+ OUTBYTE1(c1 < 0x1f ? c1 + 0x81 : c1 + 0xc1);
+ OUTBYTE2(c2 < 0x3f ? c2 + 0x40 : c2 + 0x41);
NEXT(1, 2);
}
@@ -572,12 +572,12 @@ ENCODER(shift_jis_2004)
JISX0201_ENCODE(c, code)
if (code < 0x80 || (code >= 0xa1 && code <= 0xdf)) {
- WRITEBYTE1((unsigned char)code)
+ WRITEBYTE1((unsigned char)code);
NEXT(1, 1);
continue;
}
- REQUIRE_OUTBUF(2)
+ REQUIRE_OUTBUF(2);
insize = 1;
if (code == NOCHAR) {
@@ -654,8 +654,8 @@ ENCODER(shift_jis_2004)
if (c1 & 1)
c2 += 0x5e;
c1 >>= 1;
- OUTBYTE1(c1 + (c1 < 0x1f ? 0x81 : 0xc1))
- OUTBYTE2(c2 + (c2 < 0x3f ? 0x40 : 0x41))
+ OUTBYTE1(c1 + (c1 < 0x1f ? 0x81 : 0xc1));
+ OUTBYTE2(c2 + (c2 < 0x3f ? 0x40 : 0x41));
NEXT(insize, 2);
}
diff --git a/Modules/cjkcodecs/_codecs_kr.c b/Modules/cjkcodecs/_codecs_kr.c
index 062a0ff..6a3a1f7 100644
--- a/Modules/cjkcodecs/_codecs_kr.c
+++ b/Modules/cjkcodecs/_codecs_kr.c
@@ -38,7 +38,7 @@ ENCODER(euc_kr)
DBCHAR code;
if (c < 0x80) {
- WRITEBYTE1((unsigned char)c)
+ WRITEBYTE1((unsigned char)c);
NEXT(1, 1);
continue;
}
@@ -46,7 +46,7 @@ ENCODER(euc_kr)
if (c > 0xFFFF)
return 1;
- REQUIRE_OUTBUF(2)
+ REQUIRE_OUTBUF(2);
if (TRYMAP_ENC(cp949, code, c))
;
else
@@ -54,33 +54,33 @@ ENCODER(euc_kr)
if ((code & 0x8000) == 0) {
/* KS X 1001 coded character */
- OUTBYTE1((code >> 8) | 0x80)
- OUTBYTE2((code & 0xFF) | 0x80)
+ OUTBYTE1((code >> 8) | 0x80);
+ OUTBYTE2((code & 0xFF) | 0x80);
NEXT(1, 2);
}
else { /* Mapping is found in CP949 extension,
* but we encode it in KS X 1001:1998 Annex 3,
* make-up sequence for EUC-KR. */
- REQUIRE_OUTBUF(8)
+ REQUIRE_OUTBUF(8);
/* syllable composition precedence */
- OUTBYTE1(EUCKR_JAMO_FIRSTBYTE)
- OUTBYTE2(EUCKR_JAMO_FILLER)
+ OUTBYTE1(EUCKR_JAMO_FIRSTBYTE);
+ OUTBYTE2(EUCKR_JAMO_FILLER);
/* All codepoints in CP949 extension are in unicode
* Hangul Syllable area. */
assert(0xac00 <= c && c <= 0xd7a3);
c -= 0xac00;
- OUTBYTE3(EUCKR_JAMO_FIRSTBYTE)
- OUTBYTE4(u2cgk_choseong[c / 588])
+ OUTBYTE3(EUCKR_JAMO_FIRSTBYTE);
+ OUTBYTE4(u2cgk_choseong[c / 588]);
NEXT_OUT(4);
- OUTBYTE1(EUCKR_JAMO_FIRSTBYTE)
- OUTBYTE2(u2cgk_jungseong[(c / 28) % 21])
- OUTBYTE3(EUCKR_JAMO_FIRSTBYTE)
- OUTBYTE4(u2cgk_jongseong[c % 28])
+ OUTBYTE1(EUCKR_JAMO_FIRSTBYTE);
+ OUTBYTE2(u2cgk_jungseong[(c / 28) % 21]);
+ OUTBYTE3(EUCKR_JAMO_FIRSTBYTE);
+ OUTBYTE4(u2cgk_jongseong[c % 28]);
NEXT(1, 4);
}
}
@@ -175,7 +175,7 @@ ENCODER(cp949)
DBCHAR code;
if (c < 0x80) {
- WRITEBYTE1((unsigned char)c)
+ WRITEBYTE1((unsigned char)c);
NEXT(1, 1);
continue;
}
@@ -183,17 +183,17 @@ ENCODER(cp949)
if (c > 0xFFFF)
return 1;
- REQUIRE_OUTBUF(2)
+ REQUIRE_OUTBUF(2);
if (TRYMAP_ENC(cp949, code, c))
;
else
return 1;
- OUTBYTE1((code >> 8) | 0x80)
+ OUTBYTE1((code >> 8) | 0x80);
if (code & 0x8000)
- OUTBYTE2(code & 0xFF) /* MSB set: CP949 */
+ OUTBYTE2(code & 0xFF); /* MSB set: CP949 */
else
- OUTBYTE2((code & 0xFF) | 0x80) /* MSB unset: ks x 1001 */
+ OUTBYTE2((code & 0xFF) | 0x80); /* MSB unset: ks x 1001 */
NEXT(1, 2);
}
@@ -265,7 +265,7 @@ ENCODER(johab)
DBCHAR code;
if (c < 0x80) {
- WRITEBYTE1((unsigned char)c)
+ WRITEBYTE1((unsigned char)c);
NEXT(1, 1);
continue;
}
@@ -273,7 +273,7 @@ ENCODER(johab)
if (c > 0xFFFF)
return 1;
- REQUIRE_OUTBUF(2)
+ REQUIRE_OUTBUF(2);
if (c >= 0xac00 && c <= 0xd7a3) {
c -= 0xac00;
@@ -297,8 +297,8 @@ ENCODER(johab)
t1 = (c1 < 0x4a ? (c1 - 0x21 + 0x1b2) :
(c1 - 0x21 + 0x197));
t2 = ((t1 & 1) ? 0x5e : 0) + (c2 - 0x21);
- OUTBYTE1(t1 >> 1)
- OUTBYTE2(t2 < 0x4e ? t2 + 0x31 : t2 + 0x43)
+ OUTBYTE1(t1 >> 1);
+ OUTBYTE2(t2 < 0x4e ? t2 + 0x31 : t2 + 0x43);
NEXT(1, 2);
continue;
}
@@ -308,8 +308,8 @@ ENCODER(johab)
else
return 1;
- OUTBYTE1(code >> 8)
- OUTBYTE2(code & 0xff)
+ OUTBYTE1(code >> 8);
+ OUTBYTE2(code & 0xff);
NEXT(1, 2);
}
diff --git a/Modules/cjkcodecs/_codecs_tw.c b/Modules/cjkcodecs/_codecs_tw.c
index c294f15..016770c 100644
--- a/Modules/cjkcodecs/_codecs_tw.c
+++ b/Modules/cjkcodecs/_codecs_tw.c
@@ -18,7 +18,7 @@ ENCODER(big5)
DBCHAR code;
if (c < 0x80) {
- REQUIRE_OUTBUF(1)
+ REQUIRE_OUTBUF(1);
**outbuf = (unsigned char)c;
NEXT(1, 1);
continue;
@@ -27,15 +27,15 @@ ENCODER(big5)
if (c > 0xFFFF)
return 1;
- REQUIRE_OUTBUF(2)
+ REQUIRE_OUTBUF(2);
if (TRYMAP_ENC(big5, code, c))
;
else
return 1;
- OUTBYTE1(code >> 8)
- OUTBYTE2(code & 0xFF)
+ OUTBYTE1(code >> 8);
+ OUTBYTE2(code & 0xFF);
NEXT(1, 2);
}
@@ -77,7 +77,7 @@ ENCODER(cp950)
DBCHAR code;
if (c < 0x80) {
- WRITEBYTE1((unsigned char)c)
+ WRITEBYTE1((unsigned char)c);
NEXT(1, 1);
continue;
}
@@ -85,7 +85,7 @@ ENCODER(cp950)
if (c > 0xFFFF)
return 1;
- REQUIRE_OUTBUF(2)
+ REQUIRE_OUTBUF(2);
if (TRYMAP_ENC(cp950ext, code, c))
;
else if (TRYMAP_ENC(big5, code, c))
@@ -93,8 +93,8 @@ ENCODER(cp950)
else
return 1;
- OUTBYTE1(code >> 8)
- OUTBYTE2(code & 0xFF)
+ OUTBYTE1(code >> 8);
+ OUTBYTE2(code & 0xFF);
NEXT(1, 2);
}
diff --git a/Modules/cjkcodecs/alg_jisx0201.h b/Modules/cjkcodecs/alg_jisx0201.h
index 5368e08..3034b5a 100644
--- a/Modules/cjkcodecs/alg_jisx0201.h
+++ b/Modules/cjkcodecs/alg_jisx0201.h
@@ -10,8 +10,9 @@
}
#define JISX0201_K_ENCODE(c, assi) \
- if ((c) >= 0xff61 && (c) <= 0xff9f) \
- { (assi) = (c) - 0xfec0; }
+ if ((c) >= 0xff61 && (c) <= 0xff9f) { \
+ (assi) = (c) - 0xfec0; \
+ }
#define JISX0201_ENCODE(c, assi) \
JISX0201_R_ENCODE(c, assi) \
@@ -35,18 +36,30 @@
}
#define JISX0201_R_DECODE(c, writer) \
- if ((c) < 0x5c) OUTCHAR(c); \
- else if ((c) == 0x5c) OUTCHAR(0x00a5); \
- else if ((c) < 0x7e) OUTCHAR(c); \
- else if ((c) == 0x7e) OUTCHAR(0x203e); \
- else if ((c) == 0x7f) OUTCHAR(0x7f);
+ if ((c) < 0x5c) { \
+ OUTCHAR(c); \
+ } \
+ else if ((c) == 0x5c) { \
+ OUTCHAR(0x00a5); \
+ } \
+ else if ((c) < 0x7e) { \
+ OUTCHAR(c); \
+ } \
+ else if ((c) == 0x7e) { \
+ OUTCHAR(0x203e); \
+ } \
+ else if ((c) == 0x7f) { \
+ OUTCHAR(0x7f); \
+ }
#define JISX0201_K_DECODE(c, writer) \
- if ((c) >= 0xa1 && (c) <= 0xdf) \
- OUTCHAR(0xfec0 + (c));
+ if ((c) >= 0xa1 && (c) <= 0xdf) { \
+ OUTCHAR(0xfec0 + (c)); \
+ }
#define JISX0201_K_DECODE_CHAR(c, assi) \
- if ((c) >= 0xa1 && (c) <= 0xdf) \
- (assi) = 0xfec0 + (c);
+ if ((c) >= 0xa1 && (c) <= 0xdf) { \
+ (assi) = 0xfec0 + (c); \
+ }
#define JISX0201_DECODE(c, writer) \
JISX0201_R_DECODE(c, writer) \
else JISX0201_K_DECODE(c, writer)
diff --git a/Modules/cjkcodecs/cjkcodecs.h b/Modules/cjkcodecs/cjkcodecs.h
index 4a5f0c1..2aedf25 100644
--- a/Modules/cjkcodecs/cjkcodecs.h
+++ b/Modules/cjkcodecs/cjkcodecs.h
@@ -108,24 +108,26 @@ static const struct dbcs_map *mapping_list;
} while (0)
#define NEXT(i, o) \
do { \
- NEXT_INCHAR(i); \
- NEXT_OUT(o); \
+ NEXT_INCHAR(i); \
+ NEXT_OUT(o); \
} while (0)
#define REQUIRE_INBUF(n) \
if (inleft < (n)) \
return MBERR_TOOFEW;
#define REQUIRE_OUTBUF(n) \
- if (outleft < (n)) \
- return MBERR_TOOSMALL;
+ do { \
+ if (outleft < (n)) \
+ return MBERR_TOOSMALL; \
+ } while (0)
#define INBYTE1 ((*inbuf)[0])
#define INBYTE2 ((*inbuf)[1])
#define INBYTE3 ((*inbuf)[2])
#define INBYTE4 ((*inbuf)[3])
-#define INCHAR1 PyUnicode_READ(kind, data, *inpos)
-#define INCHAR2 PyUnicode_READ(kind, data, *inpos + 1)
+#define INCHAR1 (PyUnicode_READ(kind, data, *inpos))
+#define INCHAR2 (PyUnicode_READ(kind, data, *inpos + 1))
#define OUTCHAR(c) \
do { \
@@ -138,35 +140,47 @@ static const struct dbcs_map *mapping_list;
Py_UCS4 _c1 = (c1); \
Py_UCS4 _c2 = (c2); \
if (_PyUnicodeWriter_Prepare(writer, 2, Py_MAX(_c1, c2)) < 0) \
- return MBERR_EXCEPTION; \
+ return MBERR_EXCEPTION; \
PyUnicode_WRITE(writer->kind, writer->data, writer->pos, _c1); \
PyUnicode_WRITE(writer->kind, writer->data, writer->pos + 1, _c2); \
writer->pos += 2; \
} while (0)
-#define OUTBYTE1(c) ((*outbuf)[0]) = (c);
-#define OUTBYTE2(c) ((*outbuf)[1]) = (c);
-#define OUTBYTE3(c) ((*outbuf)[2]) = (c);
-#define OUTBYTE4(c) ((*outbuf)[3]) = (c);
+#define OUTBYTE1(c) \
+ do { ((*outbuf)[0]) = (c); } while (0)
+#define OUTBYTE2(c) \
+ do { ((*outbuf)[1]) = (c); } while (0)
+#define OUTBYTE3(c) \
+ do { ((*outbuf)[2]) = (c); } while (0)
+#define OUTBYTE4(c) \
+ do { ((*outbuf)[3]) = (c); } while (0)
#define WRITEBYTE1(c1) \
- REQUIRE_OUTBUF(1) \
- (*outbuf)[0] = (c1);
+ do { \
+ REQUIRE_OUTBUF(1); \
+ (*outbuf)[0] = (c1); \
+ } while (0)
#define WRITEBYTE2(c1, c2) \
- REQUIRE_OUTBUF(2) \
- (*outbuf)[0] = (c1); \
- (*outbuf)[1] = (c2);
+ do { \
+ REQUIRE_OUTBUF(2); \
+ (*outbuf)[0] = (c1); \
+ (*outbuf)[1] = (c2); \
+ } while (0)
#define WRITEBYTE3(c1, c2, c3) \
- REQUIRE_OUTBUF(3) \
- (*outbuf)[0] = (c1); \
- (*outbuf)[1] = (c2); \
- (*outbuf)[2] = (c3);
+ do { \
+ REQUIRE_OUTBUF(3); \
+ (*outbuf)[0] = (c1); \
+ (*outbuf)[1] = (c2); \
+ (*outbuf)[2] = (c3); \
+ } while (0)
#define WRITEBYTE4(c1, c2, c3, c4) \
- REQUIRE_OUTBUF(4) \
- (*outbuf)[0] = (c1); \
- (*outbuf)[1] = (c2); \
- (*outbuf)[2] = (c3); \
- (*outbuf)[3] = (c4);
+ do { \
+ REQUIRE_OUTBUF(4); \
+ (*outbuf)[0] = (c1); \
+ (*outbuf)[1] = (c2); \
+ (*outbuf)[2] = (c3); \
+ (*outbuf)[3] = (c4); \
+ } while (0)
#define _TRYMAP_ENC(m, assi, val) \
((m)->map != NULL && (val) >= (m)->bottom && \
diff --git a/Modules/cjkcodecs/emu_jisx0213_2000.h b/Modules/cjkcodecs/emu_jisx0213_2000.h
index 877337e..672eb06 100644
--- a/Modules/cjkcodecs/emu_jisx0213_2000.h
+++ b/Modules/cjkcodecs/emu_jisx0213_2000.h
@@ -11,17 +11,20 @@
(c) == 0x525D || (c) == 0x541E || \
(c) == 0x5653 || (c) == 0x59F8 || \
(c) == 0x5C5B || (c) == 0x5E77 || \
- (c) == 0x7626 || (c) == 0x7E6B)) \
+ (c) == 0x7626 || (c) == 0x7E6B)) { \
return EMULATE_JISX0213_2000_ENCODE_INVALID; \
- else if (config == (void *)2000 && (c) == 0x9B1D) \
+ } \
+ else if (config == (void *)2000 && (c) == 0x9B1D) { \
(assi) = 0x8000 | 0x7d3b; \
+ }
#define EMULATE_JISX0213_2000_ENCODE_EMP(assi, c) \
- if (config == (void *)2000 && (c) == 0x20B9F) \
- return EMULATE_JISX0213_2000_ENCODE_INVALID;
+ if (config == (void *)2000 && (c) == 0x20B9F) { \
+ return EMULATE_JISX0213_2000_ENCODE_INVALID; \
+ }
#ifndef EMULATE_JISX0213_2000_DECODE_INVALID
-#define EMULATE_JISX0213_2000_DECODE_INVALID 2
+# define EMULATE_JISX0213_2000_DECODE_INVALID 2
#endif
#define EMULATE_JISX0213_2000_DECODE_PLANE1(assi, c1, c2) \
@@ -35,12 +38,17 @@
((c1) == 0x7E && (c2) == 0x7B) || \
((c1) == 0x7E && (c2) == 0x7C) || \
((c1) == 0x7E && (c2) == 0x7D) || \
- ((c1) == 0x7E && (c2) == 0x7E))) \
- return EMULATE_JISX0213_2000_DECODE_INVALID;
-
-#define EMULATE_JISX0213_2000_DECODE_PLANE2(writer, c1, c2) \
- if (config == (void *)2000 && (c1) == 0x7D && (c2) == 0x3B) \
- OUTCHAR(0x9B1D);
-#define EMULATE_JISX0213_2000_DECODE_PLANE2_CHAR(assi, c1, c2) \
- if (config == (void *)2000 && (c1) == 0x7D && (c2) == 0x3B) \
- (assi) = 0x9B1D;
+ ((c1) == 0x7E && (c2) == 0x7E))) { \
+ return EMULATE_JISX0213_2000_DECODE_INVALID; \
+ }
+
+#define EMULATE_JISX0213_2000_DECODE_PLANE2(writer, c1, c2) \
+ if (config == (void *)2000 && (c1) == 0x7D && (c2) == 0x3B) { \
+ OUTCHAR(0x9B1D); \
+ }
+
+#define EMULATE_JISX0213_2000_DECODE_PLANE2_CHAR(assi, c1, c2) \
+ if (config == (void *)2000 && (c1) == 0x7D && (c2) == 0x3B) { \
+ (assi) = 0x9B1D; \
+ }
+
diff --git a/Modules/cjkcodecs/multibytecodec.h b/Modules/cjkcodecs/multibytecodec.h
index 7cde8e3..5b8c222 100644
--- a/Modules/cjkcodecs/multibytecodec.h
+++ b/Modules/cjkcodecs/multibytecodec.h
@@ -118,11 +118,11 @@ typedef struct {
#define ERROR_IGNORE (PyObject *)(2)
#define ERROR_REPLACE (PyObject *)(3)
#define ERROR_ISCUSTOM(p) ((p) < ERROR_STRICT || ERROR_REPLACE < (p))
-#define ERROR_DECREF(p) do { \
- if (p != NULL && ERROR_ISCUSTOM(p)) { \
- Py_DECREF(p); \
- } \
-} while (0);
+#define ERROR_DECREF(p) \
+ do { \
+ if (p != NULL && ERROR_ISCUSTOM(p)) \
+ Py_DECREF(p); \
+ } while (0);
#define MBENC_FLUSH 0x0001 /* encode all characters encodable */
#define MBENC_MAX MBENC_FLUSH