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