2 * linux/fs/nls_euc-jp.c
5 #include <linux/module.h>
6 #include <linux/kernel.h>
7 #include <linux/string.h>
9 #include <linux/errno.h>
11 static struct nls_table
*p_nls
;
14 #define SS2 (0x8E) /* Single Shift 2 */
15 #define SS3 (0x8F) /* Single Shift 3 */
17 static int uni2char(const wchar_t uni
,
18 unsigned char *out
, int boundlen
)
24 if ( (n
= p_nls
->uni2char(uni
, out
, boundlen
)) < 0)
27 /* translate SJIS into EUC-JP */
30 if (0xA1 <= out
[0] && out
[0] <= 0xDF) {
40 /* SJIS codes 0xF0xx to 0xFFxx are machine-dependent codes and user-defining characters */
42 out
[0] = 0x81; /* 'GETA' with SJIS coding */
46 out
[0] = (out
[0]^0xA0)*2 + 0x5F;
51 out
[1] = out
[1] + 0x61;
52 else if (out
[1] < 0x9F)
53 out
[1] = out
[1] + 0x60;
55 out
[1] = out
[1] + 0x02;
63 static int char2uni(const unsigned char *rawstring
, int boundlen
,
66 unsigned char sjis_temp
[2];
79 /* translate EUC-JP into SJIS */
80 if (rawstring
[0] > 0x7F) {
81 if (rawstring
[0] == SS2
) {
83 sjis_temp
[0] = rawstring
[1];
86 } else if (rawstring
[0] == SS3
) {
88 sjis_temp
[0] = 0x81; /* 'GETA' with SJIS coding */
93 sjis_temp
[0] = ((rawstring
[0]-0x5f)/2) ^ 0xA0;
94 if (!(rawstring
[0]&1))
95 sjis_temp
[1] = rawstring
[1] - 0x02;
96 else if (rawstring
[1] < 0xE0)
97 sjis_temp
[1] = rawstring
[1] - 0x61;
99 sjis_temp
[1] = rawstring
[1] - 0x60;
103 /* JIS X 201 ROMAJI */
104 sjis_temp
[0] = rawstring
[0];
105 sjis_temp
[1] = rawstring
[1];
109 if ( (n
= p_nls
->char2uni(sjis_temp
, boundlen
, uni
)) < 0)
115 static struct nls_table table
= {
124 static int __init
init_nls_euc_jp(void)
126 p_nls
= load_nls("cp932");
129 table
.charset2upper
= p_nls
->charset2upper
;
130 table
.charset2lower
= p_nls
->charset2lower
;
131 return register_nls(&table
);
137 static void __exit
exit_nls_euc_jp(void)
139 unregister_nls(&table
);
143 module_init(init_nls_euc_jp
)
144 module_exit(exit_nls_euc_jp
)
147 * Overrides for Emacs so that we follow Linus's tabbing style.
148 * Emacs will notice this stuff at the end of the file and automatically
149 * adjust the settings for this buffer only. This must remain at the end
152 ---------------------------------------------------------------------------
155 * c-brace-imaginary-offset: 0
157 * c-argdecl-indent: 8
159 * c-continued-statement-offset: 8
160 * c-continued-brace-offset: 0