]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/UefiHiiLib/HiiLanguage.c
Update UefiHiiLib to support new defined IFR related HII APIs.
[mirror_edk2.git] / MdeModulePkg / Library / UefiHiiLib / HiiLanguage.c
1 /** @file
2 Language related HII Library implementation.
3
4 Copyright (c) 2006 - 2008, 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 Get next language from language code list (with separator ';').
20
21 If LangCode is NULL, then ASSERT.
22 If Lang is NULL, then ASSERT.
23
24 @param LangCode On input: point to first language in the list. On
25 output: point to next language in the list, or
26 NULL if no more language in the list.
27 @param Lang The first language in the list.
28
29 **/
30 VOID
31 EFIAPI
32 HiiLibGetNextLanguage (
33 IN OUT CHAR8 **LangCode,
34 OUT CHAR8 *Lang
35 )
36 {
37 UINTN Index;
38 CHAR8 *StringPtr;
39
40 ASSERT (LangCode != NULL);
41 ASSERT (*LangCode != NULL);
42 ASSERT (Lang != NULL);
43
44 Index = 0;
45 StringPtr = *LangCode;
46 while (StringPtr[Index] != 0 && StringPtr[Index] != ';') {
47 Index++;
48 }
49
50 CopyMem (Lang, StringPtr, Index);
51 Lang[Index] = 0;
52
53 if (StringPtr[Index] == ';') {
54 Index++;
55 }
56 *LangCode = StringPtr + Index;
57 }
58
59
60 /**
61 This function returns the list of supported languages, in the format specified
62 in UEFI specification Appendix M.
63
64 If HiiHandle is not a valid Handle in the default HII database, then ASSERT.
65
66 @param HiiHandle The HII package list handle.
67
68 @retval !NULL The supported languages.
69 @retval NULL If Supported Languages can not be retrived.
70
71 **/
72 CHAR8 *
73 EFIAPI
74 HiiLibGetSupportedLanguages (
75 IN EFI_HII_HANDLE HiiHandle
76 )
77 {
78 EFI_STATUS Status;
79 UINTN BufferSize;
80 CHAR8 *LanguageString;
81
82 ASSERT (IsHiiHandleRegistered (HiiHandle));
83 //
84 // Collect current supported Languages for given HII handle
85 // First try allocate 4K buffer to store the current supported languages.
86 //
87 BufferSize = 0x1000;
88 LanguageString = AllocateZeroPool (BufferSize);
89 if (LanguageString == NULL) {
90 return NULL;
91 }
92
93 Status = gHiiString->GetLanguages (gHiiString, HiiHandle, LanguageString, &BufferSize);
94
95 if (Status == EFI_BUFFER_TOO_SMALL) {
96 FreePool (LanguageString);
97 LanguageString = AllocateZeroPool (BufferSize);
98 if (LanguageString == NULL) {
99 return NULL;
100 }
101
102 Status = gHiiString->GetLanguages (gHiiString, HiiHandle, LanguageString, &BufferSize);
103 }
104
105 if (EFI_ERROR (Status)) {
106 LanguageString = NULL;
107 }
108
109 return LanguageString;
110 }
111
112
113 /**
114 This function returns the number of supported languages on HiiHandle.
115
116 If HiiHandle is not a valid Handle in the default HII database, then ASSERT.
117 If not enough resource to complete the operation, then ASSERT.
118
119 @param HiiHandle The HII package list handle.
120
121 @return The number of supported languages.
122
123 **/
124 UINT16
125 EFIAPI
126 HiiLibGetSupportedLanguageNumber (
127 IN EFI_HII_HANDLE HiiHandle
128 )
129 {
130 CHAR8 *Languages;
131 CHAR8 *LanguageString;
132 UINT16 LangNumber;
133 CHAR8 *Lang;
134
135 Languages = HiiLibGetSupportedLanguages (HiiHandle);
136 if (Languages == NULL) {
137 return 0;
138 }
139
140 LangNumber = 0;
141 Lang = AllocatePool (AsciiStrSize (Languages));
142 if (Lang != NULL) {
143 LanguageString = Languages;
144 while (*LanguageString != 0) {
145 HiiLibGetNextLanguage (&LanguageString, Lang);
146 LangNumber++;
147 }
148
149 FreePool (Lang);
150 }
151 FreePool (Languages);
152
153 return LangNumber;
154 }
155
156 /**
157 This function returns the list of supported 2nd languages, in the format specified
158 in UEFI specification Appendix M.
159
160 If HiiHandle is not a valid Handle in the default HII database, then ASSERT.
161 If not enough resource to complete the operation, then ASSERT.
162
163 @param HiiHandle The HII package list handle.
164 @param FirstLanguage Pointer to language name buffer.
165
166 @return The supported languages.
167
168 **/
169 CHAR8 *
170 EFIAPI
171 HiiLibGetSupportedSecondaryLanguages (
172 IN EFI_HII_HANDLE HiiHandle,
173 IN CONST CHAR8 *FirstLanguage
174 )
175 {
176 EFI_STATUS Status;
177 UINTN BufferSize;
178 CHAR8 *LanguageString;
179
180 ASSERT (HiiHandle != NULL);
181 ASSERT (IsHiiHandleRegistered (HiiHandle));
182 //
183 // Collect current supported 2nd Languages for given HII handle
184 // First try allocate 4K buffer to store the current supported 2nd languages.
185 //
186 BufferSize = 0x1000;
187 LanguageString = AllocateZeroPool (BufferSize);
188 if (LanguageString == NULL) {
189 return NULL;
190 }
191
192 Status = gHiiString->GetSecondaryLanguages (gHiiString, HiiHandle, FirstLanguage, LanguageString, &BufferSize);
193
194 if (Status == EFI_BUFFER_TOO_SMALL) {
195 FreePool (LanguageString);
196 LanguageString = AllocateZeroPool (BufferSize);
197 if (LanguageString == NULL) {
198 return NULL;
199 }
200
201 Status = gHiiString->GetSecondaryLanguages (gHiiString, HiiHandle, FirstLanguage, LanguageString, &BufferSize);
202 }
203
204 if (EFI_ERROR (Status)) {
205 LanguageString = NULL;
206 }
207
208 return LanguageString;
209 }
210
211
212