]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Sample/Tools/Source/HiiPack/StringParse.c
Sync all bug fixes between EDK1.04 and EDK1.06 into EdkCompatibilityPkg.
[mirror_edk2.git] / EdkCompatibilityPkg / Sample / Tools / Source / HiiPack / StringParse.c
CommitLineData
3e99020d
LG
1/*++\r
2\r
3Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>\r
4This program and the accompanying materials\r
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12Module Name:\r
13\r
14 StringParse.c \r
15\r
16Abstract:\r
17\r
18 Routines for parsing HII string packs\r
19\r
20--*/\r
21\r
22#include <stdio.h>\r
23#include <string.h>\r
24#include <stdlib.h>\r
25\r
26#include "Tiano.h"\r
27#include "EfiUtilityMsgs.h"\r
28#include "EfiInternalFormRepresentation.h"\r
29#include "Hii.h"\r
30#include "StringParse.h"\r
31#include "HiiPack.h"\r
32\r
33typedef struct _STRING_PACK_RECORD {\r
34 struct _STRING_PACK_RECORD *Next;\r
35 int Handle;\r
36 EFI_GUID PackageGuid;\r
37 EFI_GUID FormsetGuid;\r
38 EFI_HII_STRING_PACK *StringPack;\r
39 int StringPackSize;\r
40 int NumStringPacks;\r
41} STRING_PACK_RECORD;\r
42\r
43static STRING_PACK_RECORD *mStringPacks = NULL;\r
44\r
45STATUS\r
46StringGetPack (\r
47 int Handle, // matches handle passed in with StringParsePack()\r
48 EFI_HII_STRING_PACK **StringPack, // returned pointer to string pack\r
49 int *StringPackSize, // sizeof buffer pointed to by StringPack\r
50 int *NumStringPacks, // in the array pointed to by StringPack\r
51 EFI_GUID *FormsetGuid,\r
52 EFI_GUID *PackageGuid\r
53 )\r
54/*++\r
55\r
56Routine Description:\r
57\r
58 Get a string pack given to us previously\r
59 \r
60Arguments:\r
61 Handle - handle of string pack to get\r
62 StringPack - outgoing pointer to string pack on the given handle\r
63 StringPackSize - outgoing size of string pack pointed to by StringPack\r
64 NumStringPacks - outgoing number of string packs in StringPack[] array\r
65 FormsetGuid - outgoing GUID passed in with the string pack when it was parsed\r
66 PackageGuid - outgoing GUID passed in with the string pack when it was parsed\r
67\r
68Returns:\r
69\r
70 STATUS_SUCCESS - string pack with matching handle was found\r
71 STATUS_ERROR - otherwise\r
72 \r
73--*/\r
74{\r
75 STRING_PACK_RECORD *Rec;\r
76\r
77 for (Rec = mStringPacks; Rec != NULL; Rec = Rec->Next) {\r
78 if (Rec->Handle == Handle) {\r
79 *StringPack = Rec->StringPack;\r
80 *StringPackSize = Rec->StringPackSize;\r
81 *NumStringPacks = Rec->NumStringPacks;\r
82 return STATUS_SUCCESS;\r
83 }\r
84 }\r
85\r
86 return STATUS_ERROR;\r
87}\r
88\r
89STATUS\r
90StringParsePack (\r
91 int Handle,\r
92 EFI_HII_STRING_PACK *StringPack,\r
93 EFI_GUID *FormsetGuid,\r
94 EFI_GUID *PackageGuid\r
95 )\r
96/*++\r
97\r
98Routine Description:\r
99\r
100 Parse a string pack, saving the information for later retrieval by the caller\r
101 \r
102Arguments:\r
103 Handle - handle of string pack\r
104 StringPack - pointer to string pack array to parse\r
105 FormsetGuid - GUID of the string pack\r
106 PackageGuid - package GUID from the HII data table from which this string pack orginated\r
107\r
108Returns:\r
109\r
110 STATUS_SUCCESS - Stringpack processed successfully\r
111 STATUS_ERROR - otherwise\r
112 \r
113--*/\r
114{\r
115 STRING_PACK_RECORD *Rec;\r
116\r
117 STRING_PACK_RECORD *TempRec;\r
118 int PackSize;\r
119 EFI_HII_STRING_PACK *TempPack;\r
120 //\r
121 // Allocate a new string pack record\r
122 //\r
123 Rec = (STRING_PACK_RECORD *) malloc (sizeof (STRING_PACK_RECORD));\r
124 if (Rec == NULL) {\r
125 Error (NULL, 0, 0, "memory allocation failure", NULL);\r
126 return STATUS_ERROR;\r
127 }\r
128\r
129 memset (Rec, 0, sizeof (STRING_PACK_RECORD));\r
130 Rec->Handle = Handle;\r
131 if (PackageGuid != NULL) {\r
132 memcpy (&Rec->PackageGuid, PackageGuid, sizeof (EFI_GUID));\r
133 }\r
134\r
135 if (FormsetGuid != NULL) {\r
136 memcpy (&Rec->FormsetGuid, FormsetGuid, sizeof (EFI_GUID));\r
137 }\r
138 //\r
139 // Walk the string packs to find the terminator\r
140 //\r
141 TempPack = StringPack;\r
142 PackSize = 0;\r
143 while (TempPack->Header.Length > 0) {\r
144 if (TempPack->Header.Type != EFI_HII_STRING) {\r
145 Error (NULL, 0, 0, "found a non-string pack in the string pack array", NULL);\r
146 free (Rec);\r
147 return STATUS_ERROR;\r
148 }\r
149\r
150 PackSize += TempPack->Header.Length;\r
151 Rec->NumStringPacks++;\r
152 TempPack = (EFI_HII_STRING_PACK *) ((char *) TempPack + TempPack->Header.Length);\r
153 }\r
154 //\r
155 // Add space for the terminator\r
156 //\r
157 PackSize += sizeof (EFI_HII_STRING_PACK);\r
158 Rec->StringPackSize = PackSize;\r
159 //\r
160 // Make a copy of the incoming string pack\r
161 //\r
162 Rec->StringPack = (EFI_HII_STRING_PACK *) malloc (PackSize);\r
163 if (Rec->StringPack == NULL) {\r
164 Error (NULL, 0, 0, "memory allocation failure", NULL);\r
165 free (Rec);\r
166 return STATUS_ERROR;\r
167 }\r
168\r
169 memcpy ((void *) Rec->StringPack, StringPack, PackSize);\r
170 //\r
171 // Add this record to our list\r
172 //\r
173 if (mStringPacks == NULL) {\r
174 mStringPacks = Rec;\r
175 } else {\r
176 for (TempRec = mStringPacks; TempRec->Next != NULL; TempRec = TempRec->Next)\r
177 ;\r
178 TempRec->Next = Rec;\r
179 }\r
180 free (Rec->StringPack);\r
181 free (Rec);\r
182 return STATUS_SUCCESS;\r
183}\r
184\r
185STATUS\r
186StringInit (\r
187 VOID\r
188 )\r
189/*++\r
190\r
191Routine Description:\r
192\r
193 GC_TODO: Add function description\r
194\r
195Arguments:\r
196\r
197 None\r
198\r
199Returns:\r
200\r
201 GC_TODO: add return values\r
202\r
203--*/\r
204{\r
205 StringEnd ();\r
206 return STATUS_SUCCESS;\r
207}\r
208\r
209STATUS\r
210StringEnd (\r
211 VOID\r
212 )\r
213/*++\r
214\r
215Routine Description:\r
216\r
217 GC_TODO: Add function description\r
218\r
219Arguments:\r
220\r
221 None\r
222\r
223Returns:\r
224\r
225 GC_TODO: add return values\r
226\r
227--*/\r
228{\r
229 STRING_PACK_RECORD *Next;\r
230 //\r
231 // Free up all the memory we've allocated\r
232 //\r
233 while (mStringPacks != NULL) {\r
234 if (mStringPacks->StringPack != NULL) {\r
235 free (mStringPacks->StringPack);\r
236 }\r
237\r
238 Next = mStringPacks->Next;\r
239 free (mStringPacks);\r
240 mStringPacks = Next;\r
241 }\r
242\r
243 return STATUS_SUCCESS;\r
244}\r