X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ShellPkg%2FLibrary%2FUefiShellDebug1CommandsLib%2FEdit%2FFileBuffer.c;h=464f9de38e52c7da1238f4f41ad5b00f96190f7d;hb=56ba37463a5ffa44df1c5741184ba0594fadbeba;hp=fcd0de5cb5f67b14ca99a9dcf713d1d480d58059;hpb=33c031ee2092282a069ce07d30202082ceaf61fe;p=mirror_edk2.git diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c index fcd0de5cb5..464f9de38e 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c @@ -1,14 +1,8 @@ /** @file Implements filebuffer interface functions. - Copyright (c) 2005 - 2011, 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 - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -53,7 +47,7 @@ EFI_EDITOR_FILE_BUFFER FileBufferConst = { // // the whole edit area needs to be refreshed // -STATIC BOOLEAN FileBufferNeedRefresh; +BOOLEAN FileBufferNeedRefresh; // // only the current line in edit area needs to be refresh @@ -72,7 +66,6 @@ extern BOOLEAN EditorMouseAction; @param EFI_OUT_OF_RESOURCES A memory allocation failed. **/ EFI_STATUS -EFIAPI FileBufferInit ( VOID ) @@ -121,7 +114,6 @@ FileBufferInit ( @retval EFI_SUCCESS The backup operation was successful. **/ EFI_STATUS -EFIAPI FileBufferBackup ( VOID ) @@ -146,7 +138,7 @@ FileBufferBackup ( /** Advance to the next Count lines - + @param[in] Count The line number to advance by. @param[in] CurrentLine The pointer to the current line structure. @param[in] LineList The pointer to the linked list of lines. @@ -155,7 +147,6 @@ FileBufferBackup ( @return The line structure after the advance. **/ EFI_EDITOR_LINE * -EFIAPI InternalEditorMiscLineAdvance ( IN CONST UINTN Count, IN CONST EFI_EDITOR_LINE *CurrentLine, @@ -186,7 +177,7 @@ InternalEditorMiscLineAdvance ( /** Retreat to the previous Count lines. - + @param[in] Count The line number to retreat by. @param[in] CurrentLine The pointer to the current line structure. @param[in] LineList The pointer to the linked list of lines. @@ -195,7 +186,6 @@ InternalEditorMiscLineAdvance ( @return The line structure after the retreat. **/ EFI_EDITOR_LINE * -EFIAPI InternalEditorMiscLineRetreat ( IN CONST UINTN Count, IN CONST EFI_EDITOR_LINE *CurrentLine, @@ -226,7 +216,7 @@ InternalEditorMiscLineRetreat ( /** Advance/Retreat lines - + @param[in] Count line number to advance/retreat >0 : advance <0 : retreat @@ -262,7 +252,6 @@ MoveLine ( @retval EFI_SUCCESS The backup operation was successful. **/ EFI_STATUS -EFIAPI FileBufferRestoreMousePosition ( VOID ) @@ -300,8 +289,9 @@ FileBufferRestoreMousePosition ( // backup the old screen attributes // Orig = MainEditor.ColorAttributes; - New.Colors.Foreground = Orig.Colors.Background; - New.Colors.Background = Orig.Colors.Foreground; + New.Data = 0; + New.Colors.Foreground = Orig.Colors.Background & 0xF; + New.Colors.Background = Orig.Colors.Foreground & 0x7; // // clear the old mouse position @@ -342,7 +332,7 @@ FileBufferRestoreMousePosition ( // // set the new mouse position // - gST->ConOut->SetAttribute (gST->ConOut, New.Data); + gST->ConOut->SetAttribute (gST->ConOut, New.Data & 0x7F); // // clear the old mouse position @@ -357,7 +347,7 @@ FileBufferRestoreMousePosition ( CurrentLine = FileBuffer.CurrentLine; Line = MoveLine (FRow - FileBuffer.FilePosition.Row); - if (FColumn > Line->Size) { + if (Line == NULL || FColumn > Line->Size) { HasCharacter = FALSE; } @@ -405,7 +395,6 @@ FileBufferRestoreMousePosition ( @retval EFI_SUCCESS The operation was successful. **/ EFI_STATUS -EFIAPI FileBufferFreeLines ( VOID ) @@ -449,7 +438,6 @@ FileBufferFreeLines ( @retval EFI_SUCCESS The cleanup was successful. **/ EFI_STATUS -EFIAPI FileBufferCleanup ( VOID ) @@ -488,7 +476,9 @@ FileBufferPrintLine ( CHAR16 *Buffer; UINTN Limit; - CHAR16 PrintLine[200]; + CHAR16 *PrintLine; + CHAR16 *PrintLine2; + UINTN BufLen; // // print start from correct character @@ -500,19 +490,30 @@ FileBufferPrintLine ( Limit = 0; } - StrnCpy (PrintLine, Buffer, MIN(MIN(Limit,MainEditor.ScreenSize.Column), 200)); - for (; Limit < MainEditor.ScreenSize.Column; Limit++) { - PrintLine[Limit] = L' '; - } + BufLen = (MainEditor.ScreenSize.Column + 1) * sizeof (CHAR16); + PrintLine = AllocatePool (BufLen); + if (PrintLine != NULL) { + StrnCpyS (PrintLine, BufLen/sizeof(CHAR16), Buffer, MIN(Limit, MainEditor.ScreenSize.Column)); + for (Limit = StrLen (PrintLine); Limit < MainEditor.ScreenSize.Column; Limit++) { + PrintLine[Limit] = L' '; + } - PrintLine[MainEditor.ScreenSize.Column] = CHAR_NULL; + PrintLine[MainEditor.ScreenSize.Column] = CHAR_NULL; - ShellPrintEx ( - 0, - (INT32)Row - 1, - L"%s", - PrintLine - ); + PrintLine2 = AllocatePool (BufLen * 2); + if (PrintLine2 != NULL) { + ShellCopySearchAndReplace(PrintLine, PrintLine2, BufLen * 2, L"%", L"^%", FALSE, FALSE); + + ShellPrintEx ( + 0, + (INT32)Row - 1, + L"%s", + PrintLine2 + ); + FreePool (PrintLine2); + } + FreePool (PrintLine); + } return EFI_SUCCESS; } @@ -523,7 +524,6 @@ FileBufferPrintLine ( @retval EFI_SUCCESS The operation was successful. **/ EFI_STATUS -EFIAPI FileBufferRestorePosition ( VOID ) @@ -545,7 +545,6 @@ FileBufferRestorePosition ( @retval EFI_LOAD_ERROR There was an error finding what to write. **/ EFI_STATUS -EFIAPI FileBufferRefresh ( VOID ) @@ -627,11 +626,11 @@ FileBufferRefresh ( Link = Link->ForwardLink; Row++; - } while (Link != FileBuffer.ListHead && Row <= (MainEditor.ScreenSize.Row - 4)); + } while (Link != FileBuffer.ListHead && Row <= (MainEditor.ScreenSize.Row - 1)); // // while not file end and not screen full // - while (Row <= (MainEditor.ScreenSize.Row - 4)) { + while (Row <= (MainEditor.ScreenSize.Row - 1)) { EditorClearLine (Row, MainEditor.ScreenSize.Column, MainEditor.ScreenSize.Row); Row++; } @@ -657,7 +656,6 @@ FileBufferRefresh ( @return The line created. **/ EFI_EDITOR_LINE * -EFIAPI FileBufferCreateLine ( VOID ) @@ -706,13 +704,12 @@ FileBufferCreateLine ( Set FileName field in FileBuffer. @param Str The file name to set. - + @retval EFI_SUCCESS The filename was successfully set. @retval EFI_OUT_OF_RESOURCES A memory allocation failed. @retval EFI_INVALID_PARAMETER Str is not a valid filename. **/ EFI_STATUS -EFIAPI FileBufferSetFileName ( IN CONST CHAR16 *Str ) @@ -744,7 +741,6 @@ FileBufferSetFileName ( @retval EFI_SUCCESS The operation was successful. **/ EFI_STATUS -EFIAPI FileBufferFree ( VOID ) @@ -761,17 +757,16 @@ FileBufferFree ( /** Read a file from disk into the FileBuffer. - + @param[in] FileName The filename to read. @param[in] Recover TRUE if is for recover mode, no information printouts. - + @retval EFI_SUCCESS The load was successful. @retval EFI_LOAD_ERROR The load failed. @retval EFI_OUT_OF_RESOURCES A memory allocation failed. @retval EFI_INVALID_PARAMETER FileName is a directory. **/ EFI_STATUS -EFIAPI FileBufferRead ( IN CONST CHAR16 *FileName, IN CONST BOOLEAN Recover @@ -822,7 +817,7 @@ FileBufferRead ( } Info = ShellGetFileInfo(FileHandle); - + if (Info->Attribute & EFI_FILE_DIRECTORY) { StatusBarSetStatusString (L"Directory Can Not Be Edited"); FreePool (Info); @@ -1266,7 +1261,6 @@ Done: @param[out] Size The amount of the buffer used on return. **/ VOID -EFIAPI GetNewLine ( IN CONST EE_NEWLINE_TYPE Type, OUT CHAR8 *Buffer, @@ -1367,17 +1361,16 @@ GetNewLine ( Change a Unicode string to an ASCII string. @param[in] UStr The Unicode string. - @param[in] Lenght The maximum size of AStr. + @param[in] Length The maximum size of AStr. @param[out] AStr ASCII string to pass out. @return The actuall length. **/ UINTN -EFIAPI UnicodeToAscii ( - IN CONST CHAR16 *UStr, - IN CONST UINTN Length, - OUT CHAR8 *AStr + IN CONST CHAR16 *UStr, + IN CONST UINTN Length, + OUT CHAR8 *AStr ) { UINTN Index; @@ -1398,11 +1391,10 @@ UnicodeToAscii ( @param[in] FileName The file name for writing. @retval EFI_SUCCESS Data was written. - @retval EFI_LOAD_ERROR + @retval EFI_LOAD_ERROR @retval EFI_OUT_OF_RESOURCES There were not enough resources to write the file. **/ EFI_STATUS -EFIAPI FileBufferSave ( IN CONST CHAR16 *FileName ) @@ -1474,7 +1466,7 @@ FileBufferSave ( FreePool(Info); return EFI_LOAD_ERROR; } - + if (Info != NULL) { Attribute = Info->Attribute & ~EFI_FILE_READ_ONLY; FreePool(Info); @@ -1552,7 +1544,7 @@ FileBufferSave ( Size = TotalSize - LeftSize; Status = ShellWriteFile (FileHandle, &Size, Cache); if (EFI_ERROR (Status)) { - ShellDeleteFile (&FileHandle); + ShellDeleteFile (&FileHandle); FreePool (Cache); return EFI_LOAD_ERROR; } @@ -1621,7 +1613,7 @@ FileBufferSave ( // // now everything is ready , you can set the new file name to filebuffer // - if (StrCmp (FileName, FileBuffer.FileName) != 0) { + if (FileName != NULL && FileBuffer.FileName != NULL && StrCmp (FileName, FileBuffer.FileName) != 0) { // // not the same // @@ -1642,7 +1634,6 @@ FileBufferSave ( @retval EFI_SUCCESS The operation was successful. **/ EFI_STATUS -EFIAPI FileBufferScrollLeft ( VOID ) @@ -1685,11 +1676,10 @@ FileBufferScrollLeft ( /** Delete a char in line - @param[in,out] Line The line to delete in. - @param[in] Pos Position to delete the char at ( start from 0 ). + @param[in, out] Line The line to delete in. + @param[in] Pos Position to delete the char at ( start from 0 ). **/ VOID -EFIAPI LineDeleteAt ( IN OUT EFI_EDITOR_LINE *Line, IN UINTN Pos @@ -1710,11 +1700,10 @@ LineDeleteAt ( /** Concatenate Src into Dest. - @param[in,out] Dest Destination string - @param[in] Src Src String. + @param[in, out] Dest Destination string + @param[in] Src Src String. **/ VOID -EFIAPI LineCat ( IN OUT EFI_EDITOR_LINE *Dest, IN EFI_EDITOR_LINE *Src @@ -1755,7 +1744,6 @@ LineCat ( @retval EFI_OUT_OF_RESOURCES A memory allocation failed. **/ EFI_STATUS -EFIAPI FileBufferDoBackspace ( VOID ) @@ -1827,7 +1815,6 @@ FileBufferDoBackspace ( @retval EFI_OUT_OF_RESOURCES A memory allocation failed. **/ EFI_STATUS -EFIAPI FileBufferDoReturn ( VOID ) @@ -1918,13 +1905,12 @@ FileBufferDoReturn ( } /** - Delete current character from current line. This is the effect caused + Delete current character from current line. This is the effect caused by the 'del' key. @retval EFI_SUCCESS **/ EFI_STATUS -EFIAPI FileBufferDoDelete ( VOID ) @@ -1987,7 +1973,6 @@ FileBufferDoDelete ( @retval EFI_SUCCESS The operation was successful. **/ EFI_STATUS -EFIAPI FileBufferScrollRight ( VOID ) @@ -2032,7 +2017,7 @@ FileBufferScrollRight ( /** Insert a char into line - + @param[in] Line The line to insert into. @param[in] Char The char to insert. @param[in] Pos The position to insert the char at ( start from 0 ). @@ -2041,7 +2026,6 @@ FileBufferScrollRight ( @return The new string size ( include CHAR_NULL ) ( unit is Unicode character ). **/ UINTN -EFIAPI LineStrInsert ( IN EFI_EDITOR_LINE *Line, IN CHAR16 Char, @@ -2094,7 +2078,6 @@ LineStrInsert ( @retval EFI_SUCCESS The input was succesful. **/ EFI_STATUS -EFIAPI FileBufferAddChar ( IN CHAR16 Char ) @@ -2142,7 +2125,6 @@ FileBufferAddChar ( @retval EFI_OUT_OF_RESOURCES A memory allocation failed. **/ EFI_STATUS -EFIAPI FileBufferDoCharInput ( IN CONST CHAR16 Char ) @@ -2193,7 +2175,6 @@ FileBufferDoCharInput ( @retval EFI_SUCCESS The operation was successful. **/ EFI_STATUS -EFIAPI FileBufferScrollDown ( VOID ) @@ -2239,7 +2220,6 @@ FileBufferScrollDown ( @retval EFI_SUCCESS The operation was successful. **/ EFI_STATUS -EFIAPI FileBufferScrollUp ( VOID ) @@ -2282,7 +2262,6 @@ FileBufferScrollUp ( @retval EFI_SUCCESS The operation wa successful. **/ EFI_STATUS -EFIAPI FileBufferPageDown ( VOID ) @@ -2300,8 +2279,8 @@ FileBufferPageDown ( // // has next page // - if (FileBuffer.NumLines >= FRow + (MainEditor.ScreenSize.Row - 5)) { - Gap = (MainEditor.ScreenSize.Row - 5); + if (FileBuffer.NumLines >= FRow + (MainEditor.ScreenSize.Row - 2)) { + Gap = (MainEditor.ScreenSize.Row - 2); } else { // // MOVE CURSOR TO LAST LINE @@ -2333,7 +2312,6 @@ FileBufferPageDown ( @retval EFI_SUCCESS The operation was successful. **/ EFI_STATUS -EFIAPI FileBufferPageUp ( VOID ) @@ -2352,8 +2330,8 @@ FileBufferPageUp ( // // has previous page // - if (FRow > (MainEditor.ScreenSize.Row - 5)) { - Gap = (MainEditor.ScreenSize.Row - 5); + if (FRow > (MainEditor.ScreenSize.Row - 2)) { + Gap = (MainEditor.ScreenSize.Row - 2); } else { // // the first line of file will displayed on the first line of screen @@ -2389,7 +2367,6 @@ FileBufferPageUp ( @retval EFI_SUCCESS The operation was successful. **/ EFI_STATUS -EFIAPI FileBufferEnd ( VOID ) @@ -2412,7 +2389,7 @@ FileBufferEnd ( return EFI_SUCCESS; } -/** +/** Dispatch input to different handler @param[in] Key The input key. One of: ASCII KEY @@ -2427,7 +2404,6 @@ FileBufferEnd ( @retval EFI_OUT_OF_RESOURCES A memory allocation failed. **/ EFI_STATUS -EFIAPI FileBufferHandleInput ( IN CONST EFI_INPUT_KEY *Key ) @@ -2543,7 +2519,6 @@ FileBufferHandleInput ( @retval FALSE It is not above the current screen. **/ BOOLEAN -EFIAPI AboveCurrentScreen ( IN UINTN FileRow ) @@ -2567,7 +2542,6 @@ AboveCurrentScreen ( @retval FALSE It is not under the current screen. **/ BOOLEAN -EFIAPI UnderCurrentScreen ( IN UINTN FileRow ) @@ -2575,7 +2549,7 @@ UnderCurrentScreen ( // // if is to the under of the screen // - if (FileRow > FileBuffer.LowVisibleRange.Row + (MainEditor.ScreenSize.Row - 5) - 1) { + if (FileRow > FileBuffer.LowVisibleRange.Row + (MainEditor.ScreenSize.Row - 2) - 1) { return TRUE; } @@ -2591,7 +2565,6 @@ UnderCurrentScreen ( @retval FALSE It is not to the left. **/ BOOLEAN -EFIAPI LeftCurrentScreen ( IN UINTN FileCol ) @@ -2615,7 +2588,6 @@ LeftCurrentScreen ( @retval FALSE It is not to the right. **/ BOOLEAN -EFIAPI RightCurrentScreen ( IN UINTN FileCol ) @@ -2632,7 +2604,7 @@ RightCurrentScreen ( /** Advance/Retreat lines and set CurrentLine in FileBuffer to it - + @param[in] Count The line number to advance/retreat >0 : advance <0: retreat @@ -2641,7 +2613,6 @@ RightCurrentScreen ( @return The line after advance/retreat. **/ EFI_EDITOR_LINE * -EFIAPI MoveCurrentLine ( IN INTN Count ) @@ -2672,7 +2643,6 @@ MoveCurrentLine ( @param[in] NewFilePosCol The column of file position ( start from 1 ). **/ VOID -EFIAPI FileBufferMovePosition ( IN CONST UINTN NewFilePosRow, IN CONST UINTN NewFilePosCol @@ -2760,7 +2730,7 @@ FileBufferMovePosition ( // FileBuffer.FilePosition.Column = NewFilePosCol; if (ColGap < 0) { - Abs = -ColGap; + Abs = (UINTN)(-ColGap); FileBuffer.DisplayPosition.Column -= Abs; } else { FileBuffer.DisplayPosition.Column += ColGap; @@ -2780,7 +2750,7 @@ FileBufferMovePosition ( /** Cut current line out and return a pointer to it. - @param[out] CutLine Upon a successful return pointer to the pointer to + @param[out] CutLine Upon a successful return pointer to the pointer to the allocated cut line. @retval EFI_SUCCESS The cut was successful. @@ -2788,7 +2758,6 @@ FileBufferMovePosition ( @retval EFI_OUT_OF_RESOURCES A memory allocation failed. **/ EFI_STATUS -EFIAPI FileBufferCutLine ( OUT EFI_EDITOR_LINE **CutLine ) @@ -2868,7 +2837,6 @@ FileBufferCutLine ( @retval EFI_OUT_OF_RESOURCES A memory allocation failed. **/ EFI_STATUS -EFIAPI FileBufferPasteLine ( VOID ) @@ -2940,7 +2908,6 @@ FileBufferPasteLine ( @retval EFI_NOT_FOUND The string Str was not found. **/ EFI_STATUS -EFIAPI FileBufferSearch ( IN CONST CHAR16 *Str, IN CONST UINTN Offset @@ -2956,6 +2923,7 @@ FileBufferSearch ( BOOLEAN Found; Column = 0; + Position = 0; // // search if in current line @@ -2969,20 +2937,20 @@ FileBufferSearch ( Current = FileBuffer.CurrentLine->Buffer + FileBuffer.CurrentLine->Size; } + Found = FALSE; + CharPos = StrStr (Current, Str); if (CharPos != NULL) { - Position = CharPos - Current; - } else { - Position = 0; + Position = CharPos - Current + 1; + Found = TRUE; } // // found // - if (Position != 0) { + if (Found) { Column = (Position - 1) + FileBuffer.FilePosition.Column + Offset; Row = FileBuffer.FilePosition.Row; - Found = TRUE; } else { // // not found so find through next lines @@ -2995,9 +2963,11 @@ FileBufferSearch ( // Position = StrStr (Line->Buffer, Str); CharPos = StrStr (Line->Buffer, Str); if (CharPos != NULL) { - Position = CharPos - Line->Buffer; + Position = CharPos - Line->Buffer + 1; + Found = TRUE; } - if (Position != 0) { + + if (Found) { // // found // @@ -3043,7 +3013,6 @@ FileBufferSearch ( @retval EFI_OUT_OF_RESOURCES A memory allocation failed. **/ EFI_STATUS -EFIAPI FileBufferReplace ( IN CONST CHAR16 *Replace, IN CONST UINTN SearchLen @@ -3096,14 +3065,14 @@ FileBufferReplace ( // // set replace into it // - Buffer = FileBuffer.CurrentLine->Buffer + FileBuffer.FilePosition.Column; + Buffer = FileBuffer.CurrentLine->Buffer + FileBuffer.FilePosition.Column - 1; for (Index = 0; Index < ReplaceLen; Index++) { Buffer[Index] = Replace[Index]; } } if (ReplaceLen < SearchLen) { - Buffer = FileBuffer.CurrentLine->Buffer + FileBuffer.FilePosition.Column; + Buffer = FileBuffer.CurrentLine->Buffer + FileBuffer.FilePosition.Column - 1; for (Index = 0; Index < ReplaceLen; Index++) { Buffer[Index] = Replace[Index]; @@ -3122,7 +3091,7 @@ FileBufferReplace ( } if (ReplaceLen == SearchLen) { - Buffer = FileBuffer.CurrentLine->Buffer + FileBuffer.FilePosition.Column; + Buffer = FileBuffer.CurrentLine->Buffer + FileBuffer.FilePosition.Column - 1; for (Index = 0; Index < ReplaceLen; Index++) { Buffer[Index] = Replace[Index]; } @@ -3148,7 +3117,6 @@ FileBufferReplace ( @param[in] TextY The new y-coordinate. **/ VOID -EFIAPI FileBufferAdjustMousePosition ( IN CONST INT32 TextX, IN CONST INT32 TextY @@ -3207,12 +3175,12 @@ FileBufferAdjustMousePosition ( // check whether new mouse row position is beyond screen // if not, adjust it // - if (CoordinateY >= 2 && CoordinateY <= (MainEditor.ScreenSize.Row - 4)) { + if (CoordinateY >= 2 && CoordinateY <= (MainEditor.ScreenSize.Row - 1)) { FileBuffer.MousePosition.Row = CoordinateY; } else if (CoordinateY < 2) { FileBuffer.MousePosition.Row = 2; - } else if (CoordinateY > (MainEditor.ScreenSize.Row - 4)) { - FileBuffer.MousePosition.Row = (MainEditor.ScreenSize.Row - 4); + } else if (CoordinateY > (MainEditor.ScreenSize.Row - 1)) { + FileBuffer.MousePosition.Row = (MainEditor.ScreenSize.Row - 1); } } @@ -3225,7 +3193,6 @@ FileBufferAdjustMousePosition ( @param[in] Offset The column to start at. **/ EFI_STATUS -EFIAPI FileBufferReplaceAll ( IN CHAR16 *SearchStr, IN CHAR16 *ReplaceStr, @@ -3343,7 +3310,6 @@ FileBufferReplaceAll ( Set the modified state to TRUE. **/ VOID -EFIAPI FileBufferSetModified ( VOID )