| 1 |
|
| |
| 2 |
|
| /* $Id: jis.c 5403 2008-02-01 05:06:12Z hio $ */ |
| 3 |
|
| |
| 4 |
|
| #include "Japanese.h" |
| 5 |
|
| #include "sjis.h" |
| 6 |
|
| |
| 7 |
|
| #include <string.h> |
| 8 |
|
| |
| 9 |
|
| #define S2J_DISP 0 |
| 10 |
|
| #define J2S_DISP 0 |
| 11 |
|
| |
| 12 |
|
| #if S2J_DISP |
| 13 |
|
| #define ECHO_S2J(arg) fprintf arg |
| 14 |
|
| #define ON_S2J(cmd) cmd |
| 15 |
|
| #else |
| 16 |
|
| #define ECHO_S2J(arg) |
| 17 |
|
| #define ON_S2J(cmd) |
| 18 |
|
| #endif |
| 19 |
|
| #if J2S_DISP |
| 20 |
|
| #define ECHO_J2S(arg) fprintf arg |
| 21 |
|
| #define ON_J2S(cmd) cmd |
| 22 |
|
| #else |
| 23 |
|
| #define ECHO_J2S(arg) |
| 24 |
|
| #define ON_J2S(cmd) |
| 25 |
|
| #endif |
| 26 |
|
| |
| 27 |
|
| /* |
| 28 |
|
| # JIS C 6226-1979 \e$@ |
| 29 |
|
| # JIS X 0208-1983 \e$B |
| 30 |
|
| # JIS X 0208-1990 \e&@\e$B |
| 31 |
|
| # JIS X 0212-1990 \e$(D |
| 32 |
|
| */ |
| 33 |
|
| |
| 34 |
|
| #define JIS_C6226_1979 ((const unsigned char*)"\x1b$@") |
| 35 |
|
| #define JIS_X0208_1983 ((const unsigned char*)"\x1b$B") |
| 36 |
|
| #define JIS_X0208_1990 ((const unsigned char*)"\x1b&@\x1b$B") |
| 37 |
|
| #define JIS_X0212_1990 ((const unsigned char*)"\x1b$(D") |
| 38 |
|
| |
| 39 |
|
| #define JIS_ASC ((const unsigned char*)"\x1b(B") |
| 40 |
|
| #define JIS_ROMAN ((const unsigned char*)"\x1b(J") |
| 41 |
|
| #define JIS_KANA ((const unsigned char*)"\x1b(I") |
| 42 |
|
| |
| 43 |
|
| #define JIS_C6226_1979_LEN 3 |
| 44 |
|
| #define JIS_X0208_1983_LEN 3 |
| 45 |
|
| #define JIS_X0208_1990_LEN 6 |
| 46 |
|
| #define JIS_X0212_1990_LEN 4 |
| 47 |
|
| |
| 48 |
|
| #define JIS_ASC_LEN 3 |
| 49 |
|
| #define JIS_ROMAN_LEN 3 |
| 50 |
|
| #define JIS_KANA_LEN 3 |
| 51 |
|
| |
| 52 |
|
| /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
| 53 |
|
| /* sjis=>jisÊÑ´¹ */ |
| 54 |
|
| EXTERN_C |
| 55 |
|
| SV* |
| 56 |
64 |
| xs_sjis_jis(SV* sv_str) |
| 57 |
|
| { |
| 58 |
|
| unsigned char* src; |
| 59 |
|
| STRLEN len; |
| 60 |
|
| SV_Buf result; |
| 61 |
|
| int esc_asc; |
| 62 |
|
| const unsigned char* src_end; |
| 63 |
|
| |
| 64 |
64 |
▶ | if( sv_str==&PL_sv_undef ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( sv_str==&PL_sv_undef ) |
0 |
64 |
64 |
|
| 65 |
|
| { |
| 66 |
0 |
| return newSVsv(&PL_sv_undef); |
| 67 |
|
| } |
| 68 |
64 |
▶ | if( SvGMAGICAL(sv_str) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( SvGMAGICAL(sv_str) ) |
0 |
64 |
64 |
|
| 69 |
|
| { |
| 70 |
0 |
| mg_get(sv_str); |
| 71 |
|
| } |
| 72 |
64 |
▶ | if( !SvOK(sv_str) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( !SvOK(sv_str) ) |
0 |
64 |
64 |
|
| 73 |
|
| { |
| 74 |
0 |
| return newSVsv(&PL_sv_undef); |
| 75 |
|
| } |
| 76 |
|
| |
| 77 |
64 |
| src = (unsigned char*)SvPV(sv_str, len); |
| 78 |
|
| ECHO_S2J((stderr,"Unicode::Japanese::(xs)sjis_jis, len:%d\n",len)); |
| 79 |
|
| ON_S2J(bin_dump("in ",src,len)); |
| 80 |
64 |
▶ | SV_Buf_init(&result,len+8); |
Branch: 2 branches
| Branch | True | False | Total |
| SV_Buf_init(&result,len+8); |
64 |
0 |
64 |
| SV_Buf_init(&result,len+8); |
0 |
64 |
64 |
|
| 81 |
64 |
| esc_asc = 1; |
| 82 |
64 |
| src_end = src+len; |
| 83 |
|
| |
| 84 |
129 |
▶ | while( src<src_end ) |
Branch: 1 branch
| Branch | True | False | Total |
| while( src<src_end ) |
65 |
64 |
129 |
|
| 85 |
|
| { |
| 86 |
|
| ECHO_S2J((stderr, "switch: %02x : %d\n", *src, chk_sjis[*src])); |
| 87 |
65 |
| switch(chk_sjis[*src]) |
| 88 |
|
| { |
| 89 |
2 |
| case CHK_SJIS_THROUGH: |
| 90 |
|
| { /* SJIS:THROUGH => JIS:ASCII */ |
| 91 |
|
| const unsigned char* begin; |
| 92 |
2 |
▶ | if( !esc_asc ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( !esc_asc ) |
1 |
1 |
2 |
|
| 93 |
|
| { |
| 94 |
1 |
▶ | SV_Buf_append_mem(&result,JIS_ASC,JIS_ASC_LEN); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_mem(&result,JIS_ASC,JIS_ASC_LEN); |
0 |
1 |
1 |
| SV_Buf_append_mem(&result,JIS_ASC,JIS_ASC_LEN); |
0 |
0 |
0 |
| SV_Buf_append_mem(&result,JIS_ASC,JIS_ASC_LEN); |
0 |
0 |
0 |
|
| 95 |
1 |
| esc_asc = 1; |
| 96 |
|
| } |
| 97 |
|
| #if TEST && S2J_DISP |
| 98 |
|
| fprintf(stderr," (throuh) %c[%02x]",*src,*src); |
| 99 |
|
| fflush(stderr); |
| 100 |
|
| #endif |
| 101 |
2 |
| begin = src; |
| 102 |
11 |
▶ | while( ++src<src_end && chk_sjis[*src]==CHK_SJIS_THROUGH ) |
Branch: 2 branches
| Branch | True | False | Total |
| while( ++src<src_end && chk_sjis[*src]==CHK_SJIS_THROUGH ) |
9 |
2 |
11 |
| while( ++src<src_end && chk_sjis[*src]==CHK_SJIS_THROUGH ) |
9 |
0 |
9 |
|
| 103 |
|
| { |
| 104 |
|
| #if TEST && S2J_DISP |
| 105 |
|
| fprintf(stderr," %c[%02x]",*src,*src); |
| 106 |
|
| fflush(stderr); |
| 107 |
|
| #endif |
| 108 |
|
| } |
| 109 |
|
| #if TEST && S2J_DISP |
| 110 |
|
| fprintf(stderr,"\n"); |
| 111 |
|
| fflush(stderr); |
| 112 |
|
| #endif |
| 113 |
2 |
▶ | SV_Buf_append_mem(&result,begin,src-begin); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_mem(&result,begin,src-begin); |
0 |
2 |
2 |
| SV_Buf_append_mem(&result,begin,src-begin); |
0 |
0 |
0 |
| SV_Buf_append_mem(&result,begin,src-begin); |
0 |
0 |
0 |
|
| 114 |
2 |
| break; |
| 115 |
|
| } |
| 116 |
63 |
| case CHK_SJIS_C: |
| 117 |
|
| { |
| 118 |
63 |
▶ | SV_Buf_append_mem(&result,JIS_X0208_1983,JIS_X0208_1983_LEN); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_mem(&result,JIS_X0208_1983,JIS_X0208_1983_LEN); |
0 |
63 |
63 |
| SV_Buf_append_mem(&result,JIS_X0208_1983,JIS_X0208_1983_LEN); |
0 |
0 |
0 |
| SV_Buf_append_mem(&result,JIS_X0208_1983,JIS_X0208_1983_LEN); |
0 |
0 |
0 |
|
| 119 |
63 |
| esc_asc = 0; |
| 120 |
|
| ECHO_S2J((stderr," (sjis:c)")); |
| 121 |
|
| do |
| 122 |
|
| { |
| 123 |
|
| union { |
| 124 |
|
| UJ_UINT16 u16_val; |
| 125 |
|
| UJ_UINT8 u8_val[2]; |
| 126 |
|
| } tmp; |
| 127 |
|
| ECHO_S2J((stderr, "%c%c[%02x.%02x]",src[0],src[1],src[0],src[1])); |
| 128 |
64 |
▶ | if( src[1]<0x40 || 0xfc<src[1] || src[1]==0x7f ) |
Branch: 3 branches
| Branch | True | False | Total |
| if( src[1]<0x40 || 0xfc<src[1] || src[1]==0x7f ) |
64 |
0 |
64 |
| if( src[1]<0x40 || 0xfc<src[1] || src[1]==0x7f ) |
64 |
0 |
64 |
| if( src[1]<0x40 || 0xfc<src[1] || src[1]==0x7f ) |
0 |
64 |
64 |
|
| 129 |
|
| { |
| 130 |
|
| ECHO_S2J((stderr, "*")); |
| 131 |
0 |
▶ | SV_Buf_append_mem(&result,UNDEF_JIS,UNDEF_JIS_LEN); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_mem(&result,UNDEF_JIS,UNDEF_JIS_LEN); |
0 |
0 |
0 |
| SV_Buf_append_mem(&result,UNDEF_JIS,UNDEF_JIS_LEN); |
0 |
0 |
0 |
| SV_Buf_append_mem(&result,UNDEF_JIS,UNDEF_JIS_LEN); |
0 |
0 |
0 |
|
| 132 |
0 |
| ++src; |
| 133 |
0 |
| break; |
| 134 |
|
| } |
| 135 |
64 |
▶ | if( 0x9f <= src[1] ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( 0x9f <= src[1] ) |
26 |
38 |
64 |
|
| 136 |
|
| { |
| 137 |
26 |
▶ | tmp.u8_val[0] = src[0]*2 - (src[0]>=0xe0 ? 0xe0 : 0x60); |
Branch: 1 branch
| Branch | True | False | Total |
| tmp.u8_val[0] = src[0]*2 - (src[0]>=0xe0 ? 0xe0 : 0x60); |
24 |
2 |
26 |
|
| 138 |
26 |
| tmp.u8_val[1] = src[1] + 2; |
| 139 |
|
| }else |
| 140 |
|
| { |
| 141 |
38 |
▶ | tmp.u8_val[0] = src[0]*2 - (src[0]>=0xe0 ? 0xe1 : 0x61); |
Branch: 1 branch
| Branch | True | False | Total |
| tmp.u8_val[0] = src[0]*2 - (src[0]>=0xe0 ? 0xe1 : 0x61); |
26 |
12 |
38 |
|
| 142 |
38 |
| tmp.u8_val[1] = src[1] + 0x60 + (src[1] < 0x7f); |
| 143 |
|
| } |
| 144 |
64 |
| tmp.u8_val[0] &= 0x7f; |
| 145 |
64 |
| tmp.u8_val[1] &= 0x7f; |
| 146 |
64 |
▶ | SV_Buf_append_ch2(&result, tmp.u16_val); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch2(&result, tmp.u16_val); |
0 |
64 |
64 |
| SV_Buf_append_ch2(&result, tmp.u16_val); |
0 |
0 |
0 |
| SV_Buf_append_ch2(&result, tmp.u16_val); |
0 |
0 |
0 |
|
| 147 |
64 |
| src += 2; |
| 148 |
64 |
▶ | }while( src<src_end && chk_sjis[*src]==CHK_SJIS_C ); |
Branch: 2 branches
| Branch | True | False | Total |
| }while( src<src_end && chk_sjis[*src]==CHK_SJIS_C ); |
2 |
62 |
64 |
| }while( src<src_end && chk_sjis[*src]==CHK_SJIS_C ); |
1 |
1 |
2 |
|
| 149 |
|
| ECHO_S2J((stderr,"\n")); |
| 150 |
63 |
| break; |
| 151 |
|
| } |
| 152 |
0 |
| case CHK_SJIS_KANA: |
| 153 |
|
| { /* SJIS:KANA => JIS:KANA */ |
| 154 |
0 |
▶ | SV_Buf_append_mem(&result,JIS_KANA,JIS_KANA_LEN); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_mem(&result,JIS_KANA,JIS_KANA_LEN); |
0 |
0 |
0 |
| SV_Buf_append_mem(&result,JIS_KANA,JIS_KANA_LEN); |
0 |
0 |
0 |
| SV_Buf_append_mem(&result,JIS_KANA,JIS_KANA_LEN); |
0 |
0 |
0 |
|
| 155 |
0 |
| esc_asc = 0; |
| 156 |
|
| #if TEST && S2J_DISP |
| 157 |
|
| fprintf(stderr," (sjis:kana)"); |
| 158 |
|
| fflush(stderr); |
| 159 |
|
| #endif |
| 160 |
|
| do |
| 161 |
|
| { |
| 162 |
|
| #if TEST && S2J_DISP |
| 163 |
|
| fprintf(stderr," %02x",*src); |
| 164 |
|
| fflush(stderr); |
| 165 |
|
| #endif |
| 166 |
0 |
▶ | SV_Buf_append_ch(&result,*src&0x7f); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch(&result,*src&0x7f); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,*src&0x7f); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,*src&0x7f); |
0 |
0 |
0 |
|
| 167 |
0 |
▶ | }while( ++src<src_end && chk_sjis[*src]==CHK_SJIS_KANA ); |
Branch: 2 branches
| Branch | True | False | Total |
| }while( ++src<src_end && chk_sjis[*src]==CHK_SJIS_KANA ); |
0 |
0 |
0 |
| }while( ++src<src_end && chk_sjis[*src]==CHK_SJIS_KANA ); |
0 |
0 |
0 |
|
| 168 |
|
| #if TEST && S2J_DISP |
| 169 |
|
| fprintf(stderr,"\n"); |
| 170 |
|
| #endif |
| 171 |
0 |
| break; |
| 172 |
|
| } |
| 173 |
0 |
| default: |
| 174 |
|
| { |
| 175 |
|
| #ifdef TEST |
| 176 |
|
| fprintf(stderr,"xs_sjis_eucjp, unknown check-code[%02x] on char-code[%05x]\n",chk_sjis[*src],*src); |
| 177 |
|
| #endif |
| 178 |
0 |
▶ | SV_Buf_append_ch(&result,*src); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch(&result,*src); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,*src); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,*src); |
0 |
0 |
0 |
|
| 179 |
0 |
| ++src; |
| 180 |
|
| } |
| 181 |
|
| } /*switch */ |
| 182 |
|
| } /*while */ |
| 183 |
|
| |
| 184 |
64 |
▶ | if( !esc_asc ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( !esc_asc ) |
62 |
2 |
64 |
|
| 185 |
|
| { |
| 186 |
62 |
▶ | SV_Buf_append_mem(&result,JIS_ASC,JIS_ASC_LEN); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_mem(&result,JIS_ASC,JIS_ASC_LEN); |
0 |
62 |
62 |
| SV_Buf_append_mem(&result,JIS_ASC,JIS_ASC_LEN); |
0 |
0 |
0 |
| SV_Buf_append_mem(&result,JIS_ASC,JIS_ASC_LEN); |
0 |
0 |
0 |
|
| 187 |
|
| } |
| 188 |
|
| /* bin_dump("out",SV_Buf_getBegin(&result),SV_Buf_getLength(&result)); */ |
| 189 |
64 |
| SV_Buf_setLength(&result); |
| 190 |
|
| |
| 191 |
64 |
| return SV_Buf_getSv(&result); |
| 192 |
|
| } |
| 193 |
|
| |
| 194 |
|
| /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
| 195 |
|
| /* jis=>sjisÊÑ´¹ */ |
| 196 |
|
| EXTERN_C |
| 197 |
|
| SV* |
| 198 |
29 |
| xs_jis_sjis(SV* sv_str) |
| 199 |
|
| { |
| 200 |
|
| unsigned char* src; |
| 201 |
|
| STRLEN len; |
| 202 |
|
| SV_Buf result; |
| 203 |
|
| const unsigned char* src_end; |
| 204 |
|
| |
| 205 |
29 |
▶ | if( sv_str==&PL_sv_undef ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( sv_str==&PL_sv_undef ) |
0 |
29 |
29 |
|
| 206 |
|
| { |
| 207 |
0 |
| return newSVsv(&PL_sv_undef); |
| 208 |
|
| } |
| 209 |
29 |
▶ | if( SvGMAGICAL(sv_str) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( SvGMAGICAL(sv_str) ) |
0 |
29 |
29 |
|
| 210 |
|
| { |
| 211 |
0 |
| mg_get(sv_str); |
| 212 |
|
| } |
| 213 |
29 |
▶ | if( !SvOK(sv_str) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( !SvOK(sv_str) ) |
0 |
29 |
29 |
|
| 214 |
|
| { |
| 215 |
0 |
| return newSVsv(&PL_sv_undef); |
| 216 |
|
| } |
| 217 |
|
| |
| 218 |
29 |
| src = (unsigned char*)SvPV(sv_str, len); |
| 219 |
|
| ECHO_J2S((stderr,"Unicode::Japanese::(xs)jis_sjis, len:%d\n",len)); |
| 220 |
|
| ON_J2S(bin_dump("in ",src,len)); |
| 221 |
29 |
▶ | SV_Buf_init(&result,len); |
Branch: 2 branches
| Branch | True | False | Total |
| SV_Buf_init(&result,len); |
29 |
0 |
29 |
| SV_Buf_init(&result,len); |
0 |
29 |
29 |
|
| 222 |
29 |
| src_end = src+len; |
| 223 |
|
| |
| 224 |
29 |
▶ | if( len!=0 && *src!='\x1b' ) |
Branch: 2 branches
| Branch | True | False | Total |
| if( len!=0 && *src!='\x1b' ) |
29 |
0 |
29 |
| if( len!=0 && *src!='\x1b' ) |
0 |
29 |
29 |
|
| 225 |
|
| { |
| 226 |
0 |
| const unsigned char* begin = src; |
| 227 |
0 |
▶ | while( ++src<src_end && *src!='\x1b') |
Branch: 2 branches
| Branch | True | False | Total |
| while( ++src<src_end && *src!='\x1b') |
0 |
0 |
0 |
| while( ++src<src_end && *src!='\x1b') |
0 |
0 |
0 |
|
| 228 |
|
| { |
| 229 |
|
| } |
| 230 |
0 |
▶ | SV_Buf_append_mem(&result,begin,src-begin); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_mem(&result,begin,src-begin); |
0 |
0 |
0 |
| SV_Buf_append_mem(&result,begin,src-begin); |
0 |
0 |
0 |
| SV_Buf_append_mem(&result,begin,src-begin); |
0 |
0 |
0 |
|
| 231 |
|
| } |
| 232 |
87 |
▶ | while( src<src_end ) |
Branch: 1 branch
| Branch | True | False | Total |
| while( src<src_end ) |
58 |
29 |
87 |
|
| 233 |
|
| { |
| 234 |
|
| ECHO_J2S((stderr," len: %d\n",src_end-src)); |
| 235 |
58 |
▶ | if( src_end-src>=JIS_ASC_LEN && memcmp(src,JIS_ASC,JIS_ASC_LEN)==0 ) |
Branch: 2 branches
| Branch | True | False | Total |
| if( src_end-src>=JIS_ASC_LEN && memcmp(src,JIS_ASC,JIS_ASC_LEN)==0 ) |
58 |
0 |
58 |
| if( src_end-src>=JIS_ASC_LEN && memcmp(src,JIS_ASC,JIS_ASC_LEN)==0 ) |
25 |
33 |
58 |
|
| 236 |
25 |
| { /* <<jis.asc>> */ |
| 237 |
|
| const unsigned char* begin; |
| 238 |
|
| /*fprintf(stderr," <jis.asc>\n"); */ |
| 239 |
25 |
| src += JIS_ASC_LEN; |
| 240 |
25 |
| begin = src; |
| 241 |
43 |
▶ | while( src<src_end && *src!='\x1b') |
Branch: 2 branches
| Branch | True | False | Total |
| while( src<src_end && *src!='\x1b') |
19 |
24 |
43 |
| while( src<src_end && *src!='\x1b') |
18 |
1 |
19 |
|
| 242 |
|
| { |
| 243 |
18 |
| ++src; |
| 244 |
|
| } |
| 245 |
25 |
▶ | if( src!=begin ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( src!=begin ) |
5 |
20 |
25 |
|
| 246 |
|
| { |
| 247 |
5 |
▶ | SV_Buf_append_mem(&result,begin,src-begin); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_mem(&result,begin,src-begin); |
0 |
5 |
5 |
| SV_Buf_append_mem(&result,begin,src-begin); |
0 |
0 |
0 |
| SV_Buf_append_mem(&result,begin,src-begin); |
0 |
0 |
0 |
|
| 248 |
|
| } |
| 249 |
33 |
▶ | }else if( src_end-src>=JIS_ROMAN_LEN && memcmp(src,JIS_ROMAN,JIS_ROMAN_LEN)==0 ) |
Branch: 2 branches
| Branch | True | False | Total |
| }else if( src_end-src>=JIS_ROMAN_LEN && memcmp(src,JIS_ROMAN,JIS_ROMAN_LEN)==0 ) |
33 |
0 |
33 |
| }else if( src_end-src>=JIS_ROMAN_LEN && memcmp(src,JIS_ROMAN,JIS_ROMAN_LEN)==0 ) |
1 |
32 |
33 |
|
| 250 |
1 |
| { /* <<jis.roman>> */ |
| 251 |
|
| const unsigned char* begin; |
| 252 |
|
| /*fprintf(stderr," <jis.roman>\n"); */ |
| 253 |
1 |
| src += JIS_ROMAN_LEN; |
| 254 |
1 |
| begin = src; |
| 255 |
7 |
▶ | while( src<src_end && *src!='\x1b') |
Branch: 2 branches
| Branch | True | False | Total |
| while( src<src_end && *src!='\x1b') |
7 |
0 |
7 |
| while( src<src_end && *src!='\x1b') |
6 |
1 |
7 |
|
| 256 |
|
| { |
| 257 |
6 |
| ++src; |
| 258 |
|
| } |
| 259 |
1 |
▶ | if( src!=begin ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( src!=begin ) |
1 |
0 |
1 |
|
| 260 |
|
| { |
| 261 |
1 |
▶ | SV_Buf_append_mem(&result,begin,src-begin); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_mem(&result,begin,src-begin); |
0 |
1 |
1 |
| SV_Buf_append_mem(&result,begin,src-begin); |
0 |
0 |
0 |
| SV_Buf_append_mem(&result,begin,src-begin); |
0 |
0 |
0 |
|
| 262 |
|
| } |
| 263 |
32 |
▶ | }else if( src_end-src>=JIS_KANA_LEN && memcmp(src,JIS_KANA,JIS_KANA_LEN)==0 ) |
Branch: 2 branches
| Branch | True | False | Total |
| }else if( src_end-src>=JIS_KANA_LEN && memcmp(src,JIS_KANA,JIS_KANA_LEN)==0 ) |
32 |
0 |
32 |
| }else if( src_end-src>=JIS_KANA_LEN && memcmp(src,JIS_KANA,JIS_KANA_LEN)==0 ) |
2 |
30 |
32 |
|
| 264 |
|
| { /* <<jis.kana>> */ |
| 265 |
|
| /*fprintf(stderr," <jis.kana>\n"); */ |
| 266 |
2 |
| src += JIS_KANA_LEN; |
| 267 |
14 |
▶ | while( src<src_end && *src!='\x1b') |
Branch: 2 branches
| Branch | True | False | Total |
| while( src<src_end && *src!='\x1b') |
14 |
0 |
14 |
| while( src<src_end && *src!='\x1b') |
12 |
2 |
14 |
|
| 268 |
|
| { |
| 269 |
12 |
▶ | SV_Buf_append_ch(&result,*src|0x80); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch(&result,*src|0x80); |
0 |
12 |
12 |
| SV_Buf_append_ch(&result,*src|0x80); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,*src|0x80); |
0 |
0 |
0 |
|
| 270 |
12 |
| ++src; |
| 271 |
|
| } |
| 272 |
30 |
▶ | }else if( (src_end-src>=JIS_X0208_1983_LEN && memcmp(src,JIS_X0208_1983,JIS_X0208_1983_LEN)==0) |
Branch: 2 branches
| Branch | True | False | Total |
| }else if( (src_end-src>=JIS_X0208_1983_LEN && memcmp(src,JIS_X0208_1983,JIS_X0208_1983_LEN)==0) |
30 |
0 |
30 |
| }else if( (src_end-src>=JIS_X0208_1983_LEN && memcmp(src,JIS_X0208_1983,JIS_X0208_1983_LEN)==0) |
11 |
19 |
30 |
|
| 273 |
11 |
▶ | || (src_end-src>=JIS_X0208_1990_LEN && memcmp(src,JIS_X0208_1990,JIS_X0208_1990_LEN)==0) |
Branch: 2 branches
| Branch | True | False | Total |
| || (src_end-src>=JIS_X0208_1990_LEN && memcmp(src,JIS_X0208_1990,JIS_X0208_1990_LEN)==0) |
3 |
8 |
11 |
| || (src_end-src>=JIS_X0208_1990_LEN && memcmp(src,JIS_X0208_1990,JIS_X0208_1990_LEN)==0) |
2 |
1 |
3 |
|
| 274 |
10 |
▶ | || (src_end-src>=JIS_C6226_1979_LEN && memcmp(src,JIS_C6226_1979,JIS_C6226_1979_LEN)==0) |
Branch: 2 branches
| Branch | True | False | Total |
| || (src_end-src>=JIS_C6226_1979_LEN && memcmp(src,JIS_C6226_1979,JIS_C6226_1979_LEN)==0) |
10 |
0 |
10 |
| || (src_end-src>=JIS_C6226_1979_LEN && memcmp(src,JIS_C6226_1979,JIS_C6226_1979_LEN)==0) |
1 |
9 |
10 |
|
| 275 |
|
| ) |
| 276 |
|
| { /* <<jis.0208/0212>> */ |
| 277 |
|
| ECHO_J2S((stderr," <jis.c>");fflush(stderr)); |
| 278 |
21 |
▶ | src += src[1]!='&' ? 3 : 6; |
Branch: 1 branch
| Branch | True | False | Total |
| src += src[1]!='&' ? 3 : 6; |
20 |
1 |
21 |
|
| 279 |
43 |
▶ | while( src<src_end ) |
Branch: 1 branch
| Branch | True | False | Total |
| while( src<src_end ) |
43 |
0 |
43 |
|
| 280 |
|
| { |
| 281 |
|
| union { |
| 282 |
|
| UJ_UINT16 u16_val; |
| 283 |
|
| UJ_UINT8 u8_val[2]; |
| 284 |
|
| } tmp; |
| 285 |
45 |
▶ | if( *src=='\x1b' ) break; |
Branch: 1 branch
| Branch | True | False | Total |
| if( *src=='\x1b' ) break; |
19 |
24 |
43 |
|
| 286 |
|
| ECHO_J2S((stderr," %02x",src[0]);fflush(stderr)); |
| 287 |
24 |
▶ | if( *src>=0x21 && *src<0x7e ) |
Branch: 2 branches
| Branch | True | False | Total |
| if( *src>=0x21 && *src<0x7e ) |
22 |
2 |
24 |
| if( *src>=0x21 && *src<0x7e ) |
22 |
0 |
22 |
|
| 288 |
|
| {}else |
| 289 |
|
| { |
| 290 |
|
| ECHO_J2S((stderr,"+");fflush(stderr)); |
| 291 |
|
| break; |
| 292 |
|
| } |
| 293 |
22 |
▶ | if( src+1==src_end || src[1]=='\x1b' ) |
Branch: 2 branches
| Branch | True | False | Total |
| if( src+1==src_end || src[1]=='\x1b' ) |
22 |
0 |
22 |
| if( src+1==src_end || src[1]=='\x1b' ) |
22 |
0 |
22 |
|
| 294 |
|
| { |
| 295 |
|
| ECHO_J2S((stderr,"*");fflush(stderr)); |
| 296 |
|
| break; |
| 297 |
|
| } |
| 298 |
|
| ECHO_J2S((stderr," %02x",src[0]);fflush(stderr)); |
| 299 |
22 |
| tmp.u8_val[0] = src[0] | 0x80; |
| 300 |
22 |
| tmp.u8_val[1] = src[1] | 0x80; |
| 301 |
22 |
▶ | if( src[0]%2 ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( src[0]%2 ) |
17 |
5 |
22 |
|
| 302 |
|
| { |
| 303 |
17 |
▶ | tmp.u8_val[0] = (tmp.u8_val[0]>>1) + (tmp.u8_val[0] < 0xdf ? 0x31 : 0x71); |
Branch: 1 branch
| Branch | True | False | Total |
| tmp.u8_val[0] = (tmp.u8_val[0]>>1) + (tmp.u8_val[0] < 0xdf ? 0x31 : 0x71); |
15 |
2 |
17 |
|
| 304 |
17 |
▶ | tmp.u8_val[1] = tmp.u8_val[1] - ( 0x60 + (tmp.u8_val[1] < 0xe0) ); |
Branch: 1 branch
| Branch | True | False | Total |
| tmp.u8_val[1] = tmp.u8_val[1] - ( 0x60 + (tmp.u8_val[1] < 0xe0) ); |
8 |
9 |
17 |
|
| 305 |
|
| }else |
| 306 |
|
| { |
| 307 |
5 |
▶ | tmp.u8_val[0] = (tmp.u8_val[0]>>1) + (tmp.u8_val[0] < 0xdf ? 0x30 : 0x70); |
Branch: 1 branch
| Branch | True | False | Total |
| tmp.u8_val[0] = (tmp.u8_val[0]>>1) + (tmp.u8_val[0] < 0xdf ? 0x30 : 0x70); |
2 |
3 |
5 |
|
| 308 |
5 |
| tmp.u8_val[1] = tmp.u8_val[1] - 2; |
| 309 |
|
| } |
| 310 |
22 |
▶ | SV_Buf_append_ch2(&result, tmp.u16_val); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch2(&result, tmp.u16_val); |
0 |
22 |
22 |
| SV_Buf_append_ch2(&result, tmp.u16_val); |
0 |
0 |
0 |
| SV_Buf_append_ch2(&result, tmp.u16_val); |
0 |
0 |
0 |
|
| 311 |
22 |
| src += 2; |
| 312 |
|
| } |
| 313 |
|
| ECHO_J2S((stderr,"\n")); |
| 314 |
9 |
▶ | }else if( src_end-src>=JIS_X0212_1990_LEN && memcmp(src,JIS_X0212_1990,JIS_X0212_1990_LEN)==0 ) |
Branch: 2 branches
| Branch | True | False | Total |
| }else if( src_end-src>=JIS_X0212_1990_LEN && memcmp(src,JIS_X0212_1990,JIS_X0212_1990_LEN)==0 ) |
6 |
3 |
9 |
| }else if( src_end-src>=JIS_X0212_1990_LEN && memcmp(src,JIS_X0212_1990,JIS_X0212_1990_LEN)==0 ) |
1 |
5 |
6 |
|
| 315 |
1 |
| { /* <<jis.0212>> */ |
| 316 |
|
| const unsigned char* begin; |
| 317 |
|
| int i; |
| 318 |
|
| ECHO_J2S((stderr," <jis.0212>");fflush(stderr)); |
| 319 |
1 |
| src += JIS_X0212_1990_LEN; |
| 320 |
1 |
| begin = src; |
| 321 |
3 |
▶ | while( src<src_end && *src!='\x1b') |
Branch: 2 branches
| Branch | True | False | Total |
| while( src<src_end && *src!='\x1b') |
3 |
0 |
3 |
| while( src<src_end && *src!='\x1b') |
2 |
1 |
3 |
|
| 322 |
|
| { |
| 323 |
2 |
| ++src; |
| 324 |
|
| } |
| 325 |
2 |
▶ | for( i=0; i<(src-begin)/2; ++i ) |
Branch: 1 branch
| Branch | True | False | Total |
| for( i=0; i<(src-begin)/2; ++i ) |
1 |
1 |
2 |
|
| 326 |
|
| { |
| 327 |
1 |
▶ | SV_Buf_append_mem(&result,UNDEF_SJIS,UNDEF_SJIS_LEN); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_mem(&result,UNDEF_SJIS,UNDEF_SJIS_LEN); |
0 |
1 |
1 |
| SV_Buf_append_mem(&result,UNDEF_SJIS,UNDEF_SJIS_LEN); |
0 |
0 |
0 |
| SV_Buf_append_mem(&result,UNDEF_SJIS,UNDEF_SJIS_LEN); |
0 |
0 |
0 |
|
| 328 |
|
| } |
| 329 |
8 |
▶ | }else if( src[0]!='\x1b') /* !='\e' */ |
Branch: 1 branch
| Branch | True | False | Total |
| }else if( src[0]!='\x1b') /* !='\e' */ |
5 |
3 |
8 |
|
| 330 |
|
| { /* <<no escape>> */ |
| 331 |
|
| const unsigned char* begin; |
| 332 |
|
| ECHO_J2S((stderr," <no.escape>");fflush(stderr)); |
| 333 |
5 |
| begin = src; |
| 334 |
22 |
▶ | while( src<src_end && *src!='\x1b') |
Branch: 2 branches
| Branch | True | False | Total |
| while( src<src_end && *src!='\x1b') |
17 |
5 |
22 |
| while( src<src_end && *src!='\x1b') |
17 |
0 |
17 |
|
| 335 |
|
| { |
| 336 |
17 |
| ++src; |
| 337 |
|
| } |
| 338 |
5 |
▶ | if( src!=begin ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( src!=begin ) |
5 |
0 |
5 |
|
| 339 |
|
| { |
| 340 |
8 |
▶ | SV_Buf_append_mem(&result,begin,src-begin); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_mem(&result,begin,src-begin); |
3 |
2 |
5 |
| SV_Buf_append_mem(&result,begin,src-begin); |
3 |
0 |
3 |
| SV_Buf_append_mem(&result,begin,src-begin); |
0 |
3 |
3 |
|
| 341 |
|
| } |
| 342 |
|
| }else |
| 343 |
|
| { /* <<unknown escape>> */ |
| 344 |
|
| ECHO_J2S((stderr," <escape.unknown>");fflush(stderr)); |
| 345 |
3 |
▶ | SV_Buf_append_ch(&result,*src); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch(&result,*src); |
0 |
3 |
3 |
| SV_Buf_append_ch(&result,*src); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,*src); |
0 |
0 |
0 |
|
| 346 |
3 |
| ++src; |
| 347 |
|
| } |
| 348 |
|
| } /*while */ |
| 349 |
|
| |
| 350 |
|
| ON_J2S(bin_dump("out",SV_Buf_getBegin(&result), SV_Buf_getLength(&result))); |
| 351 |
29 |
| SV_Buf_setLength(&result); |
| 352 |
|
| |
| 353 |
29 |
| return SV_Buf_getSv(&result); |
| 354 |
|
| } |