2 Unix SMB/Netbios implementation.
5 Copyright (C) Andrew Tridgell 1992-1998
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 Adding for Japanese language by <fujita@ainix.isac.co.jp> 1994.9.5
22 and extend coding system to EUC/SJIS/JIS/HEX at 1994.10.11
23 and add all jis codes sequence at 1995.8.16
24 Notes: Hexadecimal code by <ohki@gssm.otuka.tsukuba.ac.jp>
25 and add upper/lower case conversion 1997.8.21
30 /* FOR SHIFT JIS CODE */
31 #define is_shift_jis(c) \
32 ((0x81 <= ((unsigned char) (c)) && ((unsigned char) (c)) <= 0x9f) \
33 || (0xe0 <= ((unsigned char) (c)) && ((unsigned char) (c)) <= 0xfc))
34 #define is_shift_jis2(c) \
35 (0x40 <= ((unsigned char) (c)) && ((unsigned char) (c)) <= 0xfc \
36 && ((unsigned char) (c)) != 0x7f)
37 #define is_kana(c) ((0xa0 <= ((unsigned char) (c)) && ((unsigned char) (c)) <= 0xdf))
40 #define is_sj_upper2(c) \
41 ((0x60 <= (unsigned char) (c)) && ((unsigned char) (c) <= 0x79))
42 #define is_sj_lower2(c) \
43 ((0x81 <= (unsigned char) (c)) && ((unsigned char) (c) <= 0x9A))
44 #define sjis_alph 0x82
45 #define is_sj_alph(c) (sjis_alph == (unsigned char) (c))
46 #define is_sj_upper(c1, c2) (is_sj_alph (c1) && is_sj_upper2 (c2))
47 #define is_sj_lower(c1, c2) (is_sj_alph (c1) && is_sj_lower2 (c2))
48 #define sj_toupper2(c) \
49 (is_sj_lower2 (c) ? ((int) ((unsigned char) (c) - 0x81 + 0x60)) : \
50 ((int) (unsigned char) (c)))
51 #define sj_tolower2(c) \
52 (is_sj_upper2 (c) ? ((int) ((unsigned char) (c) - 0x60 + 0x81)) : \
53 ((int) (unsigned char) (c)))
55 #define is_sj_ru_upper2(c) \
56 ((0x40 <= (unsigned char) (c)) && ((unsigned char) (c) <= 0x60))
57 #define is_sj_ru_lower2(c) \
58 (((0x70 <= (unsigned char) (c)) && ((unsigned char) (c) <= 0x7e)) || \
59 ((0x80 <= (unsigned char) (c)) && ((unsigned char) (c) <= 0x91)))
60 #define sjis_russian 0x84
61 #define is_sj_russian(c) (sjis_russian == (unsigned char) (c))
62 #define is_sj_ru_upper(c1, c2) (is_sj_russian (c1) && is_sj_ru_upper2 (c2))
63 #define is_sj_ru_lower(c1, c2) (is_sj_russian (c1) && is_sj_ru_lower2 (c2))
64 #define sj_ru_toupper2(c) \
65 (is_sj_ru_lower2 (c) ? ((int) ((unsigned char) (c) + \
66 (((unsigned char)(c) >= 0x4f) ? (0x70 - 0x40) : (0x80 - 0x4f)))) : \
67 ((int) (unsigned char) (c)))
68 #define sj_ru_tolower2(c) \
69 (is_sj_ru_upper2 (c) ? ((int) ((unsigned char) (c) - \
70 (((unsigned char)(c) >= 0x80) ? (0x70 - 0x40) : (0x80 - 0x4f)))) : \
71 ((int) (unsigned char) (c)))
75 #define euc_kana (0x8e)
76 #define is_euc_kana(c) (((unsigned char) (c)) == euc_kana)
77 #define is_euc(c) (0xa0 < ((unsigned char) (c)) && ((unsigned char) (c)) < 0xff)
79 #define euc_sup (0x8f)
80 #define is_euc_sup(c) (((unsigned char ) (c)) == euc_sup)
83 /* default jis third shift code, use for output */
90 /* in: \E$B or \E$@ */
91 /* out: \E(J or \E(B or \E(H */
92 #define jis_esc (0x1b)
99 #define is_esc(c) (((unsigned char) (c)) == jis_esc)
100 #define is_so1(c) (((unsigned char) (c)) == jis_so1)
101 #define is_so2(c) (((unsigned char) (c)) == jis_so2 || ((unsigned char) (c)) == '@')
102 #define is_si1(c) (((unsigned char) (c)) == jis_si1)
103 #define is_si2(c) (((unsigned char) (c)) == jis_si2 || ((unsigned char) (c)) == 'B' \
104 || ((unsigned char) (c)) == 'H')
105 #define is_so(c) (((unsigned char) (c)) == jis_so)
106 #define is_si(c) (((unsigned char) (c)) == jis_si)
107 #define junet_kana1 ('(')
108 #define junet_kana2 ('I')
109 #define is_juk1(c) (((unsigned char) (c)) == junet_kana1)
110 #define is_juk2(c) (((unsigned char) (c)) == junet_kana2)
112 #define _KJ_ROMAN (0)
113 #define _KJ_KANJI (1)
119 ( ((int) '0' <= ((int) (x)) && ((int) (x)) <= (int)'9')? \
120 (((int) (x))-(int)'0'): \
121 ((int) 'a'<= ((int) (x)) && ((int) (x))<= (int) 'f')? \
122 (((int) (x)) - (int)'a'+10): \
123 (((int) (x)) - (int)'A'+10) )
125 ( (((int) (x)) >= 10)? (((int) (x))-10 + (int) 'a'): (((int) (x)) + (int) '0') )
127 /* For Hangul (Korean - code page 949). */
128 #define is_hangul(c) ((0x81 <= ((unsigned char) (c)) && ((unsigned char) (c)) <= 0xfd))
130 /* For traditional Chinese (known as Big5 encoding - code page 950). */
131 #define is_big5_c1(c) ((0xa1 <= ((unsigned char) (c)) && ((unsigned char) (c)) <= 0xf9))
133 /* For simplified Chinese (code page - 936). */
134 #define is_simpch_c1(c) ((0xa1 <= ((unsigned char) (c)) && ((unsigned char) (c)) <= 0xf7))
136 #else /* not _KANJI_C_ */
139 * The following is needed for AIX systems that have
140 * their own #defines for strchr, strrchr, strstr
160 /* Ensure we use our definitions in all other files than kanji.c. */
162 /* Function pointers we will replace. */
163 extern char *(*multibyte_strchr)(const char *s, int c);
164 extern char *(*multibyte_strrchr)(const char *s, int c);
165 extern char *(*multibyte_strstr)(const char *s1, const char *s2);
166 extern char *(*multibyte_strtok)(char *s1, const char *s2);
167 extern char *(*_dos_to_unix)(char *str, BOOL overwrite);
168 extern char *(*_unix_to_dos)(char *str, BOOL overwrite);
169 extern char *(*_dos_to_dos)(char *str, BOOL overwrite);
170 extern BOOL (*is_multibyte_char)(char c);
171 extern int (*_skip_multibyte_char)(char c);
173 #define strchr(s1, c) ((*multibyte_strchr)((s1), (c)))
174 #define strrchr(s1, c) ((*multibyte_strrchr)((s1), (c)))
175 #define strstr(s1, s2) ((*multibyte_strstr)((s1), (s2)))
176 #define strtok(s1, s2) ((*multibyte_strtok)((s1), (s2)))
177 #define dos_to_unix(x,y) ((*_dos_to_unix)((x), (y)))
178 #define unix_to_dos(x,y) ((*_unix_to_dos)((x), (y)))
179 #define dos_to_dos(x,y) ((*_dos_to_dos)((x), (y)))
180 #define skip_multibyte_char(c) ((*_skip_multibyte_char)((c)))
182 #endif /* _KANJI_C_ */
184 #define UNKNOWN_CODE (-1)
185 #define SJIS_CODE (0)
187 #define JIS7_CODE (2)
188 #define JIS8_CODE (3)
189 #define JUNET_CODE (4)
192 #define DOSV_CODE SJIS_CODE
193 #define EUC3_CODE (7)
194 #define UTF8_CODE (8)
200 #define EXTSJISC(c) (0xf0 <= ((unsigned char)(c)) \
201 && ((unsigned char)(c) <= 0xfc))
202 #define GETAHI (0x81)
203 #define GETALO (0xac)
205 typedef struct _sjis_regur_t {
211 /* When Converting to EUC and JIS, there is no room for
212 * these SJIS codes whose hi byte is larger than 0xf0.
214 * So we must drop or convert it to harmless code.
215 * This is not standard way, so it is ad hoc but practical.
216 * It is also thought of backward and future compatibility.
221 static sjis_regur_t sjisconv[] = {
222 {0xfa40, 0xfa49, 0xeeef},
223 {0xfa4a, 0xfa53, 0x8754},
224 {0xfa54, 0xfa54, 0x81ca},
225 {0xfa55, 0xfa57, 0xeefa},
226 {0xfa58, 0xfa58, 0x878a},
227 {0xfa59, 0xfa59, 0x8782},
228 {0xfa5a, 0xfa5a, 0x8784},
229 {0xfa5b, 0xfa5b, 0x81e6},
230 {0xfa5c, 0xfa7e, 0xed40},
231 {0xfa80, 0xfa9b, 0xed63},
232 {0xfa9c, 0xfafc, 0xed80},
233 {0xfb40, 0xfb5b, 0xede1},
234 {0xfb5c, 0xfb7e, 0xee40},
235 {0xfb80, 0xfb9b, 0xee63},
236 {0xfb9c, 0xfbfc, 0xee80},
237 {0xfc40, 0xfc4b, 0xeee1}
239 #define SJISCONVTBLSIZ (sizeof(sjisconv) / sizeof(sjis_regur_t))
241 static sjis_regur_t sjisrev[] = {
242 {0x81ca, 0x81ca, 0xfa54},
243 {0x81e6, 0x81e6, 0xfa5b},
244 {0x8754, 0x875d, 0xfa4a},
245 {0x8782, 0x8782, 0xfa59},
246 {0x8784, 0x8784, 0xfa5a},
247 {0x878a, 0x878a, 0xfa58},
248 {0xed40, 0xed62, 0xfa5c},
249 {0xed63, 0xed7e, 0xfa80},
250 {0xed80, 0xede0, 0xfa9c},
251 {0xede1, 0xedfc, 0xfb40},
252 {0xee40, 0xee62, 0xfb5c},
253 {0xee63, 0xee7e, 0xfb80},
254 {0xee80, 0xeee0, 0xfb9c},
255 {0xeee1, 0xeeec, 0xfc40},
256 {0xeeef, 0xeef8, 0xfa40},
257 {0xeefa, 0xeefc, 0xfa55}
259 #define SJISREVTBLSIZ (sizeof(sjisrev) / sizeof(sjis_regur_t))
261 /* EUC3BYTE DEFINITIONS */
263 typedef struct _sjis_euc_map_t {
268 static sjis_euc_map_t euc3conv2[] = {
283 #define EUC3CONV2TBLSIZ (sizeof(euc3conv2) / sizeof(sjis_euc_map_t))
286 /* IBM Kanji to EUC 3byte */
287 static int euc3conv[] = {
289 0xf3f3, 0xf3f4, 0xf3f5, 0xf3f6, 0xf3f7, 0xf3f8, 0xf3f9, 0xf3fa, 0xf3fb, 0xf3fc, 0xf3fd, 0xf3fe, 0xf4a1, 0xf4a2, 0xf4a3, 0xf4a4,
291 0xf4a5, 0xf4a6, 0xf4a7, 0xf4a8, 0, 0xa2c3, 0xf4a9, 0xf4aa, 0xf4ab, 0xf4ac, 0xf4ad, 0, 0xd4e3, 0xdcdf, 0xe4e9, 0xe3f8,
293 0xd9a1, 0xb1bb, 0xf4ae, 0xc2ad, 0xc3fc, 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b9, 0xf4e7, 0xdfc3,
327 0xf4e8, 0xf4e9, 0xe0d9, 0xf4ea, 0xf4eb, 0xe1e2, 0xf4ec, 0xf4ed, 0xf4ee, 0xe2c7, 0xe3a8, 0xe3a6, 0xe3a9, 0xe3af, 0xe3b0, 0xe3aa,
329 0xe3ab, 0xe3bc, 0xe3c1, 0xe3bf, 0xe3d5, 0xe3d8, 0xe3d6, 0xe3df, 0xe3e3, 0xe3e1, 0xe3d4, 0xe3e9, 0xe4a6, 0xe3f1, 0xe3f2, 0xe4cb,
331 0xe4c1, 0xe4c3, 0xe4be, 0xf4ef, 0xe4c0, 0xe4c7, 0xe4bf, 0xe4e0, 0xe4de, 0xe4d1, 0xf4f0, 0xe4dc, 0xe4d2, 0xe4db, 0xe4d4, 0xe4fa,
333 0xe4ef, 0xe5b3, 0xe5bf, 0xe5c9, 0xe5d0, 0xe5e2, 0xe5ea, 0xe5eb, 0xf4f1, 0xf4f2, 0xf4f3, 0xe6e8, 0xe6ef, 0xe7ac, 0xf4f4, 0xe7ae,
335 0xf4f5, 0xe7b1, 0xf4f6, 0xe7b2, 0xe8b1, 0xe8b6, 0xf4f7, 0xf4f8, 0xe8dd, 0xf4f9, 0xf4fa, 0xe9d1, 0xf4fb,
337 0xe9ed, 0xeacd, 0xf4fc, 0xeadb, 0xeae6, 0xeaea, 0xeba5, 0xebfb, 0xebfa, 0xf4fd, 0xecd6, 0xf4fe
340 #define EUC3CONVTBLSIZ (sizeof(euc3conv) / sizeof(int))
342 /* EUC3byte to SJIS Code */
344 typedef struct _sjis_euc_revmap_t {
349 static sjis_euc_revmap_t euc3rev[] = {
738 #define EUC3REVTBLSIZ (sizeof(euc3rev) / sizeof(sjis_euc_revmap_t))
740 #endif /* _KANJI_C_ */
741 #endif /* _KANJI_H_ */