2004-07-18 00:06:29 -03:00
|
|
|
/*
|
|
|
|
* _codecs_iso2022.c: Codecs collection for ISO-2022 encodings.
|
|
|
|
*
|
|
|
|
* Written by Hye-Shik Chang <perky@FreeBSD.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define USING_IMPORTED_MAPS
|
|
|
|
#define USING_BINARY_PAIR_SEARCH
|
|
|
|
#define EXTERN_JISX0213_PAIR
|
|
|
|
#define EMULATE_JISX0213_2000_ENCODE_INVALID MAP_UNMAPPABLE
|
|
|
|
#define EMULATE_JISX0213_2000_DECODE_INVALID MAP_UNMAPPABLE
|
|
|
|
|
2023-04-27 10:02:43 -03:00
|
|
|
#define CJK_MOD_SPECIFIC_STATE \
|
|
|
|
/* kr */ \
|
|
|
|
const encode_map *cp949_encmap; \
|
|
|
|
const decode_map *ksx1001_decmap; \
|
|
|
|
\
|
|
|
|
/* jp */ \
|
|
|
|
const encode_map *jisxcommon_encmap; \
|
|
|
|
const decode_map *jisx0208_decmap; \
|
|
|
|
const decode_map *jisx0212_decmap; \
|
|
|
|
const encode_map *jisx0213_bmp_encmap; \
|
|
|
|
const decode_map *jisx0213_1_bmp_decmap; \
|
|
|
|
const decode_map *jisx0213_2_bmp_decmap; \
|
|
|
|
const encode_map *jisx0213_emp_encmap; \
|
|
|
|
const decode_map *jisx0213_1_emp_decmap; \
|
|
|
|
const decode_map *jisx0213_2_emp_decmap; \
|
|
|
|
\
|
|
|
|
/* cn */ \
|
|
|
|
const encode_map *gbcommon_encmap; \
|
|
|
|
const decode_map *gb2312_decmap;
|
|
|
|
|
|
|
|
|
2004-07-18 00:06:29 -03:00
|
|
|
#include "cjkcodecs.h"
|
|
|
|
#include "alg_jisx0201.h"
|
|
|
|
#include "emu_jisx0213_2000.h"
|
|
|
|
#include "mappings_jisx0213_pair.h"
|
|
|
|
|
|
|
|
/* STATE
|
|
|
|
|
|
|
|
state->c[0-3]
|
|
|
|
|
2010-05-09 12:52:27 -03:00
|
|
|
00000000
|
|
|
|
||^^^^^|
|
|
|
|
|+-----+---- G0-3 Character Set
|
|
|
|
+----------- Is G0-3 double byte?
|
2004-07-18 00:06:29 -03:00
|
|
|
|
|
|
|
state->c[4]
|
|
|
|
|
2010-05-09 12:52:27 -03:00
|
|
|
00000000
|
|
|
|
||
|
|
|
|
|+---- Locked-Shift?
|
|
|
|
+----- ESC Throughout
|
2004-07-18 00:06:29 -03:00
|
|
|
*/
|
|
|
|
|
2010-05-09 12:52:27 -03:00
|
|
|
#define ESC 0x1B
|
|
|
|
#define SO 0x0E
|
|
|
|
#define SI 0x0F
|
|
|
|
#define LF 0x0A
|
|
|
|
|
|
|
|
#define MAX_ESCSEQLEN 16
|
|
|
|
|
|
|
|
#define CHARSET_ISO8859_1 'A'
|
|
|
|
#define CHARSET_ASCII 'B'
|
|
|
|
#define CHARSET_ISO8859_7 'F'
|
|
|
|
#define CHARSET_JISX0201_K 'I'
|
|
|
|
#define CHARSET_JISX0201_R 'J'
|
|
|
|
|
|
|
|
#define CHARSET_GB2312 ('A'|CHARSET_DBCS)
|
|
|
|
#define CHARSET_JISX0208 ('B'|CHARSET_DBCS)
|
|
|
|
#define CHARSET_KSX1001 ('C'|CHARSET_DBCS)
|
|
|
|
#define CHARSET_JISX0212 ('D'|CHARSET_DBCS)
|
|
|
|
#define CHARSET_GB2312_8565 ('E'|CHARSET_DBCS)
|
|
|
|
#define CHARSET_CNS11643_1 ('G'|CHARSET_DBCS)
|
|
|
|
#define CHARSET_CNS11643_2 ('H'|CHARSET_DBCS)
|
|
|
|
#define CHARSET_JISX0213_2000_1 ('O'|CHARSET_DBCS)
|
|
|
|
#define CHARSET_JISX0213_2 ('P'|CHARSET_DBCS)
|
|
|
|
#define CHARSET_JISX0213_2004_1 ('Q'|CHARSET_DBCS)
|
|
|
|
#define CHARSET_JISX0208_O ('@'|CHARSET_DBCS)
|
|
|
|
|
|
|
|
#define CHARSET_DBCS 0x80
|
|
|
|
#define ESCMARK(mark) ((mark) & 0x7f)
|
|
|
|
|
|
|
|
#define IS_ESCEND(c) (((c) >= 'A' && (c) <= 'Z') || (c) == '@')
|
2004-07-18 00:06:29 -03:00
|
|
|
#define IS_ISO2022ESC(c2) \
|
2010-05-09 12:52:27 -03:00
|
|
|
((c2) == '(' || (c2) == ')' || (c2) == '$' || \
|
|
|
|
(c2) == '.' || (c2) == '&')
|
|
|
|
/* this is not a complete list of ISO-2022 escape sequence headers.
|
|
|
|
* but, it's enough to implement CJK instances of iso-2022. */
|
|
|
|
|
|
|
|
#define MAP_UNMAPPABLE 0xFFFF
|
|
|
|
#define MAP_MULTIPLE_AVAIL 0xFFFE /* for JIS X 0213 */
|
|
|
|
|
|
|
|
#define F_SHIFTED 0x01
|
|
|
|
#define F_ESCTHROUGHOUT 0x02
|
|
|
|
|
2013-10-28 20:59:44 -03:00
|
|
|
#define STATE_SETG(dn, v) do { ((state)->c[dn]) = (v); } while (0)
|
2010-05-09 12:52:27 -03:00
|
|
|
#define STATE_GETG(dn) ((state)->c[dn])
|
|
|
|
|
|
|
|
#define STATE_G0 STATE_GETG(0)
|
|
|
|
#define STATE_G1 STATE_GETG(1)
|
|
|
|
#define STATE_G2 STATE_GETG(2)
|
|
|
|
#define STATE_G3 STATE_GETG(3)
|
|
|
|
#define STATE_SETG0(v) STATE_SETG(0, v)
|
|
|
|
#define STATE_SETG1(v) STATE_SETG(1, v)
|
|
|
|
#define STATE_SETG2(v) STATE_SETG(2, v)
|
|
|
|
#define STATE_SETG3(v) STATE_SETG(3, v)
|
|
|
|
|
2013-10-28 20:59:44 -03:00
|
|
|
#define STATE_SETFLAG(f) do { ((state)->c[4]) |= (f); } while (0)
|
2010-05-09 12:52:27 -03:00
|
|
|
#define STATE_GETFLAG(f) ((state)->c[4] & (f))
|
2013-10-28 20:59:44 -03:00
|
|
|
#define STATE_CLEARFLAG(f) do { ((state)->c[4]) &= ~(f); } while (0)
|
|
|
|
#define STATE_CLEARFLAGS() do { ((state)->c[4]) = 0; } while (0)
|
2010-05-09 12:52:27 -03:00
|
|
|
|
2023-04-27 10:02:43 -03:00
|
|
|
#define ISO2022_CONFIG ((const struct iso2022_config *)(codec->config))
|
2010-05-09 12:52:27 -03:00
|
|
|
#define CONFIG_ISSET(flag) (ISO2022_CONFIG->flags & (flag))
|
|
|
|
#define CONFIG_DESIGNATIONS (ISO2022_CONFIG->designations)
|
2004-07-18 00:06:29 -03:00
|
|
|
|
|
|
|
/* iso2022_config.flags */
|
2010-05-09 12:52:27 -03:00
|
|
|
#define NO_SHIFT 0x01
|
|
|
|
#define USE_G2 0x02
|
|
|
|
#define USE_JISX0208_EXT 0x04
|
2004-07-18 00:06:29 -03:00
|
|
|
|
|
|
|
/*-*- internal data structures -*-*/
|
|
|
|
|
2023-04-27 10:02:43 -03:00
|
|
|
typedef int (*iso2022_init_func)(const MultibyteCodec *codec);
|
|
|
|
typedef Py_UCS4 (*iso2022_decode_func)(const MultibyteCodec *codec,
|
|
|
|
const unsigned char *data);
|
|
|
|
typedef DBCHAR (*iso2022_encode_func)(const MultibyteCodec *codec,
|
|
|
|
const Py_UCS4 *data,
|
|
|
|
Py_ssize_t *length);
|
2004-07-18 00:06:29 -03:00
|
|
|
|
|
|
|
struct iso2022_designation {
|
2010-05-09 12:52:27 -03:00
|
|
|
unsigned char mark;
|
|
|
|
unsigned char plane;
|
|
|
|
unsigned char width;
|
|
|
|
iso2022_init_func initializer;
|
|
|
|
iso2022_decode_func decoder;
|
|
|
|
iso2022_encode_func encoder;
|
2004-07-18 00:06:29 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct iso2022_config {
|
2010-05-09 12:52:27 -03:00
|
|
|
int flags;
|
|
|
|
const struct iso2022_designation *designations; /* non-ascii desigs */
|
2004-07-18 00:06:29 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
/*-*- iso-2022 codec implementation -*-*/
|
|
|
|
|
|
|
|
CODEC_INIT(iso2022)
|
|
|
|
{
|
2011-02-22 16:15:44 -04:00
|
|
|
const struct iso2022_designation *desig;
|
2023-04-27 10:02:43 -03:00
|
|
|
for (desig = CONFIG_DESIGNATIONS; desig->mark; desig++) {
|
|
|
|
if (desig->initializer != NULL && desig->initializer(codec) != 0) {
|
2010-05-09 12:52:27 -03:00
|
|
|
return -1;
|
2023-04-27 10:02:43 -03:00
|
|
|
}
|
|
|
|
}
|
2010-05-09 12:52:27 -03:00
|
|
|
return 0;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
ENCODER_INIT(iso2022)
|
|
|
|
{
|
2013-10-28 20:59:44 -03:00
|
|
|
STATE_CLEARFLAGS();
|
|
|
|
STATE_SETG0(CHARSET_ASCII);
|
|
|
|
STATE_SETG1(CHARSET_ASCII);
|
2010-05-09 12:52:27 -03:00
|
|
|
return 0;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
ENCODER_RESET(iso2022)
|
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
if (STATE_GETFLAG(F_SHIFTED)) {
|
2013-10-28 20:19:27 -03:00
|
|
|
WRITEBYTE1(SI);
|
2013-04-13 21:06:32 -03:00
|
|
|
NEXT_OUT(1);
|
2013-10-28 20:59:44 -03:00
|
|
|
STATE_CLEARFLAG(F_SHIFTED);
|
2010-05-09 12:52:27 -03:00
|
|
|
}
|
|
|
|
if (STATE_G0 != CHARSET_ASCII) {
|
2013-10-28 20:19:27 -03:00
|
|
|
WRITEBYTE3(ESC, '(', 'B');
|
2013-04-13 21:06:32 -03:00
|
|
|
NEXT_OUT(3);
|
2013-10-28 20:59:44 -03:00
|
|
|
STATE_SETG0(CHARSET_ASCII);
|
2010-05-09 12:52:27 -03:00
|
|
|
}
|
|
|
|
return 0;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
ENCODER(iso2022)
|
|
|
|
{
|
2013-04-13 21:06:32 -03:00
|
|
|
while (*inpos < inlen) {
|
2010-05-09 12:52:27 -03:00
|
|
|
const struct iso2022_designation *dsg;
|
|
|
|
DBCHAR encoded;
|
2013-04-13 21:06:32 -03:00
|
|
|
Py_UCS4 c = INCHAR1;
|
2010-05-09 12:52:27 -03:00
|
|
|
Py_ssize_t insize;
|
|
|
|
|
|
|
|
if (c < 0x80) {
|
|
|
|
if (STATE_G0 != CHARSET_ASCII) {
|
2013-10-28 20:19:27 -03:00
|
|
|
WRITEBYTE3(ESC, '(', 'B');
|
2013-10-28 20:59:44 -03:00
|
|
|
STATE_SETG0(CHARSET_ASCII);
|
2013-04-13 21:06:32 -03:00
|
|
|
NEXT_OUT(3);
|
2010-05-09 12:52:27 -03:00
|
|
|
}
|
|
|
|
if (STATE_GETFLAG(F_SHIFTED)) {
|
2013-10-28 20:19:27 -03:00
|
|
|
WRITEBYTE1(SI);
|
2013-10-28 20:59:44 -03:00
|
|
|
STATE_CLEARFLAG(F_SHIFTED);
|
2013-04-13 21:06:32 -03:00
|
|
|
NEXT_OUT(1);
|
2010-05-09 12:52:27 -03:00
|
|
|
}
|
2013-10-28 20:19:27 -03:00
|
|
|
WRITEBYTE1((unsigned char)c);
|
2013-04-13 21:06:32 -03:00
|
|
|
NEXT(1, 1);
|
2010-05-09 12:52:27 -03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-04-13 21:06:32 -03:00
|
|
|
insize = 1;
|
2010-05-09 12:52:27 -03:00
|
|
|
|
|
|
|
encoded = MAP_UNMAPPABLE;
|
|
|
|
for (dsg = CONFIG_DESIGNATIONS; dsg->mark; dsg++) {
|
2023-11-06 06:59:22 -04:00
|
|
|
Py_UCS4 buf[2] = {c, 0};
|
2010-05-09 12:52:27 -03:00
|
|
|
Py_ssize_t length = 1;
|
2023-11-06 06:59:22 -04:00
|
|
|
encoded = dsg->encoder(codec, buf, &length);
|
2010-05-09 12:52:27 -03:00
|
|
|
if (encoded == MAP_MULTIPLE_AVAIL) {
|
|
|
|
/* this implementation won't work for pair
|
|
|
|
* of non-bmp characters. */
|
2013-04-13 21:06:32 -03:00
|
|
|
if (inlen - *inpos < 2) {
|
2010-05-09 12:52:27 -03:00
|
|
|
if (!(flags & MBENC_FLUSH))
|
|
|
|
return MBERR_TOOFEW;
|
|
|
|
length = -1;
|
|
|
|
}
|
2023-11-06 06:59:22 -04:00
|
|
|
else {
|
|
|
|
buf[1] = INCHAR2;
|
2010-05-09 12:52:27 -03:00
|
|
|
length = 2;
|
2023-11-06 06:59:22 -04:00
|
|
|
}
|
|
|
|
encoded = dsg->encoder(codec, buf, &length);
|
2010-05-09 12:52:27 -03:00
|
|
|
if (encoded != MAP_UNMAPPABLE) {
|
|
|
|
insize = length;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (encoded != MAP_UNMAPPABLE)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dsg->mark)
|
|
|
|
return 1;
|
|
|
|
assert(dsg->width == 1 || dsg->width == 2);
|
|
|
|
|
|
|
|
switch (dsg->plane) {
|
|
|
|
case 0: /* G0 */
|
|
|
|
if (STATE_GETFLAG(F_SHIFTED)) {
|
2013-10-28 20:19:27 -03:00
|
|
|
WRITEBYTE1(SI);
|
2013-10-28 20:59:44 -03:00
|
|
|
STATE_CLEARFLAG(F_SHIFTED);
|
2013-04-13 21:06:32 -03:00
|
|
|
NEXT_OUT(1);
|
2010-05-09 12:52:27 -03:00
|
|
|
}
|
|
|
|
if (STATE_G0 != dsg->mark) {
|
|
|
|
if (dsg->width == 1) {
|
2013-10-28 20:19:27 -03:00
|
|
|
WRITEBYTE3(ESC, '(', ESCMARK(dsg->mark));
|
2013-10-28 20:59:44 -03:00
|
|
|
STATE_SETG0(dsg->mark);
|
2013-04-13 21:06:32 -03:00
|
|
|
NEXT_OUT(3);
|
2010-05-09 12:52:27 -03:00
|
|
|
}
|
|
|
|
else if (dsg->mark == CHARSET_JISX0208) {
|
2013-10-28 20:19:27 -03:00
|
|
|
WRITEBYTE3(ESC, '$', ESCMARK(dsg->mark));
|
2013-10-28 20:59:44 -03:00
|
|
|
STATE_SETG0(dsg->mark);
|
2013-04-13 21:06:32 -03:00
|
|
|
NEXT_OUT(3);
|
2010-05-09 12:52:27 -03:00
|
|
|
}
|
|
|
|
else {
|
2013-04-13 21:06:32 -03:00
|
|
|
WRITEBYTE4(ESC, '$', '(',
|
2013-10-28 20:19:27 -03:00
|
|
|
ESCMARK(dsg->mark));
|
2013-10-28 20:59:44 -03:00
|
|
|
STATE_SETG0(dsg->mark);
|
2013-04-13 21:06:32 -03:00
|
|
|
NEXT_OUT(4);
|
2010-05-09 12:52:27 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1: /* G1 */
|
|
|
|
if (STATE_G1 != dsg->mark) {
|
|
|
|
if (dsg->width == 1) {
|
2013-10-28 20:19:27 -03:00
|
|
|
WRITEBYTE3(ESC, ')', ESCMARK(dsg->mark));
|
2013-10-28 20:59:44 -03:00
|
|
|
STATE_SETG1(dsg->mark);
|
2013-04-13 21:06:32 -03:00
|
|
|
NEXT_OUT(3);
|
2010-05-09 12:52:27 -03:00
|
|
|
}
|
|
|
|
else {
|
2013-10-28 20:59:44 -03:00
|
|
|
WRITEBYTE4(ESC, '$', ')', ESCMARK(dsg->mark));
|
|
|
|
STATE_SETG1(dsg->mark);
|
2013-04-13 21:06:32 -03:00
|
|
|
NEXT_OUT(4);
|
2010-05-09 12:52:27 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!STATE_GETFLAG(F_SHIFTED)) {
|
2013-10-28 20:19:27 -03:00
|
|
|
WRITEBYTE1(SO);
|
2013-10-28 20:59:44 -03:00
|
|
|
STATE_SETFLAG(F_SHIFTED);
|
2013-04-13 21:06:32 -03:00
|
|
|
NEXT_OUT(1);
|
2010-05-09 12:52:27 -03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default: /* G2 and G3 is not supported: no encoding in
|
|
|
|
* CJKCodecs are using them yet */
|
|
|
|
return MBERR_INTERNAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dsg->width == 1) {
|
2013-10-28 20:19:27 -03:00
|
|
|
WRITEBYTE1((unsigned char)encoded);
|
2013-04-13 21:06:32 -03:00
|
|
|
NEXT_OUT(1);
|
2010-05-09 12:52:27 -03:00
|
|
|
}
|
|
|
|
else {
|
2013-10-28 20:19:27 -03:00
|
|
|
WRITEBYTE2(encoded >> 8, encoded & 0xff);
|
2013-04-13 21:06:32 -03:00
|
|
|
NEXT_OUT(2);
|
2010-05-09 12:52:27 -03:00
|
|
|
}
|
2013-04-13 21:06:32 -03:00
|
|
|
NEXT_INCHAR(insize);
|
2010-05-09 12:52:27 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
DECODER_INIT(iso2022)
|
|
|
|
{
|
2013-10-28 20:59:44 -03:00
|
|
|
STATE_CLEARFLAGS();
|
|
|
|
STATE_SETG0(CHARSET_ASCII);
|
|
|
|
STATE_SETG1(CHARSET_ASCII);
|
|
|
|
STATE_SETG2(CHARSET_ASCII);
|
2010-05-09 12:52:27 -03:00
|
|
|
return 0;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
DECODER_RESET(iso2022)
|
|
|
|
{
|
2013-10-28 20:59:44 -03:00
|
|
|
STATE_SETG0(CHARSET_ASCII);
|
|
|
|
STATE_CLEARFLAG(F_SHIFTED);
|
2010-05-09 12:52:27 -03:00
|
|
|
return 0;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
2006-03-04 12:08:19 -04:00
|
|
|
static Py_ssize_t
|
2023-04-27 10:02:43 -03:00
|
|
|
iso2022processesc(const MultibyteCodec *codec, MultibyteCodec_State *state,
|
2010-05-09 12:52:27 -03:00
|
|
|
const unsigned char **inbuf, Py_ssize_t *inleft)
|
2004-07-18 00:06:29 -03:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
unsigned char charset, designation;
|
2015-02-16 03:40:12 -04:00
|
|
|
Py_ssize_t i, esclen = 0;
|
2010-05-09 12:52:27 -03:00
|
|
|
|
|
|
|
for (i = 1;i < MAX_ESCSEQLEN;i++) {
|
|
|
|
if (i >= *inleft)
|
|
|
|
return MBERR_TOOFEW;
|
|
|
|
if (IS_ESCEND((*inbuf)[i])) {
|
|
|
|
esclen = i + 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (CONFIG_ISSET(USE_JISX0208_EXT) && i+1 < *inleft &&
|
2013-10-28 20:59:44 -03:00
|
|
|
(*inbuf)[i] == '&' && (*inbuf)[i+1] == '@') {
|
2010-05-09 12:52:27 -03:00
|
|
|
i += 2;
|
2013-10-28 20:59:44 -03:00
|
|
|
}
|
2010-05-09 12:52:27 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (esclen) {
|
2015-02-16 03:40:12 -04:00
|
|
|
case 0:
|
|
|
|
return 1; /* unterminated escape sequence */
|
2010-05-09 12:52:27 -03:00
|
|
|
case 3:
|
2013-04-13 21:06:32 -03:00
|
|
|
if (INBYTE2 == '$') {
|
|
|
|
charset = INBYTE3 | CHARSET_DBCS;
|
2010-05-09 12:52:27 -03:00
|
|
|
designation = 0;
|
|
|
|
}
|
|
|
|
else {
|
2013-04-13 21:06:32 -03:00
|
|
|
charset = INBYTE3;
|
2013-10-28 20:09:41 -03:00
|
|
|
if (INBYTE2 == '(')
|
|
|
|
designation = 0;
|
|
|
|
else if (INBYTE2 == ')')
|
|
|
|
designation = 1;
|
2013-04-13 21:06:32 -03:00
|
|
|
else if (CONFIG_ISSET(USE_G2) && INBYTE2 == '.')
|
2010-05-09 12:52:27 -03:00
|
|
|
designation = 2;
|
2013-10-28 20:09:41 -03:00
|
|
|
else
|
|
|
|
return 3;
|
2010-05-09 12:52:27 -03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
2013-04-13 21:06:32 -03:00
|
|
|
if (INBYTE2 != '$')
|
2010-05-09 12:52:27 -03:00
|
|
|
return 4;
|
|
|
|
|
2013-04-13 21:06:32 -03:00
|
|
|
charset = INBYTE4 | CHARSET_DBCS;
|
2013-10-28 20:09:41 -03:00
|
|
|
if (INBYTE3 == '(')
|
|
|
|
designation = 0;
|
|
|
|
else if (INBYTE3 == ')')
|
|
|
|
designation = 1;
|
|
|
|
else
|
|
|
|
return 4;
|
2010-05-09 12:52:27 -03:00
|
|
|
break;
|
|
|
|
case 6: /* designation with prefix */
|
|
|
|
if (CONFIG_ISSET(USE_JISX0208_EXT) &&
|
|
|
|
(*inbuf)[3] == ESC && (*inbuf)[4] == '$' &&
|
|
|
|
(*inbuf)[5] == 'B') {
|
|
|
|
charset = 'B' | CHARSET_DBCS;
|
|
|
|
designation = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 6;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return esclen;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* raise error when the charset is not designated for this encoding */
|
|
|
|
if (charset != CHARSET_ASCII) {
|
|
|
|
const struct iso2022_designation *dsg;
|
|
|
|
|
2013-10-28 20:59:44 -03:00
|
|
|
for (dsg = CONFIG_DESIGNATIONS; dsg->mark; dsg++) {
|
2010-05-09 12:52:27 -03:00
|
|
|
if (dsg->mark == charset)
|
|
|
|
break;
|
2013-10-28 20:59:44 -03:00
|
|
|
}
|
2010-05-09 12:52:27 -03:00
|
|
|
if (!dsg->mark)
|
|
|
|
return esclen;
|
|
|
|
}
|
|
|
|
|
2013-10-28 20:59:44 -03:00
|
|
|
STATE_SETG(designation, charset);
|
2010-05-09 12:52:27 -03:00
|
|
|
*inleft -= esclen;
|
|
|
|
(*inbuf) += esclen;
|
|
|
|
return 0;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
2013-10-28 20:19:27 -03:00
|
|
|
#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); \
|
|
|
|
}
|
2004-07-18 00:06:29 -03:00
|
|
|
|
2006-03-04 12:08:19 -04:00
|
|
|
static Py_ssize_t
|
2023-04-27 10:02:43 -03:00
|
|
|
iso2022processg2(const MultibyteCodec *codec, MultibyteCodec_State *state,
|
2010-05-09 12:52:27 -03:00
|
|
|
const unsigned char **inbuf, Py_ssize_t *inleft,
|
2013-04-11 17:09:04 -03:00
|
|
|
_PyUnicodeWriter *writer)
|
2004-07-18 00:06:29 -03:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
/* not written to use encoder, decoder functions because only few
|
|
|
|
* encodings use G2 designations in CJKCodecs */
|
|
|
|
if (STATE_G2 == CHARSET_ISO8859_1) {
|
2013-04-13 21:06:32 -03:00
|
|
|
if (INBYTE3 < 0x80)
|
|
|
|
OUTCHAR(INBYTE3 + 0x80);
|
2010-05-09 12:52:27 -03:00
|
|
|
else
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
else if (STATE_G2 == CHARSET_ISO8859_7) {
|
2013-04-13 21:06:32 -03:00
|
|
|
ISO8859_7_DECODE(INBYTE3 ^ 0x80, writer)
|
2013-10-28 20:09:41 -03:00
|
|
|
else
|
|
|
|
return 3;
|
2010-05-09 12:52:27 -03:00
|
|
|
}
|
|
|
|
else if (STATE_G2 == CHARSET_ASCII) {
|
2013-10-28 20:09:41 -03:00
|
|
|
if (INBYTE3 & 0x80)
|
|
|
|
return 3;
|
|
|
|
else
|
|
|
|
OUTCHAR(INBYTE3);
|
2010-05-09 12:52:27 -03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return MBERR_INTERNAL;
|
|
|
|
|
|
|
|
(*inbuf) += 3;
|
|
|
|
*inleft -= 3;
|
|
|
|
return 0;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
DECODER(iso2022)
|
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
const struct iso2022_designation *dsgcache = NULL;
|
|
|
|
|
|
|
|
while (inleft > 0) {
|
2013-04-13 21:06:32 -03:00
|
|
|
unsigned char c = INBYTE1;
|
2010-05-09 12:52:27 -03:00
|
|
|
Py_ssize_t err;
|
|
|
|
|
|
|
|
if (STATE_GETFLAG(F_ESCTHROUGHOUT)) {
|
|
|
|
/* ESC throughout mode:
|
|
|
|
* for non-iso2022 escape sequences */
|
2013-04-11 17:09:04 -03:00
|
|
|
OUTCHAR(c); /* assume as ISO-8859-1 */
|
|
|
|
NEXT_IN(1);
|
2010-05-09 12:52:27 -03:00
|
|
|
if (IS_ESCEND(c)) {
|
2013-10-28 20:59:44 -03:00
|
|
|
STATE_CLEARFLAG(F_ESCTHROUGHOUT);
|
2010-05-09 12:52:27 -03:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case ESC:
|
2013-10-28 20:59:44 -03:00
|
|
|
REQUIRE_INBUF(2);
|
2013-04-13 21:06:32 -03:00
|
|
|
if (IS_ISO2022ESC(INBYTE2)) {
|
2023-04-27 10:02:43 -03:00
|
|
|
err = iso2022processesc(codec, state,
|
2010-05-09 12:52:27 -03:00
|
|
|
inbuf, &inleft);
|
|
|
|
if (err != 0)
|
|
|
|
return err;
|
|
|
|
}
|
2013-04-13 21:06:32 -03:00
|
|
|
else if (CONFIG_ISSET(USE_G2) && INBYTE2 == 'N') {/* SS2 */
|
2013-10-28 20:59:44 -03:00
|
|
|
REQUIRE_INBUF(3);
|
2023-04-27 10:02:43 -03:00
|
|
|
err = iso2022processg2(codec, state,
|
2013-04-11 17:09:04 -03:00
|
|
|
inbuf, &inleft, writer);
|
2010-05-09 12:52:27 -03:00
|
|
|
if (err != 0)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
else {
|
2013-04-11 17:09:04 -03:00
|
|
|
OUTCHAR(ESC);
|
2013-10-28 20:59:44 -03:00
|
|
|
STATE_SETFLAG(F_ESCTHROUGHOUT);
|
2013-04-11 17:09:04 -03:00
|
|
|
NEXT_IN(1);
|
2010-05-09 12:52:27 -03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SI:
|
|
|
|
if (CONFIG_ISSET(NO_SHIFT))
|
|
|
|
goto bypass;
|
2013-10-28 20:59:44 -03:00
|
|
|
STATE_CLEARFLAG(F_SHIFTED);
|
2013-04-11 17:09:04 -03:00
|
|
|
NEXT_IN(1);
|
2010-05-09 12:52:27 -03:00
|
|
|
break;
|
|
|
|
case SO:
|
|
|
|
if (CONFIG_ISSET(NO_SHIFT))
|
|
|
|
goto bypass;
|
2013-10-28 20:59:44 -03:00
|
|
|
STATE_SETFLAG(F_SHIFTED);
|
2013-04-11 17:09:04 -03:00
|
|
|
NEXT_IN(1);
|
2010-05-09 12:52:27 -03:00
|
|
|
break;
|
|
|
|
case LF:
|
2013-10-28 20:59:44 -03:00
|
|
|
STATE_CLEARFLAG(F_SHIFTED);
|
2013-04-11 17:09:04 -03:00
|
|
|
OUTCHAR(LF);
|
|
|
|
NEXT_IN(1);
|
2010-05-09 12:52:27 -03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (c < 0x20) /* C0 */
|
|
|
|
goto bypass;
|
|
|
|
else if (c >= 0x80)
|
|
|
|
return 1;
|
|
|
|
else {
|
|
|
|
const struct iso2022_designation *dsg;
|
|
|
|
unsigned char charset;
|
2013-04-11 17:09:04 -03:00
|
|
|
Py_UCS4 decoded;
|
2010-05-09 12:52:27 -03:00
|
|
|
|
|
|
|
if (STATE_GETFLAG(F_SHIFTED))
|
|
|
|
charset = STATE_G1;
|
|
|
|
else
|
|
|
|
charset = STATE_G0;
|
|
|
|
|
|
|
|
if (charset == CHARSET_ASCII) {
|
2013-10-28 20:59:44 -03:00
|
|
|
bypass:
|
|
|
|
OUTCHAR(c);
|
|
|
|
NEXT_IN(1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dsgcache != NULL &&
|
|
|
|
dsgcache->mark == charset)
|
|
|
|
dsg = dsgcache;
|
|
|
|
else {
|
|
|
|
for (dsg = CONFIG_DESIGNATIONS;
|
|
|
|
dsg->mark != charset
|
2004-07-18 00:06:29 -03:00
|
|
|
#ifdef Py_DEBUG
|
2013-10-28 20:59:44 -03:00
|
|
|
&& dsg->mark != '\0'
|
2004-07-18 00:06:29 -03:00
|
|
|
#endif
|
2013-10-28 20:59:44 -03:00
|
|
|
; dsg++)
|
|
|
|
{
|
|
|
|
/* noop */
|
|
|
|
}
|
|
|
|
assert(dsg->mark != '\0');
|
|
|
|
dsgcache = dsg;
|
|
|
|
}
|
|
|
|
|
|
|
|
REQUIRE_INBUF(dsg->width);
|
2023-04-27 10:02:43 -03:00
|
|
|
decoded = dsg->decoder(codec, *inbuf);
|
2013-10-28 20:59:44 -03:00
|
|
|
if (decoded == MAP_UNMAPPABLE)
|
|
|
|
return dsg->width;
|
|
|
|
|
|
|
|
if (decoded < 0x10000) {
|
|
|
|
OUTCHAR(decoded);
|
|
|
|
}
|
|
|
|
else if (decoded < 0x30000) {
|
|
|
|
OUTCHAR(decoded);
|
|
|
|
}
|
|
|
|
else { /* JIS X 0213 pairs */
|
2013-04-11 17:09:04 -03:00
|
|
|
OUTCHAR2(decoded >> 16, decoded & 0xffff);
|
2010-05-09 12:52:27 -03:00
|
|
|
}
|
2013-04-11 17:09:04 -03:00
|
|
|
NEXT_IN(dsg->width);
|
2010-05-09 12:52:27 -03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-*- mapping access functions -*-*/
|
|
|
|
|
|
|
|
static int
|
2023-04-27 10:02:43 -03:00
|
|
|
ksx1001_init(const MultibyteCodec *codec)
|
2004-07-18 00:06:29 -03:00
|
|
|
{
|
2023-04-27 10:02:43 -03:00
|
|
|
cjkcodecs_module_state *st = codec->modstate;
|
|
|
|
if (IMPORT_MAP(kr, cp949, &st->cp949_encmap, NULL) ||
|
|
|
|
IMPORT_MAP(kr, ksx1001, NULL, &st->ksx1001_decmap))
|
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
return -1;
|
2023-04-27 10:02:43 -03:00
|
|
|
}
|
2010-05-09 12:52:27 -03:00
|
|
|
return 0;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
2013-04-11 17:09:04 -03:00
|
|
|
static Py_UCS4
|
2023-04-27 10:02:43 -03:00
|
|
|
ksx1001_decoder(const MultibyteCodec *codec, const unsigned char *data)
|
2004-07-18 00:06:29 -03:00
|
|
|
{
|
2013-04-11 17:09:04 -03:00
|
|
|
Py_UCS4 u;
|
2023-04-27 10:02:43 -03:00
|
|
|
if (TRYMAP_DEC_ST(ksx1001, u, data[0], data[1]))
|
2010-05-09 12:52:27 -03:00
|
|
|
return u;
|
|
|
|
else
|
|
|
|
return MAP_UNMAPPABLE;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static DBCHAR
|
2023-04-27 10:02:43 -03:00
|
|
|
ksx1001_encoder(const MultibyteCodec *codec, const Py_UCS4 *data,
|
|
|
|
Py_ssize_t *length)
|
2004-07-18 00:06:29 -03:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
DBCHAR coded;
|
|
|
|
assert(*length == 1);
|
|
|
|
if (*data < 0x10000) {
|
2023-04-27 10:02:43 -03:00
|
|
|
if (TRYMAP_ENC_ST(cp949, coded, *data)) {
|
2010-05-09 12:52:27 -03:00
|
|
|
if (!(coded & 0x8000))
|
|
|
|
return coded;
|
2013-10-28 19:54:13 -03:00
|
|
|
}
|
2010-05-09 12:52:27 -03:00
|
|
|
}
|
|
|
|
return MAP_UNMAPPABLE;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2023-04-27 10:02:43 -03:00
|
|
|
jisx0208_init(const MultibyteCodec *codec)
|
2004-07-18 00:06:29 -03:00
|
|
|
{
|
2023-04-27 10:02:43 -03:00
|
|
|
cjkcodecs_module_state *st = codec->modstate;
|
|
|
|
if (IMPORT_MAP(jp, jisxcommon, &st->jisxcommon_encmap, NULL) ||
|
|
|
|
IMPORT_MAP(jp, jisx0208, NULL, &st->jisx0208_decmap))
|
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
return -1;
|
2023-04-27 10:02:43 -03:00
|
|
|
}
|
2010-05-09 12:52:27 -03:00
|
|
|
return 0;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
2013-04-11 17:09:04 -03:00
|
|
|
static Py_UCS4
|
2023-04-27 10:02:43 -03:00
|
|
|
jisx0208_decoder(const MultibyteCodec *codec, const unsigned char *data)
|
2004-07-18 00:06:29 -03:00
|
|
|
{
|
2013-04-11 17:09:04 -03:00
|
|
|
Py_UCS4 u;
|
2010-05-09 12:52:27 -03:00
|
|
|
if (data[0] == 0x21 && data[1] == 0x40) /* F/W REVERSE SOLIDUS */
|
|
|
|
return 0xff3c;
|
2023-04-27 10:02:43 -03:00
|
|
|
else if (TRYMAP_DEC_ST(jisx0208, u, data[0], data[1]))
|
2010-05-09 12:52:27 -03:00
|
|
|
return u;
|
|
|
|
else
|
|
|
|
return MAP_UNMAPPABLE;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static DBCHAR
|
2023-04-27 10:02:43 -03:00
|
|
|
jisx0208_encoder(const MultibyteCodec *codec, const Py_UCS4 *data,
|
|
|
|
Py_ssize_t *length)
|
2004-07-18 00:06:29 -03:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
DBCHAR coded;
|
|
|
|
assert(*length == 1);
|
|
|
|
if (*data < 0x10000) {
|
|
|
|
if (*data == 0xff3c) /* F/W REVERSE SOLIDUS */
|
|
|
|
return 0x2140;
|
2023-04-27 10:02:43 -03:00
|
|
|
else if (TRYMAP_ENC_ST(jisxcommon, coded, *data)) {
|
2010-05-09 12:52:27 -03:00
|
|
|
if (!(coded & 0x8000))
|
|
|
|
return coded;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return MAP_UNMAPPABLE;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2023-04-27 10:02:43 -03:00
|
|
|
jisx0212_init(const MultibyteCodec *codec)
|
2004-07-18 00:06:29 -03:00
|
|
|
{
|
2023-04-27 10:02:43 -03:00
|
|
|
cjkcodecs_module_state *st = codec->modstate;
|
|
|
|
if (IMPORT_MAP(jp, jisxcommon, &st->jisxcommon_encmap, NULL) ||
|
|
|
|
IMPORT_MAP(jp, jisx0212, NULL, &st->jisx0212_decmap))
|
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
return -1;
|
2023-04-27 10:02:43 -03:00
|
|
|
}
|
2010-05-09 12:52:27 -03:00
|
|
|
return 0;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
2013-04-11 17:09:04 -03:00
|
|
|
static Py_UCS4
|
2023-04-27 10:02:43 -03:00
|
|
|
jisx0212_decoder(const MultibyteCodec *codec, const unsigned char *data)
|
2004-07-18 00:06:29 -03:00
|
|
|
{
|
2013-04-11 17:09:04 -03:00
|
|
|
Py_UCS4 u;
|
2023-04-27 10:02:43 -03:00
|
|
|
if (TRYMAP_DEC_ST(jisx0212, u, data[0], data[1]))
|
2010-05-09 12:52:27 -03:00
|
|
|
return u;
|
|
|
|
else
|
|
|
|
return MAP_UNMAPPABLE;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static DBCHAR
|
2023-04-27 10:02:43 -03:00
|
|
|
jisx0212_encoder(const MultibyteCodec *codec, const Py_UCS4 *data,
|
|
|
|
Py_ssize_t *length)
|
2004-07-18 00:06:29 -03:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
DBCHAR coded;
|
|
|
|
assert(*length == 1);
|
|
|
|
if (*data < 0x10000) {
|
2023-04-27 10:02:43 -03:00
|
|
|
if (TRYMAP_ENC_ST(jisxcommon, coded, *data)) {
|
2010-05-09 12:52:27 -03:00
|
|
|
if (coded & 0x8000)
|
|
|
|
return coded & 0x7fff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return MAP_UNMAPPABLE;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2023-04-27 10:02:43 -03:00
|
|
|
jisx0213_init(const MultibyteCodec *codec)
|
|
|
|
{
|
|
|
|
cjkcodecs_module_state *st = codec->modstate;
|
|
|
|
if (jisx0208_init(codec) ||
|
|
|
|
IMPORT_MAP(jp, jisx0213_bmp, &st->jisx0213_bmp_encmap, NULL) ||
|
|
|
|
IMPORT_MAP(jp, jisx0213_1_bmp, NULL, &st->jisx0213_1_bmp_decmap) ||
|
|
|
|
IMPORT_MAP(jp, jisx0213_2_bmp, NULL, &st->jisx0213_2_bmp_decmap) ||
|
|
|
|
IMPORT_MAP(jp, jisx0213_emp, &st->jisx0213_emp_encmap, NULL) ||
|
|
|
|
IMPORT_MAP(jp, jisx0213_1_emp, NULL, &st->jisx0213_1_emp_decmap) ||
|
|
|
|
IMPORT_MAP(jp, jisx0213_2_emp, NULL, &st->jisx0213_2_emp_decmap) ||
|
|
|
|
IMPORT_MAP(jp, jisx0213_pair,
|
|
|
|
&jisx0213_pair_encmap, &jisx0213_pair_decmap))
|
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
return -1;
|
2023-04-27 10:02:43 -03:00
|
|
|
}
|
2010-05-09 12:52:27 -03:00
|
|
|
return 0;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
#define config ((void *)2000)
|
2013-04-11 17:09:04 -03:00
|
|
|
static Py_UCS4
|
2023-04-27 10:02:43 -03:00
|
|
|
jisx0213_2000_1_decoder(const MultibyteCodec *codec, const unsigned char *data)
|
2004-07-18 00:06:29 -03:00
|
|
|
{
|
2013-04-11 17:09:04 -03:00
|
|
|
Py_UCS4 u;
|
2023-04-27 10:02:43 -03:00
|
|
|
EMULATE_JISX0213_2000_DECODE_PLANE1(config, u, data[0], data[1])
|
2010-05-09 12:52:27 -03:00
|
|
|
else if (data[0] == 0x21 && data[1] == 0x40) /* F/W REVERSE SOLIDUS */
|
|
|
|
return 0xff3c;
|
2023-04-27 10:02:43 -03:00
|
|
|
else if (TRYMAP_DEC_ST(jisx0208, u, data[0], data[1]))
|
2013-10-28 20:09:41 -03:00
|
|
|
;
|
2023-04-27 10:02:43 -03:00
|
|
|
else if (TRYMAP_DEC_ST(jisx0213_1_bmp, u, data[0], data[1]))
|
2013-10-28 20:09:41 -03:00
|
|
|
;
|
2023-04-27 10:02:43 -03:00
|
|
|
else if (TRYMAP_DEC_ST(jisx0213_1_emp, u, data[0], data[1]))
|
2010-05-09 12:52:27 -03:00
|
|
|
u |= 0x20000;
|
2013-10-28 20:09:41 -03:00
|
|
|
else if (TRYMAP_DEC(jisx0213_pair, u, data[0], data[1]))
|
|
|
|
;
|
2010-05-09 12:52:27 -03:00
|
|
|
else
|
|
|
|
return MAP_UNMAPPABLE;
|
|
|
|
return u;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
2013-04-11 17:09:04 -03:00
|
|
|
static Py_UCS4
|
2023-04-27 10:02:43 -03:00
|
|
|
jisx0213_2000_2_decoder(const MultibyteCodec *codec, const unsigned char *data)
|
2004-07-18 00:06:29 -03:00
|
|
|
{
|
2013-04-11 17:09:04 -03:00
|
|
|
Py_UCS4 u;
|
2023-04-27 10:02:43 -03:00
|
|
|
EMULATE_JISX0213_2000_DECODE_PLANE2_CHAR(config, u, data[0], data[1])
|
|
|
|
if (TRYMAP_DEC_ST(jisx0213_2_bmp, u, data[0], data[1]))
|
2013-10-28 20:09:41 -03:00
|
|
|
;
|
2023-04-27 10:02:43 -03:00
|
|
|
else if (TRYMAP_DEC_ST(jisx0213_2_emp, u, data[0], data[1]))
|
2010-05-09 12:52:27 -03:00
|
|
|
u |= 0x20000;
|
|
|
|
else
|
|
|
|
return MAP_UNMAPPABLE;
|
|
|
|
return u;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
#undef config
|
|
|
|
|
2013-04-11 17:09:04 -03:00
|
|
|
static Py_UCS4
|
2023-04-27 10:02:43 -03:00
|
|
|
jisx0213_2004_1_decoder(const MultibyteCodec *codec, const unsigned char *data)
|
2004-07-18 00:06:29 -03:00
|
|
|
{
|
2013-04-11 17:09:04 -03:00
|
|
|
Py_UCS4 u;
|
2010-05-09 12:52:27 -03:00
|
|
|
if (data[0] == 0x21 && data[1] == 0x40) /* F/W REVERSE SOLIDUS */
|
|
|
|
return 0xff3c;
|
2023-04-27 10:02:43 -03:00
|
|
|
else if (TRYMAP_DEC_ST(jisx0208, u, data[0], data[1]))
|
2013-10-28 20:09:41 -03:00
|
|
|
;
|
2023-04-27 10:02:43 -03:00
|
|
|
else if (TRYMAP_DEC_ST(jisx0213_1_bmp, u, data[0], data[1]))
|
2013-10-28 20:09:41 -03:00
|
|
|
;
|
2023-04-27 10:02:43 -03:00
|
|
|
else if (TRYMAP_DEC_ST(jisx0213_1_emp, u, data[0], data[1]))
|
2010-05-09 12:52:27 -03:00
|
|
|
u |= 0x20000;
|
2013-10-28 20:09:41 -03:00
|
|
|
else if (TRYMAP_DEC(jisx0213_pair, u, data[0], data[1]))
|
|
|
|
;
|
2010-05-09 12:52:27 -03:00
|
|
|
else
|
|
|
|
return MAP_UNMAPPABLE;
|
|
|
|
return u;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
2013-04-11 17:09:04 -03:00
|
|
|
static Py_UCS4
|
2023-04-27 10:02:43 -03:00
|
|
|
jisx0213_2004_2_decoder(const MultibyteCodec *codec, const unsigned char *data)
|
2004-07-18 00:06:29 -03:00
|
|
|
{
|
2013-04-11 17:09:04 -03:00
|
|
|
Py_UCS4 u;
|
2023-04-27 10:02:43 -03:00
|
|
|
if (TRYMAP_DEC_ST(jisx0213_2_bmp, u, data[0], data[1]))
|
2013-10-28 20:09:41 -03:00
|
|
|
;
|
2023-04-27 10:02:43 -03:00
|
|
|
else if (TRYMAP_DEC_ST(jisx0213_2_emp, u, data[0], data[1]))
|
2010-05-09 12:52:27 -03:00
|
|
|
u |= 0x20000;
|
|
|
|
else
|
|
|
|
return MAP_UNMAPPABLE;
|
|
|
|
return u;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static DBCHAR
|
2023-04-27 10:02:43 -03:00
|
|
|
jisx0213_encoder(const MultibyteCodec *codec, const Py_UCS4 *data,
|
|
|
|
Py_ssize_t *length, const void *config)
|
2004-07-18 00:06:29 -03:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
DBCHAR coded;
|
|
|
|
|
|
|
|
switch (*length) {
|
|
|
|
case 1: /* first character */
|
|
|
|
if (*data >= 0x10000) {
|
|
|
|
if ((*data) >> 16 == 0x20000 >> 16) {
|
2023-04-27 10:02:43 -03:00
|
|
|
EMULATE_JISX0213_2000_ENCODE_EMP(config, coded, *data)
|
|
|
|
else if (TRYMAP_ENC_ST(jisx0213_emp, coded, (*data) & 0xffff))
|
2010-05-09 12:52:27 -03:00
|
|
|
return coded;
|
|
|
|
}
|
|
|
|
return MAP_UNMAPPABLE;
|
|
|
|
}
|
|
|
|
|
2023-04-27 10:02:43 -03:00
|
|
|
EMULATE_JISX0213_2000_ENCODE_BMP(config, coded, *data)
|
|
|
|
else if (TRYMAP_ENC_ST(jisx0213_bmp, coded, *data)) {
|
2010-05-09 12:52:27 -03:00
|
|
|
if (coded == MULTIC)
|
|
|
|
return MAP_MULTIPLE_AVAIL;
|
|
|
|
}
|
2023-04-27 10:02:43 -03:00
|
|
|
else if (TRYMAP_ENC_ST(jisxcommon, coded, *data)) {
|
2010-05-09 12:52:27 -03:00
|
|
|
if (coded & 0x8000)
|
|
|
|
return MAP_UNMAPPABLE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return MAP_UNMAPPABLE;
|
|
|
|
return coded;
|
2013-10-28 20:59:44 -03:00
|
|
|
|
2010-05-09 12:52:27 -03:00
|
|
|
case 2: /* second character of unicode pair */
|
|
|
|
coded = find_pairencmap((ucs2_t)data[0], (ucs2_t)data[1],
|
2013-10-28 20:59:44 -03:00
|
|
|
jisx0213_pair_encmap, JISX0213_ENCPAIRS);
|
2017-08-25 13:31:22 -03:00
|
|
|
if (coded != DBCINV)
|
2010-05-09 12:52:27 -03:00
|
|
|
return coded;
|
2017-08-25 13:31:22 -03:00
|
|
|
/* fall through */
|
2013-10-28 20:59:44 -03:00
|
|
|
|
2010-05-09 12:52:27 -03:00
|
|
|
case -1: /* flush unterminated */
|
|
|
|
*length = 1;
|
|
|
|
coded = find_pairencmap((ucs2_t)data[0], 0,
|
2013-10-28 20:59:44 -03:00
|
|
|
jisx0213_pair_encmap, JISX0213_ENCPAIRS);
|
2010-05-09 12:52:27 -03:00
|
|
|
if (coded == DBCINV)
|
|
|
|
return MAP_UNMAPPABLE;
|
|
|
|
else
|
|
|
|
return coded;
|
2013-10-28 20:59:44 -03:00
|
|
|
break;
|
|
|
|
|
2010-05-09 12:52:27 -03:00
|
|
|
default:
|
|
|
|
return MAP_UNMAPPABLE;
|
|
|
|
}
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static DBCHAR
|
2023-04-27 10:02:43 -03:00
|
|
|
jisx0213_2000_1_encoder(const MultibyteCodec *codec, const Py_UCS4 *data,
|
|
|
|
Py_ssize_t *length)
|
2004-07-18 00:06:29 -03:00
|
|
|
{
|
2023-04-27 10:02:43 -03:00
|
|
|
DBCHAR coded = jisx0213_encoder(codec, data, length, (void *)2000);
|
2010-05-09 12:52:27 -03:00
|
|
|
if (coded == MAP_UNMAPPABLE || coded == MAP_MULTIPLE_AVAIL)
|
|
|
|
return coded;
|
|
|
|
else if (coded & 0x8000)
|
|
|
|
return MAP_UNMAPPABLE;
|
|
|
|
else
|
|
|
|
return coded;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static DBCHAR
|
2023-04-27 10:02:43 -03:00
|
|
|
jisx0213_2000_1_encoder_paironly(const MultibyteCodec *codec,
|
|
|
|
const Py_UCS4 *data, Py_ssize_t *length)
|
2004-07-18 00:06:29 -03:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
DBCHAR coded;
|
|
|
|
Py_ssize_t ilength = *length;
|
|
|
|
|
2023-04-27 10:02:43 -03:00
|
|
|
coded = jisx0213_encoder(codec, data, length, (void *)2000);
|
2010-05-09 12:52:27 -03:00
|
|
|
switch (ilength) {
|
|
|
|
case 1:
|
|
|
|
if (coded == MAP_MULTIPLE_AVAIL)
|
|
|
|
return MAP_MULTIPLE_AVAIL;
|
|
|
|
else
|
|
|
|
return MAP_UNMAPPABLE;
|
|
|
|
case 2:
|
|
|
|
if (*length != 2)
|
|
|
|
return MAP_UNMAPPABLE;
|
|
|
|
else
|
|
|
|
return coded;
|
|
|
|
default:
|
|
|
|
return MAP_UNMAPPABLE;
|
|
|
|
}
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static DBCHAR
|
2023-04-27 10:02:43 -03:00
|
|
|
jisx0213_2000_2_encoder(const MultibyteCodec *codec, const Py_UCS4 *data,
|
|
|
|
Py_ssize_t *length)
|
2004-07-18 00:06:29 -03:00
|
|
|
{
|
2023-04-27 10:02:43 -03:00
|
|
|
DBCHAR coded = jisx0213_encoder(codec, data, length, (void *)2000);
|
2010-05-09 12:52:27 -03:00
|
|
|
if (coded == MAP_UNMAPPABLE || coded == MAP_MULTIPLE_AVAIL)
|
|
|
|
return coded;
|
|
|
|
else if (coded & 0x8000)
|
|
|
|
return coded & 0x7fff;
|
|
|
|
else
|
|
|
|
return MAP_UNMAPPABLE;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static DBCHAR
|
2023-04-27 10:02:43 -03:00
|
|
|
jisx0213_2004_1_encoder(const MultibyteCodec *codec, const Py_UCS4 *data,
|
|
|
|
Py_ssize_t *length)
|
2004-07-18 00:06:29 -03:00
|
|
|
{
|
2023-04-27 10:02:43 -03:00
|
|
|
DBCHAR coded = jisx0213_encoder(codec, data, length, NULL);
|
2010-05-09 12:52:27 -03:00
|
|
|
if (coded == MAP_UNMAPPABLE || coded == MAP_MULTIPLE_AVAIL)
|
|
|
|
return coded;
|
|
|
|
else if (coded & 0x8000)
|
|
|
|
return MAP_UNMAPPABLE;
|
|
|
|
else
|
|
|
|
return coded;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static DBCHAR
|
2023-04-27 10:02:43 -03:00
|
|
|
jisx0213_2004_1_encoder_paironly(const MultibyteCodec *codec,
|
|
|
|
const Py_UCS4 *data, Py_ssize_t *length)
|
2004-07-18 00:06:29 -03:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
DBCHAR coded;
|
|
|
|
Py_ssize_t ilength = *length;
|
|
|
|
|
2023-04-27 10:02:43 -03:00
|
|
|
coded = jisx0213_encoder(codec, data, length, NULL);
|
2010-05-09 12:52:27 -03:00
|
|
|
switch (ilength) {
|
|
|
|
case 1:
|
|
|
|
if (coded == MAP_MULTIPLE_AVAIL)
|
|
|
|
return MAP_MULTIPLE_AVAIL;
|
|
|
|
else
|
|
|
|
return MAP_UNMAPPABLE;
|
|
|
|
case 2:
|
|
|
|
if (*length != 2)
|
|
|
|
return MAP_UNMAPPABLE;
|
|
|
|
else
|
|
|
|
return coded;
|
|
|
|
default:
|
|
|
|
return MAP_UNMAPPABLE;
|
|
|
|
}
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static DBCHAR
|
2023-04-27 10:02:43 -03:00
|
|
|
jisx0213_2004_2_encoder(const MultibyteCodec *codec, const Py_UCS4 *data,
|
|
|
|
Py_ssize_t *length)
|
2004-07-18 00:06:29 -03:00
|
|
|
{
|
2023-04-27 10:02:43 -03:00
|
|
|
DBCHAR coded = jisx0213_encoder(codec, data, length, NULL);
|
2010-05-09 12:52:27 -03:00
|
|
|
if (coded == MAP_UNMAPPABLE || coded == MAP_MULTIPLE_AVAIL)
|
|
|
|
return coded;
|
|
|
|
else if (coded & 0x8000)
|
|
|
|
return coded & 0x7fff;
|
|
|
|
else
|
|
|
|
return MAP_UNMAPPABLE;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
2013-04-11 17:09:04 -03:00
|
|
|
static Py_UCS4
|
2023-04-27 10:02:43 -03:00
|
|
|
jisx0201_r_decoder(const MultibyteCodec *codec, const unsigned char *data)
|
2004-07-18 00:06:29 -03:00
|
|
|
{
|
2013-04-11 17:09:04 -03:00
|
|
|
Py_UCS4 u;
|
|
|
|
JISX0201_R_DECODE_CHAR(*data, u)
|
2013-10-28 20:09:41 -03:00
|
|
|
else
|
|
|
|
return MAP_UNMAPPABLE;
|
2010-05-09 12:52:27 -03:00
|
|
|
return u;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static DBCHAR
|
2023-04-27 10:02:43 -03:00
|
|
|
jisx0201_r_encoder(const MultibyteCodec *codec, const Py_UCS4 *data,
|
|
|
|
Py_ssize_t *length)
|
2004-07-18 00:06:29 -03:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
DBCHAR coded;
|
|
|
|
JISX0201_R_ENCODE(*data, coded)
|
2013-10-28 20:09:41 -03:00
|
|
|
else
|
|
|
|
return MAP_UNMAPPABLE;
|
2010-05-09 12:52:27 -03:00
|
|
|
return coded;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
2013-04-11 17:09:04 -03:00
|
|
|
static Py_UCS4
|
2023-04-27 10:02:43 -03:00
|
|
|
jisx0201_k_decoder(const MultibyteCodec *codec, const unsigned char *data)
|
2004-07-18 00:06:29 -03:00
|
|
|
{
|
2013-04-11 17:09:04 -03:00
|
|
|
Py_UCS4 u;
|
|
|
|
JISX0201_K_DECODE_CHAR(*data ^ 0x80, u)
|
2013-10-28 20:09:41 -03:00
|
|
|
else
|
|
|
|
return MAP_UNMAPPABLE;
|
2010-05-09 12:52:27 -03:00
|
|
|
return u;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static DBCHAR
|
2023-04-27 10:02:43 -03:00
|
|
|
jisx0201_k_encoder(const MultibyteCodec *codec, const Py_UCS4 *data,
|
|
|
|
Py_ssize_t *length)
|
2004-07-18 00:06:29 -03:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
DBCHAR coded;
|
|
|
|
JISX0201_K_ENCODE(*data, coded)
|
2013-10-28 20:09:41 -03:00
|
|
|
else
|
|
|
|
return MAP_UNMAPPABLE;
|
2010-05-09 12:52:27 -03:00
|
|
|
return coded - 0x80;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2023-04-27 10:02:43 -03:00
|
|
|
gb2312_init(const MultibyteCodec *codec)
|
2004-07-18 00:06:29 -03:00
|
|
|
{
|
2023-04-27 10:02:43 -03:00
|
|
|
cjkcodecs_module_state *st = codec->modstate;
|
|
|
|
if (IMPORT_MAP(cn, gbcommon, &st->gbcommon_encmap, NULL) ||
|
|
|
|
IMPORT_MAP(cn, gb2312, NULL, &st->gb2312_decmap))
|
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
return -1;
|
2023-04-27 10:02:43 -03:00
|
|
|
}
|
2010-05-09 12:52:27 -03:00
|
|
|
return 0;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
2013-04-11 17:09:04 -03:00
|
|
|
static Py_UCS4
|
2023-04-27 10:02:43 -03:00
|
|
|
gb2312_decoder(const MultibyteCodec *codec, const unsigned char *data)
|
2004-07-18 00:06:29 -03:00
|
|
|
{
|
2013-04-11 17:09:04 -03:00
|
|
|
Py_UCS4 u;
|
2023-04-27 10:02:43 -03:00
|
|
|
if (TRYMAP_DEC_ST(gb2312, u, data[0], data[1]))
|
2010-05-09 12:52:27 -03:00
|
|
|
return u;
|
|
|
|
else
|
|
|
|
return MAP_UNMAPPABLE;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static DBCHAR
|
2023-04-27 10:02:43 -03:00
|
|
|
gb2312_encoder(const MultibyteCodec *codec, const Py_UCS4 *data,
|
|
|
|
Py_ssize_t *length)
|
2004-07-18 00:06:29 -03:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
DBCHAR coded;
|
|
|
|
assert(*length == 1);
|
|
|
|
if (*data < 0x10000) {
|
2023-04-27 10:02:43 -03:00
|
|
|
if (TRYMAP_ENC_ST(gbcommon, coded, *data)) {
|
2010-05-09 12:52:27 -03:00
|
|
|
if (!(coded & 0x8000))
|
|
|
|
return coded;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return MAP_UNMAPPABLE;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-11 17:09:04 -03:00
|
|
|
static Py_UCS4
|
2023-04-27 10:02:43 -03:00
|
|
|
dummy_decoder(const MultibyteCodec *codec, const unsigned char *data)
|
2004-07-18 00:06:29 -03:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
return MAP_UNMAPPABLE;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static DBCHAR
|
2023-04-27 10:02:43 -03:00
|
|
|
dummy_encoder(const MultibyteCodec *codec, const Py_UCS4 *data,
|
|
|
|
Py_ssize_t *length)
|
2004-07-18 00:06:29 -03:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
return MAP_UNMAPPABLE;
|
2004-07-18 00:06:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-*- registry tables -*-*/
|
|
|
|
|
2010-05-09 12:52:27 -03:00
|
|
|
#define REGISTRY_KSX1001_G0 { CHARSET_KSX1001, 0, 2, \
|
|
|
|
ksx1001_init, \
|
|
|
|
ksx1001_decoder, ksx1001_encoder }
|
|
|
|
#define REGISTRY_KSX1001_G1 { CHARSET_KSX1001, 1, 2, \
|
|
|
|
ksx1001_init, \
|
|
|
|
ksx1001_decoder, ksx1001_encoder }
|
|
|
|
#define REGISTRY_JISX0201_R { CHARSET_JISX0201_R, 0, 1, \
|
|
|
|
NULL, \
|
|
|
|
jisx0201_r_decoder, jisx0201_r_encoder }
|
|
|
|
#define REGISTRY_JISX0201_K { CHARSET_JISX0201_K, 0, 1, \
|
|
|
|
NULL, \
|
|
|
|
jisx0201_k_decoder, jisx0201_k_encoder }
|
|
|
|
#define REGISTRY_JISX0208 { CHARSET_JISX0208, 0, 2, \
|
|
|
|
jisx0208_init, \
|
|
|
|
jisx0208_decoder, jisx0208_encoder }
|
|
|
|
#define REGISTRY_JISX0208_O { CHARSET_JISX0208_O, 0, 2, \
|
|
|
|
jisx0208_init, \
|
|
|
|
jisx0208_decoder, jisx0208_encoder }
|
|
|
|
#define REGISTRY_JISX0212 { CHARSET_JISX0212, 0, 2, \
|
|
|
|
jisx0212_init, \
|
|
|
|
jisx0212_decoder, jisx0212_encoder }
|
|
|
|
#define REGISTRY_JISX0213_2000_1 { CHARSET_JISX0213_2000_1, 0, 2, \
|
|
|
|
jisx0213_init, \
|
|
|
|
jisx0213_2000_1_decoder, \
|
|
|
|
jisx0213_2000_1_encoder }
|
2004-07-18 00:06:29 -03:00
|
|
|
#define REGISTRY_JISX0213_2000_1_PAIRONLY { CHARSET_JISX0213_2000_1, 0, 2, \
|
2010-05-09 12:52:27 -03:00
|
|
|
jisx0213_init, \
|
|
|
|
jisx0213_2000_1_decoder, \
|
|
|
|
jisx0213_2000_1_encoder_paironly }
|
|
|
|
#define REGISTRY_JISX0213_2000_2 { CHARSET_JISX0213_2, 0, 2, \
|
|
|
|
jisx0213_init, \
|
|
|
|
jisx0213_2000_2_decoder, \
|
|
|
|
jisx0213_2000_2_encoder }
|
|
|
|
#define REGISTRY_JISX0213_2004_1 { CHARSET_JISX0213_2004_1, 0, 2, \
|
|
|
|
jisx0213_init, \
|
|
|
|
jisx0213_2004_1_decoder, \
|
|
|
|
jisx0213_2004_1_encoder }
|
2004-07-18 00:06:29 -03:00
|
|
|
#define REGISTRY_JISX0213_2004_1_PAIRONLY { CHARSET_JISX0213_2004_1, 0, 2, \
|
2010-05-09 12:52:27 -03:00
|
|
|
jisx0213_init, \
|
|
|
|
jisx0213_2004_1_decoder, \
|
|
|
|
jisx0213_2004_1_encoder_paironly }
|
|
|
|
#define REGISTRY_JISX0213_2004_2 { CHARSET_JISX0213_2, 0, 2, \
|
|
|
|
jisx0213_init, \
|
|
|
|
jisx0213_2004_2_decoder, \
|
|
|
|
jisx0213_2004_2_encoder }
|
|
|
|
#define REGISTRY_GB2312 { CHARSET_GB2312, 0, 2, \
|
|
|
|
gb2312_init, \
|
|
|
|
gb2312_decoder, gb2312_encoder }
|
|
|
|
#define REGISTRY_CNS11643_1 { CHARSET_CNS11643_1, 1, 2, \
|
|
|
|
cns11643_init, \
|
|
|
|
cns11643_1_decoder, cns11643_1_encoder }
|
|
|
|
#define REGISTRY_CNS11643_2 { CHARSET_CNS11643_2, 2, 2, \
|
|
|
|
cns11643_init, \
|
|
|
|
cns11643_2_decoder, cns11643_2_encoder }
|
|
|
|
#define REGISTRY_ISO8859_1 { CHARSET_ISO8859_1, 2, 1, \
|
|
|
|
NULL, dummy_decoder, dummy_encoder }
|
|
|
|
#define REGISTRY_ISO8859_7 { CHARSET_ISO8859_7, 2, 1, \
|
|
|
|
NULL, dummy_decoder, dummy_encoder }
|
|
|
|
#define REGISTRY_SENTINEL { 0, }
|
|
|
|
#define CONFIGDEF(var, attrs) \
|
|
|
|
static const struct iso2022_config iso2022_##var##_config = { \
|
|
|
|
attrs, iso2022_##var##_designations \
|
|
|
|
};
|
2004-07-18 00:06:29 -03:00
|
|
|
|
2004-08-19 14:49:56 -03:00
|
|
|
static const struct iso2022_designation iso2022_kr_designations[] = {
|
2010-05-09 12:52:27 -03:00
|
|
|
REGISTRY_KSX1001_G1, REGISTRY_SENTINEL
|
2004-07-18 00:06:29 -03:00
|
|
|
};
|
2004-08-19 14:49:56 -03:00
|
|
|
CONFIGDEF(kr, 0)
|
2004-07-18 00:06:29 -03:00
|
|
|
|
2004-08-19 14:49:56 -03:00
|
|
|
static const struct iso2022_designation iso2022_jp_designations[] = {
|
2010-05-09 12:52:27 -03:00
|
|
|
REGISTRY_JISX0208, REGISTRY_JISX0201_R, REGISTRY_JISX0208_O,
|
|
|
|
REGISTRY_SENTINEL
|
2004-07-18 00:06:29 -03:00
|
|
|
};
|
2004-08-19 14:49:56 -03:00
|
|
|
CONFIGDEF(jp, NO_SHIFT | USE_JISX0208_EXT)
|
2004-07-18 00:06:29 -03:00
|
|
|
|
2004-08-19 14:49:56 -03:00
|
|
|
static const struct iso2022_designation iso2022_jp_1_designations[] = {
|
2010-05-09 12:52:27 -03:00
|
|
|
REGISTRY_JISX0208, REGISTRY_JISX0212, REGISTRY_JISX0201_R,
|
|
|
|
REGISTRY_JISX0208_O, REGISTRY_SENTINEL
|
2004-07-18 00:06:29 -03:00
|
|
|
};
|
2004-08-19 14:49:56 -03:00
|
|
|
CONFIGDEF(jp_1, NO_SHIFT | USE_JISX0208_EXT)
|
2004-07-18 00:06:29 -03:00
|
|
|
|
2004-08-19 14:49:56 -03:00
|
|
|
static const struct iso2022_designation iso2022_jp_2_designations[] = {
|
2010-05-09 12:52:27 -03:00
|
|
|
REGISTRY_JISX0208, REGISTRY_JISX0212, REGISTRY_KSX1001_G0,
|
|
|
|
REGISTRY_GB2312, REGISTRY_JISX0201_R, REGISTRY_JISX0208_O,
|
|
|
|
REGISTRY_ISO8859_1, REGISTRY_ISO8859_7, REGISTRY_SENTINEL
|
2004-07-18 00:06:29 -03:00
|
|
|
};
|
2004-08-19 14:49:56 -03:00
|
|
|
CONFIGDEF(jp_2, NO_SHIFT | USE_G2 | USE_JISX0208_EXT)
|
2004-07-18 00:06:29 -03:00
|
|
|
|
2004-08-19 14:49:56 -03:00
|
|
|
static const struct iso2022_designation iso2022_jp_2004_designations[] = {
|
2010-05-09 12:52:27 -03:00
|
|
|
REGISTRY_JISX0213_2004_1_PAIRONLY, REGISTRY_JISX0208,
|
|
|
|
REGISTRY_JISX0213_2004_1, REGISTRY_JISX0213_2004_2, REGISTRY_SENTINEL
|
2004-07-18 00:06:29 -03:00
|
|
|
};
|
2004-08-19 14:49:56 -03:00
|
|
|
CONFIGDEF(jp_2004, NO_SHIFT | USE_JISX0208_EXT)
|
2004-07-18 00:06:29 -03:00
|
|
|
|
2004-08-19 14:49:56 -03:00
|
|
|
static const struct iso2022_designation iso2022_jp_3_designations[] = {
|
2010-05-09 12:52:27 -03:00
|
|
|
REGISTRY_JISX0213_2000_1_PAIRONLY, REGISTRY_JISX0208,
|
|
|
|
REGISTRY_JISX0213_2000_1, REGISTRY_JISX0213_2000_2, REGISTRY_SENTINEL
|
2004-07-18 00:06:29 -03:00
|
|
|
};
|
2004-08-19 14:49:56 -03:00
|
|
|
CONFIGDEF(jp_3, NO_SHIFT | USE_JISX0208_EXT)
|
2004-07-18 00:06:29 -03:00
|
|
|
|
2004-08-19 14:49:56 -03:00
|
|
|
static const struct iso2022_designation iso2022_jp_ext_designations[] = {
|
2010-05-09 12:52:27 -03:00
|
|
|
REGISTRY_JISX0208, REGISTRY_JISX0212, REGISTRY_JISX0201_R,
|
|
|
|
REGISTRY_JISX0201_K, REGISTRY_JISX0208_O, REGISTRY_SENTINEL
|
2004-07-18 00:06:29 -03:00
|
|
|
};
|
2004-08-19 14:49:56 -03:00
|
|
|
CONFIGDEF(jp_ext, NO_SHIFT | USE_JISX0208_EXT)
|
2004-07-18 00:06:29 -03:00
|
|
|
|
|
|
|
|
2023-04-16 21:41:25 -03:00
|
|
|
BEGIN_MAPPINGS_LIST(0)
|
2004-07-18 00:06:29 -03:00
|
|
|
/* no mapping table here */
|
|
|
|
END_MAPPINGS_LIST
|
|
|
|
|
2023-04-16 21:41:25 -03:00
|
|
|
#define ISO2022_CODEC(variation) \
|
|
|
|
NEXT_CODEC = (MultibyteCodec){ \
|
2010-05-09 12:52:27 -03:00
|
|
|
"iso2022_" #variation, \
|
|
|
|
&iso2022_##variation##_config, \
|
|
|
|
iso2022_codec_init, \
|
|
|
|
_STATEFUL_METHODS(iso2022) \
|
2023-04-16 21:41:25 -03:00
|
|
|
};
|
2004-07-18 00:06:29 -03:00
|
|
|
|
2023-04-16 21:41:25 -03:00
|
|
|
BEGIN_CODECS_LIST(7)
|
2004-07-18 00:06:29 -03:00
|
|
|
ISO2022_CODEC(kr)
|
|
|
|
ISO2022_CODEC(jp)
|
|
|
|
ISO2022_CODEC(jp_1)
|
|
|
|
ISO2022_CODEC(jp_2)
|
|
|
|
ISO2022_CODEC(jp_2004)
|
|
|
|
ISO2022_CODEC(jp_3)
|
|
|
|
ISO2022_CODEC(jp_ext)
|
|
|
|
END_CODECS_LIST
|
|
|
|
|
|
|
|
I_AM_A_MODULE_FOR(iso2022)
|