X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=ShellPkg%2FLibrary%2FUefiShellLib%2FUefiShellLib.c;h=f04adbb63ffe650a9a0b77b06d5e324a57dbcc4b;hp=cf89a4ac87edb844ad2bfe3962bec4f3ec09e874;hb=9becf2f0759eab29afcb088ee5c49f522d1d6619;hpb=e3b76f3b5e80df1219fb4adf0199b9606e84b8e7 diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.c b/ShellPkg/Library/UefiShellLib/UefiShellLib.c index cf89a4ac87..f04adbb63f 100644 --- a/ShellPkg/Library/UefiShellLib/UefiShellLib.c +++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.c @@ -1,8 +1,9 @@ /** @file Provides interface to shell functionality for shell commands and applications. + (C) Copyright 2016 Hewlett Packard Enterprise Development LP
Copyright 2016 Dell Inc. - Copyright (c) 2006 - 2016, 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 @@ -14,12 +15,9 @@ **/ #include "UefiShellLib.h" -#include #include #include -#define FIND_XXXXX_FILE_BUFFER_SIZE (SIZE_OF_EFI_FILE_INFO + MAX_FILE_NAME_LEN) - // // globals... // @@ -36,6 +34,7 @@ EFI_SHELL_PROTOCOL *gEfiShellProtocol; EFI_SHELL_PARAMETERS_PROTOCOL *gEfiShellParametersProtocol; EFI_HANDLE mEfiShellEnvironment2Handle; FILE_HANDLE_FUNCTION_MAP FileFunctionMap; +EFI_UNICODE_COLLATION_PROTOCOL *mUnicodeCollationProtocol; /** Check if a Unicode character is a hexadecimal character. @@ -90,7 +89,6 @@ ShellIsDecimalDigitCharacter ( @retval EFI_OUT_OF_RESOURCES Memory allocation failed. **/ EFI_STATUS -EFIAPI ShellFindSE2 ( IN EFI_HANDLE ImageHandle ) @@ -174,7 +172,6 @@ ShellFindSE2 ( @retval EFI_SUCCESS The operationw as successful. **/ EFI_STATUS -EFIAPI ShellLibConstructorWorker ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable @@ -182,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 // @@ -241,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; @@ -295,6 +301,7 @@ ShellLibConstructor ( gEfiShellParametersProtocol = NULL; mEfiShellInterface = NULL; mEfiShellEnvironment2Handle = NULL; + mUnicodeCollationProtocol = NULL; // // verify that auto initialize is not set false @@ -322,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); } @@ -371,8 +388,11 @@ ShellLibDestructor ( EFI_STATUS EFIAPI ShellInitialize ( + VOID ) { + EFI_STATUS Status; + // // if auto initialize is not false then skip // @@ -383,7 +403,8 @@ ShellInitialize ( // // deinit the current stuff // - ASSERT_EFI_ERROR(ShellLibDestructor(gImageHandle, gST)); + Status = ShellLibDestructor (gImageHandle, gST); + ASSERT_EFI_ERROR (Status); // // init the new stuff @@ -451,7 +472,6 @@ ShellSetFileInfo ( @param FilePath on input the device path to the file. On output the remaining device path. - @param DeviceHandle pointer to the system device handle. @param FileHandle pointer to the file handle. @param OpenMode the mode to open the file with. @param Attributes the file's file attributes. @@ -477,7 +497,6 @@ EFI_STATUS EFIAPI ShellOpenFileByDevicePath( IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath, - OUT EFI_HANDLE *DeviceHandle, OUT SHELL_FILE_HANDLE *FileHandle, IN UINT64 OpenMode, IN UINT64 Attributes @@ -485,13 +504,9 @@ ShellOpenFileByDevicePath( { CHAR16 *FileName; EFI_STATUS Status; - EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *EfiSimpleFileSystemProtocol; - EFI_FILE_PROTOCOL *Handle1; - EFI_FILE_PROTOCOL *Handle2; - CHAR16 *FnafPathName; - UINTN PathLen; + EFI_FILE_PROTOCOL *File; - if (FilePath == NULL || FileHandle == NULL || DeviceHandle == NULL) { + if (FilePath == NULL || FileHandle == NULL) { return (EFI_INVALID_PARAMETER); } @@ -515,117 +530,15 @@ ShellOpenFileByDevicePath( // // use old shell method. // - Status = gBS->LocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, - FilePath, - DeviceHandle); - if (EFI_ERROR (Status)) { - return Status; - } - Status = gBS->OpenProtocol(*DeviceHandle, - &gEfiSimpleFileSystemProtocolGuid, - (VOID**)&EfiSimpleFileSystemProtocol, - gImageHandle, - NULL, - EFI_OPEN_PROTOCOL_GET_PROTOCOL); - if (EFI_ERROR (Status)) { - return Status; - } - Status = EfiSimpleFileSystemProtocol->OpenVolume(EfiSimpleFileSystemProtocol, &Handle1); + Status = EfiOpenFileByDevicePath (FilePath, &File, OpenMode, Attributes); if (EFI_ERROR (Status)) { - FileHandle = NULL; return Status; } - // - // go down directories one node at a time. - // - while (!IsDevicePathEnd (*FilePath)) { - // - // For file system access each node should be a file path component - // - if (DevicePathType (*FilePath) != MEDIA_DEVICE_PATH || - DevicePathSubType (*FilePath) != MEDIA_FILEPATH_DP - ) { - FileHandle = NULL; - return (EFI_INVALID_PARAMETER); - } - // - // Open this file path node - // - Handle2 = Handle1; - Handle1 = NULL; - - // - // File Name Alignment Fix (FNAF) - // Handle2->Open may be incapable of handling a unaligned CHAR16 data. - // The structure pointed to by FilePath may be not CHAR16 aligned. - // This code copies the potentially unaligned PathName data from the - // FilePath structure to the aligned FnafPathName for use in the - // calls to Handl2->Open. - // - - // - // Determine length of PathName, in bytes. - // - PathLen = DevicePathNodeLength (*FilePath) - SIZE_OF_FILEPATH_DEVICE_PATH; - - // - // Allocate memory for the aligned copy of the string Extra allocation is to allow for forced alignment - // Copy bytes from possibly unaligned location to aligned location - // - FnafPathName = AllocateCopyPool(PathLen, (UINT8 *)((FILEPATH_DEVICE_PATH*)*FilePath)->PathName); - if (FnafPathName == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - // - // Try to test opening an existing file - // - Status = Handle2->Open ( - Handle2, - &Handle1, - FnafPathName, - OpenMode &~EFI_FILE_MODE_CREATE, - 0 - ); - - // - // see if the error was that it needs to be created - // - if ((EFI_ERROR (Status)) && (OpenMode != (OpenMode &~EFI_FILE_MODE_CREATE))) { - Status = Handle2->Open ( - Handle2, - &Handle1, - FnafPathName, - OpenMode, - Attributes - ); - } - - // - // Free the alignment buffer - // - FreePool(FnafPathName); - - // - // Close the last node - // - Handle2->Close (Handle2); - - if (EFI_ERROR(Status)) { - return (Status); - } - - // - // Get the next node - // - *FilePath = NextDevicePathNode (*FilePath); - } - // // This is a weak spot since if the undefined SHELL_FILE_HANDLE format changes this must change also! // - *FileHandle = (VOID*)Handle1; + *FileHandle = (VOID*)File; return (EFI_SUCCESS); } @@ -669,7 +582,6 @@ ShellOpenFileByName( IN UINT64 Attributes ) { - EFI_HANDLE DeviceHandle; EFI_DEVICE_PATH_PROTOCOL *FilePath; EFI_STATUS Status; EFI_FILE_INFO *FileInfo; @@ -699,7 +611,7 @@ ShellOpenFileByName( // Create the directory to create the file in // FileNameCopy = AllocateCopyPool (StrSize (FileName), FileName); - if (FileName == NULL) { + if (FileNameCopy == NULL) { return (EFI_OUT_OF_RESOURCES); } PathCleanUpDirectories (FileNameCopy); @@ -717,7 +629,21 @@ ShellOpenFileByName( Status = gEfiShellProtocol->OpenFileByName(FileName, FileHandle, OpenMode); - if (StrCmp(FileName, L"NUL") != 0 && !EFI_ERROR(Status) && ((OpenMode & EFI_FILE_MODE_CREATE) != 0)){ + if (EFI_ERROR(Status)) { + return Status; + } + + if (mUnicodeCollationProtocol == NULL) { + Status = gBS->LocateProtocol (&gEfiUnicodeCollation2ProtocolGuid, NULL, (VOID**)&mUnicodeCollationProtocol); + if (EFI_ERROR (Status)) { + gEfiShellProtocol->CloseFile (*FileHandle); + return Status; + } + } + + if ((mUnicodeCollationProtocol->StriColl (mUnicodeCollationProtocol, (CHAR16*)FileName, L"NUL") != 0) && + (mUnicodeCollationProtocol->StriColl (mUnicodeCollationProtocol, (CHAR16*)FileName, L"NULL") != 0) && + !EFI_ERROR(Status) && ((OpenMode & EFI_FILE_MODE_CREATE) != 0)){ FileInfo = FileFunctionMap.GetFileInfo(*FileHandle); ASSERT(FileInfo != NULL); FileInfo->Attribute = Attributes; @@ -739,7 +665,6 @@ ShellOpenFileByName( FilePath = mEfiShellEnvironment2->NameToPath ((CHAR16*)FileName); if (FilePath != NULL) { return (ShellOpenFileByDevicePath(&FilePath, - &DeviceHandle, FileHandle, OpenMode, Attributes)); @@ -1403,7 +1328,6 @@ typedef struct { @retval the resultant head of the double linked new format list; **/ LIST_ENTRY* -EFIAPI InternalShellConvertFileListType ( IN LIST_ENTRY *FileList, IN OUT LIST_ENTRY *ListHead @@ -1873,7 +1797,6 @@ typedef struct { @retval FALSE the Parameter was not found. Type is not valid. **/ BOOLEAN -EFIAPI InternalIsOnCheckList ( IN CONST CHAR16 *Name, IN CONST SHELL_PARAM_ITEM *CheckList, @@ -1942,7 +1865,6 @@ InternalIsOnCheckList ( @retval FALSE the Parameter not a flag. **/ BOOLEAN -EFIAPI InternalIsFlag ( IN CONST CHAR16 *Name, IN CONST BOOLEAN AlwaysAllowNumbers, @@ -1999,7 +1921,6 @@ InternalIsFlag ( ProblemParam if provided. **/ EFI_STATUS -EFIAPI InternalCommandLineParse ( IN CONST SHELL_PARAM_ITEM *CheckList, OUT LIST_ENTRY **CheckPackage, @@ -2018,6 +1939,7 @@ InternalCommandLineParse ( UINTN Count; CONST CHAR16 *TempPointer; UINTN CurrentValueSize; + CHAR16 *NewValue; CurrentItemPackage = NULL; GetItemValue = 0; @@ -2116,25 +2038,32 @@ InternalCommandLineParse ( // get the item VALUE for a previous flag // CurrentValueSize = ValueSize + StrSize(Argv[LoopCounter]) + sizeof(CHAR16); - CurrentItemPackage->Value = ReallocatePool(ValueSize, CurrentValueSize, CurrentItemPackage->Value); - ASSERT(CurrentItemPackage->Value != NULL); + NewValue = ReallocatePool(ValueSize, CurrentValueSize, CurrentItemPackage->Value); + if (NewValue == NULL) { + SHELL_FREE_NON_NULL (CurrentItemPackage->Value); + SHELL_FREE_NON_NULL (CurrentItemPackage); + ShellCommandLineFreeVarList (*CheckPackage); + *CheckPackage = NULL; + return EFI_OUT_OF_RESOURCES; + } + CurrentItemPackage->Value = NewValue; if (ValueSize == 0) { - StrCpyS( CurrentItemPackage->Value, - CurrentValueSize/sizeof(CHAR16), + StrCpyS( CurrentItemPackage->Value, + CurrentValueSize/sizeof(CHAR16), Argv[LoopCounter] ); } else { - StrCatS( CurrentItemPackage->Value, - CurrentValueSize/sizeof(CHAR16), + StrCatS( CurrentItemPackage->Value, + CurrentValueSize/sizeof(CHAR16), L" " ); - StrCatS( CurrentItemPackage->Value, - CurrentValueSize/sizeof(CHAR16), + StrCatS( CurrentItemPackage->Value, + CurrentValueSize/sizeof(CHAR16), Argv[LoopCounter] ); } ValueSize += StrSize(Argv[LoopCounter]) + sizeof(CHAR16); - + GetItemValue--; if (GetItemValue == 0) { InsertHeadList(*CheckPackage, &CurrentItemPackage->Link); @@ -2680,7 +2609,6 @@ ShellCopySearchAndReplace( @retval !EFI_SUCCESS The operation failed. **/ EFI_STATUS -EFIAPI InternalPrintTo ( IN CONST CHAR16 *String ) @@ -2694,10 +2622,10 @@ InternalPrintTo ( return (gEfiShellProtocol->WriteFile(gEfiShellParametersProtocol->StdOut, &Size, (VOID*)String)); } if (mEfiShellInterface != NULL) { - if (mEfiShellInterface->RedirArgc == 0) { + if (mEfiShellInterface->RedirArgc == 0) { // // Divide in half for old shell. Must be string length not size. - // + // Size /=2; // Divide in half only when no redirection. } return (mEfiShellInterface->StdOut->Write(mEfiShellInterface->StdOut, &Size, (VOID*)String)); @@ -2736,7 +2664,6 @@ InternalPrintTo ( @return EFI_DEVICE_ERROR The console device reported an error. **/ EFI_STATUS -EFIAPI InternalShellPrintWorker( IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, @@ -2809,7 +2736,7 @@ InternalShellPrintWorker( // update the attribute // if (ResumeLocation != NULL) { - if (*(ResumeLocation-1) == L'^') { + if ((ResumeLocation != mPostReplaceFormat2) && (*(ResumeLocation-1) == L'^')) { // // Move cursor back 1 position to overwrite the ^ // @@ -2832,10 +2759,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: // @@ -2965,13 +2892,14 @@ ShellPrintHiiEx( CHAR16 *HiiFormatString; EFI_STATUS RetVal; + RetVal = EFI_DEVICE_ERROR; + VA_START (Marker, HiiFormatHandle); HiiFormatString = HiiGetString(HiiFormatHandle, HiiFormatStringId, Language); - ASSERT(HiiFormatString != NULL); - - RetVal = InternalShellPrintWorker(Col, Row, HiiFormatString, Marker); - - SHELL_FREE_NON_NULL(HiiFormatString); + if (HiiFormatString != NULL) { + RetVal = InternalShellPrintWorker (Col, Row, HiiFormatString, Marker); + SHELL_FREE_NON_NULL (HiiFormatString); + } VA_END(Marker); return (RetVal); @@ -3135,7 +3063,7 @@ ShellHexStrToUintn( if (!EFI_ERROR(ShellConvertStringToUint64(String, &RetVal, TRUE, TRUE))) { return ((UINTN)RetVal); } - + return ((UINTN)(-1)); } @@ -3274,7 +3202,7 @@ StrnCatGrow ( if (*Destination == NULL) { return (NULL); } - + StrnCatS(*Destination, NewSize/sizeof(CHAR16), Source, Count); return *Destination; } @@ -3283,7 +3211,7 @@ StrnCatGrow ( Prompt the user and return the resultant answer to the requestor. This function will display the requested question on the shell prompt and then - wait for an apropriate answer to be input from the console. + wait for an appropriate answer to be input from the console. if the SHELL_PROMPT_REQUEST_TYPE is SHELL_PROMPT_REQUEST_TYPE_YESNO, ShellPromptResponseTypeQuitContinue or SHELL_PROMPT_REQUEST_TYPE_YESNOCANCEL then *Response is of type SHELL_PROMPT_RESPONSE. @@ -3383,7 +3311,8 @@ ShellPromptForResponse ( break; } } - break; case ShellPromptResponseTypeYesNoAllCancel: + break; + case ShellPromptResponseTypeYesNoAllCancel: if (Prompt != NULL) { ShellPrintEx(-1, -1, L"%s", Prompt); } @@ -3401,7 +3330,11 @@ ShellPromptForResponse ( if (EFI_ERROR(Status)) { break; } - ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar); + + if (Key.UnicodeChar <= 127 && Key.UnicodeChar >= 32) { + ShellPrintEx (-1, -1, L"%c", Key.UnicodeChar); + } + switch (Key.UnicodeChar) { case L'Y': case L'y': @@ -3585,7 +3518,6 @@ ShellPromptForResponseHii ( @retval FALSE There is a non-numeric character. **/ BOOLEAN -EFIAPI InternalShellIsHexOrDecimalNumber ( IN CONST CHAR16 *String, IN CONST BOOLEAN ForceHex, @@ -3594,29 +3526,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 // @@ -3633,7 +3572,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; } @@ -3698,7 +3637,6 @@ ShellFileExists( **/ CHAR16 -EFIAPI InternalShellCharToUpper ( IN CHAR16 Char ) @@ -3724,7 +3662,6 @@ InternalShellCharToUpper ( **/ UINTN -EFIAPI InternalShellHexCharToUintn ( IN CHAR16 Char ) @@ -3733,7 +3670,7 @@ InternalShellHexCharToUintn ( return Char - L'0'; } - return (UINTN) (10 + InternalShellCharToUpper (Char) - L'A'); + return (10 + InternalShellCharToUpper (Char) - L'A'); } /** @@ -3767,7 +3704,6 @@ InternalShellHexCharToUintn ( @retval EFI_DEVICE_ERROR An overflow occured. **/ EFI_STATUS -EFIAPI InternalShellStrHexToUint64 ( IN CONST CHAR16 *String, OUT UINT64 *Value, @@ -3869,7 +3805,6 @@ InternalShellStrHexToUint64 ( @retval EFI_DEVICE_ERROR An overflow occured. **/ EFI_STATUS -EFIAPI InternalShellStrDecimalToUint64 ( IN CONST CHAR16 *String, OUT UINT64 *Value, @@ -3899,7 +3834,7 @@ InternalShellStrDecimalToUint64 ( Result = 0; // - // Stop upon space if requested + // Stop upon space if requested // (if the whole value was 0) // if (StopAtSpace && *String == L' ') { @@ -4210,7 +4145,7 @@ ShellFileHandleReadLine( @param[in] CommandToGetHelpOn Pointer to a string containing the command name of help file to be printed. @param[in] SectionToGetHelpOn Pointer to the section specifier(s). - @param[in] PrintCommandText If TRUE, prints the command followed by the help content, otherwise prints + @param[in] PrintCommandText If TRUE, prints the command followed by the help content, otherwise prints the help content only. @retval EFI_DEVICE_ERROR The help data format was incorrect. @retval EFI_NOT_FOUND The help data could not be found. @@ -4224,33 +4159,33 @@ ShellPrintHelp ( IN BOOLEAN PrintCommandText ) { - EFI_STATUS Status; - CHAR16 *OutText; - - OutText = NULL; - + EFI_STATUS Status; + CHAR16 *OutText; + + OutText = NULL; + // // Get the string to print based // - Status = gEfiShellProtocol->GetHelpText (CommandToGetHelpOn, SectionToGetHelpOn, &OutText); - + Status = gEfiShellProtocol->GetHelpText (CommandToGetHelpOn, SectionToGetHelpOn, &OutText); + // // make sure we got a valid string // if (EFI_ERROR(Status)){ return Status; - } + } if (OutText == NULL || StrLen(OutText) == 0) { - return EFI_NOT_FOUND; - } - + return EFI_NOT_FOUND; + } + // // Chop off trailing stuff we dont need // while (OutText[StrLen(OutText)-1] == L'\r' || OutText[StrLen(OutText)-1] == L'\n' || OutText[StrLen(OutText)-1] == L' ') { OutText[StrLen(OutText)-1] = CHAR_NULL; } - + // // Print this out to the console // @@ -4259,17 +4194,17 @@ ShellPrintHelp ( } else { ShellPrintEx(-1, -1, L"%N%s\r\n", OutText); } - + SHELL_FREE_NON_NULL(OutText); - return EFI_SUCCESS; + return EFI_SUCCESS; } /** Function to delete a file by name - + @param[in] FileName Pointer to file name to delete. - + @retval EFI_SUCCESS the file was deleted sucessfully @retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not deleted @@ -4296,39 +4231,38 @@ ShellDeleteFileByName( { EFI_STATUS Status; SHELL_FILE_HANDLE FileHandle; - + Status = ShellFileExists(FileName); - + if (Status == EFI_SUCCESS){ Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0x0); if (Status == EFI_SUCCESS){ Status = ShellDeleteFile(&FileHandle); } - } + } return(Status); - + } /** Cleans off all the quotes in the string. @param[in] OriginalString pointer to the string to be cleaned. - @param[out] CleanString The new string with all quotes removed. - Memory allocated in the function and free + @param[out] CleanString The new string with all quotes removed. + Memory allocated in the function and free by caller. @retval EFI_SUCCESS The operation was successful. **/ EFI_STATUS -EFIAPI InternalShellStripQuotes ( IN CONST CHAR16 *OriginalString, OUT CHAR16 **CleanString ) { CHAR16 *Walker; - + if (OriginalString == NULL || CleanString == NULL) { return EFI_INVALID_PARAMETER; }