]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/UefiHiiLib/HiiLanguage.c
45e178c44646ddb7e36cef6a659b4cc17547d56e
[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 Retrieves a pointer to the a Null-terminated ASCII string containing the list
62 of languages that an HII handle in the HII Database supports. The returned
63 string is allocated using AllocatePool(). The caller is responsible for freeing
64 the returned string using FreePool(). The format of the returned string follows
65 the language format assumed the HII Database.
66
67 If HiiHandle is NULL, then ASSERT().
68
69 @param[in] HiiHandle A handle that was previously registered in the HII Database.
70
71 @retval NULL HiiHandle is not registered in the HII database
72 @retval NULL There are not enough resources available to retrieve the suported
73 languages.
74 @retval NULL The list of suported languages could not be retrieved.
75 @retval Other A pointer to the Null-terminated ASCII string of supported languages.
76
77 **/
78 CHAR8 *
79 EFIAPI
80 HiiGetSupportedLanguages (
81 IN EFI_HII_HANDLE HiiHandle
82 )
83 {
84 EFI_STATUS Status;
85 UINTN LanguageSize;
86 CHAR8 TempSupportedLanguages;
87 CHAR8 *SupportedLanguages;
88
89 ASSERT (HiiHandle != NULL);
90
91 //
92 // Retrieve the size required for the supported languages buffer.
93 //
94 LanguageSize = 0;
95 Status = gHiiString->GetLanguages (gHiiString, HiiHandle, &TempSupportedLanguages, &LanguageSize);
96
97 //
98 // If GetLanguages() returns EFI_SUCCESS for a zero size,
99 // then there are no supported languages registered for HiiHandle. If GetLanguages()
100 // returns an error other than EFI_BUFFER_TOO_SMALL, then HiiHandle is not present
101 // in the HII Database
102 //
103 if (Status != EFI_BUFFER_TOO_SMALL) {
104 //
105 // Return NULL if the size can not be retrieved, or if HiiHandle is not in the HII Database
106 //
107 return NULL;
108 }
109
110 //
111 // Allocate the supported languages buffer.
112 //
113 SupportedLanguages = AllocateZeroPool (LanguageSize);
114 if (SupportedLanguages == NULL) {
115 //
116 // Return NULL if allocation fails.
117 //
118 return NULL;
119 }
120
121 //
122 // Retrieve the supported languages string
123 //
124 Status = gHiiString->GetLanguages (gHiiString, HiiHandle, SupportedLanguages, &LanguageSize);
125 if (EFI_ERROR (Status)) {
126 //
127 // Free the buffer and return NULL if the supported languages can not be retrieved.
128 //
129 FreePool (SupportedLanguages);
130 return NULL;
131 }
132
133 //
134 // Return the Null-terminated ASCII string of supported languages
135 //
136 return SupportedLanguages;
137 }
138