]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Library/UefiHiiLib/HiiLanguage.c
HII Library Class interface refine.
[mirror_edk2.git] / MdeModulePkg / Library / UefiHiiLib / HiiLanguage.c
... / ...
CommitLineData
1/** @file\r
2 Language related HII Library implementation.\r
3\r
4 Copyright (c) 2006 - 2008, Intel Corporation<BR>\r
5 All rights reserved. This program and the accompanying materials\r
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
13**/\r
14\r
15\r
16#include "InternalHiiLib.h"\r
17\r
18/**\r
19 Get next language from language code list (with separator ';').\r
20\r
21 If LangCode is NULL, then ASSERT.\r
22 If Lang is NULL, then ASSERT.\r
23\r
24 @param LangCode On input: point to first language in the list. On\r
25 output: point to next language in the list, or\r
26 NULL if no more language in the list.\r
27 @param Lang The first language in the list.\r
28\r
29**/\r
30VOID\r
31EFIAPI\r
32HiiLibGetNextLanguage (\r
33 IN OUT CHAR8 **LangCode,\r
34 OUT CHAR8 *Lang\r
35 )\r
36{\r
37 UINTN Index;\r
38 CHAR8 *StringPtr;\r
39\r
40 ASSERT (LangCode != NULL);\r
41 ASSERT (*LangCode != NULL);\r
42 ASSERT (Lang != NULL);\r
43\r
44 Index = 0;\r
45 StringPtr = *LangCode;\r
46 while (StringPtr[Index] != 0 && StringPtr[Index] != ';') {\r
47 Index++;\r
48 }\r
49\r
50 CopyMem (Lang, StringPtr, Index);\r
51 Lang[Index] = 0;\r
52\r
53 if (StringPtr[Index] == ';') {\r
54 Index++;\r
55 }\r
56 *LangCode = StringPtr + Index;\r
57}\r
58\r
59\r
60/**\r
61 Retrieves a pointer to the a Null-terminated ASCII string containing the list \r
62 of languages that an HII handle in the HII Database supports. The returned \r
63 string is allocated using AllocatePool(). The caller is responsible for freeing\r
64 the returned string using FreePool(). The format of the returned string follows\r
65 the language format assumed the HII Database.\r
66 \r
67 If HiiHandle is NULL, then ASSERT().\r
68\r
69 @param[in] HiiHandle A handle that was previously registered in the HII Database.\r
70\r
71 @retval NULL HiiHandle is not registered in the HII database\r
72 @retval NULL There are not enough resources available to retrieve the suported \r
73 languages.\r
74 @retval NULL The list of suported languages could not be retrieved.\r
75 @retval Other A pointer to the Null-terminated ASCII string of supported languages.\r
76\r
77**/\r
78CHAR8 *\r
79EFIAPI\r
80HiiGetSupportedLanguages (\r
81 IN EFI_HII_HANDLE HiiHandle\r
82 )\r
83{\r
84 EFI_STATUS Status;\r
85 UINTN LanguageSize;\r
86 CHAR8 TempSupportedLanguages;\r
87 CHAR8 *SupportedLanguages;\r
88\r
89 ASSERT (HiiHandle != NULL);\r
90\r
91 //\r
92 // Retrieve the size required for the supported languages buffer.\r
93 //\r
94 LanguageSize = 0;\r
95 Status = gHiiString->GetLanguages (gHiiString, HiiHandle, &TempSupportedLanguages, &LanguageSize);\r
96\r
97 //\r
98 // If GetLanguages() returns EFI_SUCCESS for a zero size, \r
99 // then there are no supported languages registered for HiiHandle. If GetLanguages() \r
100 // returns an error other than EFI_BUFFER_TOO_SMALL, then HiiHandle is not present\r
101 // in the HII Database\r
102 //\r
103 if (Status != EFI_BUFFER_TOO_SMALL) {\r
104 //\r
105 // Return NULL if the size can not be retrieved, or if HiiHandle is not in the HII Database\r
106 //\r
107 return NULL;\r
108 }\r
109\r
110 //\r
111 // Allocate the supported languages buffer.\r
112 //\r
113 SupportedLanguages = AllocateZeroPool (LanguageSize);\r
114 if (SupportedLanguages == NULL) {\r
115 //\r
116 // Return NULL if allocation fails.\r
117 //\r
118 return NULL;\r
119 }\r
120\r
121 //\r
122 // Retrieve the supported languages string\r
123 //\r
124 Status = gHiiString->GetLanguages (gHiiString, HiiHandle, SupportedLanguages, &LanguageSize);\r
125 if (EFI_ERROR (Status)) {\r
126 //\r
127 // Free the buffer and return NULL if the supported languages can not be retrieved.\r
128 //\r
129 FreePool (SupportedLanguages);\r
130 return NULL;\r
131 }\r
132\r
133 //\r
134 // Return the Null-terminated ASCII string of supported languages\r
135 //\r
136 return SupportedLanguages;\r
137}\r
138\r