2020-04-10 01:11:40 -04:00
|
|
|
#ifndef RUBY_TRANSCODE_DATA_H
|
|
|
|
#define RUBY_TRANSCODE_DATA_H 1
|
2007-12-24 08:51:19 -05:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
transcode_data.h -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
created at: Mon 10 Dec 2007 14:01:47 JST 2007
|
|
|
|
|
|
|
|
Copyright (C) 2007 Martin Duerst
|
|
|
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
#include "ruby/ruby.h"
|
|
|
|
|
2013-04-05 06:29:38 -04:00
|
|
|
RUBY_SYMBOL_EXPORT_BEGIN
|
2010-07-21 17:38:25 -04:00
|
|
|
|
2008-09-03 08:35:29 -04:00
|
|
|
#define WORDINDEX_SHIFT_BITS 2
|
|
|
|
#define WORDINDEX2INFO(widx) ((widx) << WORDINDEX_SHIFT_BITS)
|
|
|
|
#define INFO2WORDINDEX(info) ((info) >> WORDINDEX_SHIFT_BITS)
|
2008-09-02 09:26:02 -04:00
|
|
|
#define BYTE_LOOKUP_BASE(bl) ((bl)[0])
|
|
|
|
#define BYTE_LOOKUP_INFO(bl) ((bl)[1])
|
2008-09-01 10:33:56 -04:00
|
|
|
|
2008-09-02 09:26:02 -04:00
|
|
|
#define PType (unsigned int)
|
2007-12-10 00:01:47 -05:00
|
|
|
|
2009-05-04 20:05:11 -04:00
|
|
|
#define NOMAP (PType 0x01) /* direct map */
|
2007-12-28 04:26:55 -05:00
|
|
|
#define ONEbt (0x02) /* one byte payload */
|
|
|
|
#define TWObt (0x03) /* two bytes payload */
|
|
|
|
#define THREEbt (0x05) /* three bytes payload */
|
|
|
|
#define FOURbt (0x06) /* four bytes payload, UTF-8 only, macros start at getBT0 */
|
|
|
|
#define INVALID (PType 0x07) /* invalid byte sequence */
|
|
|
|
#define UNDEF (PType 0x09) /* legal but undefined */
|
|
|
|
#define ZERObt (PType 0x0A) /* zero bytes of payload, i.e. remove */
|
|
|
|
#define FUNii (PType 0x0B) /* function from info to info */
|
2008-01-20 01:12:48 -05:00
|
|
|
#define FUNsi (PType 0x0D) /* function from start to info */
|
|
|
|
#define FUNio (PType 0x0E) /* function from info to output */
|
|
|
|
#define FUNso (PType 0x0F) /* function from start to output */
|
2008-09-15 11:42:30 -04:00
|
|
|
#define STR1 (PType 0x11) /* string 4 <= len <= 259 bytes: 1byte length + content */
|
2009-01-14 06:12:30 -05:00
|
|
|
#define GB4bt (PType 0x12) /* GB18030 four bytes payload */
|
2009-12-10 06:59:12 -05:00
|
|
|
#define FUNsio (PType 0x13) /* function from start and info to output */
|
2008-09-07 05:13:16 -04:00
|
|
|
|
* array.c, bignum.c, dln.c, error.c, gc.c, io.c, marshal.c,
numeric.c, pack.c, strftime.c, string.c, thread.c, transcode.c,
transcode_data.h, util.c, variable.c, vm_dump.c,
include/ruby/encoding.h, missing/crypt.c, missing/vsnprintf.c:
suppress VC type warnings. [ruby-core:22726]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-03-12 05:16:15 -04:00
|
|
|
#define STR1_LENGTH(byte_addr) (unsigned int)(*(byte_addr) + 4)
|
2008-09-07 05:13:16 -04:00
|
|
|
#define STR1_BYTEINDEX(w) ((w) >> 6)
|
|
|
|
#define makeSTR1(bi) (((bi) << 6) | STR1)
|
2008-09-15 11:42:30 -04:00
|
|
|
#define makeSTR1LEN(len) ((len)-4)
|
2007-12-28 04:26:55 -05:00
|
|
|
|
|
|
|
#define o1(b1) (PType((((unsigned char)(b1))<<8)|ONEbt))
|
2015-08-07 20:29:13 -04:00
|
|
|
#define o2(b1,b2) (PType((((unsigned char)(b1))<<8)|\
|
2022-07-21 12:23:58 -04:00
|
|
|
(((unsigned char)(b2))<<16)|\
|
|
|
|
TWObt))
|
2015-08-07 20:29:13 -04:00
|
|
|
#define o3(b1,b2,b3) (PType(((((unsigned char)(b1))<<8)|\
|
2022-07-21 12:23:58 -04:00
|
|
|
(((unsigned char)(b2))<<16)|\
|
|
|
|
(((unsigned int)(unsigned char)(b3))<<24)|\
|
|
|
|
THREEbt)&\
|
|
|
|
0xffffffffU))
|
2015-08-07 20:29:13 -04:00
|
|
|
#define o4(b0,b1,b2,b3) (PType(((((unsigned char)(b1))<<8)|\
|
2022-07-21 12:23:58 -04:00
|
|
|
(((unsigned char)(b2))<<16)|\
|
|
|
|
(((unsigned int)(unsigned char)(b3))<<24)|\
|
|
|
|
((((unsigned char)(b0))&0x07)<<5)|\
|
|
|
|
FOURbt)&\
|
|
|
|
0xffffffffU))
|
2015-08-07 20:29:13 -04:00
|
|
|
#define g4(b0,b1,b2,b3) (PType(((((unsigned char)(b0))<<8)|\
|
2022-07-21 12:23:58 -04:00
|
|
|
(((unsigned char)(b2))<<16)|\
|
|
|
|
((((unsigned char)(b1))&0x0f)<<24)|\
|
|
|
|
((((unsigned int)(unsigned char)(b3))&0x0f)<<28)|\
|
|
|
|
GB4bt)&\
|
|
|
|
0xffffffffU))
|
2009-12-10 06:59:12 -05:00
|
|
|
#define funsio(diff) (PType((((unsigned int)(diff))<<8)|FUNsio))
|
2007-12-28 04:26:55 -05:00
|
|
|
|
* array.c, bignum.c, dln.c, error.c, gc.c, io.c, marshal.c,
numeric.c, pack.c, strftime.c, string.c, thread.c, transcode.c,
transcode_data.h, util.c, variable.c, vm_dump.c,
include/ruby/encoding.h, missing/crypt.c, missing/vsnprintf.c:
suppress VC type warnings. [ruby-core:22726]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-03-12 05:16:15 -04:00
|
|
|
#define getBT1(a) ((unsigned char)((a)>> 8))
|
|
|
|
#define getBT2(a) ((unsigned char)((a)>>16))
|
|
|
|
#define getBT3(a) ((unsigned char)((a)>>24))
|
|
|
|
#define getBT0(a) (((unsigned char)((a)>> 5)&0x07)|0xF0) /* for UTF-8 only!!! */
|
2007-12-28 04:26:55 -05:00
|
|
|
|
* array.c, bignum.c, dln.c, error.c, gc.c, io.c, marshal.c,
numeric.c, pack.c, strftime.c, string.c, thread.c, transcode.c,
transcode_data.h, util.c, variable.c, vm_dump.c,
include/ruby/encoding.h, missing/crypt.c, missing/vsnprintf.c:
suppress VC type warnings. [ruby-core:22726]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-03-12 05:16:15 -04:00
|
|
|
#define getGB4bt0(a) ((unsigned char)((a)>> 8))
|
2010-06-17 21:44:52 -04:00
|
|
|
#define getGB4bt1(a) (((unsigned char)((a)>>24)&0x0F)|0x30)
|
* array.c, bignum.c, dln.c, error.c, gc.c, io.c, marshal.c,
numeric.c, pack.c, strftime.c, string.c, thread.c, transcode.c,
transcode_data.h, util.c, variable.c, vm_dump.c,
include/ruby/encoding.h, missing/crypt.c, missing/vsnprintf.c:
suppress VC type warnings. [ruby-core:22726]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-03-12 05:16:15 -04:00
|
|
|
#define getGB4bt2(a) ((unsigned char)((a)>>16))
|
2010-06-17 21:44:52 -04:00
|
|
|
#define getGB4bt3(a) (((unsigned char)((a)>>28)&0x0F)|0x30)
|
2009-01-14 06:12:30 -05:00
|
|
|
|
2007-12-28 04:26:55 -05:00
|
|
|
#define o2FUNii(b1,b2) (PType((((unsigned char)(b1))<<8)|(((unsigned char)(b2))<<16)|FUNii))
|
2007-12-10 00:01:47 -05:00
|
|
|
|
|
|
|
/* do we need these??? maybe not, can be done with simple tables */
|
|
|
|
#define ONETRAIL /* legal but undefined if one more trailing UTF-8 */
|
|
|
|
#define TWOTRAIL /* legal but undefined if two more trailing UTF-8 */
|
|
|
|
#define THREETRAIL /* legal but undefined if three more trailing UTF-8 */
|
|
|
|
|
2008-08-15 19:13:01 -04:00
|
|
|
typedef enum {
|
2015-08-07 20:29:13 -04:00
|
|
|
asciicompat_converter, /* ASCII-compatible -> ASCII-compatible */
|
|
|
|
asciicompat_decoder, /* ASCII-incompatible -> ASCII-compatible */
|
|
|
|
asciicompat_encoder /* ASCII-compatible -> ASCII-incompatible */
|
2009-11-03 12:46:28 -05:00
|
|
|
/* ASCII-incompatible -> ASCII-incompatible is intentionally omitted. */
|
2008-09-08 10:33:17 -04:00
|
|
|
} rb_transcoder_asciicompat_type_t;
|
2008-08-15 19:13:01 -04:00
|
|
|
|
2008-08-11 18:00:48 -04:00
|
|
|
typedef struct rb_transcoder rb_transcoder;
|
|
|
|
|
2007-12-24 08:51:19 -05:00
|
|
|
/* static structure, one per supported encoding pair */
|
2008-08-11 18:00:48 -04:00
|
|
|
struct rb_transcoder {
|
2008-09-04 11:46:18 -04:00
|
|
|
const char *src_encoding;
|
|
|
|
const char *dst_encoding;
|
2008-09-02 09:26:02 -04:00
|
|
|
unsigned int conv_tree_start;
|
2008-09-01 13:40:32 -04:00
|
|
|
const unsigned char *byte_array;
|
2008-09-03 07:48:17 -04:00
|
|
|
unsigned int byte_array_length;
|
2008-09-02 09:26:02 -04:00
|
|
|
const unsigned int *word_array;
|
2008-09-03 07:48:17 -04:00
|
|
|
unsigned int word_array_length;
|
2008-09-01 13:40:32 -04:00
|
|
|
int word_size;
|
2008-08-09 02:02:01 -04:00
|
|
|
int input_unit_length;
|
|
|
|
int max_input;
|
2007-12-24 08:51:19 -05:00
|
|
|
int max_output;
|
2008-09-08 10:33:17 -04:00
|
|
|
rb_transcoder_asciicompat_type_t asciicompat_type;
|
2008-09-03 10:12:06 -04:00
|
|
|
size_t state_size;
|
2008-09-03 12:31:14 -04:00
|
|
|
int (*state_init_func)(void*); /* ret==0:success ret!=0:failure(errno) */
|
|
|
|
int (*state_fini_func)(void*); /* ret==0:success ret!=0:failure(errno) */
|
2008-09-03 10:12:06 -04:00
|
|
|
VALUE (*func_ii)(void*, VALUE); /* info -> info */
|
|
|
|
VALUE (*func_si)(void*, const unsigned char*, size_t); /* start -> info */
|
2008-09-14 14:35:17 -04:00
|
|
|
ssize_t (*func_io)(void*, VALUE, const unsigned char*, size_t); /* info -> output */
|
|
|
|
ssize_t (*func_so)(void*, const unsigned char*, size_t, unsigned char*, size_t); /* start -> output */
|
|
|
|
ssize_t (*finish_func)(void*, unsigned char*, size_t); /* -> output */
|
2008-09-14 22:11:50 -04:00
|
|
|
ssize_t (*resetsize_func)(void*); /* -> len */
|
|
|
|
ssize_t (*resetstate_func)(void*, unsigned char*, size_t); /* -> output */
|
2009-12-10 06:59:12 -05:00
|
|
|
ssize_t (*func_sio)(void*, const unsigned char*, size_t, VALUE, unsigned char*, size_t); /* start -> output */
|
2008-08-11 18:00:48 -04:00
|
|
|
};
|
2007-12-25 00:57:04 -05:00
|
|
|
|
|
|
|
void rb_declare_transcoder(const char *enc1, const char *enc2, const char *lib);
|
|
|
|
void rb_register_transcoder(const rb_transcoder *);
|
2007-12-24 08:51:19 -05:00
|
|
|
|
2012-05-16 01:39:06 -04:00
|
|
|
/*
|
|
|
|
* To get rid of collision of initializer symbols in statically-linked encodings
|
|
|
|
* and transcoders
|
|
|
|
*/
|
|
|
|
#if defined(EXTSTATIC) && EXTSTATIC
|
|
|
|
# define TRANS_INIT(name) void Init_trans_ ## name(void)
|
|
|
|
#else
|
|
|
|
# define TRANS_INIT(name) void Init_ ## name(void)
|
|
|
|
#endif
|
|
|
|
|
2013-04-05 06:29:38 -04:00
|
|
|
RUBY_SYMBOL_EXPORT_END
|
2010-07-21 17:38:25 -04:00
|
|
|
|
2007-12-24 08:51:19 -05:00
|
|
|
#endif /* RUBY_TRANSCODE_DATA_H */
|