2008-08-07 18:53:30 +04:00
|
|
|
#include "transcode_data.h"
|
|
|
|
|
|
|
|
<%
|
2008-09-07 18:49:05 +04:00
|
|
|
map = {
|
|
|
|
"1b2842" => :func_so, # designate US-ASCII to G0. "ESC ( B"
|
|
|
|
"1b284a" => :func_so, # designate JIS X 0201 latin to G0. "ESC ( J"
|
|
|
|
"1b2440" => :func_so, # designate JIS X 0208 1978 to G0. "ESC $ @"
|
|
|
|
"1b2442" => :func_so, # designate JIS X 0208 1983 to G0. "ESC $ B"
|
|
|
|
"{00-0d,10-1a,1c-7f}" => :func_si,
|
|
|
|
}
|
|
|
|
transcode_generate_node(ActionMap.parse(map), "iso2022jp_decoder")
|
|
|
|
|
|
|
|
map_jisx0208_rest = {
|
|
|
|
"{21-7e}" => :func_so
|
|
|
|
}
|
|
|
|
transcode_generate_node(ActionMap.parse(map_jisx0208_rest), "iso2022jp_decoder_jisx0208_rest")
|
2008-08-07 18:53:30 +04:00
|
|
|
|
2008-09-07 18:49:05 +04:00
|
|
|
map = {
|
|
|
|
"{00-0d,10-1a,1c-7f}" => :func_so,
|
|
|
|
"90{a1-fe}{a1-fe}" => :func_so,
|
|
|
|
"92{a1-fe}{a1-fe}" => :func_so,
|
|
|
|
}
|
|
|
|
transcode_generate_node(ActionMap.parse(map), "iso2022jp_encoder")
|
2008-08-31 21:35:00 +04:00
|
|
|
|
2008-09-07 18:49:05 +04:00
|
|
|
map = {
|
|
|
|
"{00-0d,10-1a,1c-7f}" => :nomap,
|
|
|
|
"90{a1-fe}{a1-fe}" => :func_so,
|
|
|
|
"92{a1-fe}{a1-fe}" => :func_so,
|
|
|
|
}
|
|
|
|
transcode_generate_node(ActionMap.parse(map), "stateless_iso2022jp_to_eucjp")
|
2008-08-31 21:35:00 +04:00
|
|
|
|
2008-09-07 18:49:05 +04:00
|
|
|
map = {
|
2008-08-31 21:35:00 +04:00
|
|
|
"{0e,0f,1b}" => :undef,
|
2008-09-07 18:49:05 +04:00
|
|
|
"{00-0d,10-1a,1c-7f}" => :nomap,
|
2008-08-31 21:35:00 +04:00
|
|
|
"{a1-fe}{a1-fe}" => :func_so,
|
|
|
|
"8e{a1-fe}" => :undef,
|
|
|
|
"8f{a1-fe}{a1-fe}" => :undef,
|
|
|
|
}
|
2008-09-07 18:49:05 +04:00
|
|
|
transcode_generate_node(ActionMap.parse(map), "eucjp_to_stateless_iso2022jp")
|
2008-08-31 21:35:00 +04:00
|
|
|
|
2009-04-29 16:50:57 +04:00
|
|
|
map = {
|
|
|
|
"1b2842" => :func_so, # designate US-ASCII to G0. "ESC ( B"
|
|
|
|
"1b2849" => :func_so, # designate JIS X 0201 katakana to G0. "ESC ( I"
|
|
|
|
"1b284a" => :func_so, # designate JIS X 0201 latin to G0. "ESC ( J"
|
|
|
|
"1b2440" => :func_so, # designate JIS X 0208 1978 to G0. "ESC $ @"
|
|
|
|
"1b2442" => :func_so, # designate JIS X 0208 1983 to G0. "ESC $ B"
|
|
|
|
"0e" => :func_so, # designate JIS X 0201 katakana to G0. "SO"
|
|
|
|
"0f" => :func_so, # designate US-ASCII to G0. "SI"
|
2010-04-01 12:18:38 +04:00
|
|
|
"{00-0d,10-1a,1c-92,a1-df}" => :func_si,
|
2009-04-29 16:50:57 +04:00
|
|
|
}
|
|
|
|
transcode_generate_node(ActionMap.parse(map), "cp50221_decoder")
|
|
|
|
|
|
|
|
map = {
|
|
|
|
"{0e,0f,1b}" => :undef,
|
|
|
|
"{00-0d,10-1a,1c-7f}" => :func_so,
|
|
|
|
"{a1-fe}{a1-fe}" => :func_so,
|
|
|
|
"8e{a1-fe}" => :func_so,
|
|
|
|
}
|
|
|
|
transcode_generate_node(ActionMap.parse(map), "cp50221_encoder")
|
|
|
|
|
2008-08-07 18:53:30 +04:00
|
|
|
%>
|
|
|
|
|
2008-08-31 21:35:00 +04:00
|
|
|
<%= transcode_generated_code %>
|
2008-08-07 18:53:30 +04:00
|
|
|
|
2008-09-03 18:12:06 +04:00
|
|
|
#define G0_ASCII 0
|
2008-09-07 18:49:05 +04:00
|
|
|
/* ignore JIS X 0201 latin */
|
|
|
|
#define G0_JISX0208_1978 1
|
|
|
|
#define G0_JISX0208_1983 2
|
2009-04-29 16:50:57 +04:00
|
|
|
#define G0_JISX0201_KATAKANA 3
|
2008-09-07 18:49:05 +04:00
|
|
|
|
|
|
|
#define EMACS_MULE_LEADING_CODE_JISX0208_1978 0220
|
|
|
|
#define EMACS_MULE_LEADING_CODE_JISX0208_1983 0222
|
2008-09-03 18:12:06 +04:00
|
|
|
|
|
|
|
static int
|
|
|
|
iso2022jp_init(void *statep)
|
|
|
|
{
|
|
|
|
unsigned char *sp = statep;
|
|
|
|
*sp = G0_ASCII;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-08-07 18:53:30 +04:00
|
|
|
static VALUE
|
2008-09-07 18:49:05 +04:00
|
|
|
fun_si_iso2022jp_decoder(void *statep, const unsigned char *s, size_t l)
|
2008-08-07 18:53:30 +04:00
|
|
|
{
|
2008-09-03 18:12:06 +04:00
|
|
|
unsigned char *sp = statep;
|
|
|
|
if (*sp == G0_ASCII)
|
2008-08-07 18:53:30 +04:00
|
|
|
return (VALUE)NOMAP;
|
|
|
|
else if (0x21 <= s[0] && s[0] <= 0x7e)
|
2008-09-07 18:49:05 +04:00
|
|
|
return (VALUE)iso2022jp_decoder_jisx0208_rest;
|
2008-08-07 18:53:30 +04:00
|
|
|
else
|
|
|
|
return (VALUE)INVALID;
|
|
|
|
}
|
|
|
|
|
2008-09-14 22:35:17 +04:00
|
|
|
static ssize_t
|
2008-09-14 22:06:20 +04:00
|
|
|
fun_so_iso2022jp_decoder(void *statep, const unsigned char *s, size_t l, unsigned char* o, size_t osize)
|
2008-08-07 18:53:30 +04:00
|
|
|
{
|
2008-09-03 18:12:06 +04:00
|
|
|
unsigned char *sp = statep;
|
2008-08-07 18:53:30 +04:00
|
|
|
if (s[0] == 0x1b) {
|
|
|
|
if (s[1] == '(') {
|
|
|
|
switch (s[l-1]) {
|
|
|
|
case 'B':
|
|
|
|
case 'J':
|
2008-09-03 18:12:06 +04:00
|
|
|
*sp = G0_ASCII;
|
2008-08-07 18:53:30 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch (s[l-1]) {
|
|
|
|
case '@':
|
2008-09-07 18:49:05 +04:00
|
|
|
*sp = G0_JISX0208_1978;
|
|
|
|
break;
|
|
|
|
|
2008-08-07 18:53:30 +04:00
|
|
|
case 'B':
|
2008-09-07 18:49:05 +04:00
|
|
|
*sp = G0_JISX0208_1983;
|
2008-08-07 18:53:30 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else {
|
2008-09-07 18:49:05 +04:00
|
|
|
if (*sp == G0_JISX0208_1978)
|
|
|
|
o[0] = EMACS_MULE_LEADING_CODE_JISX0208_1978;
|
|
|
|
else
|
|
|
|
o[0] = EMACS_MULE_LEADING_CODE_JISX0208_1983;
|
|
|
|
o[1] = s[0] | 0x80;
|
|
|
|
o[2] = s[1] | 0x80;
|
|
|
|
return 3;
|
2008-08-07 18:53:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const rb_transcoder
|
2008-09-07 18:49:05 +04:00
|
|
|
rb_iso2022jp_decoder = {
|
2008-09-07 19:05:12 +04:00
|
|
|
"ISO-2022-JP", "stateless-ISO-2022-JP", iso2022jp_decoder,
|
2008-09-01 22:18:50 +04:00
|
|
|
TRANSCODE_TABLE_INFO,
|
2008-08-09 10:02:01 +04:00
|
|
|
1, /* input_unit_length */
|
|
|
|
3, /* max_input */
|
|
|
|
3, /* max_output */
|
2008-09-08 18:33:17 +04:00
|
|
|
asciicompat_decoder, /* asciicompat_type */
|
2008-09-03 18:12:06 +04:00
|
|
|
1, iso2022jp_init, iso2022jp_init, /* state_size, state_init, state_fini */
|
2008-09-07 18:49:05 +04:00
|
|
|
NULL, fun_si_iso2022jp_decoder, NULL, fun_so_iso2022jp_decoder
|
2008-08-07 18:53:30 +04:00
|
|
|
};
|
|
|
|
|
2008-09-14 22:35:17 +04:00
|
|
|
static ssize_t
|
2008-09-14 22:06:20 +04:00
|
|
|
fun_so_iso2022jp_encoder(void *statep, const unsigned char *s, size_t l, unsigned char *o, size_t osize)
|
2008-08-07 18:53:30 +04:00
|
|
|
{
|
2008-09-03 18:12:06 +04:00
|
|
|
unsigned char *sp = statep;
|
2008-08-07 18:53:30 +04:00
|
|
|
unsigned char *output0 = o;
|
2008-09-07 18:49:05 +04:00
|
|
|
int newstate;
|
|
|
|
|
|
|
|
if (l == 1)
|
|
|
|
newstate = G0_ASCII;
|
|
|
|
else if (s[0] == EMACS_MULE_LEADING_CODE_JISX0208_1978)
|
|
|
|
newstate = G0_JISX0208_1978;
|
|
|
|
else
|
|
|
|
newstate = G0_JISX0208_1983;
|
2008-08-07 18:53:30 +04:00
|
|
|
|
2008-09-07 18:49:05 +04:00
|
|
|
if (*sp != newstate) {
|
|
|
|
if (newstate == G0_ASCII) {
|
2008-08-07 18:53:30 +04:00
|
|
|
*o++ = 0x1b;
|
|
|
|
*o++ = '(';
|
|
|
|
*o++ = 'B';
|
2008-09-07 18:49:05 +04:00
|
|
|
}
|
|
|
|
else if (newstate == G0_JISX0208_1978) {
|
|
|
|
*o++ = 0x1b;
|
|
|
|
*o++ = '$';
|
|
|
|
*o++ = '@';
|
2008-08-07 18:53:30 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
*o++ = 0x1b;
|
|
|
|
*o++ = '$';
|
|
|
|
*o++ = 'B';
|
|
|
|
}
|
2008-09-07 18:49:05 +04:00
|
|
|
*sp = newstate;
|
2008-08-07 18:53:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (l == 1) {
|
|
|
|
*o++ = s[0] & 0x7f;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*o++ = s[1] & 0x7f;
|
2008-09-07 18:49:05 +04:00
|
|
|
*o++ = s[2] & 0x7f;
|
2008-08-07 18:53:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return o - output0;
|
|
|
|
}
|
|
|
|
|
2008-09-15 06:11:50 +04:00
|
|
|
static ssize_t
|
2008-09-07 18:49:05 +04:00
|
|
|
iso2022jp_encoder_reset_sequence_size(void *statep)
|
2008-08-14 19:56:39 +04:00
|
|
|
{
|
2008-09-03 18:12:06 +04:00
|
|
|
unsigned char *sp = statep;
|
2008-09-07 18:49:05 +04:00
|
|
|
if (*sp != G0_ASCII)
|
2008-08-14 19:56:39 +04:00
|
|
|
return 3;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-09-14 22:35:17 +04:00
|
|
|
static ssize_t
|
2008-09-14 22:06:20 +04:00
|
|
|
finish_iso2022jp_encoder(void *statep, unsigned char *o, size_t osize)
|
2008-08-07 18:53:30 +04:00
|
|
|
{
|
2008-09-03 18:12:06 +04:00
|
|
|
unsigned char *sp = statep;
|
2008-08-07 18:53:30 +04:00
|
|
|
unsigned char *output0 = o;
|
|
|
|
|
2008-09-03 18:12:06 +04:00
|
|
|
if (*sp == G0_ASCII)
|
2008-08-07 18:53:30 +04:00
|
|
|
return 0;
|
|
|
|
|
2008-09-03 18:12:06 +04:00
|
|
|
*o++ = 0x1b;
|
|
|
|
*o++ = '(';
|
|
|
|
*o++ = 'B';
|
|
|
|
*sp = G0_ASCII;
|
2008-08-07 18:53:30 +04:00
|
|
|
|
|
|
|
return o - output0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const rb_transcoder
|
2008-09-07 18:49:05 +04:00
|
|
|
rb_iso2022jp_encoder = {
|
2008-09-07 19:05:12 +04:00
|
|
|
"stateless-ISO-2022-JP", "ISO-2022-JP", iso2022jp_encoder,
|
2008-09-01 22:18:50 +04:00
|
|
|
TRANSCODE_TABLE_INFO,
|
2008-08-09 10:02:01 +04:00
|
|
|
1, /* input_unit_length */
|
|
|
|
3, /* max_input */
|
|
|
|
5, /* max_output */
|
2008-09-08 18:33:17 +04:00
|
|
|
asciicompat_encoder, /* asciicompat_type */
|
2008-09-03 18:12:06 +04:00
|
|
|
1, iso2022jp_init, iso2022jp_init, /* state_size, state_init, state_fini */
|
2008-09-07 18:49:05 +04:00
|
|
|
NULL, NULL, NULL, fun_so_iso2022jp_encoder,
|
|
|
|
finish_iso2022jp_encoder,
|
|
|
|
iso2022jp_encoder_reset_sequence_size, finish_iso2022jp_encoder
|
|
|
|
};
|
|
|
|
|
2008-09-14 22:35:17 +04:00
|
|
|
static ssize_t
|
2008-09-14 22:06:20 +04:00
|
|
|
fun_so_stateless_iso2022jp_to_eucjp(void *statep, const unsigned char *s, size_t l, unsigned char *o, size_t osize)
|
2008-09-07 18:49:05 +04:00
|
|
|
{
|
|
|
|
o[0] = s[1];
|
|
|
|
o[1] = s[2];
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const rb_transcoder
|
|
|
|
rb_stateless_iso2022jp_to_eucjp = {
|
2008-09-07 19:05:12 +04:00
|
|
|
"stateless-ISO-2022-JP", "EUC-JP", stateless_iso2022jp_to_eucjp,
|
2008-09-07 18:49:05 +04:00
|
|
|
TRANSCODE_TABLE_INFO,
|
|
|
|
1, /* input_unit_length */
|
|
|
|
3, /* max_input */
|
|
|
|
2, /* max_output */
|
2008-09-08 18:33:17 +04:00
|
|
|
asciicompat_converter, /* asciicompat_type */
|
2008-09-07 18:49:05 +04:00
|
|
|
0, NULL, NULL, /* state_size, state_init, state_fini */
|
|
|
|
NULL, NULL, NULL, fun_so_stateless_iso2022jp_to_eucjp,
|
|
|
|
};
|
|
|
|
|
2008-09-14 22:35:17 +04:00
|
|
|
static ssize_t
|
2008-09-14 22:06:20 +04:00
|
|
|
fun_so_eucjp_to_stateless_iso2022jp(void *statep, const unsigned char *s, size_t l, unsigned char *o, size_t osize)
|
2008-09-07 18:49:05 +04:00
|
|
|
{
|
|
|
|
o[0] = EMACS_MULE_LEADING_CODE_JISX0208_1983;
|
|
|
|
o[1] = s[0];
|
|
|
|
o[2] = s[1];
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const rb_transcoder
|
|
|
|
rb_eucjp_to_stateless_iso2022jp = {
|
2008-09-07 19:05:12 +04:00
|
|
|
"EUC-JP", "stateless-ISO-2022-JP", eucjp_to_stateless_iso2022jp,
|
2008-09-07 18:49:05 +04:00
|
|
|
TRANSCODE_TABLE_INFO,
|
|
|
|
1, /* input_unit_length */
|
|
|
|
3, /* max_input */
|
|
|
|
3, /* max_output */
|
2008-09-08 18:33:17 +04:00
|
|
|
asciicompat_converter, /* asciicompat_type */
|
2008-09-07 18:49:05 +04:00
|
|
|
0, NULL, NULL, /* state_size, state_init, state_fini */
|
|
|
|
NULL, NULL, NULL, fun_so_eucjp_to_stateless_iso2022jp,
|
2008-08-07 18:53:30 +04:00
|
|
|
};
|
|
|
|
|
2009-04-29 16:50:57 +04:00
|
|
|
static VALUE
|
|
|
|
fun_si_cp50221_decoder(void *statep, const unsigned char *s, size_t l)
|
|
|
|
{
|
|
|
|
unsigned char *sp = statep;
|
2010-04-01 12:18:38 +04:00
|
|
|
int c;
|
2009-04-29 16:50:57 +04:00
|
|
|
switch (*sp) {
|
|
|
|
case G0_ASCII:
|
2010-04-01 12:18:38 +04:00
|
|
|
if (0xA1 <= s[0] && s[0] <= 0xDF)
|
|
|
|
return (VALUE)FUNso;
|
2009-04-29 16:50:57 +04:00
|
|
|
return (VALUE)NOMAP;
|
|
|
|
case G0_JISX0201_KATAKANA:
|
2010-04-01 12:18:38 +04:00
|
|
|
c = s[0] & 0x7F;
|
|
|
|
if (0x21 <= c && c <= 0x5f)
|
2009-04-29 16:50:57 +04:00
|
|
|
return (VALUE)FUNso;
|
|
|
|
break;
|
|
|
|
case G0_JISX0208_1978:
|
2010-04-01 12:18:38 +04:00
|
|
|
if ((0x21 <= s[0] && s[0] <= 0x28) || (0x30 <= s[0] && s[0] <= 0x74))
|
2009-04-29 16:50:57 +04:00
|
|
|
return (VALUE)iso2022jp_decoder_jisx0208_rest;
|
|
|
|
break;
|
|
|
|
case G0_JISX0208_1983:
|
2010-04-01 12:18:38 +04:00
|
|
|
if ((0x21 <= s[0] && s[0] <= 0x28) ||
|
2009-04-29 16:50:57 +04:00
|
|
|
s[0] == 0x2D ||
|
2010-04-01 12:18:38 +04:00
|
|
|
(0x30 <= s[0] && s[0] <= 0x74) ||
|
|
|
|
(0x79 <= s[0] && s[0] <= 0x7C))
|
2009-04-29 16:50:57 +04:00
|
|
|
/* 0x7F <= s[0] && s[0] <= 0x92) */
|
|
|
|
return (VALUE)iso2022jp_decoder_jisx0208_rest;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (VALUE)INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t
|
|
|
|
fun_so_cp50221_decoder(void *statep, const unsigned char *s, size_t l, unsigned char* o, size_t osize)
|
|
|
|
{
|
|
|
|
unsigned char *sp = statep;
|
|
|
|
switch (s[0]) {
|
|
|
|
case 0x1b:
|
|
|
|
if (s[1] == '(') {
|
|
|
|
switch (s[l-1]) {
|
|
|
|
case 'B':
|
|
|
|
case 'J':
|
|
|
|
*sp = G0_ASCII;
|
|
|
|
break;
|
|
|
|
case 'I':
|
|
|
|
*sp = G0_JISX0201_KATAKANA;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch (s[l-1]) {
|
|
|
|
case '@':
|
|
|
|
*sp = G0_JISX0208_1978;
|
|
|
|
break;
|
|
|
|
case 'B':
|
|
|
|
*sp = G0_JISX0208_1983;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
case 0x0E:
|
|
|
|
*sp = G0_JISX0201_KATAKANA;
|
|
|
|
return 0;
|
|
|
|
case 0x0F:
|
|
|
|
*sp = G0_ASCII;
|
|
|
|
return 0;
|
|
|
|
default:
|
2010-04-01 12:18:38 +04:00
|
|
|
if (*sp == G0_JISX0201_KATAKANA ||
|
|
|
|
(0xA1 <= s[0] && s[0] <= 0xDF && *sp == G0_ASCII)) {
|
2009-04-29 16:50:57 +04:00
|
|
|
o[0] = 0x8E;
|
|
|
|
o[1] = s[0] | 0x80;
|
|
|
|
}
|
|
|
|
/* else if (0x7F == s[0] && s[0] <= 0x88) { */
|
|
|
|
/* User Defined Characters */
|
|
|
|
/* o[n++] = s[0] | 0xE0; */
|
|
|
|
/* o[n++] = s[1] | 0x80; */
|
|
|
|
/* else if (0x89 <= s[0] && s[0] <= 0x92) { */
|
|
|
|
/* User Defined Characters 2 */
|
|
|
|
/* o[n++] = 0x8f; */
|
|
|
|
/* o[n++] = s[0] + 0x6C; */
|
|
|
|
/* o[n++] = s[1] | 0x80; */
|
|
|
|
/* } */
|
|
|
|
else {
|
|
|
|
/* JIS X 0208 */
|
|
|
|
/* NEC Special Characters */
|
|
|
|
/* NEC-selected IBM extended Characters */
|
|
|
|
o[0] = s[0] | 0x80;
|
|
|
|
o[1] = s[1] | 0x80;
|
|
|
|
}
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const rb_transcoder
|
|
|
|
rb_cp50221_decoder = {
|
|
|
|
"CP50221", "cp51932", cp50221_decoder,
|
|
|
|
TRANSCODE_TABLE_INFO,
|
|
|
|
1, /* input_unit_length */
|
|
|
|
3, /* max_input */
|
|
|
|
3, /* max_output */
|
|
|
|
asciicompat_decoder, /* asciicompat_type */
|
|
|
|
1, iso2022jp_init, iso2022jp_init, /* state_size, state_init, state_fini */
|
|
|
|
NULL, fun_si_cp50221_decoder, NULL, fun_so_cp50221_decoder
|
|
|
|
};
|
|
|
|
|
|
|
|
static ssize_t
|
|
|
|
fun_so_cp50221_encoder(void *statep, const unsigned char *s, size_t l, unsigned char *o, size_t osize)
|
|
|
|
{
|
|
|
|
unsigned char *sp = statep;
|
|
|
|
unsigned char *output0 = o;
|
|
|
|
int newstate;
|
|
|
|
|
|
|
|
if (l == 1)
|
|
|
|
newstate = G0_ASCII;
|
|
|
|
else if (s[0] == 0x8E) {
|
|
|
|
s++;
|
|
|
|
l = 1;
|
|
|
|
newstate = G0_JISX0201_KATAKANA;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
newstate = G0_JISX0208_1983;
|
|
|
|
|
|
|
|
if (*sp != newstate) {
|
|
|
|
if (newstate == G0_ASCII) {
|
|
|
|
*o++ = 0x1b;
|
|
|
|
*o++ = '(';
|
|
|
|
*o++ = 'B';
|
|
|
|
}
|
|
|
|
else if (newstate == G0_JISX0201_KATAKANA) {
|
|
|
|
*o++ = 0x1b;
|
|
|
|
*o++ = '(';
|
|
|
|
*o++ = 'I';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*o++ = 0x1b;
|
|
|
|
*o++ = '$';
|
|
|
|
*o++ = 'B';
|
|
|
|
}
|
|
|
|
*sp = newstate;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (l == 1) {
|
|
|
|
*o++ = s[0] & 0x7f;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*o++ = s[0] & 0x7f;
|
|
|
|
*o++ = s[1] & 0x7f;
|
|
|
|
}
|
|
|
|
|
|
|
|
return o - output0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const rb_transcoder
|
|
|
|
rb_cp50221_encoder = {
|
|
|
|
"CP51932", "CP50221", cp50221_encoder,
|
|
|
|
TRANSCODE_TABLE_INFO,
|
|
|
|
1, /* input_unit_length */
|
|
|
|
3, /* max_input */
|
|
|
|
5, /* max_output */
|
|
|
|
asciicompat_encoder, /* asciicompat_type */
|
|
|
|
1, iso2022jp_init, iso2022jp_init, /* state_size, state_init, state_fini */
|
|
|
|
NULL, NULL, NULL, fun_so_cp50221_encoder,
|
|
|
|
finish_iso2022jp_encoder,
|
|
|
|
iso2022jp_encoder_reset_sequence_size, finish_iso2022jp_encoder
|
|
|
|
};
|
|
|
|
|
2008-08-07 18:53:30 +04:00
|
|
|
void
|
|
|
|
Init_iso2022(void)
|
|
|
|
{
|
2008-09-07 18:49:05 +04:00
|
|
|
rb_register_transcoder(&rb_iso2022jp_decoder);
|
|
|
|
rb_register_transcoder(&rb_iso2022jp_encoder);
|
|
|
|
rb_register_transcoder(&rb_stateless_iso2022jp_to_eucjp);
|
|
|
|
rb_register_transcoder(&rb_eucjp_to_stateless_iso2022jp);
|
2009-04-29 16:50:57 +04:00
|
|
|
rb_register_transcoder(&rb_cp50221_decoder);
|
|
|
|
rb_register_transcoder(&rb_cp50221_encoder);
|
2008-08-07 18:53:30 +04:00
|
|
|
}
|
|
|
|
|