]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/HiiLib/HiiLanguage.c
Clean up ExtendedHiiLib, HiiLib, IfrSupportLib, ExtendedIfrSupportLib for Doxygen...
[mirror_edk2.git] / MdePkg / Library / HiiLib / HiiLanguage.c
1 /** @file
2 Language related HII Library implementation.
3
4 Copyright (c) 2006, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15
16 #include "InternalHiiLib.h"
17
18 /**
19 Determine what is the current language setting. The space reserved for Lang
20 must be at least RFC_3066_ENTRY_SIZE bytes;
21
22 If Lang is NULL, then ASSERT.
23
24 @param Lang Pointer of system language. Lang will always be filled with
25 a valid RFC 3066 language string. If "PlatformLang" is not
26 set in the system, the default language specifed by PcdUefiVariableDefaultPlatformLang
27 is returned.
28
29 @return EFI_SUCCESS If the EFI Variable with "PlatformLang" is set and return in Lang.
30 @return EFI_NOT_FOUND If the EFI Variable with "PlatformLang" is not set, but a valid default language is return in Lang.
31
32 **/
33 EFI_STATUS
34 EFIAPI
35 HiiLibGetCurrentLanguage (
36 OUT CHAR8 *Lang
37 )
38 {
39 EFI_STATUS Status;
40 UINTN Size;
41
42 ASSERT (Lang != NULL);
43
44 //
45 // Get current language setting
46 //
47 Size = RFC_3066_ENTRY_SIZE;
48 Status = gRT->GetVariable (
49 L"PlatformLang",
50 &gEfiGlobalVariableGuid,
51 NULL,
52 &Size,
53 Lang
54 );
55
56 if (EFI_ERROR (Status)) {
57 AsciiStrCpy (Lang, (CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLang));
58 }
59
60 return Status;
61 }
62
63
64 /**
65 Get next language from language code list (with separator ';').
66
67 If LangCode is NULL, then ASSERT.
68 If Lang is NULL, then ASSERT.
69
70 @param LangCode On input: point to first language in the list. On
71 output: point to next language in the list, or
72 NULL if no more language in the list.
73 @param Lang The first language in the list.
74
75 **/
76 VOID
77 EFIAPI
78 HiiLibGetNextLanguage (
79 IN OUT CHAR8 **LangCode,
80 OUT CHAR8 *Lang
81 )
82 {
83 UINTN Index;
84 CHAR8 *StringPtr;
85
86 ASSERT (LangCode != NULL);
87 ASSERT (Lang != NULL);
88
89 Index = 0;
90 StringPtr = *LangCode;
91 while (StringPtr[Index] != 0 && StringPtr[Index] != ';') {
92 Index++;
93 }
94
95 CopyMem (Lang, StringPtr, Index);
96 Lang[Index] = 0;
97
98 if (StringPtr[Index] == ';') {
99 Index++;
100 }
101 *LangCode = StringPtr + Index;
102 }
103
104
105 /**
106 This function returns the list of supported languages, in the format specified
107 in UEFI specification Appendix M.
108
109 If HiiHandle is not a valid Handle in the default HII database, then ASSERT.
110
111 @param HiiHandle The HII package list handle.
112
113 @retval !NULL The supported languages.
114 @retval NULL If Supported Languages can not be retrived.
115
116 **/
117 CHAR8 *
118 EFIAPI
119 HiiLibGetSupportedLanguages (
120 IN EFI_HII_HANDLE HiiHandle
121 )
122 {
123 EFI_STATUS Status;
124 UINTN BufferSize;
125 CHAR8 *LanguageString;
126
127 ASSERT (HiiHandle != NULL);
128 ASSERT (IsHiiHandleRegistered (HiiHandle));
129 //
130 // Collect current supported Languages for given HII handle
131 //
132 BufferSize = 0x1000;
133 LanguageString = AllocateZeroPool (BufferSize);
134 if (LanguageString == NULL) {
135 return NULL;
136 }
137
138 LocateHiiProtocols ();
139
140 Status = mHiiStringProt->GetLanguages (mHiiStringProt, HiiHandle, LanguageString, &BufferSize);
141
142 if (Status == EFI_BUFFER_TOO_SMALL) {
143 gBS->FreePool (LanguageString);
144 LanguageString = AllocateZeroPool (BufferSize);
145 if (LanguageString == NULL) {
146 return NULL;
147 }
148
149 Status = mHiiStringProt->GetLanguages (mHiiStringProt, HiiHandle, LanguageString, &BufferSize);
150 }
151
152 if (EFI_ERROR (Status)) {
153 LanguageString = NULL;
154 }
155
156 return LanguageString;
157 }
158
159
160 /**
161 This function returns the number of supported languages on HiiHandle.
162
163 If HiiHandle is not a valid Handle in the default HII database, then ASSERT.
164 If not enough resource to complete the operation, then ASSERT.
165
166 @param HiiHandle The HII package list handle.
167
168 @return The number of supported languages.
169
170 **/
171 UINT16
172 EFIAPI
173 HiiLibGetSupportedLanguageNumber (
174 IN EFI_HII_HANDLE HiiHandle
175 )
176 {
177 CHAR8 *Languages;
178 CHAR8 *LanguageString;
179 UINT16 LangNumber;
180 CHAR8 Lang[RFC_3066_ENTRY_SIZE];
181
182 Languages = HiiLibGetSupportedLanguages (HiiHandle);
183 if (Languages == NULL) {
184 return 0;
185 }
186
187 LangNumber = 0;
188 LanguageString = Languages;
189 while (*LanguageString != 0) {
190 HiiLibGetNextLanguage (&LanguageString, Lang);
191 LangNumber++;
192 }
193 gBS->FreePool (Languages);
194
195 return LangNumber;
196 }
197
198 /**
199 This function returns the list of supported 2nd languages, in the format specified
200 in UEFI specification Appendix M.
201
202 If HiiHandle is not a valid Handle in the default HII database, then ASSERT.
203 If not enough resource to complete the operation, then ASSERT.
204
205 @param HiiHandle The HII package list handle.
206 @param FirstLanguage Pointer to language name buffer.
207
208 @return The supported languages.
209
210 **/
211 CHAR8 *
212 EFIAPI
213 HiiLibGetSupportedSecondaryLanguages (
214 IN EFI_HII_HANDLE HiiHandle,
215 IN CONST CHAR8 *FirstLanguage
216 )
217 {
218 EFI_STATUS Status;
219 UINTN BufferSize;
220 CHAR8 *LanguageString;
221
222 ASSERT (HiiHandle != NULL);
223 ASSERT (IsHiiHandleRegistered (HiiHandle));
224 //
225 // Collect current supported 2nd Languages for given HII handle
226 //
227 BufferSize = 0x1000;
228 LanguageString = AllocateZeroPool (BufferSize);
229 if (LanguageString == NULL) {
230 return NULL;
231 }
232
233 LocateHiiProtocols ();
234
235 Status = mHiiStringProt->GetSecondaryLanguages (mHiiStringProt, HiiHandle, FirstLanguage, LanguageString, &BufferSize);
236
237 if (Status == EFI_BUFFER_TOO_SMALL) {
238 gBS->FreePool (LanguageString);
239 LanguageString = AllocateZeroPool (BufferSize);
240 if (LanguageString == NULL) {
241 return NULL;
242 }
243
244 Status = mHiiStringProt->GetSecondaryLanguages (mHiiStringProt, HiiHandle, FirstLanguage, LanguageString, &BufferSize);
245 }
246
247 if (EFI_ERROR (Status)) {
248 LanguageString = NULL;
249 }
250
251 return LanguageString;
252 }
253
254