]>
git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Sample/Tools/Source/HiiPack/StringParse.c
8dd26e1529c32d4124343c484ff74fd437218ebb
3 Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
4 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
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.
18 Routines for parsing HII string packs
27 #include "EfiUtilityMsgs.h"
28 #include "EfiInternalFormRepresentation.h"
30 #include "StringParse.h"
33 typedef struct _STRING_PACK_RECORD
{
34 struct _STRING_PACK_RECORD
*Next
;
38 EFI_HII_STRING_PACK
*StringPack
;
43 static STRING_PACK_RECORD
*mStringPacks
= NULL
;
47 int Handle
, // matches handle passed in with StringParsePack()
48 EFI_HII_STRING_PACK
**StringPack
, // returned pointer to string pack
49 int *StringPackSize
, // sizeof buffer pointed to by StringPack
50 int *NumStringPacks
, // in the array pointed to by StringPack
51 EFI_GUID
*FormsetGuid
,
58 Get a string pack given to us previously
61 Handle - handle of string pack to get
62 StringPack - outgoing pointer to string pack on the given handle
63 StringPackSize - outgoing size of string pack pointed to by StringPack
64 NumStringPacks - outgoing number of string packs in StringPack[] array
65 FormsetGuid - outgoing GUID passed in with the string pack when it was parsed
66 PackageGuid - outgoing GUID passed in with the string pack when it was parsed
70 STATUS_SUCCESS - string pack with matching handle was found
71 STATUS_ERROR - otherwise
75 STRING_PACK_RECORD
*Rec
;
77 for (Rec
= mStringPacks
; Rec
!= NULL
; Rec
= Rec
->Next
) {
78 if (Rec
->Handle
== Handle
) {
79 *StringPack
= Rec
->StringPack
;
80 *StringPackSize
= Rec
->StringPackSize
;
81 *NumStringPacks
= Rec
->NumStringPacks
;
82 return STATUS_SUCCESS
;
92 EFI_HII_STRING_PACK
*StringPack
,
93 EFI_GUID
*FormsetGuid
,
100 Parse a string pack, saving the information for later retrieval by the caller
103 Handle - handle of string pack
104 StringPack - pointer to string pack array to parse
105 FormsetGuid - GUID of the string pack
106 PackageGuid - package GUID from the HII data table from which this string pack orginated
110 STATUS_SUCCESS - Stringpack processed successfully
111 STATUS_ERROR - otherwise
115 STRING_PACK_RECORD
*Rec
;
117 STRING_PACK_RECORD
*TempRec
;
119 EFI_HII_STRING_PACK
*TempPack
;
121 // Allocate a new string pack record
123 Rec
= (STRING_PACK_RECORD
*) malloc (sizeof (STRING_PACK_RECORD
));
125 Error (NULL
, 0, 0, "memory allocation failure", NULL
);
129 memset (Rec
, 0, sizeof (STRING_PACK_RECORD
));
130 Rec
->Handle
= Handle
;
131 if (PackageGuid
!= NULL
) {
132 memcpy (&Rec
->PackageGuid
, PackageGuid
, sizeof (EFI_GUID
));
135 if (FormsetGuid
!= NULL
) {
136 memcpy (&Rec
->FormsetGuid
, FormsetGuid
, sizeof (EFI_GUID
));
139 // Walk the string packs to find the terminator
141 TempPack
= StringPack
;
143 while (TempPack
->Header
.Length
> 0) {
144 if (TempPack
->Header
.Type
!= EFI_HII_STRING
) {
145 Error (NULL
, 0, 0, "found a non-string pack in the string pack array", NULL
);
150 PackSize
+= TempPack
->Header
.Length
;
151 Rec
->NumStringPacks
++;
152 TempPack
= (EFI_HII_STRING_PACK
*) ((char *) TempPack
+ TempPack
->Header
.Length
);
155 // Add space for the terminator
157 PackSize
+= sizeof (EFI_HII_STRING_PACK
);
158 Rec
->StringPackSize
= PackSize
;
160 // Make a copy of the incoming string pack
162 Rec
->StringPack
= (EFI_HII_STRING_PACK
*) malloc (PackSize
);
163 if (Rec
->StringPack
== NULL
) {
164 Error (NULL
, 0, 0, "memory allocation failure", NULL
);
169 memcpy ((void *) Rec
->StringPack
, StringPack
, PackSize
);
171 // Add this record to our list
173 if (mStringPacks
== NULL
) {
176 for (TempRec
= mStringPacks
; TempRec
->Next
!= NULL
; TempRec
= TempRec
->Next
)
180 free (Rec
->StringPack
);
182 return STATUS_SUCCESS
;
193 GC_TODO: Add function description
201 GC_TODO: add return values
206 return STATUS_SUCCESS
;
217 GC_TODO: Add function description
225 GC_TODO: add return values
229 STRING_PACK_RECORD
*Next
;
231 // Free up all the memory we've allocated
233 while (mStringPacks
!= NULL
) {
234 if (mStringPacks
->StringPack
!= NULL
) {
235 free (mStringPacks
->StringPack
);
238 Next
= mStringPacks
->Next
;
243 return STATUS_SUCCESS
;