]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Compatibility/Uc2OnUcThunk/Uc2OnUcThunk.c
Retire language conversion APIs from HII library class.
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / Uc2OnUcThunk / Uc2OnUcThunk.c
CommitLineData
03e6b4b2 1/** @file\r
2Module produce UC2 on top of UC.\r
3\r
4UEFI 2.1 specification supersedes Inte's EFI Specification 1.10.\r
5EFI_UNICODE_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 UC2 on top of UC. This module is used on platform when both of\r
8these two conditions are true:\r
91) EFI 1.10 module producing UC present\r
102) And the rest of modules on the platform consume 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
03e6b4b2 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
03e6b4b2 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 ISO639-2 to RFC3066 and return the converted language.\r
187 Caller is responsible for freeing the allocated buffer.\r
188\r
189 LanguageIso639 contain a single ISO639-2 code such as\r
190 "eng" or "fra".\r
191\r
192 If LanguageIso639 is NULL, then ASSERT.\r
193 If LanguageRfc3066 is NULL, then ASSERT.\r
194\r
195 @param LanguageIso639 ISO639-2 language code.\r
196\r
197 @return the allocated buffer or NULL, if the language is not found.\r
198\r
199**/\r
200CHAR8*\r
201EFIAPI\r
202ConvertIso639LanguageToRfc3066Language (\r
203 IN CONST CHAR8 *LanguageIso639\r
204 )\r
205{\r
206 UINTN Index;\r
207 CHAR8 *Rfc3066Language;\r
208 \r
209 for (Index = 0; Iso639ToRfc3066ConversionTable[Index] != 0; Index += 5) {\r
210 if (CompareMem (LanguageIso639, &Iso639ToRfc3066ConversionTable[Index], 3) == 0) {\r
211 Rfc3066Language = AllocateZeroPool (3);\r
212 if (Rfc3066Language != NULL) {\r
213 Rfc3066Language = CopyMem (Rfc3066Language, &Iso639ToRfc3066ConversionTable[Index + 3], 2);\r
214 }\r
215 return Rfc3066Language;\r
216 }\r
217 }\r
218\r
219 return NULL;\r
220}\r
221\r
03e6b4b2 222/**\r
223 Performs a case-insensitive comparison of two Null-terminated Unicode \r
224 strings.\r
225\r
226 @param This Protocol instance pointer.\r
227 @param Str1 A pointer to a Null-terminated Unicode string.\r
228 @param Str2 A pointer to a Null-terminated Unicode string.\r
229\r
230 @retval 0 Str1 is equivalent to Str2\r
231 @retval > 0 Str1 is lexically greater than Str2\r
232 @retval < 0 Str1 is lexically less than Str2\r
233\r
234**/\r
235INTN\r
236EFIAPI\r
237StriColl (\r
238 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
239 IN CHAR16 *Str1,\r
240 IN CHAR16 *Str2\r
e00e1d46 241 );\r
03e6b4b2 242\r
243/**\r
244 Converts all the Unicode characters in a Null-terminated Unicode string to \r
245 lower case Unicode characters.\r
246\r
247 @param This Protocol instance pointer.\r
248 @param Str A pointer to a Null-terminated Unicode string.\r
249\r
250**/\r
251VOID\r
252EFIAPI\r
253StrLwr (\r
254 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
255 IN OUT CHAR16 *Str\r
e00e1d46 256 );\r
03e6b4b2 257\r
258/**\r
259 Converts all the Unicode characters in a Null-terminated Unicode string to upper\r
260 case Unicode characters.\r
261\r
262 @param This Protocol instance pointer.\r
263 @param Str A pointer to a Null-terminated Unicode string.\r
264\r
265**/\r
266VOID\r
267EFIAPI\r
268StrUpr (\r
269 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
270 IN OUT CHAR16 *Str\r
e00e1d46 271 );\r
03e6b4b2 272\r
273/**\r
274 Performs a case-insensitive comparison of a Null-terminated Unicode \r
275 pattern string and a Null-terminated Unicode string.\r
276\r
277 @param This Protocol instance pointer.\r
278 @param String A pointer to a Null-terminated Unicode string.\r
279 @param Pattern A pointer to a Null-terminated Unicode pattern string.\r
280\r
281 @retval TRUE Pattern was found in String.\r
282 @retval FALSE Pattern was not found in String.\r
283\r
284**/\r
285BOOLEAN\r
286EFIAPI\r
287MetaiMatch (\r
288 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
289 IN CHAR16 *String,\r
290 IN CHAR16 *Pattern\r
e00e1d46 291 );\r
03e6b4b2 292\r
293/**\r
294 Converts an 8.3 FAT file name in an OEM character set to a Null-terminated \r
295 Unicode string.\r
296\r
297 @param This Protocol instance pointer.\r
298 @param FatSize The size of the string Fat in bytes.\r
299 @param Fat A pointer to a Null-terminated string that contains an 8.3 file\r
300 name using an OEM character set.\r
301 @param String A pointer to a Null-terminated Unicode string. The string must\r
302 be preallocated to hold FatSize Unicode characters.\r
303\r
304**/\r
305VOID\r
306EFIAPI\r
307FatToStr (\r
308 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
309 IN UINTN FatSize,\r
310 IN CHAR8 *Fat,\r
311 OUT CHAR16 *String\r
e00e1d46 312 );\r
03e6b4b2 313\r
314/**\r
315 Converts a Null-terminated Unicode string to legal characters in a FAT \r
316 filename using an OEM character set. \r
317\r
318 @param This Protocol instance pointer.\r
319 @param String A pointer to a Null-terminated Unicode string. The string must\r
320 be preallocated to hold FatSize Unicode characters.\r
321 @param FatSize The size of the string Fat in bytes.\r
322 @param Fat A pointer to a Null-terminated string that contains an 8.3 file\r
323 name using an OEM character set.\r
324\r
325 @retval TRUE Fat is a Long File Name\r
326 @retval FALSE Fat is an 8.3 file name\r
327\r
328**/\r
329BOOLEAN\r
330EFIAPI\r
331StrToFat (\r
332 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
333 IN CHAR16 *String,\r
334 IN UINTN FatSize,\r
335 OUT CHAR8 *Fat\r
e00e1d46 336 );\r
03e6b4b2 337\r
a3a83173 338#define UC2_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('_', 'U', 'C', '2')\r
03e6b4b2 339\r
340typedef struct {\r
341 UINT32 Signature;\r
342 EFI_UNICODE_COLLATION_PROTOCOL UC2;\r
343 EFI_UNICODE_COLLATION_PROTOCOL *UC;\r
344} UC2_PRIVATE_DATA;\r
345\r
29ec49a5 346#define UC2_PRIVATE_DATA_FROM_THIS(a) CR (a, UC2_PRIVATE_DATA, UC2, UC2_PRIVATE_DATA_SIGNATURE)\r
03e6b4b2 347\r
348//\r
349// Firmware Volume Protocol template\r
350//\r
351EFI_EVENT mUc2Registration;\r
352\r
353UC2_PRIVATE_DATA gUC2PrivateDataTemplate = {\r
354 UC2_PRIVATE_DATA_SIGNATURE,\r
355 {\r
356 StriColl,\r
357 MetaiMatch,\r
358 StrLwr,\r
359 StrUpr,\r
360 FatToStr,\r
361 StrToFat,\r
362 NULL\r
363 },\r
364 NULL\r
365};\r
366\r
367//\r
368// Module globals\r
369//\r
370\r
371VOID\r
372EFIAPI\r
cd289975 373UcNotificationEvent (\r
03e6b4b2 374 IN EFI_EVENT Event,\r
375 IN VOID *Context\r
376 )\r
377{\r
378 EFI_STATUS Status;\r
379 UINTN BufferSize;\r
380 EFI_HANDLE Handle;\r
381 UC2_PRIVATE_DATA *Private;\r
382 EFI_UNICODE_COLLATION_PROTOCOL *Uc2;\r
383\r
384 while (TRUE) {\r
385 BufferSize = sizeof (Handle);\r
386 Status = gBS->LocateHandle (\r
387 ByRegisterNotify,\r
388 &gEfiUnicodeCollationProtocolGuid,\r
389 mUc2Registration,\r
390 &BufferSize,\r
391 &Handle\r
392 );\r
393 if (EFI_ERROR (Status)) {\r
394 //\r
395 // Exit Path of While Loop....\r
396 //\r
397 break;\r
398 }\r
399\r
400 //\r
401 // Skip this handle if the Firmware Volume Protocol is already installed\r
402 //\r
403 Status = gBS->HandleProtocol (\r
404 Handle,\r
405 &gEfiUnicodeCollation2ProtocolGuid,\r
406 (VOID **)&Uc2\r
407 );\r
408 if (!EFI_ERROR (Status)) {\r
409 continue;\r
410 }\r
411\r
412 //\r
413 // Allocate private data structure\r
414 //\r
415 Private = AllocateCopyPool (sizeof (UC2_PRIVATE_DATA), &gUC2PrivateDataTemplate);\r
416 if (Private == NULL) {\r
417 continue;\r
418 }\r
419\r
420 //\r
421 // Retrieve the UC Protocol\r
422 //\r
423 Status = gBS->HandleProtocol (\r
424 Handle,\r
425 &gEfiUnicodeCollationProtocolGuid,\r
426 (VOID **)&Private->UC\r
427 );\r
428 ASSERT_EFI_ERROR (Status);\r
429\r
430 //\r
431 // Fill in rest of private data structure\r
432 //\r
0b09813f 433 Private->UC2.SupportedLanguages = ConvertIso639LanguageToRfc3066Language (Private->UC->SupportedLanguages);\r
434 if (Private->UC2.SupportedLanguages != NULL) {\r
03e6b4b2 435\r
436 //\r
437 // Install Firmware Volume Protocol onto same handle\r
438 //\r
439 Status = gBS->InstallMultipleProtocolInterfaces (\r
440 &Handle,\r
441 &gEfiUnicodeCollation2ProtocolGuid,\r
442 &Private->UC2,\r
443 NULL\r
444 );\r
445 ASSERT_EFI_ERROR (Status);\r
446 }\r
447 }\r
448}\r
449\r
450\r
451/**\r
452 The user Entry Point for DXE driver. The user code starts with this function\r
453 as the real entry point for the image goes into a library that calls this \r
454 function.\r
455\r
456 @param[in] ImageHandle The firmware allocated handle for the EFI image. \r
457 @param[in] SystemTable A pointer to the EFI System Table.\r
458 \r
459 @retval EFI_SUCCESS The entry point is executed successfully.\r
460 @retval other Some error occurs when executing this entry point.\r
461\r
462**/\r
463EFI_STATUS\r
464EFIAPI\r
465InitializeUC2 (\r
466 IN EFI_HANDLE ImageHandle,\r
467 IN EFI_SYSTEM_TABLE *SystemTable\r
468 )\r
469{\r
470 EfiCreateProtocolNotifyEvent (\r
471 &gEfiUnicodeCollationProtocolGuid,\r
472 TPL_CALLBACK,\r
cd289975 473 UcNotificationEvent,\r
03e6b4b2 474 NULL,\r
475 &mUc2Registration\r
476 );\r
477 return EFI_SUCCESS;\r
478}\r
479\r
480\r
481/**\r
482 Performs a case-insensitive comparison of two Null-terminated Unicode \r
483 strings.\r
484\r
485 @param This Protocol instance pointer.\r
486 @param Str1 A pointer to a Null-terminated Unicode string.\r
487 @param Str2 A pointer to a Null-terminated Unicode string.\r
488\r
489 @retval 0 Str1 is equivalent to Str2\r
490 @retval > 0 Str1 is lexically greater than Str2\r
491 @retval < 0 Str1 is lexically less than Str2\r
492\r
493**/\r
494INTN\r
495EFIAPI\r
496StriColl (\r
497 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
498 IN CHAR16 *Str1,\r
499 IN CHAR16 *Str2\r
500 )\r
501{\r
502 UC2_PRIVATE_DATA *Private;\r
503 \r
504 Private = UC2_PRIVATE_DATA_FROM_THIS (This);\r
505 \r
506 return Private->UC->StriColl (Private->UC, Str1, Str2);\r
507}\r
508\r
509\r
510/**\r
511 Converts all the Unicode characters in a Null-terminated Unicode string to \r
512 lower case Unicode characters.\r
513\r
514 @param This Protocol instance pointer.\r
515 @param Str A pointer to a Null-terminated Unicode string.\r
516\r
517**/\r
518VOID\r
519EFIAPI\r
520StrLwr (\r
521 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
522 IN OUT CHAR16 *Str\r
523 )\r
524{\r
525 UC2_PRIVATE_DATA *Private;\r
526 \r
527 Private = UC2_PRIVATE_DATA_FROM_THIS (This);\r
528 \r
529 Private->UC->StrLwr (Private->UC, Str);\r
530}\r
531\r
532\r
533/**\r
534 Converts all the Unicode characters in a Null-terminated Unicode string to upper\r
535 case Unicode characters.\r
536\r
537 @param This Protocol instance pointer.\r
538 @param Str A pointer to a Null-terminated Unicode string.\r
539\r
540**/\r
541VOID\r
542EFIAPI\r
543StrUpr (\r
544 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
545 IN OUT CHAR16 *Str\r
546 )\r
547{\r
548 UC2_PRIVATE_DATA *Private;\r
549 \r
550 Private = UC2_PRIVATE_DATA_FROM_THIS (This);\r
551 \r
552 Private->UC->StrUpr (Private->UC, Str);\r
553}\r
554\r
555/**\r
556 Performs a case-insensitive comparison of a Null-terminated Unicode \r
557 pattern string and a Null-terminated Unicode string.\r
558\r
559 @param This Protocol instance pointer.\r
560 @param String A pointer to a Null-terminated Unicode string.\r
561 @param Pattern A pointer to a Null-terminated Unicode pattern string.\r
562\r
563 @retval TRUE Pattern was found in String.\r
564 @retval FALSE Pattern was not found in String.\r
565\r
566**/\r
567BOOLEAN\r
568EFIAPI\r
569MetaiMatch (\r
570 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
571 IN CHAR16 *String,\r
572 IN CHAR16 *Pattern\r
573 )\r
574{\r
575 UC2_PRIVATE_DATA *Private;\r
576 \r
577 Private = UC2_PRIVATE_DATA_FROM_THIS (This);\r
578 \r
579 return Private->UC->MetaiMatch (Private->UC, String, Pattern);\r
580}\r
581\r
582\r
583/**\r
584 Converts an 8.3 FAT file name in an OEM character set to a Null-terminated \r
585 Unicode string.\r
586\r
587 @param This Protocol instance pointer.\r
588 @param FatSize The size of the string Fat in bytes.\r
589 @param Fat A pointer to a Null-terminated string that contains an 8.3 file\r
590 name using an OEM character set.\r
591 @param String A pointer to a Null-terminated Unicode string. The string must\r
592 be preallocated to hold FatSize Unicode characters.\r
593\r
594**/\r
595VOID\r
596EFIAPI\r
597FatToStr (\r
598 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
599 IN UINTN FatSize,\r
600 IN CHAR8 *Fat,\r
601 OUT CHAR16 *String\r
602 )\r
603{\r
604 UC2_PRIVATE_DATA *Private;\r
605 \r
606 Private = UC2_PRIVATE_DATA_FROM_THIS (This);\r
607 \r
608 Private->UC->FatToStr (Private->UC, FatSize, Fat, String);\r
609}\r
610\r
611\r
612/**\r
613 Converts a Null-terminated Unicode string to legal characters in a FAT \r
614 filename using an OEM character set. \r
615\r
616 @param This Protocol instance pointer.\r
617 @param String A pointer to a Null-terminated Unicode string. The string must\r
618 be preallocated to hold FatSize Unicode characters.\r
619 @param FatSize The size of the string Fat in bytes.\r
620 @param Fat A pointer to a Null-terminated string that contains an 8.3 file\r
621 name using an OEM character set.\r
622\r
623 @retval TRUE Fat is a Long File Name\r
624 @retval FALSE Fat is an 8.3 file name\r
625\r
626**/\r
627BOOLEAN\r
628EFIAPI\r
629StrToFat (\r
630 IN EFI_UNICODE_COLLATION_PROTOCOL *This,\r
631 IN CHAR16 *String,\r
632 IN UINTN FatSize,\r
633 OUT CHAR8 *Fat\r
634 )\r
635{\r
636 UC2_PRIVATE_DATA *Private;\r
637 \r
638 Private = UC2_PRIVATE_DATA_FROM_THIS (This);\r
639 \r
640 return Private->UC->StrToFat (Private->UC, String, FatSize, Fat);\r
641}\r
642\r