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