_fallcUTF.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* XlcUTF.h 1.1 - Fujitsu source for CDEnext 95/11/06 20:32:06 */
  24. /* $XConsortium: _fallcUTF.h /main/1 1996/04/08 15:19:33 cde-fuj $ */
  25. /******************************************************************
  26. Copyright 1993 by SunSoft, Inc.
  27. Permission to use, copy, modify, distribute, and sell this software
  28. and its documentation for any purpose is hereby granted without fee,
  29. provided that the above copyright notice appear in all copies and
  30. that both that copyright notice and this permission notice appear
  31. in supporting documentation, and that the name of SunSoft, Inc.
  32. not be used in advertising or publicity pertaining to distribution
  33. of the software without specific, written prior permission.
  34. SunSoft, Inc. makes no representations about the suitability of
  35. this software for any purpose. It is provided "as is" without
  36. express or implied warranty.
  37. SunSoft Inc. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  38. SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  39. IN NO EVENT SHALL SunSoft, Inc. BE LIABLE FOR ANY SPECIAL, INDIRECT
  40. OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
  41. OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  42. OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  43. OR PERFORMANCE OF THIS SOFTWARE.
  44. Author: Hiromu Inukai (inukai@Japan.Sun.COM) SunSoft, inc.
  45. ******************************************************************/
  46. #include "_fallibint.h"
  47. #include "_fallcGeneric.h"
  48. #include <X11/Xos.h>
  49. #include <stdio.h>
  50. typedef unsigned short Rune; /* 16 bits */
  51. #define Runeerror 0x80 /* decoding error in UTF */
  52. #define Runeself 0x80 /* rune and UTF sequences are the same (<) */
  53. #define UTFmax 3 /* maximum bytes per rune */
  54. #define BADMAP (0xFFFD)
  55. #define ESC 033
  56. #define NRUNE 65536
  57. #define NLATIN 0x6ff
  58. #define LATINMAX 256
  59. #define KUTENMAX 8407
  60. #define KSCMAX 8743
  61. #define GBMAX 8795
  62. #define tab8859_1 "tab8859_1"
  63. #define tab8859_2 "tab8859_2"
  64. #define tab8859_3 "tab8859_3"
  65. #define tab8859_4 "tab8859_4"
  66. #define tab8859_5 "tab8859_5"
  67. #define tab8859_6 "tab8859_6"
  68. #define tab8859_7 "tab8859_7"
  69. #define tab8859_8 "tab8859_8"
  70. #define tab8859_9 "tab8859_9"
  71. #define jis0208 "jis0208"
  72. #define ksc5601 "ksc5601"
  73. #define gb2312 "gb2312"
  74. #define emit(x) *r = (Rune)x;
  75. typedef enum {
  76. N11n_none, /* No need to normalize (1byte) */
  77. N11n_ja, /* Normalize for ja */
  78. N11n_ko, /* Normalize for ko */
  79. N11n_zh /* Normalize for zh */
  80. } NormalizeType;
  81. typedef struct _UtfDataRec {
  82. XlcCharSet charset;
  83. void (*initialize)( /* Table Initializer */
  84. long *tbl,
  85. long fallback
  86. );
  87. long *fromtbl; /* UTF -> CharSet */
  88. NormalizeType type; /* Normalize type */
  89. void (*cstorune)( /* CharSet -> UTF */
  90. unsigned char c,
  91. Rune *r
  92. );
  93. Bool already_init;
  94. struct _UtfDataRec *next; /* next entry */
  95. } UtfDataRec, *UtfData;
  96. typedef struct _XlcUTFDataRec {
  97. char *name;
  98. XlcSide side;
  99. void (*initialize)();
  100. void (*cstorune)(
  101. unsigned char c,
  102. Rune *r
  103. );
  104. NormalizeType type;
  105. long fallback_value;
  106. } XlcUTFDataRec, *XlcUTFData;
  107. typedef struct _StateRec {
  108. XlcCharSet charset;
  109. XlcCharSet GL_charset;
  110. XlcCharSet GR_charset;
  111. } StateRec, *State;
  112. #define MAX_UTF_CHARSET (sizeof(default_utf_data)/sizeof(XlcUTFDataRec))
  113. #define Char1 Runeself
  114. #define Rune1 Runeself
  115. #define Char21 0xA1
  116. #define Rune21 0x0100
  117. #define Char22 0xF6
  118. #define Rune22 0x4016
  119. #define Char3 0xFC
  120. #define Rune3 0x10000 /* really 0x38E2E */
  121. #define Esc 0xBE
  122. #define Bad Runeerror
  123. #define T1 0x00
  124. #define Tx 0x80
  125. #define T2 0xC0
  126. #define T3 0xE0
  127. #define T4 0xF0
  128. #define T5 0xF8
  129. #define T6 0xFC
  130. #define Bit1 7
  131. #define Bitx 6
  132. #define Bit2 5
  133. #define Bit3 4
  134. #define Bit4 3
  135. #define Bit5 2
  136. #define Bit6 2
  137. #define Mask1 (1<<Bit1)-1
  138. #define Maskx (1<<Bitx)-1
  139. #define Mask2 (1<<Bit2)-1
  140. #define Mask3 (1<<Bit3)-1
  141. #define Mask4 (1<<Bit4)-1
  142. #define Mask5 (1<<Bit5)-1
  143. #define Mask6 (1<<Bit6)-1
  144. #define Wchar1 (1<<Bit1)-1
  145. #define Wchar2 (1<<(Bit2+Bitx))-1
  146. #define Wchar3 (1<<(Bit3+2*Bitx))-1
  147. #define Wchar4 (1<<(Bit4+3*Bitx))-1
  148. #define Wchar5 (1<<(Bit5+4*Bitx))-1
  149. #ifndef EILSEQ
  150. #define EILSEQ 123
  151. #endif
  152. #define J2S(_h, _l) { \
  153. /* lower: 21-7e >> 40-9d,9e-fb >> 40-7e,(skip 7f),80-fc */ \
  154. if (((_l) += (((_h)-- % 2) ? 0x1f : 0x7d)) > 0x7e) (_l)++; \
  155. /* upper: 21-7e >> 81-af >> 81-9f,(skip a0-df),e0-ef */ \
  156. if (((_h) = ((_h) / 2 + 0x71)) > 0x9f) (_h) += 0x40; \
  157. }
  158. #define S2J(_h, _l) { \
  159. /* lower: 40-7e,80-fc >> 21-5f,61-dd >> 21-7e,7f-dc */ \
  160. if (((_l) -= 0x1f) > 0x60) (_l)--; \
  161. /* upper: 81-9f,e0-ef >> 00-1e,5f-6e >> 00-2e >> 21-7d */ \
  162. if (((_h) -= 0x81) > 0x5e) (_h) -= 0x40; (_h) *= 2, (_h) += 0x21; \
  163. /* upper: ,21-7d >> ,22-7e ; lower: ,7f-dc >> ,21-7e */ \
  164. if ((_l) > 0x7e) (_h)++, (_l) -= 0x5e; \
  165. }
  166. #define ISJKANA(_b) (0xa0 <= (_b) && (_b) < 0xe0)
  167. #define CANS2JH(_h) ((0x81 <= (_h) && (_h) < 0xf0) && !ISJKANA(_h))
  168. #define CANS2JL(_l) (0x40 <= (_l) && (_l) < 0xfd && (_l) != 0x7f)
  169. #define CANS2J(_h, _l) (CANS2JH(_h) && CANS2JL(_l))