]> git.proxmox.com Git - mirror_edk2.git/blob - EdkNt32Pkg/Dxe/PlatformBds/Generic/String.c
add in FrameworkIfrSupportLib
[mirror_edk2.git] / EdkNt32Pkg / Dxe / PlatformBds / Generic / String.c
1 /*++
2
3 Copyright (c) 2006 - 2007, 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_STATUS
33 InitializeStringSupport (
34 VOID
35 )
36 /*++
37
38 Routine Description:
39
40 Initialize HII global accessor for string support
41
42 Arguments:
43 None
44
45 Returns:
46 String from ID.
47
48 --*/
49 {
50 EFI_STATUS Status;
51 EFI_HII_PACKAGES *PackageList;
52 //
53 // There should only ever be one HII protocol
54 //
55 Status = gBS->LocateProtocol (
56 &gEfiHiiProtocolGuid,
57 NULL,
58 &Hii
59 );
60 if (!EFI_ERROR (Status)) {
61 PackageList = PreparePackages (1, &gBdsStringPackGuid, BdsStrings);
62 Status = Hii->NewPack (Hii, PackageList, &gStringPackHandle);
63 FreePool (PackageList);
64 }
65
66 return Status;
67 }
68
69 CHAR16 *
70 GetStringById (
71 IN STRING_REF Id
72 )
73 /*++
74
75 Routine Description:
76
77 Get string by string id from HII Interface
78
79 Arguments:
80
81 Id - String ID.
82
83 Returns:
84
85 CHAR16 * - String from ID.
86 NULL - If error occurs.
87
88 --*/
89 {
90 CHAR16 *String;
91 UINTN StringLength;
92 EFI_STATUS Status;
93
94 //
95 // Set default string size assumption at no more than 256 bytes
96 //
97 StringLength = 0x100;
98
99 String = AllocateZeroPool (StringLength);
100 if (String == NULL) {
101 //
102 // If this happens, we are oh-so-dead, but return a NULL in any case.
103 //
104 return NULL;
105 }
106 //
107 // Get the current string for the current Language
108 //
109 Status = Hii->GetString (Hii, gStringPackHandle, Id, FALSE, NULL, &StringLength, String);
110 if (EFI_ERROR (Status)) {
111 if (Status == EFI_BUFFER_TOO_SMALL) {
112 //
113 // Free the old pool
114 //
115 FreePool (String);
116
117 //
118 // Allocate new pool with correct value
119 //
120 String = AllocatePool (StringLength);
121 ASSERT (String != NULL);
122
123 Status = Hii->GetString (Hii, gStringPackHandle, Id, FALSE, NULL, &StringLength, String);
124 if (!EFI_ERROR (Status)) {
125 return String;
126 }
127 }
128
129 return NULL;
130 }
131
132 return String;
133 }