]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/Strings.c
For UNI file, some String may not be defined for a language. This has been true for...
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / FrameworkHiiToUefiHiiThunk / Strings.c
1 /**@file
2
3 This file contains the keyboard processing code to the HII database.
4
5 Copyright (c) 2006 - 2008, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16
17 #include "HiiDatabase.h"
18
19 EFI_STATUS
20 EFIAPI
21 HiiTestString (
22 IN EFI_HII_PROTOCOL *This,
23 IN CHAR16 *StringToTest,
24 IN OUT UINT32 *FirstMissing,
25 OUT UINT32 *GlyphBufferSize
26 )
27 /*++
28
29 Routine Description:
30 Test if all of the characters in a string have corresponding font characters.
31
32 Arguments:
33
34 Returns:
35
36 --*/
37 {
38 ASSERT (FALSE);
39 return EFI_SUCCESS;
40 }
41
42 EFI_STATUS
43 GetTagGuidByFrameworkHiiHandle (
44 IN CONST EFI_HII_THUNK_PRIVATE_DATA *Private,
45 IN FRAMEWORK_EFI_HII_HANDLE FrameworkHiiHandle,
46 OUT EFI_GUID *TagGuid
47 )
48 {
49 LIST_ENTRY *ListEntry;
50 HII_TRHUNK_HANDLE_MAPPING_DATABASE_ENTRY *HandleMapEntry;
51
52 ASSERT (TagGuid != NULL);
53
54 for (ListEntry = Private->HiiThunkHandleMappingDBListHead.ForwardLink;
55 ListEntry != &Private->HiiThunkHandleMappingDBListHead;
56 ListEntry = ListEntry->ForwardLink
57 ) {
58
59 HandleMapEntry = HII_TRHUNK_HANDLE_MAPPING_DATABASE_ENTRY_FROM_LISTENTRY (ListEntry);
60
61 if (FrameworkHiiHandle == HandleMapEntry->FrameworkHiiHandle) {
62 CopyGuid (TagGuid, &HandleMapEntry->TagGuid);
63 return EFI_SUCCESS;
64 }
65 }
66
67 return EFI_NOT_FOUND;
68 }
69
70 EFI_STATUS
71 HiiThunkNewStringForAllStringPackages (
72 IN CONST EFI_HII_THUNK_PRIVATE_DATA *Private,
73 OUT CONST EFI_GUID *TagGuid,
74 IN CHAR16 *Language,
75 IN OUT STRING_REF *Reference,
76 IN CHAR16 *NewString
77 )
78 {
79 EFI_STATUS Status;
80 LIST_ENTRY *ListEntry;
81 HII_TRHUNK_HANDLE_MAPPING_DATABASE_ENTRY *HandleMapEntry;
82 EFI_STRING_ID StringId1;
83 EFI_STRING_ID StringId2;
84 CHAR8 *UefiStringProtocolLanguage;
85 BOOLEAN Found;
86
87 ASSERT (TagGuid != NULL);
88
89 StringId1 = (EFI_STRING_ID) 0;
90 StringId2 = (EFI_STRING_ID) 0;
91 Found = FALSE;
92
93 //
94 // BugBug: We will handle the case that Language is not NULL later.
95 //
96 ASSERT (Language == NULL);
97
98 //if (Language == NULL) {
99 UefiStringProtocolLanguage = NULL;
100 //}
101
102 for (ListEntry = Private->HiiThunkHandleMappingDBListHead.ForwardLink;
103 ListEntry != &Private->HiiThunkHandleMappingDBListHead;
104 ListEntry = ListEntry->ForwardLink
105 ) {
106
107 HandleMapEntry = HII_TRHUNK_HANDLE_MAPPING_DATABASE_ENTRY_FROM_LISTENTRY (ListEntry);
108
109 if (CompareGuid (TagGuid, &HandleMapEntry->TagGuid)) {
110 Found = TRUE;
111 if (*Reference == 0) {
112 Status = HiiLibNewString (HandleMapEntry->UefiHiiHandle, &StringId2, NewString);
113 } else {
114 Status = HiiLibSetString (HandleMapEntry->UefiHiiHandle, *Reference, NewString);
115 }
116 if (EFI_ERROR (Status)) {
117 return Status;
118 }
119 if (*Reference == 0) {
120 if (StringId1 == (EFI_STRING_ID) 0) {
121 StringId1 = StringId2;
122 } else {
123 if (StringId1 != StringId2) {
124 ASSERT(FALSE);
125 return EFI_INVALID_PARAMETER;
126 }
127 }
128 }
129 }
130 }
131
132 if (Found) {
133 *Reference = StringId1;
134 Status = EFI_SUCCESS;
135 } else {
136 ASSERT (FALSE);
137 Status = EFI_NOT_FOUND;
138 }
139
140 return Status;
141 }
142
143 EFI_STATUS
144 EFIAPI
145 HiiNewString (
146 IN EFI_HII_PROTOCOL *This,
147 IN CHAR16 *Language,
148 IN FRAMEWORK_EFI_HII_HANDLE Handle,
149 IN OUT STRING_REF *Reference,
150 IN CHAR16 *NewString
151 )
152 /*++
153
154 Routine Description:
155 This function allows a new String to be added to an already existing String Package.
156 We will make a buffer the size of the package + StrSize of the new string. We will
157 copy the string package that first gets changed and the following language packages until
158 we encounter the NULL string package. All this time we will ensure that the offsets have
159 been adjusted.
160
161 Arguments:
162
163 Returns:
164
165 --*/
166 {
167 EFI_STATUS Status;
168 EFI_HII_THUNK_PRIVATE_DATA *Private;
169 EFI_GUID TagGuid;
170
171 Private = EFI_HII_THUNK_PRIVATE_DATA_FROM_THIS(This);
172
173 Status = GetTagGuidByFrameworkHiiHandle (Private, Handle, &TagGuid);
174 ASSERT_EFI_ERROR (Status);
175
176 Status = HiiThunkNewStringForAllStringPackages (Private, &TagGuid, Language, Reference, NewString);
177 //
178 // For UNI file, some String may not be defined for a language. This has been true for a lot of platform code.
179 // For this case, EFI_NOT_FOUND will be returned. To allow the old code to be run without porting, we don't assert
180 // on EFI_NOT_FOUND. The missing String will be declared if user select differnt languages for the platform.
181 //
182 ASSERT_EFI_ERROR (EFI_ERROR (Status) && Status != EFI_NOT_FOUND);
183
184 return Status;
185 }
186
187 EFI_STATUS
188 EFIAPI
189 HiiResetStrings (
190 IN EFI_HII_PROTOCOL *This,
191 IN FRAMEWORK_EFI_HII_HANDLE Handle
192 )
193 /*++
194
195 Routine Description:
196
197 This function removes any new strings that were added after the initial string export for this handle.
198
199 Arguments:
200
201 Returns:
202
203 --*/
204 {
205 ASSERT (FALSE);
206 return EFI_UNSUPPORTED;
207 }
208
209 EFI_STATUS
210 EFIAPI
211 HiiGetString (
212 IN EFI_HII_PROTOCOL *This,
213 IN FRAMEWORK_EFI_HII_HANDLE Handle,
214 IN STRING_REF Token,
215 IN BOOLEAN Raw,
216 IN CHAR16 *LanguageString,
217 IN OUT UINTN *BufferLengthTemp,
218 OUT EFI_STRING StringBuffer
219 )
220 /*++
221
222 Routine Description:
223
224 This function extracts a string from a package already registered with the EFI HII database.
225
226 Arguments:
227 This - A pointer to the EFI_HII_PROTOCOL instance.
228 Handle - The HII handle on which the string resides.
229 Token - The string token assigned to the string.
230 Raw - If TRUE, the string is returned unedited in the internal storage format described
231 above. If false, the string returned is edited by replacing <cr> with <space>
232 and by removing special characters such as the <wide> prefix.
233 LanguageString - Pointer to a NULL-terminated string containing a single ISO 639-2 language
234 identifier, indicating the language to print. If the LanguageString is empty (starts
235 with a NULL), the default system language will be used to determine the language.
236 BufferLength - Length of the StringBuffer. If the status reports that the buffer width is too
237 small, this parameter is filled with the length of the buffer needed.
238 StringBuffer - The buffer designed to receive the characters in the string. Type EFI_STRING is
239 defined in String.
240
241 Returns:
242 EFI_INVALID_PARAMETER - If input parameter is invalid.
243 EFI_BUFFER_TOO_SMALL - If the *BufferLength is too small.
244 EFI_SUCCESS - Operation is successful.
245
246 --*/
247 {
248 LIST_ENTRY *ListEntry;
249 HII_TRHUNK_HANDLE_MAPPING_DATABASE_ENTRY *HandleMapEntry;
250 CHAR8 *AsciiLanguage;
251 EFI_HII_THUNK_PRIVATE_DATA *Private;
252
253 Private = EFI_HII_THUNK_PRIVATE_DATA_FROM_THIS(This);
254
255 if (LanguageString == NULL) {
256 AsciiLanguage = NULL;
257 } else {
258 AsciiLanguage = AllocateZeroPool (StrLen (LanguageString) + 1);
259 if (AsciiLanguage == NULL) {
260 return EFI_OUT_OF_RESOURCES;
261 }
262 UnicodeStrToAsciiStr (LanguageString, AsciiLanguage);
263 }
264
265 for (ListEntry = Private->HiiThunkHandleMappingDBListHead.ForwardLink;
266 ListEntry != &Private->HiiThunkHandleMappingDBListHead;
267 ListEntry = ListEntry->ForwardLink
268 ) {
269
270 HandleMapEntry = HII_TRHUNK_HANDLE_MAPPING_DATABASE_ENTRY_FROM_LISTENTRY (ListEntry);
271
272 if (Handle == HandleMapEntry->FrameworkHiiHandle) {
273 if (AsciiLanguage == NULL) {
274 return HiiLibGetString (HandleMapEntry->UefiHiiHandle, Token, StringBuffer, BufferLengthTemp);
275 } else {
276 return mHiiStringProtocol->GetString (
277 mHiiStringProtocol,
278 AsciiLanguage,
279 HandleMapEntry->UefiHiiHandle,
280 Token,
281 StringBuffer,
282 BufferLengthTemp,
283 NULL
284 );
285 }
286 }
287 }
288
289 return EFI_NOT_FOUND;
290 }
291
292 EFI_STATUS
293 EFIAPI
294 HiiGetLine (
295 IN EFI_HII_PROTOCOL *This,
296 IN FRAMEWORK_EFI_HII_HANDLE Handle,
297 IN STRING_REF Token,
298 IN OUT UINT16 *Index,
299 IN UINT16 LineWidth,
300 IN CHAR16 *LanguageString,
301 IN OUT UINT16 *BufferLength,
302 OUT EFI_STRING StringBuffer
303 )
304 /*++
305
306 Routine Description:
307
308 This function allows a program to extract a part of a string of not more than a given width.
309 With repeated calls, this allows a calling program to extract "lines" of text that fit inside
310 columns. The effort of measuring the fit of strings inside columns is localized to this call.
311
312 Arguments:
313
314 Returns:
315
316 --*/
317 {
318 ASSERT (FALSE);
319 return EFI_UNSUPPORTED;
320 }
321