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