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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
/*++
Copyright (c) 2004 - 2010, Intel Corporation. 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.
Module Name:
StringParse.c
Abstract:
Routines for parsing HII string packs
--*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "Tiano.h"
#include "EfiUtilityMsgs.h"
#include "EfiInternalFormRepresentation.h"
#include "Hii.h"
#include "StringParse.h"
#include "HiiPack.h"
typedef struct _STRING_PACK_RECORD {
struct _STRING_PACK_RECORD *Next;
int Handle;
EFI_GUID PackageGuid;
EFI_GUID FormsetGuid;
EFI_HII_STRING_PACK *StringPack;
int StringPackSize;
int NumStringPacks;
} STRING_PACK_RECORD;
static STRING_PACK_RECORD *mStringPacks = NULL;
STATUS
StringGetPack (
int Handle, // matches handle passed in with StringParsePack()
EFI_HII_STRING_PACK **StringPack, // returned pointer to string pack
int *StringPackSize, // sizeof buffer pointed to by StringPack
int *NumStringPacks, // in the array pointed to by StringPack
EFI_GUID *FormsetGuid,
EFI_GUID *PackageGuid
)
/*++
Routine Description:
Get a string pack given to us previously
Arguments:
Handle - handle of string pack to get
StringPack - outgoing pointer to string pack on the given handle
StringPackSize - outgoing size of string pack pointed to by StringPack
NumStringPacks - outgoing number of string packs in StringPack[] array
FormsetGuid - outgoing GUID passed in with the string pack when it was parsed
PackageGuid - outgoing GUID passed in with the string pack when it was parsed
Returns:
STATUS_SUCCESS - string pack with matching handle was found
STATUS_ERROR - otherwise
--*/
{
STRING_PACK_RECORD *Rec;
for (Rec = mStringPacks; Rec != NULL; Rec = Rec->Next) {
if (Rec->Handle == Handle) {
*StringPack = Rec->StringPack;
*StringPackSize = Rec->StringPackSize;
*NumStringPacks = Rec->NumStringPacks;
return STATUS_SUCCESS;
}
}
return STATUS_ERROR;
}
STATUS
StringParsePack (
int Handle,
EFI_HII_STRING_PACK *StringPack,
EFI_GUID *FormsetGuid,
EFI_GUID *PackageGuid
)
/*++
Routine Description:
Parse a string pack, saving the information for later retrieval by the caller
Arguments:
Handle - handle of string pack
StringPack - pointer to string pack array to parse
FormsetGuid - GUID of the string pack
PackageGuid - package GUID from the HII data table from which this string pack orginated
Returns:
STATUS_SUCCESS - Stringpack processed successfully
STATUS_ERROR - otherwise
--*/
{
STRING_PACK_RECORD *Rec;
STRING_PACK_RECORD *TempRec;
int PackSize;
EFI_HII_STRING_PACK *TempPack;
//
// Allocate a new string pack record
//
Rec = (STRING_PACK_RECORD *) malloc (sizeof (STRING_PACK_RECORD));
if (Rec == NULL) {
Error (NULL, 0, 0, "memory allocation failure", NULL);
return STATUS_ERROR;
}
memset (Rec, 0, sizeof (STRING_PACK_RECORD));
Rec->Handle = Handle;
if (PackageGuid != NULL) {
memcpy (&Rec->PackageGuid, PackageGuid, sizeof (EFI_GUID));
}
if (FormsetGuid != NULL) {
memcpy (&Rec->FormsetGuid, FormsetGuid, sizeof (EFI_GUID));
}
//
// Walk the string packs to find the terminator
//
TempPack = StringPack;
PackSize = 0;
while (TempPack->Header.Length > 0) {
if (TempPack->Header.Type != EFI_HII_STRING) {
Error (NULL, 0, 0, "found a non-string pack in the string pack array", NULL);
free (Rec);
return STATUS_ERROR;
}
PackSize += TempPack->Header.Length;
Rec->NumStringPacks++;
TempPack = (EFI_HII_STRING_PACK *) ((char *) TempPack + TempPack->Header.Length);
}
//
// Add space for the terminator
//
PackSize += sizeof (EFI_HII_STRING_PACK);
Rec->StringPackSize = PackSize;
//
// Make a copy of the incoming string pack
//
Rec->StringPack = (EFI_HII_STRING_PACK *) malloc (PackSize);
if (Rec->StringPack == NULL) {
Error (NULL, 0, 0, "memory allocation failure", NULL);
free (Rec);
return STATUS_ERROR;
}
memcpy ((void *) Rec->StringPack, StringPack, PackSize);
//
// Add this record to our list
//
if (mStringPacks == NULL) {
mStringPacks = Rec;
} else {
for (TempRec = mStringPacks; TempRec->Next != NULL; TempRec = TempRec->Next)
;
TempRec->Next = Rec;
}
free (Rec->StringPack);
free (Rec);
return STATUS_SUCCESS;
}
STATUS
StringInit (
VOID
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
None
Returns:
GC_TODO: add return values
--*/
{
StringEnd ();
return STATUS_SUCCESS;
}
STATUS
StringEnd (
VOID
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
None
Returns:
GC_TODO: add return values
--*/
{
STRING_PACK_RECORD *Next;
//
// Free up all the memory we've allocated
//
while (mStringPacks != NULL) {
if (mStringPacks->StringPack != NULL) {
free (mStringPacks->StringPack);
}
Next = mStringPacks->Next;
free (mStringPacks);
mStringPacks = Next;
}
return STATUS_SUCCESS;
}
|