\r
(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
Copyright 2016 Dell Inc.\r
- Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2006 - 2018, 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
{\r
EFI_STATUS Status;\r
\r
- //\r
- // UEFI 2.0 shell interfaces (used preferentially)\r
- //\r
- Status = gBS->OpenProtocol(\r
- ImageHandle,\r
- &gEfiShellProtocolGuid,\r
- (VOID **)&gEfiShellProtocol,\r
- ImageHandle,\r
- NULL,\r
- EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
- );\r
- if (EFI_ERROR(Status)) {\r
+ if (gEfiShellProtocol == NULL) {\r
//\r
- // Search for the shell protocol\r
+ // UEFI 2.0 shell interfaces (used preferentially)\r
//\r
- Status = gBS->LocateProtocol(\r
+ Status = gBS->OpenProtocol (\r
+ ImageHandle,\r
&gEfiShellProtocolGuid,\r
+ (VOID **)&gEfiShellProtocol,\r
+ ImageHandle,\r
NULL,\r
- (VOID **)&gEfiShellProtocol\r
- );\r
- if (EFI_ERROR(Status)) {\r
- gEfiShellProtocol = NULL;\r
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ //\r
+ // Search for the shell protocol\r
+ //\r
+ Status = gBS->LocateProtocol (\r
+ &gEfiShellProtocolGuid,\r
+ NULL,\r
+ (VOID **)&gEfiShellProtocol\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ gEfiShellProtocol = NULL;\r
+ }\r
}\r
}\r
- Status = gBS->OpenProtocol(\r
- ImageHandle,\r
- &gEfiShellParametersProtocolGuid,\r
- (VOID **)&gEfiShellParametersProtocol,\r
- ImageHandle,\r
- NULL,\r
- EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
- );\r
- if (EFI_ERROR(Status)) {\r
- gEfiShellParametersProtocol = NULL;\r
+\r
+ if (gEfiShellParametersProtocol == NULL) {\r
+ Status = gBS->OpenProtocol (\r
+ ImageHandle,\r
+ &gEfiShellParametersProtocolGuid,\r
+ (VOID **)&gEfiShellParametersProtocol,\r
+ ImageHandle,\r
+ NULL,\r
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ gEfiShellParametersProtocol = NULL;\r
+ }\r
}\r
\r
- if (gEfiShellParametersProtocol == NULL || gEfiShellProtocol == NULL) {\r
+ if (gEfiShellProtocol == NULL) {\r
//\r
// Moved to seperate function due to complexity\r
//\r
}\r
\r
//\r
- // only success getting 2 of either the old or new, but no 1/2 and 1/2\r
+ // Getting either EDK Shell's ShellEnvironment2 and ShellInterface protocol\r
+ // or UEFI Shell's Shell protocol.\r
+ // When ShellLib is linked to a driver producing DynamicCommand protocol,\r
+ // ShellParameters protocol is set by DynamicCommand.Handler().\r
//\r
- if ((mEfiShellEnvironment2 != NULL && mEfiShellInterface != NULL) ||\r
- (gEfiShellProtocol != NULL && gEfiShellParametersProtocol != NULL) ) {\r
+ if ((mEfiShellEnvironment2 != NULL && mEfiShellInterface != NULL) ||\r
+ (gEfiShellProtocol != NULL)\r
+ ) {\r
if (gEfiShellProtocol != NULL) {\r
FileFunctionMap.GetFileInfo = gEfiShellProtocol->GetFileInfo;\r
FileFunctionMap.SetFileInfo = gEfiShellProtocol->SetFileInfo;\r
IN EFI_SYSTEM_TABLE *SystemTable\r
)\r
{\r
+ EFI_STATUS Status;\r
+\r
if (mEfiShellEnvironment2 != NULL) {\r
- gBS->CloseProtocol(mEfiShellEnvironment2Handle==NULL?ImageHandle:mEfiShellEnvironment2Handle,\r
+ Status = gBS->CloseProtocol(mEfiShellEnvironment2Handle==NULL?ImageHandle:mEfiShellEnvironment2Handle,\r
&gEfiShellEnvironment2Guid,\r
ImageHandle,\r
NULL);\r
- mEfiShellEnvironment2 = NULL;\r
+ if (!EFI_ERROR (Status)) {\r
+ mEfiShellEnvironment2 = NULL;\r
+ mEfiShellEnvironment2Handle = NULL;\r
+ }\r
}\r
if (mEfiShellInterface != NULL) {\r
- gBS->CloseProtocol(ImageHandle,\r
+ Status = gBS->CloseProtocol(ImageHandle,\r
&gEfiShellInterfaceGuid,\r
ImageHandle,\r
NULL);\r
- mEfiShellInterface = NULL;\r
+ if (!EFI_ERROR (Status)) {\r
+ mEfiShellInterface = NULL;\r
+ }\r
}\r
if (gEfiShellProtocol != NULL) {\r
- gBS->CloseProtocol(ImageHandle,\r
+ Status = gBS->CloseProtocol(ImageHandle,\r
&gEfiShellProtocolGuid,\r
ImageHandle,\r
NULL);\r
- gEfiShellProtocol = NULL;\r
+ if (!EFI_ERROR (Status)) {\r
+ gEfiShellProtocol = NULL;\r
+ }\r
}\r
if (gEfiShellParametersProtocol != NULL) {\r
- gBS->CloseProtocol(ImageHandle,\r
+ Status = gBS->CloseProtocol(ImageHandle,\r
&gEfiShellParametersProtocolGuid,\r
ImageHandle,\r
NULL);\r
- gEfiShellParametersProtocol = NULL;\r
+ if (!EFI_ERROR (Status)) {\r
+ gEfiShellParametersProtocol = NULL;\r
+ }\r
}\r
- mEfiShellEnvironment2Handle = NULL;\r
\r
return (EFI_SUCCESS);\r
}\r
EFI_STATUS\r
EFIAPI\r
ShellInitialize (\r
+ VOID\r
)\r
{\r
EFI_STATUS Status;\r
}\r
CurrentItemPackage->Value = NewValue;\r
if (ValueSize == 0) {\r
- StrCpyS( CurrentItemPackage->Value, \r
- CurrentValueSize/sizeof(CHAR16), \r
+ StrCpyS( CurrentItemPackage->Value,\r
+ CurrentValueSize/sizeof(CHAR16),\r
Argv[LoopCounter]\r
);\r
} else {\r
- StrCatS( CurrentItemPackage->Value, \r
- CurrentValueSize/sizeof(CHAR16), \r
+ StrCatS( CurrentItemPackage->Value,\r
+ CurrentValueSize/sizeof(CHAR16),\r
L" "\r
);\r
- StrCatS( CurrentItemPackage->Value, \r
- CurrentValueSize/sizeof(CHAR16), \r
+ StrCatS( CurrentItemPackage->Value,\r
+ CurrentValueSize/sizeof(CHAR16),\r
Argv[LoopCounter]\r
);\r
}\r
ValueSize += StrSize(Argv[LoopCounter]) + sizeof(CHAR16);\r
- \r
+\r
GetItemValue--;\r
if (GetItemValue == 0) {\r
InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);\r
return (gEfiShellProtocol->WriteFile(gEfiShellParametersProtocol->StdOut, &Size, (VOID*)String));\r
}\r
if (mEfiShellInterface != NULL) {\r
- if (mEfiShellInterface->RedirArgc == 0) { \r
+ if (mEfiShellInterface->RedirArgc == 0) {\r
//\r
// Divide in half for old shell. Must be string length not size.\r
- // \r
+ //\r
Size /=2; // Divide in half only when no redirection.\r
}\r
return (mEfiShellInterface->StdOut->Write(mEfiShellInterface->StdOut, &Size, (VOID*)String));\r
if (!EFI_ERROR(ShellConvertStringToUint64(String, &RetVal, TRUE, TRUE))) {\r
return ((UINTN)RetVal);\r
}\r
- \r
+\r
return ((UINTN)(-1));\r
}\r
\r
if (*Destination == NULL) {\r
return (NULL);\r
}\r
- \r
+\r
StrnCatS(*Destination, NewSize/sizeof(CHAR16), Source, Count);\r
return *Destination;\r
}\r
)\r
{\r
BOOLEAN Hex;\r
+ BOOLEAN LeadingZero;\r
+\r
+ if (String == NULL) {\r
+ return FALSE;\r
+ }\r
\r
//\r
// chop off a single negative sign\r
//\r
- if (String != NULL && *String == L'-') {\r
+ if (*String == L'-') {\r
String++;\r
}\r
\r
- if (String == NULL) {\r
- return (FALSE);\r
+ if (*String == CHAR_NULL) {\r
+ return FALSE;\r
}\r
\r
//\r
// chop leading zeroes\r
//\r
- while(String != NULL && *String == L'0'){\r
+ LeadingZero = FALSE;\r
+ while(*String == L'0'){\r
String++;\r
+ LeadingZero = TRUE;\r
}\r
//\r
// allow '0x' or '0X', but not 'x' or 'X'\r
//\r
- if (String != NULL && (*String == L'x' || *String == L'X')) {\r
- if (*(String-1) != L'0') {\r
+ if (*String == L'x' || *String == L'X') {\r
+ if (!LeadingZero) {\r
//\r
// we got an x without a preceeding 0\r
//\r
//\r
// loop through the remaining characters and use the lib function\r
//\r
- for ( ; String != NULL && *String != CHAR_NULL && !(StopAtSpace && *String == L' ') ; String++){\r
+ for ( ; *String != CHAR_NULL && !(StopAtSpace && *String == L' ') ; String++){\r
if (TimeNumbers && (String[0] == L':')) {\r
continue;\r
}\r
Result = 0;\r
\r
//\r
- // Stop upon space if requested \r
+ // Stop upon space if requested\r
// (if the whole value was 0)\r
//\r
if (StopAtSpace && *String == L' ') {\r
\r
@param[in] CommandToGetHelpOn Pointer to a string containing the command name of help file to be printed.\r
@param[in] SectionToGetHelpOn Pointer to the section specifier(s).\r
- @param[in] PrintCommandText If TRUE, prints the command followed by the help content, otherwise prints \r
+ @param[in] PrintCommandText If TRUE, prints the command followed by the help content, otherwise prints\r
the help content only.\r
@retval EFI_DEVICE_ERROR The help data format was incorrect.\r
@retval EFI_NOT_FOUND The help data could not be found.\r
IN BOOLEAN PrintCommandText\r
)\r
{\r
- EFI_STATUS Status;\r
- CHAR16 *OutText;\r
- \r
- OutText = NULL;\r
- \r
+ EFI_STATUS Status;\r
+ CHAR16 *OutText;\r
+\r
+ OutText = NULL;\r
+\r
//\r
// Get the string to print based\r
//\r
- Status = gEfiShellProtocol->GetHelpText (CommandToGetHelpOn, SectionToGetHelpOn, &OutText);\r
- \r
+ Status = gEfiShellProtocol->GetHelpText (CommandToGetHelpOn, SectionToGetHelpOn, &OutText);\r
+\r
//\r
// make sure we got a valid string\r
//\r
if (EFI_ERROR(Status)){\r
return Status;\r
- } \r
+ }\r
if (OutText == NULL || StrLen(OutText) == 0) {\r
- return EFI_NOT_FOUND; \r
- }\r
- \r
+ return EFI_NOT_FOUND;\r
+ }\r
+\r
//\r
// Chop off trailing stuff we dont need\r
//\r
while (OutText[StrLen(OutText)-1] == L'\r' || OutText[StrLen(OutText)-1] == L'\n' || OutText[StrLen(OutText)-1] == L' ') {\r
OutText[StrLen(OutText)-1] = CHAR_NULL;\r
}\r
- \r
+\r
//\r
// Print this out to the console\r
//\r
} else {\r
ShellPrintEx(-1, -1, L"%N%s\r\n", OutText);\r
}\r
- \r
+\r
SHELL_FREE_NON_NULL(OutText);\r
\r
- return EFI_SUCCESS;\r
+ return EFI_SUCCESS;\r
}\r
\r
/**\r
Function to delete a file by name\r
- \r
+\r
@param[in] FileName Pointer to file name to delete.\r
- \r
+\r
@retval EFI_SUCCESS the file was deleted sucessfully\r
@retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not\r
deleted\r
{\r
EFI_STATUS Status;\r
SHELL_FILE_HANDLE FileHandle;\r
- \r
+\r
Status = ShellFileExists(FileName);\r
- \r
+\r
if (Status == EFI_SUCCESS){\r
Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0x0);\r
if (Status == EFI_SUCCESS){\r
Status = ShellDeleteFile(&FileHandle);\r
}\r
- } \r
+ }\r
\r
return(Status);\r
- \r
+\r
}\r
\r
/**\r
Cleans off all the quotes in the string.\r
\r
@param[in] OriginalString pointer to the string to be cleaned.\r
- @param[out] CleanString The new string with all quotes removed. \r
- Memory allocated in the function and free \r
+ @param[out] CleanString The new string with all quotes removed.\r
+ Memory allocated in the function and free\r
by caller.\r
\r
@retval EFI_SUCCESS The operation was successful.\r
)\r
{\r
CHAR16 *Walker;\r
- \r
+\r
if (OriginalString == NULL || CleanString == NULL) {\r
return EFI_INVALID_PARAMETER;\r
}\r