-
Notifications
You must be signed in to change notification settings - Fork 2
/
UnicodeCollation.c
159 lines (133 loc) · 5.12 KB
/
UnicodeCollation.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/** @file
Unicode Collation Support component that hides the trivial difference of Unicode Collation
and Unicode collation 2 Protocol.
Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2016, The EFIDroid Project. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "LKL.h"
EFI_UNICODE_COLLATION_PROTOCOL *mUnicodeCollationInterface = NULL;
/**
Worker function to initialize Unicode Collation support.
It tries to locate Unicode Collation (2) protocol and matches it with current
platform language code.
@param AgentHandle The handle used to open Unicode Collation (2) protocol.
@param ProtocolGuid The pointer to Unicode Collation (2) protocol GUID.
@param VariableName The name of the RFC 4646 or ISO 639-2 language variable.
@param DefaultLanguage The default language in case the RFC 4646 or ISO 639-2 language is absent.
@retval EFI_SUCCESS The Unicode Collation (2) protocol has been successfully located.
@retval Others The Unicode Collation (2) protocol has not been located.
**/
EFI_STATUS
InitializeUnicodeCollationSupportWorker (
IN EFI_HANDLE AgentHandle,
IN EFI_GUID *ProtocolGuid,
IN CONST CHAR16 *VariableName,
IN CONST CHAR8 *DefaultLanguage
)
{
EFI_STATUS ReturnStatus;
EFI_STATUS Status;
UINTN NumHandles;
UINTN Index;
EFI_HANDLE *Handles;
EFI_UNICODE_COLLATION_PROTOCOL *Uci;
BOOLEAN Iso639Language;
CHAR8 *Language;
CHAR8 *BestLanguage;
Status = gBS->LocateHandleBuffer (
ByProtocol,
ProtocolGuid,
NULL,
&NumHandles,
&Handles
);
if (EFI_ERROR (Status)) {
return Status;
}
Iso639Language = (BOOLEAN) (ProtocolGuid == &gEfiUnicodeCollationProtocolGuid);
GetEfiGlobalVariable2 (VariableName, (VOID**) &Language, NULL);
ReturnStatus = EFI_UNSUPPORTED;
for (Index = 0; Index < NumHandles; Index++) {
//
// Open Unicode Collation Protocol
//
Status = gBS->OpenProtocol (
Handles[Index],
ProtocolGuid,
(VOID **) &Uci,
AgentHandle,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
continue;
}
//
// Find the best matching matching language from the supported languages
// of Unicode Collation (2) protocol.
//
BestLanguage = GetBestLanguage (
Uci->SupportedLanguages,
Iso639Language,
(Language == NULL) ? "" : Language,
DefaultLanguage,
NULL
);
if (BestLanguage != NULL) {
FreePool (BestLanguage);
mUnicodeCollationInterface = Uci;
ReturnStatus = EFI_SUCCESS;
break;
}
}
if (Language != NULL) {
FreePool (Language);
}
FreePool (Handles);
return ReturnStatus;
}
/**
Initialize Unicode Collation support.
It tries to locate Unicode Collation 2 protocol and matches it with current
platform language code. If for any reason the first attempt fails, it then tries to
use Unicode Collation Protocol.
@param AgentHandle The handle used to open Unicode Collation (2) protocol.
@retval EFI_SUCCESS The Unicode Collation (2) protocol has been successfully located.
@retval Others The Unicode Collation (2) protocol has not been located.
**/
EFI_STATUS
InitializeUnicodeCollationSupport (
IN EFI_HANDLE AgentHandle
)
{
EFI_STATUS Status;
Status = EFI_UNSUPPORTED;
//
// First try to use RFC 4646 Unicode Collation 2 Protocol.
//
Status = InitializeUnicodeCollationSupportWorker (
AgentHandle,
&gEfiUnicodeCollation2ProtocolGuid,
L"PlatformLang",
(CONST CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLang)
);
//
// If the attempt to use Unicode Collation 2 Protocol fails, then we fall back
// on the ISO 639-2 Unicode Collation Protocol.
//
if (EFI_ERROR (Status)) {
Status = InitializeUnicodeCollationSupportWorker (
AgentHandle,
&gEfiUnicodeCollationProtocolGuid,
L"Lang",
(CONST CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultLang)
);
}
return Status;
}