TianoCore EDK2 master
Loading...
Searching...
No Matches
Language.c
Go to the documentation of this file.
1
9#include "Bds.h"
10#define ISO_639_2_ENTRY_SIZE 3
11
39BOOLEAN
41 IN CHAR8 *SupportedLang,
42 IN CHAR8 *Lang,
43 IN BOOLEAN Iso639Language
44 )
45{
46 UINTN Index;
47 UINTN CompareLength;
48 UINTN LanguageLength;
49
50 if (Iso639Language) {
51 CompareLength = ISO_639_2_ENTRY_SIZE;
52 for (Index = 0; Index < AsciiStrLen (SupportedLang); Index += CompareLength) {
53 if (AsciiStrnCmp (Lang, SupportedLang + Index, CompareLength) == 0) {
54 //
55 // Successfully find the Lang string in SupportedLang string.
56 //
57 return TRUE;
58 }
59 }
60
61 return FALSE;
62 } else {
63 //
64 // Compare RFC4646 language code
65 //
66 for (LanguageLength = 0; Lang[LanguageLength] != '\0'; LanguageLength++) {
67 }
68
69 for ( ; *SupportedLang != '\0'; SupportedLang += CompareLength) {
70 //
71 // Skip ';' characters in SupportedLang
72 //
73 for ( ; *SupportedLang != '\0' && *SupportedLang == ';'; SupportedLang++) {
74 }
75
76 //
77 // Determine the length of the next language code in SupportedLang
78 //
79 for (CompareLength = 0; SupportedLang[CompareLength] != '\0' && SupportedLang[CompareLength] != ';'; CompareLength++) {
80 }
81
82 if ((CompareLength == LanguageLength) &&
83 (AsciiStrnCmp (Lang, SupportedLang, CompareLength) == 0))
84 {
85 //
86 // Successfully find the Lang string in SupportedLang string.
87 //
88 return TRUE;
89 }
90 }
91
92 return FALSE;
93 }
94}
95
108VOID
110 IN CHAR16 *LangName,
111 IN CHAR8 *SupportedLang,
112 IN CHAR8 *DefaultLang,
113 IN BOOLEAN Iso639Language
114 )
115{
116 CHAR8 *Lang;
117
118 //
119 // Find current Lang or PlatformLang from EFI Variable.
120 //
121 GetEfiGlobalVariable2 (LangName, (VOID **)&Lang, NULL);
122
123 //
124 // If Lang or PlatformLang variable is not found,
125 // or it has been set to an unsupported value(not one of the supported language codes),
126 // set the default language code to it.
127 //
128 if ((Lang == NULL) || !IsLangInSupportedLangCodes (SupportedLang, Lang, Iso639Language)) {
129 //
130 // The default language code should be one of the supported language codes.
131 //
132 ASSERT (IsLangInSupportedLangCodes (SupportedLang, DefaultLang, Iso639Language));
134 LangName,
135 &gEfiGlobalVariableGuid,
136 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
137 AsciiStrSize (DefaultLang),
138 DefaultLang
139 );
140 }
141
142 if (Lang != NULL) {
143 FreePool (Lang);
144 }
145}
146
154VOID
156 BOOLEAN LangCodesSettingRequired
157 )
158{
159 EFI_STATUS Status;
160 CHAR8 *LangCodes;
161 CHAR8 *PlatformLangCodes;
162
163 LangCodes = (CHAR8 *)PcdGetPtr (PcdUefiVariableDefaultLangCodes);
164 PlatformLangCodes = (CHAR8 *)PcdGetPtr (PcdUefiVariableDefaultPlatformLangCodes);
165 if (LangCodesSettingRequired) {
166 if (!FeaturePcdGet (PcdUefiVariableDefaultLangDeprecate)) {
167 //
168 // UEFI 2.1 depricated this variable so we support turning it off
169 //
170 Status = gRT->SetVariable (
171 L"LangCodes",
172 &gEfiGlobalVariableGuid,
173 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
174 AsciiStrSize (LangCodes),
175 LangCodes
176 );
177 //
178 // Platform needs to make sure setting volatile variable before calling 3rd party code shouldn't fail.
179 //
180 ASSERT_EFI_ERROR (Status);
181 }
182
183 Status = gRT->SetVariable (
184 L"PlatformLangCodes",
185 &gEfiGlobalVariableGuid,
186 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
187 AsciiStrSize (PlatformLangCodes),
188 PlatformLangCodes
189 );
190 //
191 // Platform needs to make sure setting volatile variable before calling 3rd party code shouldn't fail.
192 //
193 ASSERT_EFI_ERROR (Status);
194 }
195
196 if (!FeaturePcdGet (PcdUefiVariableDefaultLangDeprecate)) {
197 //
198 // UEFI 2.1 depricated this variable so we support turning it off
199 //
200 InitializeLangVariable (L"Lang", LangCodes, (CHAR8 *)PcdGetPtr (PcdUefiVariableDefaultLang), TRUE);
201 }
202
203 InitializeLangVariable (L"PlatformLang", PlatformLangCodes, (CHAR8 *)PcdGetPtr (PcdUefiVariableDefaultPlatformLang), FALSE);
204}
UINT64 UINTN
UINTN EFIAPI AsciiStrLen(IN CONST CHAR8 *String)
Definition: String.c:641
INTN EFIAPI AsciiStrnCmp(IN CONST CHAR8 *FirstString, IN CONST CHAR8 *SecondString, IN UINTN Length)
Definition: String.c:872
UINTN EFIAPI AsciiStrSize(IN CONST CHAR8 *String)
Definition: String.c:681
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID InitializeLangVariable(IN CHAR16 *LangName, IN CHAR8 *SupportedLang, IN CHAR8 *DefaultLang, IN BOOLEAN Iso639Language)
Definition: Language.c:109
BOOLEAN IsLangInSupportedLangCodes(IN CHAR8 *SupportedLang, IN CHAR8 *Lang, IN BOOLEAN Iso639Language)
Definition: Language.c:40
VOID InitializeLanguage(BOOLEAN LangCodesSettingRequired)
Definition: Language.c:155
EFI_RUNTIME_SERVICES * gRT
EFI_STATUS BdsDxeSetVariableAndReportStatusCodeOnError(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN UINT32 Attributes, IN UINTN DataSize, IN VOID *Data)
Definition: BdsEntry.c:1159
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define PcdGetPtr(TokenName)
Definition: PcdLib.h:388
#define FeaturePcdGet(TokenName)
Definition: PcdLib.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
EFI_STATUS EFIAPI GetEfiGlobalVariable2(IN CONST CHAR16 *Name, OUT VOID **Value, OUT UINTN *Size OPTIONAL)
Definition: UefiLib.c:1470
#define EFI_VARIABLE_NON_VOLATILE