]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/Strings.c
clean up the un-suitable ';' location when declaring the functions. The regular is...
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / FrameworkHiiToUefiHiiThunk / Strings.c
... / ...
CommitLineData
1/**@file\r
2 This file implements the protocol functions related to string package.\r
3 \r
4Copyright (c) 2006 - 2008, Intel Corporation\r
5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15\r
16#include "HiiDatabase.h"\r
17\r
18typedef struct {\r
19 CHAR8 *Iso639;\r
20 CHAR8 *Rfc3066;\r
21} ISO639TORFC3066MAP;\r
22\r
23ISO639TORFC3066MAP Iso639ToRfc3066Map [] = {\r
24 {"eng", "en-US"},\r
25 {"fra", "fr-FR"},\r
26};\r
27\r
28CHAR8 *\r
29ConvertIso639ToRfc3066 (\r
30 CHAR8 *Iso638Lang\r
31 )\r
32{\r
33 UINTN Index;\r
34\r
35 for (Index = 0; Index < sizeof (Iso639ToRfc3066Map) / sizeof (Iso639ToRfc3066Map[0]); Index++) {\r
36 if (AsciiStrnCmp (Iso638Lang, Iso639ToRfc3066Map[Index].Iso639, AsciiStrSize (Iso638Lang)) == 0) {\r
37 return Iso639ToRfc3066Map[Index].Rfc3066;\r
38 }\r
39 }\r
40\r
41 return (CHAR8 *) NULL;\r
42}\r
43\r
44\r
45EFI_STATUS\r
46EFIAPI\r
47HiiTestString (\r
48 IN EFI_HII_PROTOCOL *This,\r
49 IN CHAR16 *StringToTest,\r
50 IN OUT UINT32 *FirstMissing,\r
51 OUT UINT32 *GlyphBufferSize\r
52 )\r
53/*++\r
54\r
55Routine Description:\r
56 Test if all of the characters in a string have corresponding font characters.\r
57\r
58Arguments:\r
59\r
60Returns:\r
61\r
62--*/\r
63{\r
64 ASSERT (FALSE);\r
65 return EFI_SUCCESS;\r
66}\r
67\r
68\r
69\r
70EFI_STATUS\r
71GetTagGuidByFwHiiHandle (\r
72 IN CONST HII_THUNK_PRIVATE_DATA *Private,\r
73 IN FRAMEWORK_EFI_HII_HANDLE FwHiiHandle,\r
74 OUT EFI_GUID *TagGuid\r
75 )\r
76{\r
77 LIST_ENTRY *Link;\r
78 HII_THUNK_CONTEXT *ThunkContext;\r
79\r
80 ASSERT (TagGuid != NULL);\r
81\r
82 Link = GetFirstNode (&Private->ThunkContextListHead);\r
83 while (!IsNull (&Private->ThunkContextListHead, Link)) {\r
84\r
85 ThunkContext = HII_THUNK_CONTEXT_FROM_LINK (Link);\r
86\r
87 if (FwHiiHandle == ThunkContext->FwHiiHandle) {\r
88 CopyGuid (TagGuid, &ThunkContext->TagGuid);\r
89 return EFI_SUCCESS;\r
90 }\r
91\r
92 Link = GetNextNode (&Private->ThunkContextListHead, Link);\r
93 }\r
94\r
95 return EFI_NOT_FOUND;\r
96}\r
97\r
98\r
99\r
100EFI_STATUS\r
101EFIAPI\r
102HiiNewString (\r
103 IN EFI_HII_PROTOCOL *This,\r
104 IN CHAR16 *Language,\r
105 IN FRAMEWORK_EFI_HII_HANDLE Handle,\r
106 IN OUT STRING_REF *Reference,\r
107 IN CHAR16 *NewString\r
108 )\r
109/*++\r
110\r
111Routine Description:\r
112 This function allows a new String to be added to an already existing String Package.\r
113 We will make a buffer the size of the package + StrSize of the new string. We will\r
114 copy the string package that first gets changed and the following language packages until\r
115 we encounter the NULL string package. All this time we will ensure that the offsets have\r
116 been adjusted.\r
117\r
118Arguments:\r
119\r
120Returns:\r
121\r
122--*/\r
123{\r
124 EFI_STATUS Status;\r
125 HII_THUNK_PRIVATE_DATA *Private;\r
126 EFI_GUID TagGuid;\r
127 LIST_ENTRY *Link;\r
128 HII_THUNK_CONTEXT *ThunkContext;\r
129 EFI_STRING_ID StringId;\r
130 EFI_STRING_ID LastStringId;\r
131 CHAR8 AsciiLanguage[ISO_639_2_ENTRY_SIZE + 1];\r
132 BOOLEAN Found;\r
133 CHAR8 *Rfc3066AsciiLanguage;\r
134\r
135 LastStringId = (EFI_STRING_ID) 0;\r
136 StringId = (EFI_STRING_ID) 0;\r
137 Found = FALSE;\r
138 Rfc3066AsciiLanguage = NULL;\r
139\r
140 Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);\r
141\r
142 Status = GetTagGuidByFwHiiHandle (Private, Handle, &TagGuid);\r
143 ASSERT_EFI_ERROR (Status);\r
144\r
145 if (Language != NULL) {\r
146 ZeroMem (AsciiLanguage, sizeof (AsciiLanguage));;\r
147 \r
148 UnicodeStrToAsciiStr (Language, AsciiLanguage);\r
149 Rfc3066AsciiLanguage = ConvertIso639ToRfc3066 (AsciiLanguage);\r
150 ASSERT (Rfc3066AsciiLanguage != NULL);\r
151 }\r
152\r
153 Link = GetFirstNode (&Private->ThunkContextListHead);\r
154 while (!IsNull (&Private->ThunkContextListHead, Link)) {\r
155 ThunkContext = HII_THUNK_CONTEXT_FROM_LINK (Link);\r
156\r
157 if (CompareGuid (&TagGuid, &ThunkContext->TagGuid)) {\r
158 Found = TRUE;\r
159 if (*Reference == 0) {\r
160 //\r
161 // Create a new string token.\r
162 //\r
163 if (Rfc3066AsciiLanguage == NULL) {\r
164 //\r
165 // For all languages in the package list.\r
166 //\r
167 Status = HiiLibNewString (ThunkContext->UefiHiiHandle, &StringId, NewString);\r
168 } else {\r
169 //\r
170 // For specified language.\r
171 //\r
172 Status = mHiiStringProtocol->NewString (\r
173 mHiiStringProtocol,\r
174 ThunkContext->UefiHiiHandle,\r
175 &StringId,\r
176 Rfc3066AsciiLanguage,\r
177 NULL,\r
178 NewString,\r
179 NULL\r
180 );\r
181 }\r
182 } else {\r
183 //\r
184 // Update the existing string token.\r
185 //\r
186 if (Rfc3066AsciiLanguage == NULL) {\r
187 //\r
188 // For all languages in the package list.\r
189 //\r
190 Status = HiiLibSetString (ThunkContext->UefiHiiHandle, *Reference, NewString);\r
191 } else {\r
192 //\r
193 // For specified language.\r
194 //\r
195 Status = mHiiStringProtocol->SetString (\r
196 mHiiStringProtocol,\r
197 ThunkContext->UefiHiiHandle,\r
198 *Reference,\r
199 Rfc3066AsciiLanguage,\r
200 NewString,\r
201 NULL\r
202 );\r
203 }\r
204 }\r
205 if (EFI_ERROR (Status)) {\r
206 //\r
207 // Only EFI_INVALID_PARAMETER is defined in HII 0.92 specification.\r
208 //\r
209 return EFI_INVALID_PARAMETER;\r
210 }\r
211\r
212 if (*Reference == 0) {\r
213 //\r
214 // When creating new string token, make sure all created token is the same\r
215 // for all string packages registered using FW HII interface.\r
216 //\r
217 if (LastStringId == (EFI_STRING_ID) 0) {\r
218 LastStringId = StringId;\r
219 } else {\r
220 if (LastStringId != StringId) {\r
221 ASSERT(FALSE);\r
222 return EFI_INVALID_PARAMETER;\r
223 }\r
224 }\r
225 }\r
226 }\r
227\r
228 Link = GetNextNode (&Private->ThunkContextListHead, Link);\r
229 }\r
230\r
231 if (Found) {\r
232 if (*Reference == 0) {\r
233 *Reference = StringId;\r
234 }\r
235 Status = EFI_SUCCESS;\r
236 } else {\r
237 DEBUG((EFI_D_ERROR, "Thunk HiiNewString fails to find the String Packages to update\n"));\r
238 //\r
239 // BUGBUG: Remove ths ASSERT when development is done.\r
240 //\r
241 ASSERT (FALSE);\r
242 Status = EFI_NOT_FOUND;\r
243 }\r
244 \r
245 //\r
246 // For UNI file, some String may not be defined for a language. This has been true for a lot of platform code.\r
247 // For this case, EFI_NOT_FOUND will be returned. To allow the old code to be run without porting, we don't assert \r
248 // on EFI_NOT_FOUND. The missing Strings will be shown if user select a differnt languages other than the default\r
249 // English language for the platform.\r
250 //\r
251 ASSERT_EFI_ERROR (EFI_ERROR (Status) && Status != EFI_NOT_FOUND); \r
252\r
253 return Status;\r
254}\r
255\r
256EFI_STATUS\r
257EFIAPI\r
258HiiResetStrings (\r
259 IN EFI_HII_PROTOCOL *This,\r
260 IN FRAMEWORK_EFI_HII_HANDLE Handle\r
261 )\r
262/*++\r
263\r
264Routine Description:\r
265\r
266 This function removes any new strings that were added after the initial string export for this handle.\r
267\r
268Arguments:\r
269\r
270Returns:\r
271\r
272--*/\r
273{\r
274 return EFI_SUCCESS;\r
275}\r
276\r
277EFI_STATUS\r
278EFIAPI\r
279HiiGetString (\r
280 IN EFI_HII_PROTOCOL *This,\r
281 IN FRAMEWORK_EFI_HII_HANDLE Handle,\r
282 IN STRING_REF Token,\r
283 IN BOOLEAN Raw,\r
284 IN CHAR16 *LanguageString,\r
285 IN OUT UINTN *BufferLengthTemp,\r
286 OUT EFI_STRING StringBuffer\r
287 )\r
288/*++\r
289\r
290Routine Description:\r
291\r
292 This function extracts a string from a package already registered with the EFI HII database.\r
293\r
294Arguments:\r
295 This - A pointer to the EFI_HII_PROTOCOL instance.\r
296 Handle - The HII handle on which the string resides.\r
297 Token - The string token assigned to the string.\r
298 Raw - If TRUE, the string is returned unedited in the internal storage format described\r
299 above. If false, the string returned is edited by replacing <cr> with <space>\r
300 and by removing special characters such as the <wide> prefix.\r
301 LanguageString - Pointer to a NULL-terminated string containing a single ISO 639-2 language\r
302 identifier, indicating the language to print. If the LanguageString is empty (starts\r
303 with a NULL), the default system language will be used to determine the language.\r
304 BufferLength - Length of the StringBuffer. If the status reports that the buffer width is too\r
305 small, this parameter is filled with the length of the buffer needed.\r
306 StringBuffer - The buffer designed to receive the characters in the string. Type EFI_STRING is\r
307 defined in String.\r
308\r
309Returns:\r
310 EFI_INVALID_PARAMETER - If input parameter is invalid.\r
311 EFI_BUFFER_TOO_SMALL - If the *BufferLength is too small.\r
312 EFI_SUCCESS - Operation is successful.\r
313\r
314--*/\r
315{\r
316 CHAR8 *Iso639AsciiLanguage;\r
317 HII_THUNK_PRIVATE_DATA *Private;\r
318 CHAR8 *Rfc3066AsciiLanguage;\r
319 EFI_HII_HANDLE UefiHiiHandle;\r
320 EFI_STATUS Status;\r
321\r
322 Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);\r
323\r
324 Iso639AsciiLanguage = NULL;\r
325 Rfc3066AsciiLanguage = NULL;\r
326\r
327 if (LanguageString != NULL) {\r
328 Iso639AsciiLanguage = AllocateZeroPool (StrLen (LanguageString) + 1);\r
329 if (Iso639AsciiLanguage == NULL) {\r
330 return EFI_OUT_OF_RESOURCES;\r
331 }\r
332 UnicodeStrToAsciiStr (LanguageString, Iso639AsciiLanguage);\r
333\r
334 //\r
335 // Caller of Framework HII Interface uses the Language Identification String defined \r
336 // in Iso639. So map it to the Language Identifier defined in RFC3066.\r
337 //\r
338 Rfc3066AsciiLanguage = ConvertIso639ToRfc3066 (Iso639AsciiLanguage);\r
339\r
340 //\r
341 // If Rfc3066AsciiLanguage is NULL, more language mapping must be added to \r
342 // Iso639ToRfc3066Map.\r
343 //\r
344 ASSERT (Rfc3066AsciiLanguage != NULL);\r
345 \r
346 }\r
347\r
348 UefiHiiHandle = FwHiiHandleToUefiHiiHandle (Private, Handle);\r
349 if (UefiHiiHandle == NULL) {\r
350 Status = EFI_NOT_FOUND;\r
351 goto Done;\r
352 }\r
353\r
354 if (Rfc3066AsciiLanguage == NULL) {\r
355 Status = HiiLibGetString (UefiHiiHandle, Token, StringBuffer, BufferLengthTemp);\r
356 } else {\r
357 Status = mHiiStringProtocol->GetString (\r
358 mHiiStringProtocol,\r
359 Rfc3066AsciiLanguage,\r
360 UefiHiiHandle,\r
361 Token,\r
362 StringBuffer,\r
363 BufferLengthTemp,\r
364 NULL\r
365 );\r
366 }\r
367\r
368Done:\r
369 SafeFreePool (Iso639AsciiLanguage);\r
370 \r
371 return Status;\r
372}\r
373\r
374EFI_STATUS\r
375EFIAPI\r
376HiiGetLine (\r
377 IN EFI_HII_PROTOCOL *This,\r
378 IN FRAMEWORK_EFI_HII_HANDLE Handle,\r
379 IN STRING_REF Token,\r
380 IN OUT UINT16 *Index,\r
381 IN UINT16 LineWidth,\r
382 IN CHAR16 *LanguageString,\r
383 IN OUT UINT16 *BufferLength,\r
384 OUT EFI_STRING StringBuffer\r
385 )\r
386/*++\r
387\r
388Routine Description:\r
389\r
390 This function allows a program to extract a part of a string of not more than a given width.\r
391 With repeated calls, this allows a calling program to extract "lines" of text that fit inside\r
392 columns. The effort of measuring the fit of strings inside columns is localized to this call.\r
393\r
394Arguments:\r
395\r
396Returns:\r
397\r
398--*/\r
399{\r
400 ASSERT (FALSE);\r
401 return EFI_UNSUPPORTED;\r
402}\r
403\r
404\r