]>
Commit | Line | Data |
---|---|---|
f42be642 | 1 | /** @file\r |
61e33430 | 2 | Driver to implement English version of Unicode Collation Protocol.\r |
adbcbf8f | 3 | \r |
4f077902 | 4 | Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r |
e5eed7d3 | 5 | This program and the accompanying materials\r |
adbcbf8f | 6 | are licensed and made available under the terms and conditions of the BSD License\r |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
f42be642 | 13 | **/\r |
adbcbf8f | 14 | \r |
15 | \r | |
16 | #include "UnicodeCollationEng.h"\r | |
17 | \r | |
48557c65 | 18 | CHAR8 mEngUpperMap[MAP_TABLE_SIZE];\r |
19 | CHAR8 mEngLowerMap[MAP_TABLE_SIZE];\r | |
20 | CHAR8 mEngInfoMap[MAP_TABLE_SIZE];\r | |
adbcbf8f | 21 | \r |
22 | CHAR8 mOtherChars[] = {\r | |
23 | '0',\r | |
24 | '1',\r | |
25 | '2',\r | |
26 | '3',\r | |
27 | '4',\r | |
28 | '5',\r | |
29 | '6',\r | |
30 | '7',\r | |
31 | '8',\r | |
32 | '9',\r | |
33 | '\\',\r | |
34 | '.',\r | |
35 | '_',\r | |
36 | '^',\r | |
37 | '$',\r | |
38 | '~',\r | |
39 | '!',\r | |
40 | '#',\r | |
41 | '%',\r | |
42 | '&',\r | |
43 | '-',\r | |
44 | '{',\r | |
45 | '}',\r | |
46 | '(',\r | |
47 | ')',\r | |
48 | '@',\r | |
49 | '`',\r | |
50 | '\'',\r | |
51 | '\0'\r | |
52 | };\r | |
53 | \r | |
ff61847d | 54 | EFI_HANDLE mHandle = NULL;\r |
adbcbf8f | 55 | \r |
2d9a7522 | 56 | //\r |
57 | // EFI Unicode Collation Protocol supporting ISO 639-2 language code\r | |
58 | //\r | |
59 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_COLLATION_PROTOCOL UnicodeEng = {\r | |
adbcbf8f | 60 | EngStriColl,\r |
61 | EngMetaiMatch,\r | |
62 | EngStrLwr,\r | |
63 | EngStrUpr,\r | |
64 | EngFatToStr,\r | |
65 | EngStrToFat,\r | |
66 | "eng"\r | |
67 | };\r | |
68 | \r | |
69 | //\r | |
0254efc0 | 70 | // EFI Unicode Collation2 Protocol supporting RFC 4646 language code\r |
adbcbf8f | 71 | //\r |
2d9a7522 | 72 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_COLLATION_PROTOCOL Unicode2Eng = {\r |
73 | EngStriColl,\r | |
74 | EngMetaiMatch,\r | |
75 | EngStrLwr,\r | |
76 | EngStrUpr,\r | |
77 | EngFatToStr,\r | |
78 | EngStrToFat,\r | |
79 | "en"\r | |
80 | };\r | |
81 | \r | |
61e33430 | 82 | /**\r |
83 | The user Entry Point for English module.\r | |
84 | \r | |
85 | This function initializes unicode character mapping and then installs Unicode\r | |
86 | Collation & Unicode Collation 2 Protocols based on the feature flags. \r | |
87 | \r | |
88 | @param ImageHandle The firmware allocated handle for the EFI image. \r | |
89 | @param SystemTable A pointer to the EFI System Table.\r | |
90 | \r | |
91 | @retval EFI_SUCCESS The entry point is executed successfully.\r | |
92 | @retval other Some error occurs when executing this entry point.\r | |
93 | \r | |
94 | **/\r | |
adbcbf8f | 95 | EFI_STATUS\r |
2d9a7522 | 96 | EFIAPI\r |
adbcbf8f | 97 | InitializeUnicodeCollationEng (\r |
98 | IN EFI_HANDLE ImageHandle,\r | |
99 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
100 | )\r | |
adbcbf8f | 101 | {\r |
2d9a7522 | 102 | EFI_STATUS Status;\r |
adbcbf8f | 103 | UINTN Index;\r |
104 | UINTN Index2;\r | |
105 | \r | |
106 | //\r | |
107 | // Initialize mapping tables for the supported languages\r | |
108 | //\r | |
48557c65 | 109 | for (Index = 0; Index < MAP_TABLE_SIZE; Index++) {\r |
adbcbf8f | 110 | mEngUpperMap[Index] = (CHAR8) Index;\r |
111 | mEngLowerMap[Index] = (CHAR8) Index;\r | |
112 | mEngInfoMap[Index] = 0;\r | |
113 | \r | |
114 | if ((Index >= 'a' && Index <= 'z') || (Index >= 0xe0 && Index <= 0xf6) || (Index >= 0xf8 && Index <= 0xfe)) {\r | |
115 | \r | |
116 | Index2 = Index - 0x20;\r | |
117 | mEngUpperMap[Index] = (CHAR8) Index2;\r | |
118 | mEngLowerMap[Index2] = (CHAR8) Index;\r | |
119 | \r | |
120 | mEngInfoMap[Index] |= CHAR_FAT_VALID;\r | |
121 | mEngInfoMap[Index2] |= CHAR_FAT_VALID;\r | |
122 | }\r | |
123 | }\r | |
124 | \r | |
ea7cb08c | 125 | for (Index = 0; mOtherChars[Index] != 0; Index++) {\r |
adbcbf8f | 126 | Index2 = mOtherChars[Index];\r |
127 | mEngInfoMap[Index2] |= CHAR_FAT_VALID;\r | |
128 | }\r | |
2d9a7522 | 129 | \r |
130 | if (FeaturePcdGet (PcdUnicodeCollation2Support)) {\r | |
131 | if (FeaturePcdGet (PcdUnicodeCollationSupport)) {\r | |
132 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
133 | &mHandle,\r | |
134 | &gEfiUnicodeCollationProtocolGuid,\r | |
135 | &UnicodeEng,\r | |
136 | &gEfiUnicodeCollation2ProtocolGuid,\r | |
137 | &Unicode2Eng,\r | |
138 | NULL\r | |
139 | );\r | |
140 | ASSERT_EFI_ERROR (Status);\r | |
141 | } else {\r | |
142 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
143 | &mHandle,\r | |
144 | &gEfiUnicodeCollation2ProtocolGuid,\r | |
145 | &Unicode2Eng,\r | |
146 | NULL\r | |
147 | );\r | |
148 | ASSERT_EFI_ERROR (Status);\r | |
149 | }\r | |
150 | } else {\r | |
151 | if (FeaturePcdGet (PcdUnicodeCollationSupport)) {\r | |
152 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
153 | &mHandle,\r | |
154 | &gEfiUnicodeCollationProtocolGuid,\r | |
155 | &UnicodeEng,\r | |
156 | NULL\r | |
157 | );\r | |
158 | ASSERT_EFI_ERROR (Status);\r | |
159 | } else {\r | |
160 | //\r | |
161 | // This module must support to produce at least one of Unicode Collation Protocol\r | |
162 | // and Unicode Collation 2 Protocol.\r | |
163 | //\r | |
164 | ASSERT (FALSE);\r | |
165 | Status = EFI_UNSUPPORTED;\r | |
166 | }\r | |
167 | }\r | |
168 | \r | |
169 | return Status;\r | |
adbcbf8f | 170 | }\r |
171 | \r | |
61e33430 | 172 | \r |
173 | /**\r | |
4f077902 | 174 | Performs a case-insensitive comparison of two Null-terminated strings.\r |
61e33430 | 175 | \r |
176 | @param This Protocol instance pointer.\r | |
4f077902 SZ |
177 | @param Str1 A pointer to a Null-terminated string.\r |
178 | @param Str2 A pointer to a Null-terminated string.\r | |
61e33430 | 179 | \r |
180 | @retval 0 Str1 is equivalent to Str2\r | |
181 | @retval > 0 Str1 is lexically greater than Str2\r | |
182 | @retval < 0 Str1 is lexically less than Str2\r | |
183 | \r | |
184 | **/\r | |
adbcbf8f | 185 | INTN\r |
186 | EFIAPI\r | |
187 | EngStriColl (\r | |
188 | IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r | |
61e33430 | 189 | IN CHAR16 *Str1,\r |
190 | IN CHAR16 *Str2\r | |
adbcbf8f | 191 | )\r |
adbcbf8f | 192 | {\r |
ea7cb08c | 193 | while (*Str1 != 0) {\r |
194 | if (TO_UPPER (*Str1) != TO_UPPER (*Str2)) {\r | |
adbcbf8f | 195 | break;\r |
196 | }\r | |
197 | \r | |
61e33430 | 198 | Str1 += 1;\r |
199 | Str2 += 1;\r | |
adbcbf8f | 200 | }\r |
201 | \r | |
ea7cb08c | 202 | return TO_UPPER (*Str1) - TO_UPPER (*Str2);\r |
adbcbf8f | 203 | }\r |
204 | \r | |
61e33430 | 205 | \r |
206 | /**\r | |
4f077902 SZ |
207 | Converts all the characters in a Null-terminated string to \r |
208 | lower case characters.\r | |
61e33430 | 209 | \r |
210 | @param This Protocol instance pointer.\r | |
4f077902 | 211 | @param Str A pointer to a Null-terminated string.\r |
61e33430 | 212 | \r |
213 | **/\r | |
adbcbf8f | 214 | VOID\r |
215 | EFIAPI\r | |
216 | EngStrLwr (\r | |
217 | IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r | |
218 | IN OUT CHAR16 *Str\r | |
219 | )\r | |
adbcbf8f | 220 | {\r |
ea7cb08c | 221 | while (*Str != 0) {\r |
222 | *Str = TO_LOWER (*Str);\r | |
adbcbf8f | 223 | Str += 1;\r |
224 | }\r | |
225 | }\r | |
226 | \r | |
61e33430 | 227 | \r |
228 | /**\r | |
4f077902 SZ |
229 | Converts all the characters in a Null-terminated string to upper\r |
230 | case characters.\r | |
61e33430 | 231 | \r |
232 | @param This Protocol instance pointer.\r | |
4f077902 | 233 | @param Str A pointer to a Null-terminated string.\r |
61e33430 | 234 | \r |
235 | **/\r | |
adbcbf8f | 236 | VOID\r |
237 | EFIAPI\r | |
238 | EngStrUpr (\r | |
239 | IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r | |
240 | IN OUT CHAR16 *Str\r | |
241 | )\r | |
adbcbf8f | 242 | {\r |
ea7cb08c | 243 | while (*Str != 0) {\r |
244 | *Str = TO_UPPER (*Str);\r | |
adbcbf8f | 245 | Str += 1;\r |
246 | }\r | |
247 | }\r | |
248 | \r | |
61e33430 | 249 | /**\r |
4f077902 SZ |
250 | Performs a case-insensitive comparison of a Null-terminated\r |
251 | pattern string and a Null-terminated string.\r | |
61e33430 | 252 | \r |
253 | @param This Protocol instance pointer.\r | |
4f077902 SZ |
254 | @param String A pointer to a Null-terminated string.\r |
255 | @param Pattern A pointer to a Null-terminated pattern string.\r | |
61e33430 | 256 | \r |
257 | @retval TRUE Pattern was found in String.\r | |
258 | @retval FALSE Pattern was not found in String.\r | |
259 | \r | |
260 | **/\r | |
adbcbf8f | 261 | BOOLEAN\r |
262 | EFIAPI\r | |
263 | EngMetaiMatch (\r | |
264 | IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r | |
265 | IN CHAR16 *String,\r | |
266 | IN CHAR16 *Pattern\r | |
267 | )\r | |
adbcbf8f | 268 | {\r |
269 | CHAR16 CharC;\r | |
270 | CHAR16 CharP;\r | |
271 | CHAR16 Index3;\r | |
272 | \r | |
273 | for (;;) {\r | |
274 | CharP = *Pattern;\r | |
275 | Pattern += 1;\r | |
276 | \r | |
277 | switch (CharP) {\r | |
278 | case 0:\r | |
279 | //\r | |
280 | // End of pattern. If end of string, TRUE match\r | |
281 | //\r | |
ea7cb08c | 282 | if (*String != 0) {\r |
adbcbf8f | 283 | return FALSE;\r |
284 | } else {\r | |
285 | return TRUE;\r | |
286 | }\r | |
287 | \r | |
288 | case '*':\r | |
289 | //\r | |
290 | // Match zero or more chars\r | |
291 | //\r | |
ea7cb08c | 292 | while (*String != 0) {\r |
adbcbf8f | 293 | if (EngMetaiMatch (This, String, Pattern)) {\r |
294 | return TRUE;\r | |
295 | }\r | |
296 | \r | |
297 | String += 1;\r | |
298 | }\r | |
299 | \r | |
300 | return EngMetaiMatch (This, String, Pattern);\r | |
301 | \r | |
302 | case '?':\r | |
303 | //\r | |
304 | // Match any one char\r | |
305 | //\r | |
ea7cb08c | 306 | if (*String == 0) {\r |
adbcbf8f | 307 | return FALSE;\r |
308 | }\r | |
309 | \r | |
310 | String += 1;\r | |
311 | break;\r | |
312 | \r | |
313 | case '[':\r | |
314 | //\r | |
315 | // Match char set\r | |
316 | //\r | |
317 | CharC = *String;\r | |
ea7cb08c | 318 | if (CharC == 0) {\r |
adbcbf8f | 319 | //\r |
320 | // syntax problem\r | |
321 | //\r | |
322 | return FALSE;\r | |
323 | }\r | |
324 | \r | |
325 | Index3 = 0;\r | |
326 | CharP = *Pattern++;\r | |
ea7cb08c | 327 | while (CharP != 0) {\r |
adbcbf8f | 328 | if (CharP == ']') {\r |
329 | return FALSE;\r | |
330 | }\r | |
331 | \r | |
332 | if (CharP == '-') {\r | |
333 | //\r | |
334 | // if range of chars, get high range\r | |
335 | //\r | |
336 | CharP = *Pattern;\r | |
337 | if (CharP == 0 || CharP == ']') {\r | |
338 | //\r | |
339 | // syntax problem\r | |
340 | //\r | |
341 | return FALSE;\r | |
342 | }\r | |
343 | \r | |
ea7cb08c | 344 | if (TO_UPPER (CharC) >= TO_UPPER (Index3) && TO_UPPER (CharC) <= TO_UPPER (CharP)) {\r |
adbcbf8f | 345 | //\r |
346 | // if in range, it's a match\r | |
347 | //\r | |
348 | break;\r | |
349 | }\r | |
350 | }\r | |
351 | \r | |
352 | Index3 = CharP;\r | |
ea7cb08c | 353 | if (TO_UPPER (CharC) == TO_UPPER (CharP)) {\r |
adbcbf8f | 354 | //\r |
355 | // if char matches\r | |
356 | //\r | |
357 | break;\r | |
358 | }\r | |
359 | \r | |
360 | CharP = *Pattern++;\r | |
361 | }\r | |
362 | //\r | |
363 | // skip to end of match char set\r | |
364 | //\r | |
ea7cb08c | 365 | while ((CharP != 0) && (CharP != ']')) {\r |
adbcbf8f | 366 | CharP = *Pattern;\r |
367 | Pattern += 1;\r | |
368 | }\r | |
369 | \r | |
370 | String += 1;\r | |
371 | break;\r | |
372 | \r | |
373 | default:\r | |
374 | CharC = *String;\r | |
ea7cb08c | 375 | if (TO_UPPER (CharC) != TO_UPPER (CharP)) {\r |
adbcbf8f | 376 | return FALSE;\r |
377 | }\r | |
378 | \r | |
379 | String += 1;\r | |
380 | break;\r | |
381 | }\r | |
382 | }\r | |
383 | }\r | |
384 | \r | |
61e33430 | 385 | \r |
386 | /**\r | |
4f077902 | 387 | Converts an 8.3 FAT file name in an OEM character set to a Null-terminated string.\r |
61e33430 | 388 | \r |
389 | @param This Protocol instance pointer.\r | |
390 | @param FatSize The size of the string Fat in bytes.\r | |
391 | @param Fat A pointer to a Null-terminated string that contains an 8.3 file\r | |
4f077902 SZ |
392 | name using an 8-bit OEM character set.\r |
393 | @param String A pointer to a Null-terminated string. The string must\r | |
394 | be preallocated to hold FatSize characters.\r | |
61e33430 | 395 | \r |
396 | **/\r | |
adbcbf8f | 397 | VOID\r |
398 | EFIAPI\r | |
399 | EngFatToStr (\r | |
400 | IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r | |
401 | IN UINTN FatSize,\r | |
402 | IN CHAR8 *Fat,\r | |
403 | OUT CHAR16 *String\r | |
404 | )\r | |
adbcbf8f | 405 | {\r |
406 | //\r | |
407 | // No DBCS issues, just expand and add null terminate to end of string\r | |
408 | //\r | |
ea7cb08c | 409 | while ((*Fat != 0) && (FatSize != 0)) {\r |
adbcbf8f | 410 | *String = *Fat;\r |
411 | String += 1;\r | |
412 | Fat += 1;\r | |
413 | FatSize -= 1;\r | |
414 | }\r | |
415 | \r | |
416 | *String = 0;\r | |
417 | }\r | |
418 | \r | |
61e33430 | 419 | \r |
420 | /**\r | |
4f077902 | 421 | Converts a Null-terminated string to legal characters in a FAT \r |
61e33430 | 422 | filename using an OEM character set. \r |
423 | \r | |
424 | @param This Protocol instance pointer.\r | |
4f077902 SZ |
425 | @param String A pointer to a Null-terminated string. The string must\r |
426 | be preallocated to hold FatSize characters.\r | |
61e33430 | 427 | @param FatSize The size of the string Fat in bytes.\r |
428 | @param Fat A pointer to a Null-terminated string that contains an 8.3 file\r | |
429 | name using an OEM character set.\r | |
430 | \r | |
431 | @retval TRUE Fat is a Long File Name\r | |
432 | @retval FALSE Fat is an 8.3 file name\r | |
433 | \r | |
434 | **/\r | |
adbcbf8f | 435 | BOOLEAN\r |
436 | EFIAPI\r | |
437 | EngStrToFat (\r | |
438 | IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r | |
439 | IN CHAR16 *String,\r | |
440 | IN UINTN FatSize,\r | |
441 | OUT CHAR8 *Fat\r | |
442 | )\r | |
adbcbf8f | 443 | {\r |
444 | BOOLEAN SpecialCharExist;\r | |
445 | \r | |
446 | SpecialCharExist = FALSE;\r | |
ea7cb08c | 447 | while ((*String != 0) && (FatSize != 0)) {\r |
adbcbf8f | 448 | //\r |
449 | // Skip '.' or ' ' when making a fat name\r | |
450 | //\r | |
451 | if (*String != '.' && *String != ' ') {\r | |
452 | //\r | |
453 | // If this is a valid fat char, move it.\r | |
48557c65 | 454 | // Otherwise, move a '_' and flag the fact that the name needs a long file name.\r |
adbcbf8f | 455 | //\r |
48557c65 | 456 | if (*String < MAP_TABLE_SIZE && ((mEngInfoMap[*String] & CHAR_FAT_VALID) != 0)) {\r |
adbcbf8f | 457 | *Fat = mEngUpperMap[*String];\r |
458 | } else {\r | |
459 | *Fat = '_';\r | |
460 | SpecialCharExist = TRUE;\r | |
461 | }\r | |
462 | \r | |
463 | Fat += 1;\r | |
464 | FatSize -= 1;\r | |
465 | }\r | |
466 | \r | |
467 | String += 1;\r | |
468 | }\r | |
469 | //\r | |
470 | // Do not terminate that fat string\r | |
471 | //\r | |
472 | return SpecialCharExist;\r | |
473 | }\r |