]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/UnicodeCollationEng.c
Update the copyright notice format
[mirror_edk2.git] / MdeModulePkg / Universal / Disk / UnicodeCollation / EnglishDxe / UnicodeCollationEng.c
... / ...
CommitLineData
1/** @file\r
2 Driver to implement English version of Unicode Collation Protocol.\r
3\r
4Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15\r
16#include "UnicodeCollationEng.h"\r
17\r
18CHAR8 mEngUpperMap[MAP_TABLE_SIZE];\r
19CHAR8 mEngLowerMap[MAP_TABLE_SIZE];\r
20CHAR8 mEngInfoMap[MAP_TABLE_SIZE];\r
21\r
22CHAR8 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
54EFI_HANDLE mHandle = NULL;\r
55\r
56//\r
57// EFI Unicode Collation Protocol supporting ISO 639-2 language code\r
58//\r
59GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_COLLATION_PROTOCOL UnicodeEng = {\r
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
70// EFI Unicode Collation2 Protocol supporting RFC 4646 language code\r
71//\r
72GLOBAL_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
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
95EFI_STATUS\r
96EFIAPI\r
97InitializeUnicodeCollationEng (\r
98 IN EFI_HANDLE ImageHandle,\r
99 IN EFI_SYSTEM_TABLE *SystemTable\r
100 )\r
101{\r
102 EFI_STATUS Status;\r
103 UINTN Index;\r
104 UINTN Index2;\r
105\r
106 //\r
107 // Initialize mapping tables for the supported languages\r
108 //\r
109 for (Index = 0; Index < MAP_TABLE_SIZE; Index++) {\r
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
125 for (Index = 0; mOtherChars[Index] != 0; Index++) {\r
126 Index2 = mOtherChars[Index];\r
127 mEngInfoMap[Index2] |= CHAR_FAT_VALID;\r
128 }\r
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
170}\r
171\r
172\r
173/**\r
174 Performs a case-insensitive comparison of two Null-terminated Unicode \r
175 strings.\r
176\r
177 @param This Protocol instance pointer.\r
178 @param Str1 A pointer to a Null-terminated Unicode string.\r
179 @param Str2 A pointer to a Null-terminated Unicode string.\r
180\r
181 @retval 0 Str1 is equivalent to Str2\r
182 @retval > 0 Str1 is lexically greater than Str2\r
183 @retval < 0 Str1 is lexically less than Str2\r
184\r
185**/\r
186INTN\r
187EFIAPI\r
188EngStriColl (\r
189 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
190 IN CHAR16 *Str1,\r
191 IN CHAR16 *Str2\r
192 )\r
193{\r
194 while (*Str1 != 0) {\r
195 if (TO_UPPER (*Str1) != TO_UPPER (*Str2)) {\r
196 break;\r
197 }\r
198\r
199 Str1 += 1;\r
200 Str2 += 1;\r
201 }\r
202\r
203 return TO_UPPER (*Str1) - TO_UPPER (*Str2);\r
204}\r
205\r
206\r
207/**\r
208 Converts all the Unicode characters in a Null-terminated Unicode string to \r
209 lower case Unicode characters.\r
210\r
211 @param This Protocol instance pointer.\r
212 @param Str A pointer to a Null-terminated Unicode string.\r
213\r
214**/\r
215VOID\r
216EFIAPI\r
217EngStrLwr (\r
218 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
219 IN OUT CHAR16 *Str\r
220 )\r
221{\r
222 while (*Str != 0) {\r
223 *Str = TO_LOWER (*Str);\r
224 Str += 1;\r
225 }\r
226}\r
227\r
228\r
229/**\r
230 Converts all the Unicode characters in a Null-terminated Unicode string to upper\r
231 case Unicode characters.\r
232\r
233 @param This Protocol instance pointer.\r
234 @param Str A pointer to a Null-terminated Unicode string.\r
235\r
236**/\r
237VOID\r
238EFIAPI\r
239EngStrUpr (\r
240 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
241 IN OUT CHAR16 *Str\r
242 )\r
243{\r
244 while (*Str != 0) {\r
245 *Str = TO_UPPER (*Str);\r
246 Str += 1;\r
247 }\r
248}\r
249\r
250/**\r
251 Performs a case-insensitive comparison of a Null-terminated Unicode \r
252 pattern string and a Null-terminated Unicode string.\r
253\r
254 @param This Protocol instance pointer.\r
255 @param String A pointer to a Null-terminated Unicode string.\r
256 @param Pattern A pointer to a Null-terminated Unicode pattern string.\r
257\r
258 @retval TRUE Pattern was found in String.\r
259 @retval FALSE Pattern was not found in String.\r
260\r
261**/\r
262BOOLEAN\r
263EFIAPI\r
264EngMetaiMatch (\r
265 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
266 IN CHAR16 *String,\r
267 IN CHAR16 *Pattern\r
268 )\r
269{\r
270 CHAR16 CharC;\r
271 CHAR16 CharP;\r
272 CHAR16 Index3;\r
273\r
274 for (;;) {\r
275 CharP = *Pattern;\r
276 Pattern += 1;\r
277\r
278 switch (CharP) {\r
279 case 0:\r
280 //\r
281 // End of pattern. If end of string, TRUE match\r
282 //\r
283 if (*String != 0) {\r
284 return FALSE;\r
285 } else {\r
286 return TRUE;\r
287 }\r
288\r
289 case '*':\r
290 //\r
291 // Match zero or more chars\r
292 //\r
293 while (*String != 0) {\r
294 if (EngMetaiMatch (This, String, Pattern)) {\r
295 return TRUE;\r
296 }\r
297\r
298 String += 1;\r
299 }\r
300\r
301 return EngMetaiMatch (This, String, Pattern);\r
302\r
303 case '?':\r
304 //\r
305 // Match any one char\r
306 //\r
307 if (*String == 0) {\r
308 return FALSE;\r
309 }\r
310\r
311 String += 1;\r
312 break;\r
313\r
314 case '[':\r
315 //\r
316 // Match char set\r
317 //\r
318 CharC = *String;\r
319 if (CharC == 0) {\r
320 //\r
321 // syntax problem\r
322 //\r
323 return FALSE;\r
324 }\r
325\r
326 Index3 = 0;\r
327 CharP = *Pattern++;\r
328 while (CharP != 0) {\r
329 if (CharP == ']') {\r
330 return FALSE;\r
331 }\r
332\r
333 if (CharP == '-') {\r
334 //\r
335 // if range of chars, get high range\r
336 //\r
337 CharP = *Pattern;\r
338 if (CharP == 0 || CharP == ']') {\r
339 //\r
340 // syntax problem\r
341 //\r
342 return FALSE;\r
343 }\r
344\r
345 if (TO_UPPER (CharC) >= TO_UPPER (Index3) && TO_UPPER (CharC) <= TO_UPPER (CharP)) {\r
346 //\r
347 // if in range, it's a match\r
348 //\r
349 break;\r
350 }\r
351 }\r
352\r
353 Index3 = CharP;\r
354 if (TO_UPPER (CharC) == TO_UPPER (CharP)) {\r
355 //\r
356 // if char matches\r
357 //\r
358 break;\r
359 }\r
360\r
361 CharP = *Pattern++;\r
362 }\r
363 //\r
364 // skip to end of match char set\r
365 //\r
366 while ((CharP != 0) && (CharP != ']')) {\r
367 CharP = *Pattern;\r
368 Pattern += 1;\r
369 }\r
370\r
371 String += 1;\r
372 break;\r
373\r
374 default:\r
375 CharC = *String;\r
376 if (TO_UPPER (CharC) != TO_UPPER (CharP)) {\r
377 return FALSE;\r
378 }\r
379\r
380 String += 1;\r
381 break;\r
382 }\r
383 }\r
384}\r
385\r
386\r
387/**\r
388 Converts an 8.3 FAT file name in an OEM character set to a Null-terminated \r
389 Unicode string.\r
390\r
391 @param This Protocol instance pointer.\r
392 @param FatSize The size of the string Fat in bytes.\r
393 @param Fat A pointer to a Null-terminated string that contains an 8.3 file\r
394 name using an OEM character set.\r
395 @param String A pointer to a Null-terminated Unicode string. The string must\r
396 be preallocated to hold FatSize Unicode characters.\r
397\r
398**/\r
399VOID\r
400EFIAPI\r
401EngFatToStr (\r
402 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
403 IN UINTN FatSize,\r
404 IN CHAR8 *Fat,\r
405 OUT CHAR16 *String\r
406 )\r
407{\r
408 //\r
409 // No DBCS issues, just expand and add null terminate to end of string\r
410 //\r
411 while ((*Fat != 0) && (FatSize != 0)) {\r
412 *String = *Fat;\r
413 String += 1;\r
414 Fat += 1;\r
415 FatSize -= 1;\r
416 }\r
417\r
418 *String = 0;\r
419}\r
420\r
421\r
422/**\r
423 Converts a Null-terminated Unicode string to legal characters in a FAT \r
424 filename using an OEM character set. \r
425\r
426 @param This Protocol instance pointer.\r
427 @param String A pointer to a Null-terminated Unicode string. The string must\r
428 be preallocated to hold FatSize Unicode characters.\r
429 @param FatSize The size of the string Fat in bytes.\r
430 @param Fat A pointer to a Null-terminated string that contains an 8.3 file\r
431 name using an OEM character set.\r
432\r
433 @retval TRUE Fat is a Long File Name\r
434 @retval FALSE Fat is an 8.3 file name\r
435\r
436**/\r
437BOOLEAN\r
438EFIAPI\r
439EngStrToFat (\r
440 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
441 IN CHAR16 *String,\r
442 IN UINTN FatSize,\r
443 OUT CHAR8 *Fat\r
444 )\r
445{\r
446 BOOLEAN SpecialCharExist;\r
447\r
448 SpecialCharExist = FALSE;\r
449 while ((*String != 0) && (FatSize != 0)) {\r
450 //\r
451 // Skip '.' or ' ' when making a fat name\r
452 //\r
453 if (*String != '.' && *String != ' ') {\r
454 //\r
455 // If this is a valid fat char, move it.\r
456 // Otherwise, move a '_' and flag the fact that the name needs a long file name.\r
457 //\r
458 if (*String < MAP_TABLE_SIZE && ((mEngInfoMap[*String] & CHAR_FAT_VALID) != 0)) {\r
459 *Fat = mEngUpperMap[*String];\r
460 } else {\r
461 *Fat = '_';\r
462 SpecialCharExist = TRUE;\r
463 }\r
464\r
465 Fat += 1;\r
466 FatSize -= 1;\r
467 }\r
468\r
469 String += 1;\r
470 }\r
471 //\r
472 // Do not terminate that fat string\r
473 //\r
474 return SpecialCharExist;\r
475}\r