+/**\r
+ Calcualte the 32-bit CRC in a EFI table using the service provided by the\r
+ gRuntime service.\r
+\r
+ @param Hdr Pointer to an EFI standard header\r
+\r
+**/\r
+VOID\r
+CalculateEfiHdrCrc (\r
+ IN OUT EFI_TABLE_HEADER *Hdr\r
+ )\r
+{\r
+ UINT32 Crc;\r
+\r
+ Hdr->CRC32 = 0;\r
+\r
+ //\r
+ // If gBS->CalculateCrce32 () == CoreEfiNotAvailableYet () then\r
+ // Crc will come back as zero if we set it to zero here\r
+ //\r
+ Crc = 0;\r
+ gBS->CalculateCrc32 ((UINT8 *)Hdr, Hdr->HeaderSize, &Crc);\r
+ Hdr->CRC32 = Crc;\r
+}\r
+\r
+/**\r
+ Fix a string to only have the file name, removing starting at the first space of whatever is quoted.\r
+\r
+ @param[in] FileName The filename to start with.\r
+\r
+ @retval NULL FileName was invalid.\r
+ @return The modified FileName.\r
+**/\r
+CHAR16*\r
+EFIAPI\r
+FixFileName (\r
+ IN CHAR16 *FileName\r
+ )\r
+{\r
+ CHAR16 *Copy;\r
+ CHAR16 *TempLocation;\r
+\r
+ if (FileName == NULL) {\r
+ return (NULL);\r
+ }\r
+\r
+ if (FileName[0] == L'\"') {\r
+ Copy = FileName+1;\r
+ if ((TempLocation = StrStr(Copy , L"\"")) != NULL) {\r
+ TempLocation[0] = CHAR_NULL;\r
+ } \r
+ } else {\r
+ Copy = FileName;\r
+ while(Copy[0] == L' ') {\r
+ Copy++;\r
+ }\r
+ if ((TempLocation = StrStr(Copy , L" ")) != NULL) {\r
+ TempLocation[0] = CHAR_NULL;\r
+ } \r
+ }\r
+\r
+ if (Copy[0] == CHAR_NULL) {\r
+ return (NULL);\r
+ }\r
+\r
+ return (Copy);\r
+}\r
+\r
+/**\r
+ Fix a string to only have the environment variable name, removing starting at the first space of whatever is quoted and removing the leading and trailing %.\r
+\r
+ @param[in] FileName The filename to start with.\r
+\r
+ @retval NULL FileName was invalid.\r
+ @return The modified FileName.\r
+**/\r
+CHAR16*\r
+EFIAPI\r
+FixVarName (\r
+ IN CHAR16 *FileName\r
+ )\r
+{\r
+ CHAR16 *Copy;\r
+ CHAR16 *TempLocation;\r
+\r
+ Copy = FileName;\r
+\r
+ if (FileName[0] == L'%') {\r
+ Copy = FileName+1;\r
+ if ((TempLocation = StrStr(Copy , L"%")) != NULL) {\r
+ TempLocation[0] = CHAR_NULL;\r
+ } \r
+ }\r
+\r
+ return (FixFileName(Copy));\r
+}\r
+\r
+/**\r
+ Remove the unicode file tag from the begining of the file buffer since that will not be\r
+ used by StdIn.\r
+ \r
+ @param[in] Handle Pointer to the handle of the file to be processed.\r
+ \r
+ @retval EFI_SUCCESS The unicode file tag has been moved successfully.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+RemoveFileTag(\r
+ IN SHELL_FILE_HANDLE *Handle\r
+ )\r
+{\r
+ UINTN CharSize;\r
+ CHAR16 CharBuffer;\r
+\r
+ CharSize = sizeof(CHAR16);\r
+ CharBuffer = 0;\r
+ gEfiShellProtocol->ReadFile(*Handle, &CharSize, &CharBuffer);\r
+ if (CharBuffer != gUnicodeFileTag) {\r
+ gEfiShellProtocol->SetFilePosition(*Handle, 0);\r
+ }\r
+ return (EFI_SUCCESS);\r
+}\r
+\r
+/**\r
+ Write the unicode file tag to the specified file.\r
+\r
+ It is the caller's responsibility to ensure that\r
+ ShellInfoObject.NewEfiShellProtocol has been initialized before calling this\r
+ function.\r
+\r
+ @param[in] FileHandle The file to write the unicode file tag to.\r
+\r
+ @return Status code from ShellInfoObject.NewEfiShellProtocol->WriteFile.\r
+**/\r
+EFI_STATUS\r
+WriteFileTag (\r
+ IN SHELL_FILE_HANDLE FileHandle\r
+ )\r
+{\r
+ CHAR16 FileTag;\r
+ UINTN Size;\r
+ EFI_STATUS Status;\r
+\r
+ FileTag = gUnicodeFileTag;\r
+ Size = sizeof FileTag;\r
+ Status = ShellInfoObject.NewEfiShellProtocol->WriteFile (FileHandle, &Size,\r
+ &FileTag);\r
+ ASSERT (EFI_ERROR (Status) || Size == sizeof FileTag);\r
+ return Status;\r
+}\r
+\r
+\r