Ruby 1.9.2p136(2010-12-25revision30365)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

# transcode_data.h

Go to the documentation of this file.

    00001 /**********************************************************************
    00002
    00003   transcode_data.h -
    00004
    00005   $Author: duerst $
    00006   created at: Mon 10 Dec 2007 14:01:47 JST 2007
    00007
    00008   Copyright (C) 2007 Martin Duerst
    00009
    00010 **********************************************************************/
    00011
    00012 #include "ruby/ruby.h"
    00013
    00014 #ifndef RUBY_TRANSCODE_DATA_H
    00015 #define RUBY_TRANSCODE_DATA_H 1
    00016
    00017 #define WORDINDEX_SHIFT_BITS 2
    00018 #define WORDINDEX2INFO(widx)      ((widx) << WORDINDEX_SHIFT_BITS)
    00019 #define INFO2WORDINDEX(info)      ((info) >> WORDINDEX_SHIFT_BITS)
    00020 #define BYTE_LOOKUP_BASE(bl) ((bl)[0])
    00021 #define BYTE_LOOKUP_INFO(bl) ((bl)[1])
    00022
    00023 #define PType (unsigned int)
    00024
    00025 #define NOMAP   (PType 0x01)    /* direct map */
    00026 #define ONEbt   (0x02)          /* one byte payload */
    00027 #define TWObt   (0x03)          /* two bytes payload */
    00028 #define THREEbt (0x05)          /* three bytes payload */
    00029 #define FOURbt  (0x06)          /* four bytes payload, UTF-8 only, macros start at getBT0 */
    00030 #define INVALID (PType 0x07)    /* invalid byte sequence */
    00031 #define UNDEF   (PType 0x09)    /* legal but undefined */
    00032 #define ZERObt  (PType 0x0A)    /* zero bytes of payload, i.e. remove */
    00033 #define FUNii   (PType 0x0B)    /* function from info to info */
    00034 #define FUNsi   (PType 0x0D)    /* function from start to info */
    00035 #define FUNio   (PType 0x0E)    /* function from info to output */
    00036 #define FUNso   (PType 0x0F)    /* function from start to output */
    00037 #define STR1    (PType 0x11)    /* string 4 <= len <= 259 bytes: 1byte length + content */
    00038 #define GB4bt   (PType 0x12)    /* GB18030 four bytes payload */
    00039 #define FUNsio  (PType 0x13)    /* function from start and info to output */
    00040
    00041 #define STR1_LENGTH(byte_addr) (unsigned int)(*(byte_addr) + 4)
    00042 #define STR1_BYTEINDEX(w) ((w) >> 6)
    00043 #define makeSTR1(bi) (((bi) << 6) | STR1)
    00044 #define makeSTR1LEN(len) ((len)-4)
    00045
    00046 #define o1(b1)          (PType((((unsigned char)(b1))<<8)|ONEbt))
    00047 #define o2(b1,b2)       (PType((((unsigned char)(b1))<<8)|(((unsigned char)(b2))<<16)|TWObt))
    00048 #define o3(b1,b2,b3)    (PType(((((unsigned char)(b1))<<8)|(((unsigned char)(b2))<<16)|(((unsigned int)(unsigned char)(b3))<<24)|THREEbt)&0xffffffffU))
    00049 #define o4(b0,b1,b2,b3) (PType(((((unsigned char)(b1))<<8)|(((unsigned char)(b2))<<16)|(((unsigned char)(b3))<<24)|((((unsigned char)(b0))&0x07)<<5)|FOURbt)&0xffffffffU))
    00050 #define g4(b0,b1,b2,b3) (PType(((((unsigned char)(b0))<<8)|(((unsigned char)(b2))<<16)|((((unsigned char)(b1))&0x0f)<<24)|((((unsigned int)(unsigned char)(b3))&0x0f)<<28)|GB4bt)&0xffffffffU))
    00051 #define funsio(diff)    (PType((((unsigned int)(diff))<<8)|FUNsio))
    00052
    00053 #define getBT1(a)       ((unsigned char)((a)>> 8))
    00054 #define getBT2(a)       ((unsigned char)((a)>>16))
    00055 #define getBT3(a)       ((unsigned char)((a)>>24))
    00056 #define getBT0(a)       (((unsigned char)((a)>> 5)&0x07)|0xF0)   /* for UTF-8 only!!! */
    00057
    00058 #define getGB4bt0(a)    ((unsigned char)((a)>> 8))
    00059 #define getGB4bt1(a)    ((unsigned char)((a)>>24)&0x0F|0x30)
    00060 #define getGB4bt2(a)    ((unsigned char)((a)>>16))
    00061 #define getGB4bt3(a)    ((unsigned char)((a)>>28)&0x0F|0x30)
    00062
    00063 #define o2FUNii(b1,b2)  (PType((((unsigned char)(b1))<<8)|(((unsigned char)(b2))<<16)|FUNii))
    00064
    00065 /* do we need these??? maybe not, can be done with simple tables */
    00066 #define ONETRAIL       /* legal but undefined if one more trailing UTF-8 */
    00067 #define TWOTRAIL       /* legal but undefined if two more trailing UTF-8 */
    00068 #define THREETRAIL     /* legal but undefined if three more trailing UTF-8 */
    00069
    00070 typedef enum {
    00071   asciicompat_converter,        /* ASCII-compatible -> ASCII-compatible */
    00072   asciicompat_decoder,          /* ASCII-incompatible -> ASCII-compatible */
    00073   asciicompat_encoder           /* ASCII-compatible -> ASCII-incompatible */
    00074   /* ASCII-incompatible -> ASCII-incompatible is intentionally omitted. */
    00075 } rb_transcoder_asciicompat_type_t;
    00076
    00077 typedef struct rb_transcoder rb_transcoder;
    00078
    00079 /* static structure, one per supported encoding pair */
    00080 struct rb_transcoder {
    00081     const char *src_encoding;
    00082     const char *dst_encoding;
    00083     unsigned int conv_tree_start;
    00084     const unsigned char *byte_array;
    00085     unsigned int byte_array_length;
    00086     const unsigned int *word_array;
    00087     unsigned int word_array_length;
    00088     int word_size;
    00089     int input_unit_length;
    00090     int max_input;
    00091     int max_output;
    00092     rb_transcoder_asciicompat_type_t asciicompat_type;
    00093     size_t state_size;
    00094     int (*state_init_func)(void*); /* ret==0:success ret!=0:failure(errno) */
    00095     int (*state_fini_func)(void*); /* ret==0:success ret!=0:failure(errno) */
    00096     VALUE (*func_ii)(void*, VALUE); /* info  -> info   */
    00097     VALUE (*func_si)(void*, const unsigned char*, size_t); /* start -> info   */
    00098     ssize_t (*func_io)(void*, VALUE, const unsigned char*, size_t); /* info  -> output */
    00099     ssize_t (*func_so)(void*, const unsigned char*, size_t, unsigned char*, size_t); /* start -> output */
    00100     ssize_t (*finish_func)(void*, unsigned char*, size_t); /* -> output */
    00101     ssize_t (*resetsize_func)(void*); /* -> len */
    00102     ssize_t (*resetstate_func)(void*, unsigned char*, size_t); /* -> output */
    00103     ssize_t (*func_sio)(void*, const unsigned char*, size_t, VALUE, unsigned char*, size_t); /* start -> output */
    00104 };
    00105
    00106 void rb_declare_transcoder(const char *enc1, const char *enc2, const char *lib);
    00107 void rb_register_transcoder(const rb_transcoder *);
    00108
    00109 #endif /* RUBY_TRANSCODE_DATA_H */
    00110