1 /* -*- c-basic-offset:2; tab-width:2; indent-tabs-mode:nil -*- */
2
3 #include <string.h> /* memcpy */
4
5 #include "ef_ja_jp_map.h"
6
7 #include "ef_ucs4_map.h"
8 #include "ef_ucs4_jisx0201.h"
9 #include "ef_ucs4_jisx0208.h"
10 #include "ef_ucs4_jisx0212.h"
11 #include "ef_ucs4_jisx0213.h"
12
13 /* --- static variables --- */
14
15 static ef_map_ucs4_to_func_t map_ucs4_to_funcs[] = {
16 ef_map_ucs4_to_jisx0201_roman, ef_map_ucs4_to_jisx0201_kata,
17 ef_map_ucs4_to_jisx0208_1983, ef_map_ucs4_to_jisx0212_1990,
18 ef_map_ucs4_to_jisx0213_2000_1, ef_map_ucs4_to_jisx0213_2000_2,
19
20 };
21
22 /* --- global functions --- */
23
ef_map_ucs4_to_ja_jp(ef_char_t * jajp,ef_char_t * ucs4)24 int ef_map_ucs4_to_ja_jp(ef_char_t *jajp, ef_char_t *ucs4) {
25 return ef_map_ucs4_to_with_funcs(jajp, ucs4, map_ucs4_to_funcs,
26 sizeof(map_ucs4_to_funcs) / sizeof(map_ucs4_to_funcs[0]));
27 }
28
ef_map_jisx0213_2000_1_to_jisx0208_1983(ef_char_t * jis2k,ef_char_t * jis83)29 int ef_map_jisx0213_2000_1_to_jisx0208_1983(ef_char_t *jis2k, ef_char_t *jis83) {
30 memcpy(jis2k->ch, jis83->ch, 2);
31 jis2k->size = 2;
32 jis2k->cs = JISX0213_2000_1;
33 jis2k->property = jis83->property;
34
35 return 1;
36 }
37
ef_map_jisx0208_1983_to_jisx0213_2000_1(ef_char_t * jis83,ef_char_t * jis2k)38 int ef_map_jisx0208_1983_to_jisx0213_2000_1(ef_char_t *jis83, ef_char_t *jis2k) {
39 /*
40 * XXX
41 * since JISX0213-1 is upper compatible with JISX0208 , some chars of
42 * JISX0213-1
43 * must not be mapped to JISX0208.
44 */
45 memcpy(jis83->ch, jis2k->ch, 2);
46 jis83->size = 2;
47 jis83->cs = JISX0213_2000_1;
48 jis83->property = jis2k->property;
49
50 return 1;
51 }
52
ef_map_jisx0213_2000_2_to_jisx0212_1990(ef_char_t * jis90,ef_char_t * jis2k)53 int ef_map_jisx0213_2000_2_to_jisx0212_1990(ef_char_t *jis90, ef_char_t *jis2k) {
54 return ef_map_via_ucs(jis2k, jis90, JISX0213_2000_2);
55 }
56
ef_map_jisx0212_1990_to_jisx0213_2000_2(ef_char_t * jis2k,ef_char_t * jis90)57 int ef_map_jisx0212_1990_to_jisx0213_2000_2(ef_char_t *jis2k, ef_char_t *jis90) {
58 return ef_map_via_ucs(jis90, jis2k, JISX0212_1990);
59 }
60
61 /*
62 * Gaiji characters
63 */
64
65 /* SJIS_IBM_EXT */
66
ef_map_sjis_ibm_ext_to_jisx0208_1983(ef_char_t * jis,ef_char_t * ibm)67 int ef_map_sjis_ibm_ext_to_jisx0208_1983(ef_char_t *jis, ef_char_t *ibm) {
68 return ef_map_via_ucs(jis, ibm, JISX0208_1983);
69 }
70
ef_map_sjis_ibm_ext_to_jisx0212_1990(ef_char_t * jis,ef_char_t * ibm)71 int ef_map_sjis_ibm_ext_to_jisx0212_1990(ef_char_t *jis, ef_char_t *ibm) {
72 return ef_map_via_ucs(jis, ibm, JISX0212_1990);
73 }
74
ef_map_sjis_ibm_ext_to_jisx0213_2000(ef_char_t * jis,ef_char_t * ibm)75 int ef_map_sjis_ibm_ext_to_jisx0213_2000(ef_char_t *jis, ef_char_t *ibm) {
76 ef_char_t ucs4;
77
78 if (!ef_map_to_ucs4(&ucs4, ibm)) {
79 return 0;
80 }
81
82 if (!ef_map_ucs4_to_cs(jis, &ucs4, JISX0213_2000_2) &&
83 !ef_map_ucs4_to_cs(jis, &ucs4, JISX0213_2000_1)) {
84 return 0;
85 }
86
87 return 1;
88 }
89
ef_map_jisx0212_1990_to_sjis_ibm_ext(ef_char_t * ibm,ef_char_t * jis)90 int ef_map_jisx0212_1990_to_sjis_ibm_ext(ef_char_t *ibm, ef_char_t *jis) {
91 return ef_map_via_ucs(ibm, jis, SJIS_IBM_EXT);
92 }
93
ef_map_jisx0213_2000_2_to_sjis_ibm_ext(ef_char_t * ibm,ef_char_t * jis)94 int ef_map_jisx0213_2000_2_to_sjis_ibm_ext(ef_char_t *ibm, ef_char_t *jis) {
95 return ef_map_via_ucs(ibm, jis, SJIS_IBM_EXT);
96 }
97
98 /* NEC EXT */
99
ef_map_jisx0208_nec_ext_to_jisx0208_1983(ef_char_t * jis,ef_char_t * nec_ext)100 int ef_map_jisx0208_nec_ext_to_jisx0208_1983(ef_char_t *jis, ef_char_t *nec_ext) {
101 return ef_map_via_ucs(jis, nec_ext, JISX0208_1983);
102 }
103
ef_map_jisx0208_nec_ext_to_jisx0212_1990(ef_char_t * jis,ef_char_t * nec_ext)104 int ef_map_jisx0208_nec_ext_to_jisx0212_1990(ef_char_t *jis, ef_char_t *nec_ext) {
105 return ef_map_via_ucs(jis, nec_ext, JISX0212_1990);
106 }
107
ef_map_jisx0208_nec_ext_to_jisx0213_2000(ef_char_t * jis,ef_char_t * nec_ext)108 int ef_map_jisx0208_nec_ext_to_jisx0213_2000(ef_char_t *jis, ef_char_t *nec_ext) {
109 ef_char_t ucs4;
110
111 if (!ef_map_to_ucs4(&ucs4, nec_ext)) {
112 return 0;
113 }
114
115 if (!ef_map_ucs4_to_cs(jis, &ucs4, JISX0213_2000_2) &&
116 !ef_map_ucs4_to_cs(jis, &ucs4, JISX0213_2000_1)) {
117 return 0;
118 }
119
120 return 1;
121 }
122
ef_map_jisx0212_1990_to_jisx0208_nec_ext(ef_char_t * nec_ext,ef_char_t * jis)123 int ef_map_jisx0212_1990_to_jisx0208_nec_ext(ef_char_t *nec_ext, ef_char_t *jis) {
124 return ef_map_via_ucs(nec_ext, jis, JISC6226_1978_NEC_EXT);
125 }
126
ef_map_jisx0213_2000_2_to_jisx0208_nec_ext(ef_char_t * nec_ext,ef_char_t * jis)127 int ef_map_jisx0213_2000_2_to_jisx0208_nec_ext(ef_char_t *nec_ext, ef_char_t *jis) {
128 return ef_map_via_ucs(nec_ext, jis, JISC6226_1978_NEC_EXT);
129 }
130
131 /* NEC IBM EXT */
132
ef_map_jisx0208_necibm_ext_to_jisx0208_1983(ef_char_t * jis,ef_char_t * necibm)133 int ef_map_jisx0208_necibm_ext_to_jisx0208_1983(ef_char_t *jis, ef_char_t *necibm) {
134 return ef_map_via_ucs(jis, necibm, JISX0208_1983);
135 }
136
ef_map_jisx0208_necibm_ext_to_jisx0212_1990(ef_char_t * jis,ef_char_t * necibm)137 int ef_map_jisx0208_necibm_ext_to_jisx0212_1990(ef_char_t *jis, ef_char_t *necibm) {
138 return ef_map_via_ucs(jis, necibm, JISX0212_1990);
139 }
140
ef_map_jisx0208_necibm_ext_to_jisx0213_2000(ef_char_t * jis,ef_char_t * necibm)141 int ef_map_jisx0208_necibm_ext_to_jisx0213_2000(ef_char_t *jis, ef_char_t *necibm) {
142 ef_char_t ucs4;
143
144 if (!ef_map_to_ucs4(&ucs4, necibm)) {
145 return 0;
146 }
147
148 if (!ef_map_ucs4_to_cs(jis, &ucs4, JISX0213_2000_2) &&
149 !ef_map_ucs4_to_cs(jis, &ucs4, JISX0213_2000_1)) {
150 return 0;
151 }
152
153 return 1;
154 }
155
ef_map_jisx0212_1990_to_jisx0208_necibm_ext(ef_char_t * necibm,ef_char_t * jis)156 int ef_map_jisx0212_1990_to_jisx0208_necibm_ext(ef_char_t *necibm, ef_char_t *jis) {
157 return ef_map_via_ucs(necibm, jis, JISC6226_1978_NECIBM_EXT);
158 }
159
ef_map_jisx0213_2000_2_to_jisx0208_necibm_ext(ef_char_t * necibm,ef_char_t * jis)160 int ef_map_jisx0213_2000_2_to_jisx0208_necibm_ext(ef_char_t *necibm, ef_char_t *jis) {
161 return ef_map_via_ucs(necibm, jis, JISC6226_1978_NECIBM_EXT);
162 }
163
164 /* MAC EXT */
165
ef_map_jisx0208_mac_ext_to_jisx0208_1983(ef_char_t * jis,ef_char_t * mac)166 int ef_map_jisx0208_mac_ext_to_jisx0208_1983(ef_char_t *jis, ef_char_t *mac) {
167 return ef_map_via_ucs(jis, mac, JISX0208_1983);
168 }
169
ef_map_jisx0208_mac_ext_to_jisx0212_1990(ef_char_t * jis,ef_char_t * mac)170 int ef_map_jisx0208_mac_ext_to_jisx0212_1990(ef_char_t *jis, ef_char_t *mac) {
171 return ef_map_via_ucs(jis, mac, JISX0212_1990);
172 }
173
ef_map_jisx0208_mac_ext_to_jisx0213_2000(ef_char_t * jis,ef_char_t * mac)174 int ef_map_jisx0208_mac_ext_to_jisx0213_2000(ef_char_t *jis, ef_char_t *mac) {
175 ef_char_t ucs4;
176
177 if (!ef_map_to_ucs4(&ucs4, mac)) {
178 return 0;
179 }
180
181 if (!ef_map_ucs4_to_cs(jis, &ucs4, JISX0213_2000_2) &&
182 !ef_map_ucs4_to_cs(jis, &ucs4, JISX0213_2000_1)) {
183 return 0;
184 }
185
186 return 1;
187 }
188
ef_map_jisx0212_1990_to_jisx0208_mac_ext(ef_char_t * mac,ef_char_t * jis)189 int ef_map_jisx0212_1990_to_jisx0208_mac_ext(ef_char_t *mac, ef_char_t *jis) {
190 return ef_map_via_ucs(mac, jis, JISX0208_1983_MAC_EXT);
191 }
192
ef_map_jisx0213_2000_2_to_jisx0208_mac_ext(ef_char_t * mac,ef_char_t * jis)193 int ef_map_jisx0213_2000_2_to_jisx0208_mac_ext(ef_char_t *mac, ef_char_t *jis) {
194 return ef_map_via_ucs(mac, jis, JISX0208_1983_MAC_EXT);
195 }
196