5 typedef unsigned short char16 ;
7 #include <Resource_Shiftjis.h>
8 #include <Resource_gb2312.h>
10 #define isjis(c) (((c)>=0x21 && (c)<=0x7e))
11 #define iseuc(c) (((c)>=0xa1 && (c)<=0xfe))
12 #define issjis1(c) (((c)>=0x81 && (c)<=0x9f) || ((c)>=0xe0 && (c)<=0xef))
13 #define issjis2(c) ((c)>=0x40 && (c)<=0xfc && (c)!=0x7f)
14 #define ishankana(c) ((c)>=0xa0 && (c)<=0xdf)
15 #define isshift(c) (((c)>=0x80 && (c)<=0xff))
18 static void sjis_to_jis (unsigned int *ph, unsigned int *pl)
21 if ( ! issjis1 ( *ph ) || ! issjis2 ( *pl ) ) {
28 *ph = (*ph << 1) - 0xe1;
30 *ph = (*ph << 1) - 0xe0;
35 *ph = (*ph << 1) - 0x161;
37 *ph = (*ph << 1) - 0x160;
47 static void jis_to_sjis (unsigned int *ph, unsigned int *pl)
59 *ph = (*ph + 0xe1) >> 1;
61 *ph = (*ph + 0x161) >> 1;
64 static void euc_to_sjis (unsigned int *ph, unsigned int *pl)
66 if ( (*ph & 0xFFFFFF00) || (*pl & 0xFFFFFF00) ) {
72 if ( ! iseuc ( *ph ) || ! iseuc ( *pl ) ) {
80 jis_to_sjis ( ph , pl ) ;
84 static void sjis_to_euc (unsigned int *ph, unsigned int *pl)
86 if ( (*ph & 0xFFFFFF00) || (*pl & 0xFFFFFF00) ) {
92 if ( ! issjis1 ( *ph ) || ! issjis2 ( *pl ) ) {
96 if ( *ph == 0 && *pl == 0 )
99 sjis_to_jis ( ph , pl ) ;
106 void Resource_sjis_to_unicode (unsigned int *ph, unsigned int *pl)
111 if ( (*ph & 0xFFFFFF00) || (*pl & 0xFFFFFF00) ) {
117 if ( ! issjis1 ( *ph ) || ! issjis2 ( *pl ) ) {
121 sjis = ((*ph) << 8) | (*pl) ;
122 uni = sjisuni [sjis] ;
127 void Resource_unicode_to_sjis (unsigned int *ph, unsigned int *pl)
132 if ( (*ph & 0xFFFFFF00) || (*pl & 0xFFFFFF00) ) {
137 if ( *ph == 0 && *pl == 0 )
140 uni = ((*ph) << 8) | (*pl) ;
141 sjis = unisjis [uni] ;
146 void Resource_unicode_to_euc (unsigned int *ph, unsigned int *pl)
149 if ( *ph == 0 && *pl == 0 )
152 Resource_unicode_to_sjis ( ph , pl ) ;
153 if (issjis1(*ph)) { /* let's believe it is ANSI code if it is not sjis*/
154 sjis_to_euc ( ph , pl ) ;
159 void Resource_euc_to_unicode (unsigned int *ph, unsigned int *pl)
162 if ( ! iseuc ( *ph ) || ! iseuc ( *pl ) ) {
167 if ( *ph == 0 && *pl == 0 )
170 euc_to_sjis ( ph , pl ) ;
171 Resource_sjis_to_unicode ( ph , pl ) ;
176 void Resource_gb_to_unicode (unsigned int *ph, unsigned int *pl)
182 if ( (*ph & 0xFFFFFF00) || (*pl & 0xFFFFFF00) ) {
188 if ( ! isshift ( *ph ) || ! isshift ( *pl ) ) {
195 gb = ((*ph) << 8) | (*pl) ;
201 void Resource_unicode_to_gb (unsigned int *ph, unsigned int *pl)
206 if ( (*ph & 0xFFFFFF00) || (*pl & 0xFFFFFF00) ) {
211 if ( *ph == 0 && *pl == 0 )
214 uni = ((*ph) << 8) | (*pl) ;
217 *ph = ( gb >> 8 ) | 0x80 ;
218 *pl = ( gb & 0xFF ) | 0x80 ;