libt3window
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Modules
terminal_detection.h
1 /* Copyright (C) 2011 G.P. Halkes
2  This program is free software: you can redistribute it and/or modify
3  it under the terms of the GNU General Public License version 3, as
4  published by the Free Software Foundation.
5 
6  This program is distributed in the hope that it will be useful,
7  but WITHOUT ANY WARRANTY; without even the implied warranty of
8  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  GNU General Public License for more details.
10 
11  You should have received a copy of the GNU General Public License
12  along with this program. If not, see <http://www.gnu.org/licenses/>.
13 */
14 
15 #if defined(GENERATE_STRINGS)
16 #define TEST(_str, _code) send_test_string(_str);
17 #elif defined(GENERATE_CODE)
18 #define TEST(_str, _code) if (test++ == report_nr) { _code }
19 {
20  int test = 0;
21 #endif
22 
23 /*======================
24  = Define TESTs below =
25  ======================*/
26 /* The tests defined here can use the variable column to check the reported width
27  of the given test string. Test are executed in the order presented here.
28 */
29 //FIXME: test for more encodings here
30 //FIXME: extend the GB18030 testing
31 
32 /*=== Basic character set detection ===*/
33 
34 /* This string should be 3 characters wide, if UTF-8 is supported. All characters are from
35  Unicode version 1.1, so they should be supported if UTF-8 is supported at all. EUC type
36  terminals will report length of 6 and single byte encodings will report 8.
37 
38  U+00E5 LATIN SMALL LETTER A WITH RING ABOVE,
39  U+0E3F THAI CURRENCY SYMBOL BAHT, U+2592 MEDIUM SHADE */
40 TEST("\xc3\xa5\xe0\xb8\xbf\xe2\x96\x92",
41  if (column == 3)
42  _t3_term_encoding = _T3_TERM_UTF8;
43  else if (column == 6)
44  _t3_term_encoding = _T3_TERM_CJK;
45 )
46 
47 /* Test for GB18030. For EUC type encodings, this will be length two because the
48  bytes with the high bit set will be ignored. For UTF-8, the characters with
49  the high bit set will be replaced by the replacement character, thus reporing
50  the widht as 4.
51  U+00DE LATIN CAPITAL LETTER THORN */
52 TEST("\x81\x30\x89\x37",
53  if (_t3_term_encoding == _T3_TERM_UNKNOWN) {
54  if (column == 1)
55  _t3_term_encoding = _T3_TERM_GB18030;
56  if (column == 2)
57  _t3_term_encoding = _T3_TERM_GBK; //FIXME: or GB2312 for some encoding of it
58  else if (column == 4)
59  _t3_term_encoding = _T3_TERM_SINGLE_BYTE;
60  }
61 )
62 
63 /*=== Combining character sequences ===*/
64 
65 /* [4.0] U+002E FULL STOP / U+0350 COMBINING RIGHT ARROWHEAD ABOVE */
66 TEST("\x2e\xcd\x90", /* UTF-8 version */
67  if (_t3_term_encoding == _T3_TERM_UTF8 && column == 1)
68  _t3_term_combining = T3_UNICODE_40;
69 )
70 TEST("\x2e\x81\x30\xc4\x36", /* GB-18030 version */
71  if (_t3_term_encoding == _T3_TERM_GB18030)
72  _t3_term_combining = T3_UNICODE_40;
73 )
74 
75 /* [4.1] U+002E FULL STOP / U+0358 COMBINING DOT ABOVE RIGHT */
76 TEST("\x2e\xcd\x98",
77  if (_t3_term_encoding == _T3_TERM_UTF8 && column == 1 && _t3_term_combining == T3_UNICODE_40)
78  _t3_term_combining = T3_UNICODE_41;
79 )
80 /* [5.0] U+002E FULL STOP / U+1DC4 COMBINING MACRON-ACUTE */
81 TEST("\x2e\xe1\xb7\x84",
82  if (_t3_term_encoding == _T3_TERM_UTF8 && column == 1 && _t3_term_combining == T3_UNICODE_41)
83  _t3_term_combining = T3_UNICODE_50;
84 )
85 /* [5.1] U+002E FULL STOP / U+0487 COMBINING CYRILLIC POKRYTIE */
86 TEST("\x2e\xd2\x87",
87  if (_t3_term_encoding == _T3_TERM_UTF8 && column == 1 && _t3_term_combining == T3_UNICODE_50)
88  _t3_term_combining = T3_UNICODE_51;
89 )
90 /* [5.2] U+002E FULL STOP / U+081B SAMARITAN MARK EPENTHETIC YUT */
91 TEST("\x2e\xe0\xa0\x9b",
92  if (_t3_term_encoding == _T3_TERM_UTF8 && column == 1 && _t3_term_combining == T3_UNICODE_51)
93  _t3_term_combining = T3_UNICODE_52;
94 )
95 /* [6.0] U+002E FULL STOP / U+0859 MANDAIC AFFRICATION MARK */
96 TEST("\x2e\xe0\xa1\x99",
97  if (_t3_term_encoding == _T3_TERM_UTF8 && column == 1 && _t3_term_combining == T3_UNICODE_52)
98  _t3_term_combining = T3_UNICODE_60;
99 )
100 
101 /*=== Double-width character sequences ===*/
102 
103 /* [1.1] U+5208 CJK UNIFIED IDEOGRAPH-5208, [4.0] U+FE47 PRESENTATION FORM FOR VERTICAL LEFT SQUARE BRACKET */
104 TEST("\xe5\x88\x88\xef\xb9\x87",
105  if (_t3_term_encoding == _T3_TERM_UTF8 && column == 4)
106  _t3_term_double_width = T3_UNICODE_40;
107 )
108 /* [4.1] U+FE10 PRESENTATION FORM FOR VERTICAL COMMA */
109 TEST("\xef\xb8\x90",
110  if (_t3_term_encoding == _T3_TERM_UTF8 && column == 2 && _t3_term_double_width == T3_UNICODE_40)
111  _t3_term_double_width = T3_UNICODE_41;
112 )
113 /* No new wide characters were introduced in Unicode 5.0. */
114 /* [5.1] U+31DC CJK STROKE PZ */
115 TEST("\xe3\x87\x9c",
116  if (_t3_term_encoding == _T3_TERM_UTF8 && column == 2 && _t3_term_double_width == T3_UNICODE_41)
117  _t3_term_double_width = T3_UNICODE_51;
118 )
119 /* [5.2] U+3244 CIRCLED IDEOGRAPH QUESTION */
120 TEST("\xe3\x89\x84",
121  if (_t3_term_encoding == _T3_TERM_UTF8 && column == 2 && _t3_term_double_width == T3_UNICODE_51)
122  _t3_term_double_width = T3_UNICODE_52;
123 )
124 /* [6.0] U+31B8 BOPOMOFO LETTER GH */
125 TEST("\xe3\x86\xb8",
126  if (_t3_term_encoding == _T3_TERM_UTF8 && column == 2 && _t3_term_double_width == T3_UNICODE_52)
127  _t3_term_double_width = T3_UNICODE_60;
128 )
129 
130 
131 /*==============================================
132  = Do NOT define any TESTs beyond this point. =
133  ==============================================*/
134 
135 #if defined(GENERATE_CODE)
136  if (detecting_terminal_capabilities && test - 1 == report_nr) {
137  detecting_terminal_capabilities = t3_false;
138  finish_detection();
139  result = t3_true;
140  }
141 }
142 #endif
143 #undef TEST
True.
Definition: window_api.h:44
False.
Definition: window_api.h:43