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