X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=ShellPkg%2FLibrary%2FUefiShellLib%2FUefiShellLib.c;h=e53985e2d71406a45970fd618927f36e280dc0a9;hp=64565f81d8e02160371560e290d7cf4ba81b1e86;hb=ee33344c595709ef7642c52d27a16f21e692b856;hpb=2c2c68b9d3e83af26042f03f9864fd38ce922a89 diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.c b/ShellPkg/Library/UefiShellLib/UefiShellLib.c index 64565f81d8..e53985e2d7 100644 --- a/ShellPkg/Library/UefiShellLib/UefiShellLib.c +++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.c @@ -3,7 +3,7 @@ (C) Copyright 2016 Hewlett Packard Enterprise Development LP
Copyright 2016 Dell Inc. - Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
+ Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -179,43 +179,48 @@ ShellLibConstructorWorker ( { EFI_STATUS Status; - // - // UEFI 2.0 shell interfaces (used preferentially) - // - Status = gBS->OpenProtocol( - ImageHandle, - &gEfiShellProtocolGuid, - (VOID **)&gEfiShellProtocol, - ImageHandle, - NULL, - EFI_OPEN_PROTOCOL_GET_PROTOCOL - ); - if (EFI_ERROR(Status)) { + if (gEfiShellProtocol == NULL) { // - // Search for the shell protocol + // UEFI 2.0 shell interfaces (used preferentially) // - Status = gBS->LocateProtocol( + Status = gBS->OpenProtocol ( + ImageHandle, &gEfiShellProtocolGuid, + (VOID **)&gEfiShellProtocol, + ImageHandle, NULL, - (VOID **)&gEfiShellProtocol - ); - if (EFI_ERROR(Status)) { - gEfiShellProtocol = NULL; + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR (Status)) { + // + // Search for the shell protocol + // + Status = gBS->LocateProtocol ( + &gEfiShellProtocolGuid, + NULL, + (VOID **)&gEfiShellProtocol + ); + if (EFI_ERROR (Status)) { + gEfiShellProtocol = NULL; + } } } - Status = gBS->OpenProtocol( - ImageHandle, - &gEfiShellParametersProtocolGuid, - (VOID **)&gEfiShellParametersProtocol, - ImageHandle, - NULL, - EFI_OPEN_PROTOCOL_GET_PROTOCOL - ); - if (EFI_ERROR(Status)) { - gEfiShellParametersProtocol = NULL; + + if (gEfiShellParametersProtocol == NULL) { + Status = gBS->OpenProtocol ( + ImageHandle, + &gEfiShellParametersProtocolGuid, + (VOID **)&gEfiShellParametersProtocol, + ImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR (Status)) { + gEfiShellParametersProtocol = NULL; + } } - if (gEfiShellParametersProtocol == NULL || gEfiShellProtocol == NULL) { + if (gEfiShellProtocol == NULL) { // // Moved to seperate function due to complexity // @@ -238,10 +243,14 @@ ShellLibConstructorWorker ( } // - // only success getting 2 of either the old or new, but no 1/2 and 1/2 + // Getting either EDK Shell's ShellEnvironment2 and ShellInterface protocol + // or UEFI Shell's Shell protocol. + // When ShellLib is linked to a driver producing DynamicCommand protocol, + // ShellParameters protocol is set by DynamicCommand.Handler(). // - if ((mEfiShellEnvironment2 != NULL && mEfiShellInterface != NULL) || - (gEfiShellProtocol != NULL && gEfiShellParametersProtocol != NULL) ) { + if ((mEfiShellEnvironment2 != NULL && mEfiShellInterface != NULL) || + (gEfiShellProtocol != NULL) + ) { if (gEfiShellProtocol != NULL) { FileFunctionMap.GetFileInfo = gEfiShellProtocol->GetFileInfo; FileFunctionMap.SetFileInfo = gEfiShellProtocol->SetFileInfo; @@ -320,35 +329,45 @@ ShellLibDestructor ( IN EFI_SYSTEM_TABLE *SystemTable ) { + EFI_STATUS Status; + if (mEfiShellEnvironment2 != NULL) { - gBS->CloseProtocol(mEfiShellEnvironment2Handle==NULL?ImageHandle:mEfiShellEnvironment2Handle, + Status = gBS->CloseProtocol(mEfiShellEnvironment2Handle==NULL?ImageHandle:mEfiShellEnvironment2Handle, &gEfiShellEnvironment2Guid, ImageHandle, NULL); - mEfiShellEnvironment2 = NULL; + if (!EFI_ERROR (Status)) { + mEfiShellEnvironment2 = NULL; + mEfiShellEnvironment2Handle = NULL; + } } if (mEfiShellInterface != NULL) { - gBS->CloseProtocol(ImageHandle, + Status = gBS->CloseProtocol(ImageHandle, &gEfiShellInterfaceGuid, ImageHandle, NULL); - mEfiShellInterface = NULL; + if (!EFI_ERROR (Status)) { + mEfiShellInterface = NULL; + } } if (gEfiShellProtocol != NULL) { - gBS->CloseProtocol(ImageHandle, + Status = gBS->CloseProtocol(ImageHandle, &gEfiShellProtocolGuid, ImageHandle, NULL); - gEfiShellProtocol = NULL; + if (!EFI_ERROR (Status)) { + gEfiShellProtocol = NULL; + } } if (gEfiShellParametersProtocol != NULL) { - gBS->CloseProtocol(ImageHandle, + Status = gBS->CloseProtocol(ImageHandle, &gEfiShellParametersProtocolGuid, ImageHandle, NULL); - gEfiShellParametersProtocol = NULL; + if (!EFI_ERROR (Status)) { + gEfiShellParametersProtocol = NULL; + } } - mEfiShellEnvironment2Handle = NULL; return (EFI_SUCCESS); } @@ -369,6 +388,7 @@ ShellLibDestructor ( EFI_STATUS EFIAPI ShellInitialize ( + VOID ) { EFI_STATUS Status; @@ -2849,10 +2869,10 @@ InternalShellPrintWorker( gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_WHITE, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4))); break; case (L'B'): - gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_BLUE, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4))); + gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_LIGHTBLUE, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4))); break; case (L'V'): - gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_GREEN, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4))); + gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_LIGHTGREEN, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4))); break; default: // @@ -3616,29 +3636,36 @@ InternalShellIsHexOrDecimalNumber ( ) { BOOLEAN Hex; + BOOLEAN LeadingZero; + + if (String == NULL) { + return FALSE; + } // // chop off a single negative sign // - if (String != NULL && *String == L'-') { + if (*String == L'-') { String++; } - if (String == NULL) { - return (FALSE); + if (*String == CHAR_NULL) { + return FALSE; } // // chop leading zeroes // - while(String != NULL && *String == L'0'){ + LeadingZero = FALSE; + while(*String == L'0'){ String++; + LeadingZero = TRUE; } // // allow '0x' or '0X', but not 'x' or 'X' // - if (String != NULL && (*String == L'x' || *String == L'X')) { - if (*(String-1) != L'0') { + if (*String == L'x' || *String == L'X') { + if (!LeadingZero) { // // we got an x without a preceeding 0 // @@ -3655,7 +3682,7 @@ InternalShellIsHexOrDecimalNumber ( // // loop through the remaining characters and use the lib function // - for ( ; String != NULL && *String != CHAR_NULL && !(StopAtSpace && *String == L' ') ; String++){ + for ( ; *String != CHAR_NULL && !(StopAtSpace && *String == L' ') ; String++){ if (TimeNumbers && (String[0] == L':')) { continue; }