]> git.proxmox.com Git - mirror_edk2.git/blob - EdkUnixPkg/Dxe/PlatformBds/Generic/String.c
435665eb76240122ee93b978954fae31645cd349
[mirror_edk2.git] / EdkUnixPkg / Dxe / PlatformBds / Generic / String.c
1 /*++
2
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 string.c
15
16 Abstract:
17
18 String support
19
20 Revision History
21
22 --*/
23
24 #include "Bds.h"
25 #include "String.h"
26 #include "Language.h"
27
28 extern UINT8 BdsStrings[];
29
30 EFI_GUID gBdsStringPackGuid = { 0x7bac95d3, 0xddf, 0x42f3, 0x9e, 0x24, 0x7c, 0x64, 0x49, 0x40, 0x37, 0x9a };
31
32 EFI_HII_HANDLE gStringPackHandle;
33 EFI_HII_PROTOCOL *Hii;
34
35 EFI_STATUS
36 InitializeStringSupport (
37 VOID
38 )
39 /*++
40
41 Routine Description:
42
43 Initialize HII global accessor for string support
44
45 Arguments:
46 None
47
48 Returns:
49 String from ID.
50
51 --*/
52 {
53 EFI_STATUS Status;
54 EFI_HII_PACKAGES *PackageList;
55 //
56 // There should only ever be one HII protocol
57 //
58 Status = gBS->LocateProtocol (
59 &gEfiHiiProtocolGuid,
60 NULL,
61 &Hii
62 );
63 if (!EFI_ERROR (Status)) {
64 PackageList = PreparePackages (1, &gBdsStringPackGuid, BdsStrings);
65 Status = Hii->NewPack (Hii, PackageList, &gStringPackHandle);
66 gBS->FreePool (PackageList);
67 }
68
69 return Status;
70 }
71
72 CHAR16 *
73 GetStringById (
74 IN STRING_REF Id
75 )
76 /*++
77
78 Routine Description:
79
80 Get string by string id from HII Interface
81
82 Arguments:
83
84 Id - String ID.
85
86 Returns:
87
88 CHAR16 * - String from ID.
89 NULL - If error occurs.
90
91 --*/
92 {
93 CHAR16 *String;
94 UINTN StringLength;
95 EFI_STATUS Status;
96
97 //
98 // Set default string size assumption at no more than 256 bytes
99 //
100 StringLength = 0x100;
101
102 String = AllocateZeroPool (StringLength);
103 if (String == NULL) {
104 //
105 // If this happens, we are oh-so-dead, but return a NULL in any case.
106 //
107 return NULL;
108 }
109 //
110 // Get the current string for the current Language
111 //
112 Status = Hii->GetString (Hii, gStringPackHandle, Id, FALSE, NULL, &StringLength, String);
113 if (EFI_ERROR (Status)) {
114 if (Status == EFI_BUFFER_TOO_SMALL) {
115 //
116 // Free the old pool
117 //
118 gBS->FreePool (String);
119
120 //
121 // Allocate new pool with correct value
122 //
123 String = AllocatePool (StringLength);
124 ASSERT (String != NULL);
125
126 Status = Hii->GetString (Hii, gStringPackHandle, Id, FALSE, NULL, &StringLength, String);
127 if (!EFI_ERROR (Status)) {
128 return String;
129 }
130 }
131
132 return NULL;
133 }
134
135 return String;
136 }