2 Copyright (c) 1998-1999 Matra Datavision
3 Copyright (c) 1999-2014 OPEN CASCADE SAS
5 This file is part of Open CASCADE Technology software library.
7 This library is free software; you can redistribute it and/or modify it under
8 the terms of the GNU Lesser General Public License version 2.1 as published
9 by the Free Software Foundation, with special exception defined in the file
10 OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 distribution for complete text of the license and disclaimer of any warranty.
13 Alternatively, this file may be used under the terms of Open CASCADE
14 commercial license or contractual agreement.
19 #include <sys/types.h>
21 typedef unsigned short char16 ;
23 #include <Resource_Shiftjis.h>
24 #include <Resource_GB2312.h>
26 #define isjis(c) (((c)>=0x21 && (c)<=0x7e))
27 #define iseuc(c) (((c)>=0xa1 && (c)<=0xfe))
28 #define issjis1(c) (((c)>=0x81 && (c)<=0x9f) || ((c)>=0xe0 && (c)<=0xef))
29 #define issjis2(c) ((c)>=0x40 && (c)<=0xfc && (c)!=0x7f)
30 #define ishankana(c) ((c)>=0xa0 && (c)<=0xdf)
31 #define isshift(c) (((c)>=0x80 && (c)<=0xff))
34 static void sjis_to_jis (unsigned int *ph, unsigned int *pl)
37 if ( ! issjis1 ( *ph ) || ! issjis2 ( *pl ) ) {
44 *ph = (*ph << 1) - 0xe1;
46 *ph = (*ph << 1) - 0xe0;
51 *ph = (*ph << 1) - 0x161;
53 *ph = (*ph << 1) - 0x160;
63 static void jis_to_sjis (unsigned int *ph, unsigned int *pl)
75 *ph = (*ph + 0xe1) >> 1;
77 *ph = (*ph + 0x161) >> 1;
80 static void euc_to_sjis (unsigned int *ph, unsigned int *pl)
82 if ( (*ph & 0xFFFFFF00) || (*pl & 0xFFFFFF00) ) {
88 if ( ! iseuc ( *ph ) || ! iseuc ( *pl ) ) {
96 jis_to_sjis ( ph , pl ) ;
100 static void sjis_to_euc (unsigned int *ph, unsigned int *pl)
102 if ( (*ph & 0xFFFFFF00) || (*pl & 0xFFFFFF00) ) {
108 if ( ! issjis1 ( *ph ) || ! issjis2 ( *pl ) ) {
112 if ( *ph == 0 && *pl == 0 )
115 sjis_to_jis ( ph , pl ) ;
122 void Resource_sjis_to_unicode (unsigned int *ph, unsigned int *pl)
127 if ( (*ph & 0xFFFFFF00) || (*pl & 0xFFFFFF00) ) {
133 if ( ! issjis1 ( *ph ) || ! issjis2 ( *pl ) ) {
137 sjis = (char16)(((*ph) << 8) | (*pl)) ;
138 uni = sjisuni [sjis] ;
143 void Resource_unicode_to_sjis (unsigned int *ph, unsigned int *pl)
148 if ( (*ph & 0xFFFFFF00) || (*pl & 0xFFFFFF00) ) {
153 if ( *ph == 0 && *pl == 0 )
156 uni = (char16)(((*ph) << 8) | (*pl)) ;
157 sjis = unisjis [uni] ;
162 void Resource_unicode_to_euc (unsigned int *ph, unsigned int *pl)
165 if ( *ph == 0 && *pl == 0 )
168 Resource_unicode_to_sjis ( ph , pl ) ;
169 if (issjis1(*ph)) { /* let's believe it is ANSI code if it is not sjis*/
170 sjis_to_euc ( ph , pl ) ;
175 void Resource_euc_to_unicode (unsigned int *ph, unsigned int *pl)
178 if ( ! iseuc ( *ph ) || ! iseuc ( *pl ) ) {
183 if ( *ph == 0 && *pl == 0 )
186 euc_to_sjis ( ph , pl ) ;
187 Resource_sjis_to_unicode ( ph , pl ) ;
192 void Resource_gb_to_unicode (unsigned int *ph, unsigned int *pl)
198 if ( (*ph & 0xFFFFFF00) || (*pl & 0xFFFFFF00) ) {
204 if ( ! isshift ( *ph ) || ! isshift ( *pl ) ) {
211 gb = (char16)(((*ph) << 8) | (*pl)) ;
217 void Resource_unicode_to_gb (unsigned int *ph, unsigned int *pl)
222 if ( (*ph & 0xFFFFFF00) || (*pl & 0xFFFFFF00) ) {
227 if ( *ph == 0 && *pl == 0 )
230 uni = (char16)(((*ph) << 8) | (*pl));
233 *ph = ( gb >> 8 ) | 0x80 ;
234 *pl = ( gb & 0xFF ) | 0x80 ;