1 /*++
2
3 Copyright (c) 1998 Intel Corporation
4
5 Module Name:
6
7 BoxDraw.c
8
9 Abstract:
10 Lib functions to support Box Draw Unicode code pages.
11
12
13
14 Revision History
15
16 --*/
17
18 #include "lib.h"
19
20 typedef struct {
21 CHAR16 Unicode;
22 CHAR8 PcAnsi;
23 CHAR8 Ascii;
24 } UNICODE_TO_CHAR;
25
26
27 //
28 // This list is used to define the valid extend chars.
29 // It also provides a mapping from Unicode to PCANSI or
30 // ASCII. The ASCII mapping we just made up.
31 //
32 //
33
34 STATIC UNICODE_TO_CHAR UnicodeToPcAnsiOrAscii[] = {
35 { BOXDRAW_HORIZONTAL, 0xc4, L'-'},
36 { BOXDRAW_VERTICAL, 0xb3, L'|'},
37 { BOXDRAW_DOWN_RIGHT, 0xda, L'/'},
38 { BOXDRAW_DOWN_LEFT, 0xbf, L'\\'},
39 { BOXDRAW_UP_RIGHT, 0xc0, L'\\'},
40 { BOXDRAW_UP_LEFT, 0xd9, L'/'},
41 { BOXDRAW_VERTICAL_RIGHT, 0xc3, L'|'},
42 { BOXDRAW_VERTICAL_LEFT, 0xb4, L'|'},
43 { BOXDRAW_DOWN_HORIZONTAL, 0xc2, L'+'},
44 { BOXDRAW_UP_HORIZONTAL, 0xc1, L'+'},
45 { BOXDRAW_VERTICAL_HORIZONTAL, 0xc5, L'+'},
46 { BOXDRAW_DOUBLE_HORIZONTAL, 0xcd, L'-'},
47 { BOXDRAW_DOUBLE_VERTICAL, 0xba, L'|'},
48 { BOXDRAW_DOWN_RIGHT_DOUBLE, 0xd5, L'/'},
49 { BOXDRAW_DOWN_DOUBLE_RIGHT, 0xd6, L'/'},
50 { BOXDRAW_DOUBLE_DOWN_RIGHT, 0xc9, L'/'},
51 { BOXDRAW_DOWN_LEFT_DOUBLE, 0xb8, L'\\'},
52 { BOXDRAW_DOWN_DOUBLE_LEFT, 0xb7, L'\\'},
53 { BOXDRAW_DOUBLE_DOWN_LEFT, 0xbb, L'\\'},
54 { BOXDRAW_UP_RIGHT_DOUBLE, 0xd4, L'\\'},
55 { BOXDRAW_UP_DOUBLE_RIGHT, 0xd3, L'\\'},
56 { BOXDRAW_DOUBLE_UP_RIGHT, 0xc8, L'\\'},
57 { BOXDRAW_UP_LEFT_DOUBLE, 0xbe, L'/'},
58 { BOXDRAW_UP_DOUBLE_LEFT, 0xbd, L'/'},
59 { BOXDRAW_DOUBLE_UP_LEFT, 0xbc, L'/'},
60 { BOXDRAW_VERTICAL_RIGHT_DOUBLE, 0xc6, L'|'},
61 { BOXDRAW_VERTICAL_DOUBLE_RIGHT, 0xc7, L'|'},
62 { BOXDRAW_DOUBLE_VERTICAL_RIGHT, 0xcc, L'|'},
63 { BOXDRAW_VERTICAL_LEFT_DOUBLE, 0xb5, L'|'},
64 { BOXDRAW_VERTICAL_DOUBLE_LEFT, 0xb6, L'|'},
65 { BOXDRAW_DOUBLE_VERTICAL_LEFT, 0xb9, L'|'},
66 { BOXDRAW_DOWN_HORIZONTAL_DOUBLE, 0xd1, L'+'},
67 { BOXDRAW_DOWN_DOUBLE_HORIZONTAL, 0xd2, L'+'},
68 { BOXDRAW_DOUBLE_DOWN_HORIZONTAL, 0xcb, L'+'},
69 { BOXDRAW_UP_HORIZONTAL_DOUBLE, 0xcf, L'+'},
70 { BOXDRAW_UP_DOUBLE_HORIZONTAL, 0xd0, L'+'},
71 { BOXDRAW_DOUBLE_UP_HORIZONTAL, 0xca, L'+'},
72 { BOXDRAW_VERTICAL_HORIZONTAL_DOUBLE, 0xd8, L'+'},
73 { BOXDRAW_VERTICAL_DOUBLE_HORIZONTAL, 0xd7, L'+'},
74 { BOXDRAW_DOUBLE_VERTICAL_HORIZONTAL, 0xce, L'+'},
75
76 { BLOCKELEMENT_FULL_BLOCK, 0xdb, L'*'},
77 { BLOCKELEMENT_LIGHT_SHADE, 0xb0, L'+'},
78
79 { GEOMETRICSHAPE_UP_TRIANGLE, 0x1e, L'^'},
80 { GEOMETRICSHAPE_RIGHT_TRIANGLE, 0x10, L'>'},
81 { GEOMETRICSHAPE_DOWN_TRIANGLE, 0x1f, L'v'},
82 { GEOMETRICSHAPE_LEFT_TRIANGLE, 0x11, L'<'},
83
84 /* BugBug: Left Arrow is an ESC. We can not make it print
85 on a PCANSI terminal. If we can make left arrow
86 come out on PC ANSI we can add it back.
87
88 { ARROW_LEFT, 0x1b, L'<'},
89 */
90
91 { ARROW_UP, 0x18, L'^'},
92
93 /* BugBut: Took out left arrow so right has to go too.
94 { ARROW_RIGHT, 0x1a, L'>'},
95 */
96 { ARROW_DOWN, 0x19, L'v'},
97
98 { 0x0000, 0x00, L'\0' }
99 };
100
101
102 BOOLEAN
LibIsValidTextGraphics(IN CHAR16 Graphic,OUT CHAR8 * PcAnsi,OPTIONAL OUT CHAR8 * Ascii OPTIONAL)103 LibIsValidTextGraphics (
104 IN CHAR16 Graphic,
105 OUT CHAR8 *PcAnsi, OPTIONAL
106 OUT CHAR8 *Ascii OPTIONAL
107 )
108 /*++
109
110 Routine Description:
111
112 Detects if a Unicode char is for Box Drawing text graphics.
113
114 Arguments:
115
116 Grphic - Unicode char to test.
117
118 PcAnsi - Optional pointer to return PCANSI equivalent of Graphic.
119
120 Asci - Optional pointer to return Ascii equivalent of Graphic.
121
122 Returns:
123
124 TRUE if Gpaphic is a supported Unicode Box Drawing character.
125
126 --*/{
127 UNICODE_TO_CHAR *Table;
128
129 if ((((Graphic & 0xff00) != 0x2500) && ((Graphic & 0xff00) != 0x2100))) {
130
131 //
132 // Unicode drawing code charts are all in the 0x25xx range,
133 // arrows are 0x21xx
134 //
135 return FALSE;
136 }
137
138 for (Table = UnicodeToPcAnsiOrAscii; Table->Unicode != 0x0000; Table++) {
139 if (Graphic == Table->Unicode) {
140 if (PcAnsi) {
141 *PcAnsi = Table->PcAnsi;
142 }
143 if (Ascii) {
144 *Ascii = Table->Ascii;
145 }
146 return TRUE;
147 }
148 }
149 return FALSE;
150 }
151
152 BOOLEAN
IsValidAscii(IN CHAR16 Ascii)153 IsValidAscii (
154 IN CHAR16 Ascii
155 )
156 {
157 if ((Ascii >= 0x20) && (Ascii <= 0x7f)) {
158 return TRUE;
159 }
160 return FALSE;
161 }
162
163 BOOLEAN
IsValidEfiCntlChar(IN CHAR16 c)164 IsValidEfiCntlChar (
165 IN CHAR16 c
166 )
167 {
168 if (c == CHAR_NULL || c == CHAR_BACKSPACE || c == CHAR_LINEFEED || c == CHAR_CARRIAGE_RETURN) {
169 return TRUE;
170 }
171 return FALSE;
172 }
173
174