]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Compatibility/UcOnUc2Thunk/UcOnUc2Thunk.c
Retire language conversion APIs from HII library class.
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / UcOnUc2Thunk / UcOnUc2Thunk.c
CommitLineData
a432c703 1/** @file\r
2Module produce UC on top of UC2.\r
3\r
4UEFI 2.1 specification supersedes Inte's EFI Specification 1.10.\r
5UNICODE_COLLATION_PROTOCOL defined in Inte's EFI Specification 1.10 is replaced by\r
6EFI_UNICODE_COLLATION_PROTOCOL in UEFI 2.1.\r
7This module produces UC on top of UC2. This module is used on platform when both of\r
8these two conditions are true:\r
91) EFI 1.10 module consuming UC present\r
102) And the rest of modules on the platform produce UC2\r
11\r
12Copyright (c) 2006 - 2008 Intel Corporation. <BR>\r
13All rights reserved. This program and the accompanying materials\r
14are licensed and made available under the terms and conditions of the BSD License\r
15which accompanies this distribution. The full text of the license may be found at\r
16http://opensource.org/licenses/bsd-license.php\r
17\r
18THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
19WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
20Module Name:\r
21\r
22**/\r
23\r
24#include <PiDxe.h>\r
25#include <Protocol/UnicodeCollation.h>\r
26#include <Library/BaseLib.h>\r
27#include <Library/DebugLib.h>\r
28#include <Library/UefiBootServicesTableLib.h>\r
29#include <Library/UefiDriverEntryPoint.h>\r
30#include <Library/UefiLib.h>\r
31#include <Library/MemoryAllocationLib.h>\r
32#include <Library/HiiLib.h>\r
ad5a96ab 33#include <Library/BaseMemoryLib.h>\r
a432c703 34\r
35\r
974a0271 36///\r
37/// The size of a 3 character ISO639 language code.\r
38///\r
39#define ISO_639_2_ENTRY_SIZE 3\r
40\r
ad5a96ab 41//\r
42// Lookup table of ISO639-2 3 character language codes to ISO 639-1 2 character language codes\r
43// Each entry is 5 CHAR8 values long. The first 3 CHAR8 values are the ISO 639-2 code.\r
44// The last 2 CHAR8 values are the ISO 639-1 code.\r
45//\r
46GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 Iso639ToRfc3066ConversionTable[] =\r
47"\\r
48aaraa\\r
49abkab\\r
50afraf\\r
51amham\\r
52araar\\r
53asmas\\r
54aymay\\r
55azeaz\\r
56bakba\\r
57belbe\\r
58benbn\\r
59bihbh\\r
60bisbi\\r
61bodbo\\r
62brebr\\r
63bulbg\\r
64catca\\r
65cescs\\r
66corkw\\r
67cosco\\r
68cymcy\\r
69danda\\r
70deude\\r
71dzodz\\r
72ellel\\r
73engen\\r
74epoeo\\r
75estet\\r
76euseu\\r
77faofo\\r
78fasfa\\r
79fijfj\\r
80finfi\\r
81frafr\\r
82fryfy\\r
83gaiga\\r
84gdhgd\\r
85glggl\\r
86grngn\\r
87gujgu\\r
88hauha\\r
89hebhe\\r
90hinhi\\r
91hrvhr\\r
92hunhu\\r
93hyehy\\r
94ikuiu\\r
95ileie\\r
96inaia\\r
97indid\\r
98ipkik\\r
99islis\\r
100itait\\r
101jawjw\\r
102jpnja\\r
103kalkl\\r
104kankn\\r
105kasks\\r
106katka\\r
107kazkk\\r
108khmkm\\r
109kinrw\\r
110kirky\\r
111korko\\r
112kurku\\r
113laolo\\r
114latla\\r
115lavlv\\r
116linln\\r
117litlt\\r
118ltzlb\\r
119malml\\r
120marmr\\r
121mkdmk\\r
122mlgmg\\r
123mltmt\\r
124molmo\\r
125monmn\\r
126mrimi\\r
127msams\\r
128myamy\\r
129nauna\\r
130nepne\\r
131nldnl\\r
132norno\\r
133ocioc\\r
134ormom\\r
135panpa\\r
136polpl\\r
137porpt\\r
138pusps\\r
139quequ\\r
140rohrm\\r
141ronro\\r
142runrn\\r
143rusru\\r
144sagsg\\r
145sansa\\r
146sinsi\\r
147slksk\\r
148slvsl\\r
149smise\\r
150smosm\\r
151snasn\\r
152sndsd\\r
153somso\\r
154sotst\\r
155spaes\\r
156sqisq\\r
157srpsr\\r
158sswss\\r
159sunsu\\r
160swasw\\r
161swesv\\r
162tamta\\r
163tattt\\r
164telte\\r
165tgktg\\r
166tgltl\\r
167thath\\r
168tsnts\\r
169tuktk\\r
170twitw\\r
171uigug\\r
172ukruk\\r
173urdur\\r
174uzbuz\\r
175vievi\\r
176volvo\\r
177wolwo\\r
178xhoxh\\r
179yidyi\\r
180zhaza\\r
181zhozh\\r
182zulzu\\r
183";\r
184\r
185/**\r
186 Convert language code from RFC3066 to ISO639-2.\r
187\r
188 @param LanguageRfc3066 RFC3066 language code.\r
189 @param LanguageIso639 ISO639-2 language code.\r
190\r
191 @retval EFI_SUCCESS Language code converted.\r
192 @retval EFI_NOT_FOUND Language code not found.\r
193\r
194**/\r
195EFI_STATUS\r
196EFIAPI\r
197ConvertRfc3066LanguageToIso639Language (\r
198 IN CHAR8 *LanguageRfc3066,\r
199 OUT CHAR8 *LanguageIso639\r
200 )\r
201{\r
202 UINTN Index;\r
203\r
204 if ((LanguageRfc3066[2] != '-') && (LanguageRfc3066[2] != 0)) {\r
205 CopyMem (LanguageIso639, LanguageRfc3066, 3);\r
206 return EFI_SUCCESS;\r
207 }\r
208\r
209 for (Index = 0; Iso639ToRfc3066ConversionTable[Index] != 0; Index += 5) {\r
210 if (CompareMem (LanguageRfc3066, &Iso639ToRfc3066ConversionTable[Index + 3], 2) == 0) {\r
211 CopyMem (LanguageIso639, &Iso639ToRfc3066ConversionTable[Index], 3);\r
212 return EFI_SUCCESS;\r
213 }\r
214 }\r
215\r
216 return EFI_NOT_FOUND;\r
217}\r
a432c703 218\r
219/**\r
220 Performs a case-insensitive comparison of two Null-terminated Unicode \r
221 strings.\r
222\r
223 @param This Protocol instance pointer.\r
224 @param Str1 A pointer to a Null-terminated Unicode string.\r
225 @param Str2 A pointer to a Null-terminated Unicode string.\r
226\r
227 @retval 0 Str1 is equivalent to Str2\r
228 @retval > 0 Str1 is lexically greater than Str2\r
229 @retval < 0 Str1 is lexically less than Str2\r
230\r
231**/\r
232INTN\r
233EFIAPI\r
234StriColl (\r
235 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
236 IN CHAR16 *Str1,\r
237 IN CHAR16 *Str2\r
e00e1d46 238 );\r
a432c703 239\r
240/**\r
241 Converts all the Unicode characters in a Null-terminated Unicode string to \r
242 lower case Unicode characters.\r
243\r
244 @param This Protocol instance pointer.\r
245 @param Str A pointer to a Null-terminated Unicode string.\r
246\r
247**/\r
248VOID\r
249EFIAPI\r
250StrLwr (\r
251 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
252 IN OUT CHAR16 *Str\r
e00e1d46 253 );\r
a432c703 254\r
255/**\r
256 Converts all the Unicode characters in a Null-terminated Unicode string to upper\r
257 case Unicode characters.\r
258\r
259 @param This Protocol instance pointer.\r
260 @param Str A pointer to a Null-terminated Unicode string.\r
261\r
262**/\r
263VOID\r
264EFIAPI\r
265StrUpr (\r
266 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
267 IN OUT CHAR16 *Str\r
e00e1d46 268 );\r
a432c703 269\r
270/**\r
271 Performs a case-insensitive comparison of a Null-terminated Unicode \r
272 pattern string and a Null-terminated Unicode string.\r
273\r
274 @param This Protocol instance pointer.\r
275 @param String A pointer to a Null-terminated Unicode string.\r
276 @param Pattern A pointer to a Null-terminated Unicode pattern string.\r
277\r
278 @retval TRUE Pattern was found in String.\r
279 @retval FALSE Pattern was not found in String.\r
280\r
281**/\r
282BOOLEAN\r
283EFIAPI\r
284MetaiMatch (\r
285 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
286 IN CHAR16 *String,\r
287 IN CHAR16 *Pattern\r
e00e1d46 288 );\r
a432c703 289\r
290/**\r
291 Converts an 8.3 FAT file name in an OEM character set to a Null-terminated \r
292 Unicode string.\r
293\r
294 @param This Protocol instance pointer.\r
295 @param FatSize The size of the string Fat in bytes.\r
296 @param Fat A pointer to a Null-terminated string that contains an 8.3 file\r
297 name using an OEM character set.\r
298 @param String A pointer to a Null-terminated Unicode string. The string must\r
299 be preallocated to hold FatSize Unicode characters.\r
300\r
301**/\r
302VOID\r
303EFIAPI\r
304FatToStr (\r
305 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
306 IN UINTN FatSize,\r
307 IN CHAR8 *Fat,\r
308 OUT CHAR16 *String\r
e00e1d46 309 );\r
a432c703 310\r
311/**\r
312 Converts a Null-terminated Unicode string to legal characters in a FAT \r
313 filename using an OEM character set. \r
314\r
315 @param This Protocol instance pointer.\r
316 @param String A pointer to a Null-terminated Unicode string. The string must\r
317 be preallocated to hold FatSize Unicode characters.\r
318 @param FatSize The size of the string Fat in bytes.\r
319 @param Fat A pointer to a Null-terminated string that contains an 8.3 file\r
320 name using an OEM character set.\r
321\r
322 @retval TRUE Fat is a Long File Name\r
323 @retval FALSE Fat is an 8.3 file name\r
324\r
325**/\r
326BOOLEAN\r
327EFIAPI\r
328StrToFat (\r
329 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
330 IN CHAR16 *String,\r
331 IN UINTN FatSize,\r
332 OUT CHAR8 *Fat\r
e00e1d46 333 );\r
a432c703 334\r
a3a83173 335#define UC_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('_', 'U', 'C', '_')\r
a432c703 336\r
337typedef struct {\r
338 UINT32 Signature;\r
339 EFI_UNICODE_COLLATION_PROTOCOL UC;\r
340 EFI_UNICODE_COLLATION_PROTOCOL *UC2;\r
341} UC_PRIVATE_DATA;\r
342\r
343#define UC_PRIVATE_DATA_FROM_THIS(a) CR (a, UC_PRIVATE_DATA, UC, UC_PRIVATE_DATA_SIGNATURE)\r
344\r
345//\r
346// Firmware Volume Protocol template\r
347//\r
348EFI_EVENT mUcRegistration;\r
349\r
350UC_PRIVATE_DATA gUCPrivateDataTemplate = {\r
351 UC_PRIVATE_DATA_SIGNATURE,\r
352 {\r
353 StriColl,\r
354 MetaiMatch,\r
355 StrLwr,\r
356 StrUpr,\r
357 FatToStr,\r
358 StrToFat,\r
359 NULL\r
360 },\r
361 NULL\r
362};\r
363\r
364//\r
365// Module globals\r
366//\r
367\r
368VOID\r
369EFIAPI\r
370Uc2NotificationEvent (\r
371 IN EFI_EVENT Event,\r
372 IN VOID *Context\r
373 )\r
374{\r
375 EFI_STATUS Status;\r
376 UINTN BufferSize;\r
377 EFI_HANDLE Handle;\r
378 UC_PRIVATE_DATA *Private;\r
379 EFI_UNICODE_COLLATION_PROTOCOL *Uc2;\r
380\r
381 while (TRUE) {\r
382 BufferSize = sizeof (Handle);\r
383 Status = gBS->LocateHandle (\r
384 ByRegisterNotify,\r
385 &gEfiUnicodeCollation2ProtocolGuid,\r
386 mUcRegistration,\r
387 &BufferSize,\r
388 &Handle\r
389 );\r
390 if (EFI_ERROR (Status)) {\r
391 //\r
392 // Exit Path of While Loop....\r
393 //\r
394 break;\r
395 }\r
396\r
397 //\r
398 // Skip this handle if the Firmware Volume Protocol is already installed\r
399 //\r
400 Status = gBS->HandleProtocol (\r
401 Handle,\r
402 &gEfiUnicodeCollationProtocolGuid,\r
403 (VOID **)&Uc2\r
404 );\r
405 if (!EFI_ERROR (Status)) {\r
406 continue;\r
407 }\r
408\r
409 //\r
410 // Allocate private data structure\r
411 //\r
412 Private = AllocateCopyPool (sizeof (UC_PRIVATE_DATA), &gUCPrivateDataTemplate);\r
413 if (Private == NULL) {\r
414 continue;\r
415 }\r
416\r
417 //\r
418 // Retrieve the UC Protocol\r
419 //\r
420 Status = gBS->HandleProtocol (\r
421 Handle,\r
422 &gEfiUnicodeCollation2ProtocolGuid,\r
423 (VOID **)&Private->UC2\r
424 );\r
425 ASSERT_EFI_ERROR (Status);\r
426\r
427 //\r
428 // Fill in rest of private data structure\r
429 //\r
430 Private->UC.SupportedLanguages = AllocateZeroPool (ISO_639_2_ENTRY_SIZE + 1);\r
431 Status = ConvertRfc3066LanguageToIso639Language (Private->UC2->SupportedLanguages, Private->UC.SupportedLanguages);\r
432\r
433 if (!EFI_ERROR (Status)) {\r
434\r
435 //\r
436 // Install Firmware Volume Protocol onto same handle\r
437 //\r
438 Status = gBS->InstallMultipleProtocolInterfaces (\r
439 &Handle,\r
440 &gEfiUnicodeCollationProtocolGuid,\r
441 &Private->UC,\r
442 NULL\r
443 );\r
444 ASSERT_EFI_ERROR (Status);\r
445 }\r
446 }\r
447}\r
448\r
449\r
450/**\r
451 The user Entry Point for DXE driver. The user code starts with this function\r
452 as the real entry point for the image goes into a library that calls this \r
453 function.\r
454\r
455 @param[in] ImageHandle The firmware allocated handle for the EFI image. \r
456 @param[in] SystemTable A pointer to the EFI System Table.\r
457 \r
458 @retval EFI_SUCCESS The entry point is executed successfully.\r
459 @retval other Some error occurs when executing this entry point.\r
460\r
461**/\r
462EFI_STATUS\r
463EFIAPI\r
464InitializeUC (\r
465 IN EFI_HANDLE ImageHandle,\r
466 IN EFI_SYSTEM_TABLE *SystemTable\r
467 )\r
468{\r
469 EfiCreateProtocolNotifyEvent (\r
185be2e0 470 &gEfiUnicodeCollation2ProtocolGuid,\r
a432c703 471 TPL_CALLBACK,\r
472 Uc2NotificationEvent,\r
473 NULL,\r
474 &mUcRegistration\r
475 );\r
476 return EFI_SUCCESS;\r
477}\r
478\r
479\r
480/**\r
481 Performs a case-insensitive comparison of two Null-terminated Unicode \r
482 strings.\r
483\r
484 @param This Protocol instance pointer.\r
485 @param Str1 A pointer to a Null-terminated Unicode string.\r
486 @param Str2 A pointer to a Null-terminated Unicode string.\r
487\r
488 @retval 0 Str1 is equivalent to Str2\r
489 @retval > 0 Str1 is lexically greater than Str2\r
490 @retval < 0 Str1 is lexically less than Str2\r
491\r
492**/\r
493INTN\r
494EFIAPI\r
495StriColl (\r
496 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
497 IN CHAR16 *Str1,\r
498 IN CHAR16 *Str2\r
499 )\r
500{\r
501 UC_PRIVATE_DATA *Private;\r
502 \r
503 Private = UC_PRIVATE_DATA_FROM_THIS (This);\r
504 \r
505 return Private->UC2->StriColl (Private->UC2, Str1, Str2);\r
506}\r
507\r
508\r
509/**\r
510 Converts all the Unicode characters in a Null-terminated Unicode string to \r
511 lower case Unicode characters.\r
512\r
513 @param This Protocol instance pointer.\r
514 @param Str A pointer to a Null-terminated Unicode string.\r
515\r
516**/\r
517VOID\r
518EFIAPI\r
519StrLwr (\r
520 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
521 IN OUT CHAR16 *Str\r
522 )\r
523{\r
524 UC_PRIVATE_DATA *Private;\r
525 \r
526 Private = UC_PRIVATE_DATA_FROM_THIS (This);\r
527 \r
528 Private->UC2->StrLwr (Private->UC2, Str);\r
529}\r
530\r
531\r
532/**\r
533 Converts all the Unicode characters in a Null-terminated Unicode string to upper\r
534 case Unicode characters.\r
535\r
536 @param This Protocol instance pointer.\r
537 @param Str A pointer to a Null-terminated Unicode string.\r
538\r
539**/\r
540VOID\r
541EFIAPI\r
542StrUpr (\r
543 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
544 IN OUT CHAR16 *Str\r
545 )\r
546{\r
547 UC_PRIVATE_DATA *Private;\r
548 \r
549 Private = UC_PRIVATE_DATA_FROM_THIS (This);\r
550 \r
551 Private->UC2->StrUpr (Private->UC2, Str);\r
552}\r
553\r
554/**\r
555 Performs a case-insensitive comparison of a Null-terminated Unicode \r
556 pattern string and a Null-terminated Unicode string.\r
557\r
558 @param This Protocol instance pointer.\r
559 @param String A pointer to a Null-terminated Unicode string.\r
560 @param Pattern A pointer to a Null-terminated Unicode pattern string.\r
561\r
562 @retval TRUE Pattern was found in String.\r
563 @retval FALSE Pattern was not found in String.\r
564\r
565**/\r
566BOOLEAN\r
567EFIAPI\r
568MetaiMatch (\r
569 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
570 IN CHAR16 *String,\r
571 IN CHAR16 *Pattern\r
572 )\r
573{\r
574 UC_PRIVATE_DATA *Private;\r
575 \r
576 Private = UC_PRIVATE_DATA_FROM_THIS (This);\r
577 \r
578 return Private->UC2->MetaiMatch (Private->UC2, String, Pattern);\r
579}\r
580\r
581\r
582/**\r
583 Converts an 8.3 FAT file name in an OEM character set to a Null-terminated \r
584 Unicode string.\r
585\r
586 @param This Protocol instance pointer.\r
587 @param FatSize The size of the string Fat in bytes.\r
588 @param Fat A pointer to a Null-terminated string that contains an 8.3 file\r
589 name using an OEM character set.\r
590 @param String A pointer to a Null-terminated Unicode string. The string must\r
591 be preallocated to hold FatSize Unicode characters.\r
592\r
593**/\r
594VOID\r
595EFIAPI\r
596FatToStr (\r
597 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
598 IN UINTN FatSize,\r
599 IN CHAR8 *Fat,\r
600 OUT CHAR16 *String\r
601 )\r
602{\r
603 UC_PRIVATE_DATA *Private;\r
604 \r
605 Private = UC_PRIVATE_DATA_FROM_THIS (This);\r
606 \r
607 Private->UC2->FatToStr (Private->UC2, FatSize, Fat, String);\r
608}\r
609\r
610\r
611/**\r
612 Converts a Null-terminated Unicode string to legal characters in a FAT \r
613 filename using an OEM character set. \r
614\r
615 @param This Protocol instance pointer.\r
616 @param String A pointer to a Null-terminated Unicode string. The string must\r
617 be preallocated to hold FatSize Unicode characters.\r
618 @param FatSize The size of the string Fat in bytes.\r
619 @param Fat A pointer to a Null-terminated string that contains an 8.3 file\r
620 name using an OEM character set.\r
621\r
622 @retval TRUE Fat is a Long File Name\r
623 @retval FALSE Fat is an 8.3 file name\r
624\r
625**/\r
626BOOLEAN\r
627EFIAPI\r
628StrToFat (\r
629 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
630 IN CHAR16 *String,\r
631 IN UINTN FatSize,\r
632 OUT CHAR8 *Fat\r
633 )\r
634{\r
635 UC_PRIVATE_DATA *Private;\r
636 \r
637 Private = UC_PRIVATE_DATA_FROM_THIS (This);\r
638 \r
639 return Private->UC2->StrToFat (Private->UC2, String, FatSize, Fat);\r
640}\r
641\r