]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/UefiHiiLib/HiiLanguage.c
Use default UNDI information if NII protocol not exists.
[mirror_edk2.git] / MdeModulePkg / Library / UefiHiiLib / HiiLanguage.c
CommitLineData
08e4b3cf 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 This function returns the list of supported languages, in the format specified\r
62 in UEFI specification Appendix M.\r
63\r
64 If HiiHandle is not a valid Handle in the default HII database, then ASSERT.\r
65\r
66 @param HiiHandle The HII package list handle.\r
67\r
68 @retval !NULL The supported languages.\r
69 @retval NULL If Supported Languages can not be retrived.\r
70\r
71**/\r
72CHAR8 *\r
73EFIAPI\r
74HiiLibGetSupportedLanguages (\r
75 IN EFI_HII_HANDLE HiiHandle\r
76 )\r
77{\r
78 EFI_STATUS Status;\r
79 UINTN BufferSize;\r
80 CHAR8 *LanguageString;\r
81\r
82 ASSERT (IsHiiHandleRegistered (HiiHandle));\r
83 //\r
84 // Collect current supported Languages for given HII handle\r
85 // First try allocate 4K buffer to store the current supported languages.\r
86 //\r
87 BufferSize = 0x1000;\r
88 LanguageString = AllocateZeroPool (BufferSize);\r
89 if (LanguageString == NULL) {\r
90 return NULL;\r
91 }\r
92\r
7e3bcccb 93 Status = gHiiString->GetLanguages (gHiiString, HiiHandle, LanguageString, &BufferSize);\r
08e4b3cf 94 \r
95 if (Status == EFI_BUFFER_TOO_SMALL) {\r
96 FreePool (LanguageString);\r
97 LanguageString = AllocateZeroPool (BufferSize);\r
98 if (LanguageString == NULL) {\r
99 return NULL;\r
100 }\r
101\r
7e3bcccb 102 Status = gHiiString->GetLanguages (gHiiString, HiiHandle, LanguageString, &BufferSize);\r
08e4b3cf 103 }\r
104\r
105 if (EFI_ERROR (Status)) {\r
106 LanguageString = NULL;\r
107 }\r
108\r
109 return LanguageString;\r
110}\r
111\r
112\r
113/**\r
114 This function returns the number of supported languages on HiiHandle.\r
115\r
116 If HiiHandle is not a valid Handle in the default HII database, then ASSERT.\r
117 If not enough resource to complete the operation, then ASSERT.\r
118\r
119 @param HiiHandle The HII package list handle.\r
120\r
121 @return The number of supported languages.\r
122\r
123**/\r
124UINT16\r
125EFIAPI\r
126HiiLibGetSupportedLanguageNumber (\r
127 IN EFI_HII_HANDLE HiiHandle\r
128 )\r
129{\r
130 CHAR8 *Languages;\r
131 CHAR8 *LanguageString;\r
132 UINT16 LangNumber;\r
ea7cd3ec 133 CHAR8 *Lang;\r
08e4b3cf 134\r
135 Languages = HiiLibGetSupportedLanguages (HiiHandle);\r
136 if (Languages == NULL) {\r
137 return 0;\r
138 }\r
139\r
140 LangNumber = 0;\r
ea7cd3ec 141 Lang = AllocatePool (AsciiStrSize (Languages));\r
142 if (Lang != NULL) {\r
143 LanguageString = Languages;\r
144 while (*LanguageString != 0) {\r
145 HiiLibGetNextLanguage (&LanguageString, Lang);\r
146 LangNumber++;\r
147 }\r
148\r
149 FreePool (Lang);\r
08e4b3cf 150 }\r
151 FreePool (Languages);\r
152\r
153 return LangNumber;\r
154}\r
155\r
156/**\r
157 This function returns the list of supported 2nd languages, in the format specified\r
158 in UEFI specification Appendix M.\r
159\r
160 If HiiHandle is not a valid Handle in the default HII database, then ASSERT.\r
161 If not enough resource to complete the operation, then ASSERT.\r
162\r
163 @param HiiHandle The HII package list handle.\r
164 @param FirstLanguage Pointer to language name buffer.\r
165 \r
166 @return The supported languages.\r
167\r
168**/\r
169CHAR8 *\r
170EFIAPI\r
171HiiLibGetSupportedSecondaryLanguages (\r
172 IN EFI_HII_HANDLE HiiHandle,\r
173 IN CONST CHAR8 *FirstLanguage\r
174 )\r
175{\r
176 EFI_STATUS Status;\r
177 UINTN BufferSize;\r
178 CHAR8 *LanguageString;\r
179\r
180 ASSERT (HiiHandle != NULL);\r
181 ASSERT (IsHiiHandleRegistered (HiiHandle));\r
182 //\r
183 // Collect current supported 2nd Languages for given HII handle\r
184 // First try allocate 4K buffer to store the current supported 2nd languages.\r
185 //\r
186 BufferSize = 0x1000;\r
187 LanguageString = AllocateZeroPool (BufferSize);\r
188 if (LanguageString == NULL) {\r
189 return NULL;\r
190 }\r
191\r
7e3bcccb 192 Status = gHiiString->GetSecondaryLanguages (gHiiString, HiiHandle, FirstLanguage, LanguageString, &BufferSize);\r
08e4b3cf 193 \r
194 if (Status == EFI_BUFFER_TOO_SMALL) {\r
195 FreePool (LanguageString);\r
196 LanguageString = AllocateZeroPool (BufferSize);\r
197 if (LanguageString == NULL) {\r
198 return NULL;\r
199 }\r
200\r
7e3bcccb 201 Status = gHiiString->GetSecondaryLanguages (gHiiString, HiiHandle, FirstLanguage, LanguageString, &BufferSize);\r
08e4b3cf 202 }\r
203\r
204 if (EFI_ERROR (Status)) {\r
205 LanguageString = NULL;\r
206 }\r
207\r
208 return LanguageString;\r
209}\r
210\r
211\r
11e92503 212\r