+++ /dev/null
-/*++\r
-\r
-Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-Module Name:\r
-\r
- StringParse.c \r
-\r
-Abstract:\r
-\r
- Routines for parsing HII string packs\r
-\r
---*/\r
-\r
-#include <stdio.h>\r
-#include <string.h>\r
-#include <stdlib.h>\r
-\r
-#include "Tiano.h"\r
-#include "EfiUtilityMsgs.h"\r
-#include "EfiInternalFormRepresentation.h"\r
-#include "Hii.h"\r
-#include "StringParse.h"\r
-#include "HiiPack.h"\r
-\r
-typedef struct _STRING_PACK_RECORD {\r
- struct _STRING_PACK_RECORD *Next;\r
- int Handle;\r
- EFI_GUID PackageGuid;\r
- EFI_GUID FormsetGuid;\r
- EFI_HII_STRING_PACK *StringPack;\r
- int StringPackSize;\r
- int NumStringPacks;\r
-} STRING_PACK_RECORD;\r
-\r
-static STRING_PACK_RECORD *mStringPacks = NULL;\r
-\r
-STATUS\r
-StringGetPack (\r
- int Handle, // matches handle passed in with StringParsePack()\r
- EFI_HII_STRING_PACK **StringPack, // returned pointer to string pack\r
- int *StringPackSize, // sizeof buffer pointed to by StringPack\r
- int *NumStringPacks, // in the array pointed to by StringPack\r
- EFI_GUID *FormsetGuid,\r
- EFI_GUID *PackageGuid\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Get a string pack given to us previously\r
- \r
-Arguments:\r
- Handle - handle of string pack to get\r
- StringPack - outgoing pointer to string pack on the given handle\r
- StringPackSize - outgoing size of string pack pointed to by StringPack\r
- NumStringPacks - outgoing number of string packs in StringPack[] array\r
- FormsetGuid - outgoing GUID passed in with the string pack when it was parsed\r
- PackageGuid - outgoing GUID passed in with the string pack when it was parsed\r
-\r
-Returns:\r
-\r
- STATUS_SUCCESS - string pack with matching handle was found\r
- STATUS_ERROR - otherwise\r
- \r
---*/\r
-{\r
- STRING_PACK_RECORD *Rec;\r
-\r
- for (Rec = mStringPacks; Rec != NULL; Rec = Rec->Next) {\r
- if (Rec->Handle == Handle) {\r
- *StringPack = Rec->StringPack;\r
- *StringPackSize = Rec->StringPackSize;\r
- *NumStringPacks = Rec->NumStringPacks;\r
- return STATUS_SUCCESS;\r
- }\r
- }\r
-\r
- return STATUS_ERROR;\r
-}\r
-\r
-STATUS\r
-StringParsePack (\r
- int Handle,\r
- EFI_HII_STRING_PACK *StringPack,\r
- EFI_GUID *FormsetGuid,\r
- EFI_GUID *PackageGuid\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Parse a string pack, saving the information for later retrieval by the caller\r
- \r
-Arguments:\r
- Handle - handle of string pack\r
- StringPack - pointer to string pack array to parse\r
- FormsetGuid - GUID of the string pack\r
- PackageGuid - package GUID from the HII data table from which this string pack orginated\r
-\r
-Returns:\r
-\r
- STATUS_SUCCESS - Stringpack processed successfully\r
- STATUS_ERROR - otherwise\r
- \r
---*/\r
-{\r
- STRING_PACK_RECORD *Rec;\r
-\r
- STRING_PACK_RECORD *TempRec;\r
- int PackSize;\r
- EFI_HII_STRING_PACK *TempPack;\r
- //\r
- // Allocate a new string pack record\r
- //\r
- Rec = (STRING_PACK_RECORD *) malloc (sizeof (STRING_PACK_RECORD));\r
- if (Rec == NULL) {\r
- Error (NULL, 0, 0, "memory allocation failure", NULL);\r
- return STATUS_ERROR;\r
- }\r
-\r
- memset (Rec, 0, sizeof (STRING_PACK_RECORD));\r
- Rec->Handle = Handle;\r
- if (PackageGuid != NULL) {\r
- memcpy (&Rec->PackageGuid, PackageGuid, sizeof (EFI_GUID));\r
- }\r
-\r
- if (FormsetGuid != NULL) {\r
- memcpy (&Rec->FormsetGuid, FormsetGuid, sizeof (EFI_GUID));\r
- }\r
- //\r
- // Walk the string packs to find the terminator\r
- //\r
- TempPack = StringPack;\r
- PackSize = 0;\r
- while (TempPack->Header.Length > 0) {\r
- if (TempPack->Header.Type != EFI_HII_STRING) {\r
- Error (NULL, 0, 0, "found a non-string pack in the string pack array", NULL);\r
- free (Rec);\r
- return STATUS_ERROR;\r
- }\r
-\r
- PackSize += TempPack->Header.Length;\r
- Rec->NumStringPacks++;\r
- TempPack = (EFI_HII_STRING_PACK *) ((char *) TempPack + TempPack->Header.Length);\r
- }\r
- //\r
- // Add space for the terminator\r
- //\r
- PackSize += sizeof (EFI_HII_STRING_PACK);\r
- Rec->StringPackSize = PackSize;\r
- //\r
- // Make a copy of the incoming string pack\r
- //\r
- Rec->StringPack = (EFI_HII_STRING_PACK *) malloc (PackSize);\r
- if (Rec->StringPack == NULL) {\r
- Error (NULL, 0, 0, "memory allocation failure", NULL);\r
- free (Rec);\r
- return STATUS_ERROR;\r
- }\r
-\r
- memcpy ((void *) Rec->StringPack, StringPack, PackSize);\r
- //\r
- // Add this record to our list\r
- //\r
- if (mStringPacks == NULL) {\r
- mStringPacks = Rec;\r
- } else {\r
- for (TempRec = mStringPacks; TempRec->Next != NULL; TempRec = TempRec->Next)\r
- ;\r
- TempRec->Next = Rec;\r
- }\r
- free (Rec->StringPack);\r
- free (Rec);\r
- return STATUS_SUCCESS;\r
-}\r
-\r
-STATUS\r
-StringInit (\r
- VOID\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- None\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-{\r
- StringEnd ();\r
- return STATUS_SUCCESS;\r
-}\r
-\r
-STATUS\r
-StringEnd (\r
- VOID\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
- None\r
-\r
-Returns:\r
-\r
- GC_TODO: add return values\r
-\r
---*/\r
-{\r
- STRING_PACK_RECORD *Next;\r
- //\r
- // Free up all the memory we've allocated\r
- //\r
- while (mStringPacks != NULL) {\r
- if (mStringPacks->StringPack != NULL) {\r
- free (mStringPacks->StringPack);\r
- }\r
-\r
- Next = mStringPacks->Next;\r
- free (mStringPacks);\r
- mStringPacks = Next;\r
- }\r
-\r
- return STATUS_SUCCESS;\r
-}\r