]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / Edit / FileBuffer.c
index fcd0de5cb5f67b14ca99a9dcf713d1d480d58059..088030d29f672151a077317c05f78c73bc1de3a0 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,16 +47,16 @@ 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
 //\r
-BOOLEAN                 FileBufferOnlyLineNeedRefresh;\r
+BOOLEAN  FileBufferOnlyLineNeedRefresh;\r
 \r
-BOOLEAN                 FileBufferMouseNeedRefresh;\r
+BOOLEAN  FileBufferMouseNeedRefresh;\r
 \r
-extern BOOLEAN          EditorMouseAction;\r
+extern BOOLEAN  EditorMouseAction;\r
 \r
 /**\r
   Initialization function for FileBuffer.\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
@@ -80,7 +73,7 @@ FileBufferInit (
   //\r
   // basically initialize the FileBuffer\r
   //\r
-  CopyMem (&FileBuffer         , &FileBufferConst, sizeof (EFI_EDITOR_FILE_BUFFER));\r
+  CopyMem (&FileBuffer, &FileBufferConst, sizeof (EFI_EDITOR_FILE_BUFFER));\r
   CopyMem (&FileBufferBackupVar, &FileBufferConst, sizeof (EFI_EDITOR_FILE_BUFFER));\r
 \r
   //\r
@@ -103,9 +96,9 @@ FileBufferInit (
   FileBuffer.LowVisibleRange.Row    = 2;\r
   FileBuffer.LowVisibleRange.Column = 1;\r
 \r
-  FileBufferNeedRefresh             = FALSE;\r
-  FileBufferMouseNeedRefresh        = FALSE;\r
-  FileBufferOnlyLineNeedRefresh     = FALSE;\r
+  FileBufferNeedRefresh         = FALSE;\r
+  FileBufferMouseNeedRefresh    = FALSE;\r
+  FileBufferOnlyLineNeedRefresh = FALSE;\r
 \r
   return EFI_SUCCESS;\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
@@ -129,24 +121,24 @@ FileBufferBackup (
   FileBufferBackupVar.MousePosition = FileBuffer.MousePosition;\r
 \r
   SHELL_FREE_NON_NULL (FileBufferBackupVar.FileName);\r
-  FileBufferBackupVar.FileName        = NULL;\r
-  FileBufferBackupVar.FileName        = StrnCatGrow (&FileBufferBackupVar.FileName, NULL, FileBuffer.FileName, 0);\r
+  FileBufferBackupVar.FileName = NULL;\r
+  FileBufferBackupVar.FileName = StrnCatGrow (&FileBufferBackupVar.FileName, NULL, FileBuffer.FileName, 0);\r
 \r
-  FileBufferBackupVar.ModeInsert      = FileBuffer.ModeInsert;\r
-  FileBufferBackupVar.FileType        = FileBuffer.FileType;\r
+  FileBufferBackupVar.ModeInsert = FileBuffer.ModeInsert;\r
+  FileBufferBackupVar.FileType   = FileBuffer.FileType;\r
 \r
   FileBufferBackupVar.FilePosition    = FileBuffer.FilePosition;\r
   FileBufferBackupVar.LowVisibleRange = FileBuffer.LowVisibleRange;\r
 \r
-  FileBufferBackupVar.FileModified    = FileBuffer.FileModified;\r
-  FileBufferBackupVar.ReadOnly        = FileBuffer.ReadOnly;\r
+  FileBufferBackupVar.FileModified = FileBuffer.FileModified;\r
+  FileBufferBackupVar.ReadOnly     = FileBuffer.ReadOnly;\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \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
@@ -163,10 +154,10 @@ InternalEditorMiscLineAdvance (
   )\r
 \r
 {\r
-  UINTN                 Index;\r
-  CONST EFI_EDITOR_LINE *Line;\r
+  UINTN                  Index;\r
+  CONST EFI_EDITOR_LINE  *Line;\r
 \r
-  if (CurrentLine == NULL || LineList == NULL) {\r
+  if ((CurrentLine == NULL) || (LineList == NULL)) {\r
     return NULL;\r
   }\r
 \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
@@ -203,10 +193,10 @@ InternalEditorMiscLineRetreat (
   )\r
 \r
 {\r
-  UINTN                 Index;\r
-  CONST EFI_EDITOR_LINE *Line;\r
+  UINTN                  Index;\r
+  CONST EFI_EDITOR_LINE  *Line;\r
 \r
-  if (CurrentLine == NULL || LineList == NULL) {\r
+  if ((CurrentLine == NULL) || (LineList == NULL)) {\r
     return NULL;\r
   }\r
 \r
@@ -226,31 +216,31 @@ InternalEditorMiscLineRetreat (
 \r
 /**\r
   Advance/Retreat lines\r
-  \r
+\r
   @param[in] Count  line number to advance/retreat\r
                        >0 : advance\r
                        <0 : retreat\r
 \r
-  @retval NULL An error occured.\r
+  @retval NULL An error occurred.\r
   @return The line after advance/retreat.\r
 **/\r
 EFI_EDITOR_LINE *\r
 MoveLine (\r
-  IN CONST INTN Count\r
+  IN CONST INTN  Count\r
   )\r
 {\r
-  EFI_EDITOR_LINE *Line;\r
-  UINTN           AbsCount;\r
+  EFI_EDITOR_LINE  *Line;\r
+  UINTN            AbsCount;\r
 \r
   //\r
   // if < 0, then retreat\r
   // if > 0, the advance\r
   //\r
   if (Count <= 0) {\r
-    AbsCount  = (UINTN)ABS(Count);\r
-    Line      = InternalEditorMiscLineRetreat (AbsCount,MainEditor.FileBuffer->CurrentLine,MainEditor.FileBuffer->ListHead);\r
+    AbsCount = (UINTN)ABS (Count);\r
+    Line     = InternalEditorMiscLineRetreat (AbsCount, MainEditor.FileBuffer->CurrentLine, MainEditor.FileBuffer->ListHead);\r
   } else {\r
-    Line = InternalEditorMiscLineAdvance ((UINTN)Count,MainEditor.FileBuffer->CurrentLine,MainEditor.FileBuffer->ListHead);\r
+    Line = InternalEditorMiscLineAdvance ((UINTN)Count, MainEditor.FileBuffer->CurrentLine, MainEditor.FileBuffer->ListHead);\r
   }\r
 \r
   return Line;\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
@@ -282,42 +271,43 @@ FileBufferRestoreMousePosition (
   Line = NULL;\r
 \r
   if (MainEditor.MouseSupported) {\r
-\r
     if (FileBufferMouseNeedRefresh) {\r
-\r
       FileBufferMouseNeedRefresh = FALSE;\r
 \r
       //\r
       // if mouse position not moved and only mouse action\r
       // so do not need to refresh mouse position\r
       //\r
-      if ((FileBuffer.MousePosition.Row == FileBufferBackupVar.MousePosition.Row &&\r
-          FileBuffer.MousePosition.Column == FileBufferBackupVar.MousePosition.Column)\r
-          && EditorMouseAction) {\r
+      if (  ((FileBuffer.MousePosition.Row == FileBufferBackupVar.MousePosition.Row) &&\r
+             (FileBuffer.MousePosition.Column == FileBufferBackupVar.MousePosition.Column))\r
+         && EditorMouseAction)\r
+      {\r
         return EFI_SUCCESS;\r
       }\r
+\r
       //\r
       // 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
       //\r
-      FRow          = FileBuffer.LowVisibleRange.Row + FileBufferBackupVar.MousePosition.Row - 2;\r
+      FRow = FileBuffer.LowVisibleRange.Row + FileBufferBackupVar.MousePosition.Row - 2;\r
 \r
-      FColumn       = FileBuffer.LowVisibleRange.Column + FileBufferBackupVar.MousePosition.Column - 1;\r
+      FColumn = FileBuffer.LowVisibleRange.Column + FileBufferBackupVar.MousePosition.Column - 1;\r
 \r
-      HasCharacter  = TRUE;\r
+      HasCharacter = TRUE;\r
       if (FRow > FileBuffer.NumLines) {\r
         HasCharacter = FALSE;\r
       } else {\r
         CurrentLine = FileBuffer.CurrentLine;\r
         Line        = MoveLine (FRow - FileBuffer.FilePosition.Row);\r
 \r
-        if (Line == NULL || FColumn > Line->Size) {\r
+        if ((Line == NULL) || (FColumn > Line->Size)) {\r
           HasCharacter = FALSE;\r
         }\r
 \r
@@ -339,25 +329,26 @@ FileBufferRestoreMousePosition (
           Value\r
           );\r
       }\r
+\r
       //\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
       //\r
-      FRow          = FileBuffer.LowVisibleRange.Row + FileBuffer.MousePosition.Row - 2;\r
-      FColumn       = FileBuffer.LowVisibleRange.Column + FileBuffer.MousePosition.Column - 1;\r
+      FRow    = FileBuffer.LowVisibleRange.Row + FileBuffer.MousePosition.Row - 2;\r
+      FColumn = FileBuffer.LowVisibleRange.Column + FileBuffer.MousePosition.Column - 1;\r
 \r
-      HasCharacter  = TRUE;\r
+      HasCharacter = TRUE;\r
       if (FRow > FileBuffer.NumLines) {\r
         HasCharacter = FALSE;\r
       } else {\r
         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
@@ -379,15 +370,18 @@ FileBufferRestoreMousePosition (
           Value\r
           );\r
       }\r
+\r
       //\r
       // end of HasCharacter\r
       //\r
       gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);\r
     }\r
+\r
     //\r
     // end of MouseNeedRefresh\r
     //\r
   }\r
+\r
   //\r
   // end of MouseSupported\r
   //\r
@@ -405,24 +399,22 @@ FileBufferRestoreMousePosition (
   @retval EFI_SUCCESS     The operation was successful.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 FileBufferFreeLines (\r
   VOID\r
   )\r
 {\r
-  LIST_ENTRY  *Link;\r
-  EFI_EDITOR_LINE *Line;\r
+  LIST_ENTRY       *Link;\r
+  EFI_EDITOR_LINE  *Line;\r
 \r
   //\r
   // free all the lines\r
   //\r
   if (FileBuffer.Lines != NULL) {\r
-\r
-    Line  = FileBuffer.Lines;\r
-    Link  = &(Line->Link);\r
+    Line = FileBuffer.Lines;\r
+    Link = &(Line->Link);\r
     do {\r
-      Line  = CR (Link, EFI_EDITOR_LINE, Link, LINE_LIST_SIGNATURE);\r
-      Link  = Link->ForwardLink;\r
+      Line = CR (Link, EFI_EDITOR_LINE, Link, LINE_LIST_SIGNATURE);\r
+      Link = Link->ForwardLink;\r
 \r
       //\r
       // free line's buffer and line itself\r
@@ -430,15 +422,16 @@ FileBufferFreeLines (
       LineFree (Line);\r
     } while (Link != FileBuffer.ListHead);\r
   }\r
+\r
   //\r
   // clean the line list related structure\r
   //\r
-  FileBuffer.Lines            = NULL;\r
-  FileBuffer.CurrentLine      = NULL;\r
-  FileBuffer.NumLines         = 0;\r
+  FileBuffer.Lines       = NULL;\r
+  FileBuffer.CurrentLine = NULL;\r
+  FileBuffer.NumLines    = 0;\r
 \r
-  FileBuffer.ListHead->ForwardLink  = FileBuffer.ListHead;\r
-  FileBuffer.ListHead->BackLink  = FileBuffer.ListHead;\r
+  FileBuffer.ListHead->ForwardLink = FileBuffer.ListHead;\r
+  FileBuffer.ListHead->BackLink    = FileBuffer.ListHead;\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -449,7 +442,6 @@ FileBufferFreeLines (
   @retval EFI_SUCCESS   The cleanup was successful.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 FileBufferCleanup (\r
   VOID\r
   )\r
@@ -468,7 +460,6 @@ FileBufferCleanup (
 \r
   SHELL_FREE_NON_NULL (FileBufferBackupVar.FileName);\r
   return Status;\r
-\r
 }\r
 \r
 /**\r
@@ -485,34 +476,47 @@ FileBufferPrintLine (
   IN CONST UINTN            Row\r
   )\r
 {\r
-\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
   //\r
-  Buffer  = Line->Buffer + FileBuffer.LowVisibleRange.Column - 1;\r
+  Buffer = Line->Buffer + FileBuffer.LowVisibleRange.Column - 1;\r
 \r
-  Limit   = Line->Size - FileBuffer.LowVisibleRange.Column + 1;\r
+  Limit = Line->Size - FileBuffer.LowVisibleRange.Column + 1;\r
   if (Limit > Line->Size) {\r
     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
+\r
+    FreePool (PrintLine);\r
+  }\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -523,7 +527,6 @@ FileBufferPrintLine (
   @retval EFI_SUCCESS           The operation was successful.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 FileBufferRestorePosition (\r
   VOID\r
   )\r
@@ -532,10 +535,10 @@ FileBufferRestorePosition (
   // set cursor position\r
   //\r
   return (gST->ConOut->SetCursorPosition (\r
-        gST->ConOut,\r
-        FileBuffer.DisplayPosition.Column - 1,\r
-        FileBuffer.DisplayPosition.Row - 1\r
-        ));\r
+                         gST->ConOut,\r
+                         FileBuffer.DisplayPosition.Column - 1,\r
+                         FileBuffer.DisplayPosition.Row - 1\r
+                         ));\r
 }\r
 \r
 /**\r
@@ -545,14 +548,13 @@ 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
 {\r
-  LIST_ENTRY  *Link;\r
-  EFI_EDITOR_LINE *Line;\r
-  UINTN           Row;\r
+  LIST_ENTRY       *Link;\r
+  EFI_EDITOR_LINE  *Line;\r
+  UINTN            Row;\r
 \r
   //\r
   // if it's the first time after editor launch, so should refresh\r
@@ -564,10 +566,10 @@ FileBufferRefresh (
     //\r
     if (!FileBufferNeedRefresh &&\r
         !FileBufferOnlyLineNeedRefresh &&\r
-        FileBufferBackupVar.LowVisibleRange.Row == FileBuffer.LowVisibleRange.Row &&\r
-        FileBufferBackupVar.LowVisibleRange.Column == FileBuffer.LowVisibleRange.Column\r
-        ) {\r
-\r
+        (FileBufferBackupVar.LowVisibleRange.Row == FileBuffer.LowVisibleRange.Row) &&\r
+        (FileBufferBackupVar.LowVisibleRange.Column == FileBuffer.LowVisibleRange.Column)\r
+        )\r
+    {\r
       FileBufferRestoreMousePosition ();\r
       FileBufferRestorePosition ();\r
 \r
@@ -581,10 +583,10 @@ FileBufferRefresh (
   // only need to refresh current line\r
   //\r
   if (FileBufferOnlyLineNeedRefresh &&\r
-      FileBufferBackupVar.LowVisibleRange.Row == FileBuffer.LowVisibleRange.Row &&\r
-      FileBufferBackupVar.LowVisibleRange.Column == FileBuffer.LowVisibleRange.Column\r
-      ) {\r
-\r
+      (FileBufferBackupVar.LowVisibleRange.Row == FileBuffer.LowVisibleRange.Row) &&\r
+      (FileBufferBackupVar.LowVisibleRange.Column == FileBuffer.LowVisibleRange.Column)\r
+      )\r
+  {\r
     EditorClearLine (FileBuffer.DisplayPosition.Row, MainEditor.ScreenSize.Column, MainEditor.ScreenSize.Row);\r
     FileBufferPrintLine (\r
       FileBuffer.CurrentLine,\r
@@ -605,6 +607,7 @@ FileBufferRefresh (
 \r
       return EFI_SUCCESS;\r
     }\r
+\r
     //\r
     // get the first line that will be displayed\r
     //\r
@@ -615,8 +618,8 @@ FileBufferRefresh (
       return EFI_LOAD_ERROR;\r
     }\r
 \r
-    Link  = &(Line->Link);\r
-    Row   = 2;\r
+    Link = &(Line->Link);\r
+    Row  = 2;\r
     do {\r
       Line = CR (Link, EFI_EDITOR_LINE, Link, LINE_LIST_SIGNATURE);\r
 \r
@@ -627,11 +630,12 @@ 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
     //\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,12 +661,11 @@ FileBufferRefresh (
   @return         The line created.\r
 **/\r
 EFI_EDITOR_LINE *\r
-EFIAPI\r
 FileBufferCreateLine (\r
   VOID\r
   )\r
 {\r
-  EFI_EDITOR_LINE *Line;\r
+  EFI_EDITOR_LINE  *Line;\r
 \r
   //\r
   // allocate a line structure\r
@@ -671,6 +674,7 @@ FileBufferCreateLine (
   if (Line == NULL) {\r
     return NULL;\r
   }\r
+\r
   //\r
   // initialize the structure\r
   //\r
@@ -682,7 +686,7 @@ FileBufferCreateLine (
   //\r
   // initial buffer of the line is "\0"\r
   //\r
-  ASSERT(CHAR_NULL == CHAR_NULL);\r
+  ASSERT (CHAR_NULL == CHAR_NULL);\r
   Line->Buffer = CatSPrint (NULL, L"\0");\r
   if (Line->Buffer == NULL) {\r
     return NULL;\r
@@ -706,23 +710,23 @@ 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
+  IN CONST CHAR16  *Str\r
   )\r
 {\r
   //\r
   // Verify the parameters\r
   //\r
-  if (!IsValidFileName(Str)) {\r
+  if (!IsValidFileName (Str)) {\r
     return (EFI_INVALID_PARAMETER);\r
   }\r
+\r
   //\r
   // free the old file name\r
   //\r
@@ -738,13 +742,13 @@ FileBufferSetFileName (
 \r
   return EFI_SUCCESS;\r
 }\r
+\r
 /**\r
   Free the existing file lines and reset the modified flag.\r
 \r
   @retval EFI_SUCCESS           The operation was successful.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 FileBufferFree (\r
   VOID\r
   )\r
@@ -758,39 +762,37 @@ FileBufferFree (
   return EFI_SUCCESS;\r
 }\r
 \r
-\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
+  IN CONST CHAR16   *FileName,\r
+  IN CONST BOOLEAN  Recover\r
   )\r
 {\r
-  EFI_EDITOR_LINE                 *Line;\r
-  EE_NEWLINE_TYPE                 Type;\r
-  UINTN                           LoopVar1;\r
-  UINTN                           LoopVar2;\r
-  UINTN                           LineSize;\r
-  VOID                            *Buffer;\r
-  CHAR16                          *UnicodeBuffer;\r
-  UINT8                           *AsciiBuffer;\r
-  UINTN                           FileSize;\r
-  SHELL_FILE_HANDLE               FileHandle;\r
-  BOOLEAN                         CreateFile;\r
-  EFI_STATUS                      Status;\r
-  UINTN                           LineSizeBackup;\r
-  EFI_FILE_INFO                   *Info;\r
+  EFI_EDITOR_LINE    *Line;\r
+  EE_NEWLINE_TYPE    Type;\r
+  UINTN              LoopVar1;\r
+  UINTN              LoopVar2;\r
+  UINTN              LineSize;\r
+  VOID               *Buffer;\r
+  CHAR16             *UnicodeBuffer;\r
+  UINT8              *AsciiBuffer;\r
+  UINTN              FileSize;\r
+  SHELL_FILE_HANDLE  FileHandle;\r
+  BOOLEAN            CreateFile;\r
+  EFI_STATUS         Status;\r
+  UINTN              LineSizeBackup;\r
+  EFI_FILE_INFO      *Info;\r
 \r
   Line          = NULL;\r
   LoopVar1      = 0;\r
@@ -814,15 +816,15 @@ FileBufferRead (
   //\r
   Status = ShellOpenFileByName (FileName, &FileHandle, EFI_FILE_MODE_READ, 0);\r
 \r
-  if (!EFI_ERROR(Status)) {\r
+  if (!EFI_ERROR (Status)) {\r
     CreateFile = FALSE;\r
     if (FileHandle == NULL) {\r
       StatusBarSetStatusString (L"Disk Error");\r
       return EFI_LOAD_ERROR;\r
     }\r
 \r
-    Info = ShellGetFileInfo(FileHandle);\r
-    \r
+    Info = ShellGetFileInfo (FileHandle);\r
+\r
     if (Info->Attribute & EFI_FILE_DIRECTORY) {\r
       StatusBarSetStatusString (L"Directory Can Not Be Edited");\r
       FreePool (Info);\r
@@ -834,10 +836,11 @@ FileBufferRead (
     } else {\r
       FileBuffer.ReadOnly = FALSE;\r
     }\r
+\r
     //\r
     // get file size\r
     //\r
-    FileSize = (UINTN) Info->FileSize;\r
+    FileSize = (UINTN)Info->FileSize;\r
 \r
     FreePool (Info);\r
   } else if (Status == EFI_NOT_FOUND) {\r
@@ -846,13 +849,14 @@ FileBufferRead (
     //\r
     Status = ShellOpenFileByName (FileName, &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);\r
     if (EFI_ERROR (Status)) {\r
-      if (Status == EFI_WRITE_PROTECTED ||\r
-          Status == EFI_ACCESS_DENIED ||\r
-          Status == EFI_NO_MEDIA ||\r
-          Status == EFI_MEDIA_CHANGED\r
-          ) {\r
+      if ((Status == EFI_WRITE_PROTECTED) ||\r
+          (Status == EFI_ACCESS_DENIED) ||\r
+          (Status == EFI_NO_MEDIA) ||\r
+          (Status == EFI_MEDIA_CHANGED)\r
+          )\r
+      {\r
         StatusBarSetStatusString (L"Access Denied");\r
-      } else if (Status == EFI_DEVICE_ERROR || Status == EFI_VOLUME_CORRUPTED || Status == EFI_VOLUME_FULL) {\r
+      } else if ((Status == EFI_DEVICE_ERROR) || (Status == EFI_VOLUME_CORRUPTED) || (Status == EFI_VOLUME_FULL)) {\r
         StatusBarSetStatusString (L"Disk Error");\r
       } else {\r
         StatusBarSetStatusString (L"Invalid File Name or Current-working-directory");\r
@@ -867,12 +871,14 @@ FileBufferRead (
       if (Status == EFI_WARN_DELETE_FAILURE) {\r
         Status = EFI_ACCESS_DENIED;\r
       }\r
+\r
       FileHandle = NULL;\r
       if (EFI_ERROR (Status)) {\r
         StatusBarSetStatusString (L"Access Denied");\r
         return Status;\r
       }\r
     }\r
+\r
     //\r
     // file doesn't exist, so set CreateFile to TRUE\r
     //\r
@@ -886,12 +892,13 @@ FileBufferRead (
     if (StrCmp (FileName, FileBuffer.FileName) != 0) {\r
       FileBufferSetFileName (FileName);\r
     }\r
+\r
     //\r
     // free the old lines\r
     //\r
     FileBufferFree ();\r
-\r
   }\r
+\r
   //\r
   // the file exists\r
   //\r
@@ -903,17 +910,19 @@ FileBufferRead (
     if (Buffer == NULL) {\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
+\r
     //\r
     // read file into Buffer\r
     //\r
     Status = ShellReadFile (FileHandle, &FileSize, Buffer);\r
-    ShellCloseFile(&FileHandle);\r
+    ShellCloseFile (&FileHandle);\r
     FileHandle = NULL;\r
     if (EFI_ERROR (Status)) {\r
       StatusBarSetStatusString (L"Read File Failed");\r
       SHELL_FREE_NON_NULL (Buffer);\r
       return EFI_LOAD_ERROR;\r
     }\r
+\r
     //\r
     // nothing in this file\r
     //\r
@@ -938,7 +947,7 @@ FileBufferRead (
       //\r
       // Unicode file\r
       //\r
-      if (*(UINT16 *) Buffer == EFI_UNICODE_BYTE_ORDER_MARK) {\r
+      if (*(UINT16 *)Buffer == EFI_UNICODE_BYTE_ORDER_MARK) {\r
         //\r
         // Unicode file's size should be even\r
         //\r
@@ -961,10 +970,12 @@ FileBufferRead (
       } else {\r
         FileBuffer.FileType = FileTypeAscii;\r
       }\r
+\r
       //\r
       // end of AsciiBuffer ==\r
       //\r
     }\r
+\r
     //\r
     // end of FileSize < 2\r
     // all the check ends\r
@@ -1043,10 +1054,12 @@ FileBufferRead (
             break;\r
           }\r
         }\r
+\r
         //\r
         // endif == ASCII\r
         //\r
       }\r
+\r
       //\r
       // end of for LineSize\r
       //\r
@@ -1069,6 +1082,7 @@ FileBufferRead (
         SHELL_FREE_NON_NULL (Buffer);\r
         return EFI_OUT_OF_RESOURCES;\r
       }\r
+\r
       //\r
       // calculate file length\r
       //\r
@@ -1084,53 +1098,58 @@ FileBufferRead (
         RemoveEntryList (&Line->Link);\r
         return EFI_OUT_OF_RESOURCES;\r
       }\r
+\r
       //\r
       // copy this line to Line->Buffer\r
       //\r
       for (LoopVar2 = 0; LoopVar2 < LineSize; LoopVar2++) {\r
         if (FileBuffer.FileType == FileTypeAscii) {\r
-          Line->Buffer[LoopVar2] = (CHAR16) AsciiBuffer[LoopVar1];\r
+          Line->Buffer[LoopVar2] = (CHAR16)AsciiBuffer[LoopVar1];\r
         } else {\r
           Line->Buffer[LoopVar2] = UnicodeBuffer[LoopVar1];\r
         }\r
 \r
         LoopVar1++;\r
       }\r
+\r
       //\r
       // LoopVar1 now points to where CHAR_CARRIAGE_RETURN or CHAR_LINEFEED;\r
       //\r
-      Line->Buffer[LineSize]  = 0;\r
+      Line->Buffer[LineSize] = 0;\r
 \r
-      Line->Size              = LineSize;\r
-      Line->TotalSize         = LineSize;\r
-      Line->Type              = Type;\r
+      Line->Size      = LineSize;\r
+      Line->TotalSize = LineSize;\r
+      Line->Type      = Type;\r
 \r
-      if (Type == NewLineTypeCarriageReturnLineFeed || Type == NewLineTypeLineFeedCarriageReturn) {\r
+      if ((Type == NewLineTypeCarriageReturnLineFeed) || (Type == NewLineTypeLineFeedCarriageReturn)) {\r
         LoopVar1++;\r
       }\r
 \r
       //\r
       // last character is a return, SO create a new line\r
       //\r
-      if (((Type == NewLineTypeCarriageReturnLineFeed || Type == NewLineTypeLineFeedCarriageReturn) && LineSizeBackup == FileSize - 2) ||\r
-          ((Type == NewLineTypeLineFeed || Type == NewLineTypeCarriageReturn) && LineSizeBackup == FileSize - 1)\r
-          ) {\r
+      if ((((Type == NewLineTypeCarriageReturnLineFeed) || (Type == NewLineTypeLineFeedCarriageReturn)) && (LineSizeBackup == FileSize - 2)) ||\r
+          (((Type == NewLineTypeLineFeed) || (Type == NewLineTypeCarriageReturn)) && (LineSizeBackup == FileSize - 1))\r
+          )\r
+      {\r
         Line = FileBufferCreateLine ();\r
         if (Line == NULL) {\r
           SHELL_FREE_NON_NULL (Buffer);\r
           return EFI_OUT_OF_RESOURCES;\r
         }\r
       }\r
+\r
       //\r
       // end of if\r
       //\r
     }\r
+\r
     //\r
     // end of LoopVar1\r
     //\r
     SHELL_FREE_NON_NULL (Buffer);\r
-\r
   }\r
+\r
   //\r
   // end of if CreateFile\r
   //\r
@@ -1154,83 +1173,84 @@ Done:
     StatusBarSetStatusString (UnicodeBuffer);\r
     FreePool (UnicodeBuffer);\r
   }\r
-/*\r
-    //\r
-    // check whether we have fs?: in filename\r
-    //\r
-    LoopVar1             = 0;\r
-    FSMappingPtr  = NULL;\r
-    while (FileName[LoopVar1] != 0) {\r
-      if (FileName[LoopVar1] == L':') {\r
-        FSMappingPtr = &FileName[LoopVar1];\r
-        break;\r
-      }\r
-\r
-      LoopVar1++;\r
-    }\r
 \r
-    if (FSMappingPtr == NULL) {\r
-      CurDir = ShellGetCurrentDir (NULL);\r
-    } else {\r
-      LoopVar1 = 0;\r
-      LoopVar2 = 0;\r
+  /*\r
+      //\r
+      // check whether we have fs?: in filename\r
+      //\r
+      LoopVar1             = 0;\r
+      FSMappingPtr  = NULL;\r
       while (FileName[LoopVar1] != 0) {\r
         if (FileName[LoopVar1] == L':') {\r
+          FSMappingPtr = &FileName[LoopVar1];\r
           break;\r
         }\r
 \r
-        FSMapping[LoopVar2++] = FileName[LoopVar1];\r
-\r
         LoopVar1++;\r
       }\r
 \r
-      FSMapping[LoopVar2]  = 0;\r
-      CurDir        = ShellGetCurrentDir (FSMapping);\r
-    }\r
+      if (FSMappingPtr == NULL) {\r
+        CurDir = ShellGetCurrentDir (NULL);\r
+      } else {\r
+        LoopVar1 = 0;\r
+        LoopVar2 = 0;\r
+        while (FileName[LoopVar1] != 0) {\r
+          if (FileName[LoopVar1] == L':') {\r
+            break;\r
+          }\r
 \r
-    if (CurDir != NULL) {\r
-      for (LoopVar1 = 0; LoopVar1 < StrLen (CurDir) && CurDir[LoopVar1] != ':'; LoopVar1++);\r
+          FSMapping[LoopVar2++] = FileName[LoopVar1];\r
 \r
-      CurDir[LoopVar1]   = 0;\r
-      DevicePath  = (EFI_DEVICE_PATH_PROTOCOL *) ShellGetMap (CurDir);\r
-      FreePool (CurDir);\r
-    } else {\r
-      return EFI_LOAD_ERROR;\r
-    }\r
+          LoopVar1++;\r
+        }\r
 \r
-    Status = LibDevicePathToInterface (\r
-              &gEfiSimpleFileSystemProtocolGuid,\r
-              DevicePath,\r
-              (VOID **) &Vol\r
-              );\r
-    if (EFI_ERROR (Status)) {\r
-      return EFI_LOAD_ERROR;\r
-    }\r
+        FSMapping[LoopVar2]  = 0;\r
+        CurDir        = ShellGetCurrentDir (FSMapping);\r
+      }\r
 \r
-    Status = Vol->OpenVolume (Vol, &RootFs);\r
-    if (EFI_ERROR (Status)) {\r
-      return EFI_LOAD_ERROR;\r
-    }\r
-    //\r
-    // Get volume information of file system\r
-    //\r
-    Size        = SIZE_OF_EFI_FILE_SYSTEM_INFO + 100;\r
-    VolumeInfo  = (EFI_FILE_SYSTEM_INFO *) AllocateZeroPool (Size);\r
-    Status      = RootFs->GetInfo (RootFs, &gEfiFileSystemInfoGuid, &Size, VolumeInfo);\r
-    if (EFI_ERROR (Status)) {\r
-      RootFs->Close (RootFs);\r
-      return EFI_LOAD_ERROR;\r
-    }\r
+      if (CurDir != NULL) {\r
+        for (LoopVar1 = 0; LoopVar1 < StrLen (CurDir) && CurDir[LoopVar1] != ':'; LoopVar1++);\r
 \r
-    if (VolumeInfo->ReadOnly) {\r
-      StatusBarSetStatusString (L"WARNING: Volume Read Only");\r
-    }\r
+        CurDir[LoopVar1]   = 0;\r
+        DevicePath  = (EFI_DEVICE_PATH_PROTOCOL *) ShellGetMap (CurDir);\r
+        FreePool (CurDir);\r
+      } else {\r
+        return EFI_LOAD_ERROR;\r
+      }\r
 \r
-    FreePool (VolumeInfo);\r
-    RootFs->Close (RootFs);\r
-  }\r
-//\r
-*/\r
+      Status = LibDevicePathToInterface (\r
+                &gEfiSimpleFileSystemProtocolGuid,\r
+                DevicePath,\r
+                (VOID **) &Vol\r
+                );\r
+      if (EFI_ERROR (Status)) {\r
+        return EFI_LOAD_ERROR;\r
+      }\r
+\r
+      Status = Vol->OpenVolume (Vol, &RootFs);\r
+      if (EFI_ERROR (Status)) {\r
+        return EFI_LOAD_ERROR;\r
+      }\r
+      //\r
+      // Get volume information of file system\r
+      //\r
+      Size        = SIZE_OF_EFI_FILE_SYSTEM_INFO + 100;\r
+      VolumeInfo  = (EFI_FILE_SYSTEM_INFO *) AllocateZeroPool (Size);\r
+      Status      = RootFs->GetInfo (RootFs, &gEfiFileSystemInfoGuid, &Size, VolumeInfo);\r
+      if (EFI_ERROR (Status)) {\r
+        RootFs->Close (RootFs);\r
+        return EFI_LOAD_ERROR;\r
+      }\r
+\r
+      if (VolumeInfo->ReadOnly) {\r
+        StatusBarSetStatusString (L"WARNING: Volume Read Only");\r
+      }\r
+\r
+      FreePool (VolumeInfo);\r
+      RootFs->Close (RootFs);\r
+    }\r
+  //\r
+  */\r
   //\r
   // has line\r
   //\r
@@ -1253,7 +1273,6 @@ Done:
   FileBufferOnlyLineNeedRefresh = FALSE;\r
   FileBufferMouseNeedRefresh    = TRUE;\r
 \r
-\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -1266,14 +1285,13 @@ 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
-  OUT UINT8           *Size\r
+  IN CONST EE_NEWLINE_TYPE  Type,\r
+  OUT CHAR8                 *Buffer,\r
+  OUT UINT8                 *Size\r
   )\r
 {\r
-  UINT8 NewLineSize;\r
+  UINT8  NewLineSize;\r
 \r
   //\r
   // give new line buffer,\r
@@ -1284,10 +1302,11 @@ GetNewLine (
   //\r
   // not legal new line type\r
   //\r
-  if (Type != NewLineTypeLineFeed && Type != NewLineTypeCarriageReturn && Type != NewLineTypeCarriageReturnLineFeed && Type != NewLineTypeLineFeedCarriageReturn) {\r
+  if ((Type != NewLineTypeLineFeed) && (Type != NewLineTypeCarriageReturn) && (Type != NewLineTypeCarriageReturnLineFeed) && (Type != NewLineTypeLineFeedCarriageReturn)) {\r
     *Size = 0;\r
-    return ;\r
+    return;\r
   }\r
+\r
   //\r
   // use_cr: give 0x0d\r
   //\r
@@ -1302,8 +1321,9 @@ GetNewLine (
     }\r
 \r
     *Size = NewLineSize;\r
-    return ;\r
+    return;\r
   }\r
+\r
   //\r
   // use_lf: give 0x0a\r
   //\r
@@ -1318,17 +1338,18 @@ GetNewLine (
     }\r
 \r
     *Size = NewLineSize;\r
-    return ;\r
+    return;\r
   }\r
+\r
   //\r
   // use_crlf: give 0x0d 0x0a\r
   //\r
   if (Type == NewLineTypeCarriageReturnLineFeed) {\r
     if (MainEditor.FileBuffer->FileType == FileTypeUnicode) {\r
-      Buffer[0]   = 0x0d;\r
-      Buffer[1]   = 0;\r
-      Buffer[2]   = 0x0a;\r
-      Buffer[3]   = 0;\r
+      Buffer[0] = 0x0d;\r
+      Buffer[1] = 0;\r
+      Buffer[2] = 0x0a;\r
+      Buffer[3] = 0;\r
 \r
       NewLineSize = 4;\r
     } else {\r
@@ -1338,17 +1359,18 @@ GetNewLine (
     }\r
 \r
     *Size = NewLineSize;\r
-    return ;\r
+    return;\r
   }\r
+\r
   //\r
   // use_lfcr: give 0x0a 0x0d\r
   //\r
   if (Type == NewLineTypeLineFeedCarriageReturn) {\r
     if (MainEditor.FileBuffer->FileType == FileTypeUnicode) {\r
-      Buffer[0]   = 0x0a;\r
-      Buffer[1]   = 0;\r
-      Buffer[2]   = 0x0d;\r
-      Buffer[3]   = 0;\r
+      Buffer[0] = 0x0a;\r
+      Buffer[1] = 0;\r
+      Buffer[2] = 0x0d;\r
+      Buffer[3] = 0;\r
 \r
       NewLineSize = 4;\r
     } else {\r
@@ -1358,35 +1380,33 @@ GetNewLine (
     }\r
 \r
     *Size = NewLineSize;\r
-    return ;\r
+    return;\r
   }\r
-\r
 }\r
 \r
 /**\r
   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
+  OUT CHAR8        *AStr\r
   )\r
 {\r
-  UINTN Index;\r
+  UINTN  Index;\r
 \r
   //\r
   // just buffer copy, not character copy\r
   //\r
   for (Index = 0; Index < Length; Index++) {\r
-    *AStr++ = (CHAR8) *UStr++;\r
+    *AStr++ = (CHAR8)*UStr++;\r
   }\r
 \r
   return Index;\r
@@ -1398,42 +1418,41 @@ 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
+  IN CONST CHAR16  *FileName\r
   )\r
 {\r
-  SHELL_FILE_HANDLE FileHandle;\r
-  LIST_ENTRY        *Link;\r
-  EFI_EDITOR_LINE   *Line;\r
-  CHAR16            *Str;\r
+  SHELL_FILE_HANDLE  FileHandle;\r
+  LIST_ENTRY         *Link;\r
+  EFI_EDITOR_LINE    *Line;\r
+  CHAR16             *Str;\r
 \r
-  EFI_STATUS        Status;\r
-  UINTN             Length;\r
-  UINTN             NumLines;\r
-  CHAR8             NewLineBuffer[4];\r
-  UINT8             NewLineSize;\r
+  EFI_STATUS  Status;\r
+  UINTN       Length;\r
+  UINTN       NumLines;\r
+  CHAR8       NewLineBuffer[4];\r
+  UINT8       NewLineSize;\r
 \r
-  EFI_FILE_INFO     *Info;\r
+  EFI_FILE_INFO  *Info;\r
 \r
-  UINT64            Attribute;\r
+  UINT64  Attribute;\r
 \r
-  EE_NEWLINE_TYPE   Type;\r
+  EE_NEWLINE_TYPE  Type;\r
 \r
-  UINTN             TotalSize;\r
+  UINTN  TotalSize;\r
   //\r
   // 2M\r
   //\r
-  CHAR8             *Cache;\r
-  UINTN             LeftSize;\r
-  UINTN             Size;\r
-  CHAR8             *Ptr;\r
+  CHAR8  *Cache;\r
+  UINTN  LeftSize;\r
+  UINTN  Size;\r
+  CHAR8  *Ptr;\r
 \r
-  Length    = 0;\r
+  Length = 0;\r
   //\r
   // 2M\r
   //\r
@@ -1441,12 +1460,10 @@ FileBufferSave (
 \r
   Attribute = 0;\r
 \r
-\r
-\r
   //\r
   // if is the old file\r
   //\r
-  if (FileBuffer.FileName != NULL && StrCmp (FileName, FileBuffer.FileName) == 0) {\r
+  if ((FileBuffer.FileName != NULL) && (StrCmp (FileName, FileBuffer.FileName) == 0)) {\r
     //\r
     // file has not been modified\r
     //\r
@@ -1466,29 +1483,29 @@ FileBufferSave (
   Status = ShellOpenFileByName (FileName, &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0);\r
 \r
   if (!EFI_ERROR (Status)) {\r
-    Info = ShellGetFileInfo(FileHandle);\r
+    Info = ShellGetFileInfo (FileHandle);\r
 \r
-    if (Info != NULL && Info->Attribute & EFI_FILE_DIRECTORY) {\r
+    if ((Info != NULL) && Info->Attribute & EFI_FILE_DIRECTORY) {\r
       StatusBarSetStatusString (L"Directory Can Not Be Saved");\r
-      ShellCloseFile(FileHandle);\r
-      FreePool(Info);\r
+      ShellCloseFile (&FileHandle);\r
+      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
+      FreePool (Info);\r
     }\r
 \r
     //\r
     // if file exits, so delete it\r
     //\r
     Status = ShellDeleteFile (&FileHandle);\r
-    if (EFI_ERROR (Status) || Status == EFI_WARN_DELETE_FAILURE) {\r
+    if (EFI_ERROR (Status) || (Status == EFI_WARN_DELETE_FAILURE)) {\r
       StatusBarSetStatusString (L"Write File Failed");\r
       return EFI_LOAD_ERROR;\r
     }\r
- }\r
 }\r
 \r
   Status = ShellOpenFileByName (FileName, &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, Attribute);\r
 \r
@@ -1501,8 +1518,8 @@ FileBufferSave (
   // if file is Unicode file, write Unicode header to it.\r
   //\r
   if (FileBuffer.FileType == FileTypeUnicode) {\r
-    Length  = 2;\r
-    Status  = ShellWriteFile (FileHandle, &Length, (VOID*)&gUnicodeFileTag);\r
+    Length = 2;\r
+    Status = ShellWriteFile (FileHandle, &Length, (VOID *)&gUnicodeFileTag);\r
     if (EFI_ERROR (Status)) {\r
       ShellDeleteFile (&FileHandle);\r
       return EFI_LOAD_ERROR;\r
@@ -1518,11 +1535,11 @@ FileBufferSave (
   //\r
   // write all the lines back to disk\r
   //\r
-  NumLines  = 0;\r
-  Type      = NewLineTypeCarriageReturnLineFeed;\r
+  NumLines = 0;\r
+  Type     = NewLineTypeCarriageReturnLineFeed;\r
 \r
-  Ptr       = Cache;\r
-  LeftSize  = TotalSize;\r
+  Ptr      = Cache;\r
+  LeftSize = TotalSize;\r
 \r
   for (Link = FileBuffer.ListHead->ForwardLink; Link != FileBuffer.ListHead; Link = Link->ForwardLink) {\r
     Line = CR (Link, EFI_EDITOR_LINE, Link, LINE_LIST_SIGNATURE);\r
@@ -1530,16 +1547,18 @@ FileBufferSave (
     if (Line->Type != NewLineTypeDefault) {\r
       Type = Line->Type;\r
     }\r
+\r
     //\r
     // newline character is at most 4 bytes ( two Unicode characters )\r
     //\r
     Length = 4;\r
-    if (Line->Buffer != NULL && Line->Size != 0) {\r
+    if ((Line->Buffer != NULL) && (Line->Size != 0)) {\r
       if (FileBuffer.FileType == FileTypeAscii) {\r
         Length += Line->Size;\r
       } else {\r
         Length += (Line->Size * 2);\r
       }\r
+\r
       //\r
       // end if FileTypeAscii\r
       //\r
@@ -1549,32 +1568,34 @@ FileBufferSave (
     // no cache room left, so write cache to disk\r
     //\r
     if (LeftSize < Length) {\r
-      Size    = TotalSize - LeftSize;\r
-      Status  = ShellWriteFile (FileHandle, &Size, Cache);\r
+      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
-      Ptr       = Cache;\r
-      LeftSize  = TotalSize;\r
+\r
+      Ptr      = Cache;\r
+      LeftSize = TotalSize;\r
     }\r
 \r
-    if (Line->Buffer != NULL && Line->Size != 0) {\r
+    if ((Line->Buffer != NULL) && (Line->Size != 0)) {\r
       if (FileBuffer.FileType == FileTypeAscii) {\r
         UnicodeToAscii (Line->Buffer, Line->Size, Ptr);\r
         Length = Line->Size;\r
       } else {\r
         Length = (Line->Size * 2);\r
-        CopyMem (Ptr, (CHAR8 *) Line->Buffer, Length);\r
+        CopyMem (Ptr, (CHAR8 *)Line->Buffer, Length);\r
       }\r
+\r
       //\r
       // end if FileTypeAscii\r
       //\r
-      Ptr += Length;\r
+      Ptr      += Length;\r
       LeftSize -= Length;\r
-\r
     }\r
+\r
     //\r
     // end of if Line -> Buffer != NULL && Line -> Size != 0\r
     //\r
@@ -1582,9 +1603,9 @@ FileBufferSave (
     //\r
     if (Link->ForwardLink != FileBuffer.ListHead) {\r
       GetNewLine (Type, NewLineBuffer, &NewLineSize);\r
-      CopyMem (Ptr, (CHAR8 *) NewLineBuffer, NewLineSize);\r
+      CopyMem (Ptr, (CHAR8 *)NewLineBuffer, NewLineSize);\r
 \r
-      Ptr += NewLineSize;\r
+      Ptr      += NewLineSize;\r
       LeftSize -= NewLineSize;\r
     }\r
 \r
@@ -1592,8 +1613,8 @@ FileBufferSave (
   }\r
 \r
   if (TotalSize != LeftSize) {\r
-    Size    = TotalSize - LeftSize;\r
-    Status  = ShellWriteFile (FileHandle, &Size, Cache);\r
+    Size   = TotalSize - LeftSize;\r
+    Status = ShellWriteFile (FileHandle, &Size, Cache);\r
     if (EFI_ERROR (Status)) {\r
       ShellDeleteFile (&FileHandle);\r
       FreePool (Cache);\r
@@ -1603,14 +1624,14 @@ FileBufferSave (
 \r
   FreePool (Cache);\r
 \r
-  ShellCloseFile(&FileHandle);\r
+  ShellCloseFile (&FileHandle);\r
 \r
   FileBuffer.FileModified = FALSE;\r
 \r
   //\r
   // set status string\r
   //\r
-  Str = CatSPrint (NULL, L"%d Lines Wrote", NumLines);\r
+  Str = CatSPrint (NULL, L"%d Lines Written", NumLines);\r
   if (Str == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
@@ -1621,7 +1642,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,19 +1663,18 @@ FileBufferSave (
   @retval EFI_SUCCESS     The operation was successful.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 FileBufferScrollLeft (\r
   VOID\r
   )\r
 {\r
-  EFI_EDITOR_LINE *Line;\r
-  UINTN           FRow;\r
-  UINTN           FCol;\r
+  EFI_EDITOR_LINE  *Line;\r
+  UINTN            FRow;\r
+  UINTN            FCol;\r
 \r
-  Line  = FileBuffer.CurrentLine;\r
+  Line = FileBuffer.CurrentLine;\r
 \r
-  FRow  = FileBuffer.FilePosition.Row;\r
-  FCol  = FileBuffer.FilePosition.Column;\r
+  FRow = FileBuffer.FilePosition.Row;\r
+  FCol = FileBuffer.FilePosition.Column;\r
 \r
   //\r
   // if already at start of this line, so move to the end of previous line\r
@@ -1665,8 +1685,8 @@ FileBufferScrollLeft (
     //\r
     if (Line->Link.BackLink != FileBuffer.ListHead) {\r
       FRow--;\r
-      Line  = CR (Line->Link.BackLink, EFI_EDITOR_LINE, Link, LINE_LIST_SIGNATURE);\r
-      FCol  = Line->Size + 1;\r
+      Line = CR (Line->Link.BackLink, EFI_EDITOR_LINE, Link, LINE_LIST_SIGNATURE);\r
+      FCol = Line->Size + 1;\r
     } else {\r
       return EFI_SUCCESS;\r
     }\r
@@ -1685,17 +1705,16 @@ 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
+  IN  OUT EFI_EDITOR_LINE  *Line,\r
+  IN      UINTN            Pos\r
   )\r
 {\r
-  UINTN Index;\r
+  UINTN  Index;\r
 \r
   //\r
   // move the latter characters front\r
@@ -1710,22 +1729,21 @@ 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
+  IN  OUT EFI_EDITOR_LINE  *Dest,\r
+  IN      EFI_EDITOR_LINE  *Src\r
   )\r
 {\r
   CHAR16  *Str;\r
   UINTN   Size;\r
 \r
-  Size                = Dest->Size;\r
+  Size = Dest->Size;\r
 \r
-  Dest->Buffer[Size]  = 0;\r
+  Dest->Buffer[Size] = 0;\r
 \r
   //\r
   // concatenate the two strings\r
@@ -1733,7 +1751,7 @@ LineCat (
   Str = CatSPrint (NULL, L"%s%s", Dest->Buffer, Src->Buffer);\r
   if (Str == NULL) {\r
     Dest->Buffer = NULL;\r
-    return ;\r
+    return;\r
   }\r
 \r
   Dest->Size      = Size + Src->Size;\r
@@ -1755,19 +1773,18 @@ LineCat (
   @retval EFI_OUT_OF_RESOURCES  A memory allocation failed.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 FileBufferDoBackspace (\r
   VOID\r
   )\r
 {\r
-  EFI_EDITOR_LINE *Line;\r
-  EFI_EDITOR_LINE *End;\r
-  LIST_ENTRY  *Link;\r
-  UINTN           FileColumn;\r
+  EFI_EDITOR_LINE  *Line;\r
+  EFI_EDITOR_LINE  *End;\r
+  LIST_ENTRY       *Link;\r
+  UINTN            FileColumn;\r
 \r
-  FileColumn  = FileBuffer.FilePosition.Column;\r
+  FileColumn = FileBuffer.FilePosition.Column;\r
 \r
-  Line        = FileBuffer.CurrentLine;\r
+  Line = FileBuffer.CurrentLine;\r
 \r
   //\r
   // the first column\r
@@ -1782,9 +1799,9 @@ FileBufferDoBackspace (
 \r
     FileBufferScrollLeft ();\r
 \r
-    Line  = FileBuffer.CurrentLine;\r
-    Link  = Line->Link.ForwardLink;\r
-    End   = CR (Link, EFI_EDITOR_LINE, Link, LINE_LIST_SIGNATURE);\r
+    Line = FileBuffer.CurrentLine;\r
+    Link = Line->Link.ForwardLink;\r
+    End  = CR (Link, EFI_EDITOR_LINE, Link, LINE_LIST_SIGNATURE);\r
 \r
     //\r
     // concatenate this line with previous line\r
@@ -1793,6 +1810,7 @@ FileBufferDoBackspace (
     if (Line->Buffer == NULL) {\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
+\r
     //\r
     // remove End from line list\r
     //\r
@@ -1803,7 +1821,6 @@ FileBufferDoBackspace (
 \r
     FileBufferNeedRefresh         = TRUE;\r
     FileBufferOnlyLineNeedRefresh = FALSE;\r
-\r
   } else {\r
     //\r
     // just delete the previous character\r
@@ -1827,35 +1844,34 @@ FileBufferDoBackspace (
   @retval EFI_OUT_OF_RESOURCES  A memory allocation failed.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 FileBufferDoReturn (\r
   VOID\r
   )\r
 {\r
-  EFI_EDITOR_LINE *Line;\r
-  EFI_EDITOR_LINE *NewLine;\r
-  UINTN           FileColumn;\r
-  UINTN           Index;\r
-  CHAR16          *Buffer;\r
-  UINTN           Row;\r
-  UINTN           Col;\r
+  EFI_EDITOR_LINE  *Line;\r
+  EFI_EDITOR_LINE  *NewLine;\r
+  UINTN            FileColumn;\r
+  UINTN            Index;\r
+  CHAR16           *Buffer;\r
+  UINTN            Row;\r
+  UINTN            Col;\r
 \r
   FileBufferNeedRefresh         = TRUE;\r
   FileBufferOnlyLineNeedRefresh = FALSE;\r
 \r
-  Line                          = FileBuffer.CurrentLine;\r
+  Line = FileBuffer.CurrentLine;\r
 \r
-  FileColumn                    = FileBuffer.FilePosition.Column;\r
+  FileColumn = FileBuffer.FilePosition.Column;\r
 \r
-  NewLine                       = AllocateZeroPool (sizeof (EFI_EDITOR_LINE));\r
+  NewLine = AllocateZeroPool (sizeof (EFI_EDITOR_LINE));\r
   if (NewLine == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  NewLine->Signature  = LINE_LIST_SIGNATURE;\r
-  NewLine->Size       = Line->Size - FileColumn + 1;\r
-  NewLine->TotalSize  = NewLine->Size;\r
-  NewLine->Buffer     = CatSPrint (NULL, L"\0");\r
+  NewLine->Signature = LINE_LIST_SIGNATURE;\r
+  NewLine->Size      = Line->Size - FileColumn + 1;\r
+  NewLine->TotalSize = NewLine->Size;\r
+  NewLine->Buffer    = CatSPrint (NULL, L"\0");\r
   if (NewLine->Buffer == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
@@ -1881,11 +1897,12 @@ FileBufferDoReturn (
       NewLine->Buffer[Index] = Line->Buffer[Index + FileColumn - 1];\r
     }\r
 \r
-    NewLine->Buffer[NewLine->Size]  = CHAR_NULL;\r
+    NewLine->Buffer[NewLine->Size] = CHAR_NULL;\r
 \r
-    Line->Buffer[FileColumn - 1]    = CHAR_NULL;\r
-    Line->Size                      = FileColumn - 1;\r
+    Line->Buffer[FileColumn - 1] = CHAR_NULL;\r
+    Line->Size                   = FileColumn - 1;\r
   }\r
+\r
   //\r
   // increase NumLines\r
   //\r
@@ -1894,10 +1911,10 @@ FileBufferDoReturn (
   //\r
   // insert it into the correct position of line list\r
   //\r
-  NewLine->Link.BackLink     = &(Line->Link);\r
-  NewLine->Link.ForwardLink     = Line->Link.ForwardLink;\r
+  NewLine->Link.BackLink           = &(Line->Link);\r
+  NewLine->Link.ForwardLink        = Line->Link.ForwardLink;\r
   Line->Link.ForwardLink->BackLink = &(NewLine->Link);\r
-  Line->Link.ForwardLink        = &(NewLine->Link);\r
+  Line->Link.ForwardLink           = &(NewLine->Link);\r
 \r
   //\r
   // move cursor to the start of next line\r
@@ -1918,24 +1935,23 @@ 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
 {\r
-  EFI_EDITOR_LINE *Line;\r
-  EFI_EDITOR_LINE *Next;\r
-  LIST_ENTRY  *Link;\r
-  UINTN           FileColumn;\r
+  EFI_EDITOR_LINE  *Line;\r
+  EFI_EDITOR_LINE  *Next;\r
+  LIST_ENTRY       *Link;\r
+  UINTN            FileColumn;\r
 \r
-  Line        = FileBuffer.CurrentLine;\r
-  FileColumn  = FileBuffer.FilePosition.Column;\r
+  Line       = FileBuffer.CurrentLine;\r
+  FileColumn = FileBuffer.FilePosition.Column;\r
 \r
   //\r
   // the last column\r
@@ -1947,12 +1963,13 @@ FileBufferDoDelete (
     if (Line->Link.ForwardLink == FileBuffer.ListHead) {\r
       return EFI_SUCCESS;\r
     }\r
+\r
     //\r
     // since last character,\r
     // so will add the next line to this line\r
     //\r
-    Link  = Line->Link.ForwardLink;\r
-    Next  = CR (Link, EFI_EDITOR_LINE, Link, LINE_LIST_SIGNATURE);\r
+    Link = Line->Link.ForwardLink;\r
+    Next = CR (Link, EFI_EDITOR_LINE, Link, LINE_LIST_SIGNATURE);\r
     LineCat (Line, Next);\r
     if (Line->Buffer == NULL) {\r
       return EFI_OUT_OF_RESOURCES;\r
@@ -1965,7 +1982,6 @@ FileBufferDoDelete (
 \r
     FileBufferNeedRefresh         = TRUE;\r
     FileBufferOnlyLineNeedRefresh = FALSE;\r
-\r
   } else {\r
     //\r
     // just delete current character\r
@@ -1987,22 +2003,21 @@ FileBufferDoDelete (
   @retval EFI_SUCCESS     The operation was successful.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 FileBufferScrollRight (\r
   VOID\r
   )\r
 {\r
-  EFI_EDITOR_LINE *Line;\r
-  UINTN           FRow;\r
-  UINTN           FCol;\r
+  EFI_EDITOR_LINE  *Line;\r
+  UINTN            FRow;\r
+  UINTN            FCol;\r
 \r
   Line = FileBuffer.CurrentLine;\r
   if (Line->Buffer == NULL) {\r
     return EFI_SUCCESS;\r
   }\r
 \r
-  FRow  = FileBuffer.FilePosition.Row;\r
-  FCol  = FileBuffer.FilePosition.Column;\r
+  FRow = FileBuffer.FilePosition.Row;\r
+  FCol = FileBuffer.FilePosition.Column;\r
 \r
   //\r
   // if already at end of this line, scroll it to the start of next line\r
@@ -2032,7 +2047,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 +2056,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
@@ -2055,7 +2069,7 @@ LineStrInsert (
 \r
   Index = (StrSize) * 2;\r
 \r
-  Str   = Line->Buffer;\r
+  Str = Line->Buffer;\r
 \r
   //\r
   // do not have free space\r
@@ -2068,6 +2082,7 @@ LineStrInsert (
 \r
     Line->TotalSize += 8;\r
   }\r
+\r
   //\r
   // move the later part of the string one character right\r
   //\r
@@ -2075,12 +2090,13 @@ LineStrInsert (
   for (Index = StrSize; Index > Pos; Index--) {\r
     TempStringPtr[Index] = TempStringPtr[Index - 1];\r
   }\r
+\r
   //\r
   // insert char into it.\r
   //\r
-  TempStringPtr[Index]      = Char;\r
+  TempStringPtr[Index] = Char;\r
 \r
-  Line->Buffer  = Str;\r
+  Line->Buffer = Str;\r
   Line->Size++;\r
 \r
   return StrSize + 1;\r
@@ -2094,13 +2110,12 @@ LineStrInsert (
   @retval EFI_SUCCESS           The input was succesful.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 FileBufferAddChar (\r
   IN  CHAR16  Char\r
   )\r
 {\r
-  EFI_EDITOR_LINE *Line;\r
-  UINTN           FilePos;\r
+  EFI_EDITOR_LINE  *Line;\r
+  UINTN            FilePos;\r
 \r
   Line = FileBuffer.CurrentLine;\r
 \r
@@ -2115,11 +2130,12 @@ FileBufferAddChar (
   // or replace the character.\r
   //\r
   FilePos = FileBuffer.FilePosition.Column - 1;\r
-  if (FileBuffer.ModeInsert || FilePos + 1 > Line->Size) {\r
+  if (FileBuffer.ModeInsert || (FilePos + 1 > Line->Size)) {\r
     LineStrInsert (Line, Char, FilePos, Line->Size + 1);\r
   } else {\r
     Line->Buffer[FilePos] = Char;\r
   }\r
+\r
   //\r
   // move cursor to right\r
   //\r
@@ -2142,9 +2158,8 @@ FileBufferAddChar (
   @retval EFI_OUT_OF_RESOURCES  A memory allocation failed.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 FileBufferDoCharInput (\r
-  IN CONST CHAR16 Char\r
+  IN CONST CHAR16  Char\r
   )\r
 {\r
   EFI_STATUS  Status;\r
@@ -2152,36 +2167,35 @@ FileBufferDoCharInput (
   Status = EFI_SUCCESS;\r
 \r
   switch (Char) {\r
-  case CHAR_NULL:\r
-    break;\r
+    case CHAR_NULL:\r
+      break;\r
 \r
-  case CHAR_BACKSPACE:\r
-    Status = FileBufferDoBackspace ();\r
-    break;\r
+    case CHAR_BACKSPACE:\r
+      Status = FileBufferDoBackspace ();\r
+      break;\r
 \r
-  case CHAR_TAB:\r
-    //\r
-    // Tabs are ignored\r
-    //\r
-    break;\r
-\r
-  case CHAR_LINEFEED:\r
-  case CHAR_CARRIAGE_RETURN:\r
-    Status = FileBufferDoReturn ();\r
-    break;\r
+    case CHAR_TAB:\r
+      //\r
+      // Tabs are ignored\r
+      //\r
+      break;\r
 \r
-  default:\r
-    //\r
-    // DEAL WITH ASCII CHAR, filter out thing like ctrl+f\r
-    //\r
-    if (Char > 127 || Char < 32) {\r
-      Status = StatusBarSetStatusString (L"Unknown Command");\r
-    } else {\r
-      Status = FileBufferAddChar (Char);\r
-    }\r
+    case CHAR_LINEFEED:\r
+    case CHAR_CARRIAGE_RETURN:\r
+      Status = FileBufferDoReturn ();\r
+      break;\r
 \r
-    break;\r
+    default:\r
+      //\r
+      // DEAL WITH ASCII CHAR, filter out thing like ctrl+f\r
+      //\r
+      if ((Char > 127) || (Char < 32)) {\r
+        Status = StatusBarSetStatusString (L"Unknown Command");\r
+      } else {\r
+        Status = FileBufferAddChar (Char);\r
+      }\r
 \r
+      break;\r
   }\r
 \r
   return Status;\r
@@ -2193,22 +2207,21 @@ FileBufferDoCharInput (
   @retval EFI_SUCCESS     The operation was successful.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 FileBufferScrollDown (\r
   VOID\r
   )\r
 {\r
-  EFI_EDITOR_LINE *Line;\r
-  UINTN           FRow;\r
-  UINTN           FCol;\r
+  EFI_EDITOR_LINE  *Line;\r
+  UINTN            FRow;\r
+  UINTN            FCol;\r
 \r
   Line = FileBuffer.CurrentLine;\r
   if (Line->Buffer == NULL) {\r
     return EFI_SUCCESS;\r
   }\r
 \r
-  FRow  = FileBuffer.FilePosition.Row;\r
-  FCol  = FileBuffer.FilePosition.Column;\r
+  FRow = FileBuffer.FilePosition.Row;\r
+  FCol = FileBuffer.FilePosition.Column;\r
 \r
   //\r
   // has next line\r
@@ -2223,7 +2236,6 @@ FileBufferScrollDown (
     if (FCol > Line->Size) {\r
       FCol = Line->Size + 1;\r
     }\r
-\r
   } else {\r
     return EFI_SUCCESS;\r
   }\r
@@ -2239,19 +2251,18 @@ FileBufferScrollDown (
   @retval EFI_SUCCESS     The operation was successful.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 FileBufferScrollUp (\r
   VOID\r
   )\r
 {\r
-  EFI_EDITOR_LINE *Line;\r
-  UINTN           FRow;\r
-  UINTN           FCol;\r
+  EFI_EDITOR_LINE  *Line;\r
+  UINTN            FRow;\r
+  UINTN            FCol;\r
 \r
-  Line  = FileBuffer.CurrentLine;\r
+  Line = FileBuffer.CurrentLine;\r
 \r
-  FRow  = FileBuffer.FilePosition.Row;\r
-  FCol  = FileBuffer.FilePosition.Column;\r
+  FRow = FileBuffer.FilePosition.Row;\r
+  FCol = FileBuffer.FilePosition.Column;\r
 \r
   //\r
   // has previous line\r
@@ -2266,7 +2277,6 @@ FileBufferScrollUp (
     if (FCol > Line->Size) {\r
       FCol = Line->Size + 1;\r
     }\r
-\r
   } else {\r
     return EFI_SUCCESS;\r
   }\r
@@ -2282,32 +2292,32 @@ FileBufferScrollUp (
   @retval EFI_SUCCESS     The operation wa successful.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 FileBufferPageDown (\r
   VOID\r
   )\r
 {\r
-  EFI_EDITOR_LINE *Line;\r
-  UINTN           FRow;\r
-  UINTN           FCol;\r
-  UINTN           Gap;\r
+  EFI_EDITOR_LINE  *Line;\r
+  UINTN            FRow;\r
+  UINTN            FCol;\r
+  UINTN            Gap;\r
 \r
-  Line  = FileBuffer.CurrentLine;\r
+  Line = FileBuffer.CurrentLine;\r
 \r
-  FRow  = FileBuffer.FilePosition.Row;\r
-  FCol  = FileBuffer.FilePosition.Column;\r
+  FRow = FileBuffer.FilePosition.Row;\r
+  FCol = FileBuffer.FilePosition.Column;\r
 \r
   //\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
     //\r
     Gap = FileBuffer.NumLines - FRow;\r
   }\r
+\r
   //\r
   // get correct line\r
   //\r
@@ -2316,7 +2326,7 @@ FileBufferPageDown (
   //\r
   // if that line, is not that long, so move to the end of that line\r
   //\r
-  if (Line != NULL && FCol > Line->Size) {\r
+  if ((Line != NULL) && (FCol > Line->Size)) {\r
     FCol = Line->Size + 1;\r
   }\r
 \r
@@ -2333,27 +2343,26 @@ FileBufferPageDown (
   @retval EFI_SUCCESS     The operation was successful.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 FileBufferPageUp (\r
   VOID\r
   )\r
 {\r
-  EFI_EDITOR_LINE *Line;\r
-  UINTN           FRow;\r
-  UINTN           FCol;\r
-  UINTN           Gap;\r
-  INTN            Retreat;\r
+  EFI_EDITOR_LINE  *Line;\r
+  UINTN            FRow;\r
+  UINTN            FCol;\r
+  UINTN            Gap;\r
+  INTN             Retreat;\r
 \r
-  Line  = FileBuffer.CurrentLine;\r
+  Line = FileBuffer.CurrentLine;\r
 \r
-  FRow  = FileBuffer.FilePosition.Row;\r
-  FCol  = FileBuffer.FilePosition.Column;\r
+  FRow = FileBuffer.FilePosition.Row;\r
+  FCol = FileBuffer.FilePosition.Column;\r
 \r
   //\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
@@ -2372,7 +2381,7 @@ FileBufferPageUp (
   //\r
   // if that line is not that long, so move to the end of that line\r
   //\r
-  if (Line != NULL && FCol > Line->Size) {\r
+  if ((Line != NULL) && (FCol > Line->Size)) {\r
     FCol = Line->Size + 1;\r
   }\r
 \r
@@ -2389,18 +2398,17 @@ FileBufferPageUp (
   @retval EFI_SUCCESS       The operation was successful.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 FileBufferEnd (\r
   VOID\r
   )\r
 {\r
-  EFI_EDITOR_LINE *Line;\r
-  UINTN           FRow;\r
-  UINTN           FCol;\r
+  EFI_EDITOR_LINE  *Line;\r
+  UINTN            FRow;\r
+  UINTN            FCol;\r
 \r
-  Line  = FileBuffer.CurrentLine;\r
+  Line = FileBuffer.CurrentLine;\r
 \r
-  FRow  = FileBuffer.FilePosition.Row;\r
+  FRow = FileBuffer.FilePosition.Row;\r
 \r
   //\r
   // goto the last column of the line\r
@@ -2412,7 +2420,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,9 +2435,8 @@ 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
+  IN CONST EFI_INPUT_KEY  *Key\r
   )\r
 {\r
   EFI_STATUS  Status;\r
@@ -2437,98 +2444,98 @@ FileBufferHandleInput (
   Status = EFI_SUCCESS;\r
 \r
   switch (Key->ScanCode) {\r
-  //\r
-  // ordinary key input\r
-  //\r
-  case SCAN_NULL:\r
-    if (!FileBuffer.ReadOnly) {\r
-      Status = FileBufferDoCharInput (Key->UnicodeChar);\r
-    } else {\r
-      Status = StatusBarSetStatusString (L"Read Only File Can Not Be Modified");\r
-    }\r
+    //\r
+    // ordinary key input\r
+    //\r
+    case SCAN_NULL:\r
+      if (!FileBuffer.ReadOnly) {\r
+        Status = FileBufferDoCharInput (Key->UnicodeChar);\r
+      } else {\r
+        Status = StatusBarSetStatusString (L"Read Only File Can Not Be Modified");\r
+      }\r
 \r
-    break;\r
+      break;\r
 \r
-  //\r
-  // up arrow\r
-  //\r
-  case SCAN_UP:\r
-    Status = FileBufferScrollUp ();\r
-    break;\r
+    //\r
+    // up arrow\r
+    //\r
+    case SCAN_UP:\r
+      Status = FileBufferScrollUp ();\r
+      break;\r
 \r
-  //\r
-  // down arrow\r
-  //\r
-  case SCAN_DOWN:\r
-    Status = FileBufferScrollDown ();\r
-    break;\r
+    //\r
+    // down arrow\r
+    //\r
+    case SCAN_DOWN:\r
+      Status = FileBufferScrollDown ();\r
+      break;\r
 \r
-  //\r
-  // right arrow\r
-  //\r
-  case SCAN_RIGHT:\r
-    Status = FileBufferScrollRight ();\r
-    break;\r
+    //\r
+    // right arrow\r
+    //\r
+    case SCAN_RIGHT:\r
+      Status = FileBufferScrollRight ();\r
+      break;\r
 \r
-  //\r
-  // left arrow\r
-  //\r
-  case SCAN_LEFT:\r
-    Status = FileBufferScrollLeft ();\r
-    break;\r
+    //\r
+    // left arrow\r
+    //\r
+    case SCAN_LEFT:\r
+      Status = FileBufferScrollLeft ();\r
+      break;\r
 \r
-  //\r
-  // page up\r
-  //\r
-  case SCAN_PAGE_UP:\r
-    Status = FileBufferPageUp ();\r
-    break;\r
+    //\r
+    // page up\r
+    //\r
+    case SCAN_PAGE_UP:\r
+      Status = FileBufferPageUp ();\r
+      break;\r
 \r
-  //\r
-  // page down\r
-  //\r
-  case SCAN_PAGE_DOWN:\r
-    Status = FileBufferPageDown ();\r
-    break;\r
+    //\r
+    // page down\r
+    //\r
+    case SCAN_PAGE_DOWN:\r
+      Status = FileBufferPageDown ();\r
+      break;\r
 \r
-  //\r
-  // delete\r
-  //\r
-  case SCAN_DELETE:\r
-    if (!FileBuffer.ReadOnly) {\r
-      Status = FileBufferDoDelete ();\r
-    } else {\r
-      Status = StatusBarSetStatusString (L"Read Only File Can Not Be Modified");\r
-    }\r
+    //\r
+    // delete\r
+    //\r
+    case SCAN_DELETE:\r
+      if (!FileBuffer.ReadOnly) {\r
+        Status = FileBufferDoDelete ();\r
+      } else {\r
+        Status = StatusBarSetStatusString (L"Read Only File Can Not Be Modified");\r
+      }\r
 \r
-    break;\r
+      break;\r
 \r
-  //\r
-  // home\r
-  //\r
-  case SCAN_HOME:\r
-    FileBufferMovePosition (FileBuffer.FilePosition.Row, 1);\r
-    Status = EFI_SUCCESS;\r
-    break;\r
+    //\r
+    // home\r
+    //\r
+    case SCAN_HOME:\r
+      FileBufferMovePosition (FileBuffer.FilePosition.Row, 1);\r
+      Status = EFI_SUCCESS;\r
+      break;\r
 \r
-  //\r
-  // end\r
-  //\r
-  case SCAN_END:\r
-    Status = FileBufferEnd ();\r
-    break;\r
+    //\r
+    // end\r
+    //\r
+    case SCAN_END:\r
+      Status = FileBufferEnd ();\r
+      break;\r
 \r
-  //\r
-  // insert\r
-  //\r
-  case SCAN_INSERT:\r
-    FileBuffer.ModeInsert = (BOOLEAN)!FileBuffer.ModeInsert;\r
-    Status = EFI_SUCCESS;\r
-    break;\r
+    //\r
+    // insert\r
+    //\r
+    case SCAN_INSERT:\r
+      FileBuffer.ModeInsert = (BOOLEAN) !FileBuffer.ModeInsert;\r
+      Status                = EFI_SUCCESS;\r
+      break;\r
 \r
-  default:\r
-    Status = StatusBarSetStatusString (L"Unknown Command");\r
-    break;\r
+    default:\r
+      Status = StatusBarSetStatusString (L"Unknown Command");\r
+      break;\r
   }\r
 \r
   return Status;\r
@@ -2543,9 +2550,8 @@ FileBufferHandleInput (
   @retval FALSE   It is not above the current screen.\r
 **/\r
 BOOLEAN\r
-EFIAPI\r
 AboveCurrentScreen (\r
-  IN UINTN FileRow\r
+  IN UINTN  FileRow\r
   )\r
 {\r
   //\r
@@ -2567,15 +2573,14 @@ AboveCurrentScreen (
   @retval FALSE     It is not under the current screen.\r
 **/\r
 BOOLEAN\r
-EFIAPI\r
 UnderCurrentScreen (\r
-  IN UINTN FileRow\r
+  IN UINTN  FileRow\r
   )\r
 {\r
   //\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,9 +2596,8 @@ UnderCurrentScreen (
   @retval FALSE   It is not to the left.\r
 **/\r
 BOOLEAN\r
-EFIAPI\r
 LeftCurrentScreen (\r
-  IN UINTN FileCol\r
+  IN UINTN  FileCol\r
   )\r
 {\r
   //\r
@@ -2615,9 +2619,8 @@ LeftCurrentScreen (
   @retval FALSE   It is not to the right.\r
 **/\r
 BOOLEAN\r
-EFIAPI\r
 RightCurrentScreen (\r
-  IN UINTN FileCol\r
+  IN UINTN  FileCol\r
   )\r
 {\r
   //\r
@@ -2632,28 +2635,27 @@ 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
 \r
-  @retval NULL An error occured.\r
+  @retval NULL An error occurred.\r
   @return The line after advance/retreat.\r
 **/\r
 EFI_EDITOR_LINE *\r
-EFIAPI\r
 MoveCurrentLine (\r
-  IN  INTN Count\r
+  IN  INTN  Count\r
   )\r
 {\r
-  EFI_EDITOR_LINE *Line;\r
-  UINTN           AbsCount;\r
+  EFI_EDITOR_LINE  *Line;\r
+  UINTN            AbsCount;\r
 \r
   if (Count <= 0) {\r
-    AbsCount  = (UINTN)ABS(Count);\r
-    Line      = InternalEditorMiscLineRetreat (AbsCount,MainEditor.FileBuffer->CurrentLine,MainEditor.FileBuffer->ListHead);\r
+    AbsCount = (UINTN)ABS (Count);\r
+    Line     = InternalEditorMiscLineRetreat (AbsCount, MainEditor.FileBuffer->CurrentLine, MainEditor.FileBuffer->ListHead);\r
   } else {\r
-    Line = InternalEditorMiscLineAdvance ((UINTN)Count,MainEditor.FileBuffer->CurrentLine,MainEditor.FileBuffer->ListHead);\r
+    Line = InternalEditorMiscLineAdvance ((UINTN)Count, MainEditor.FileBuffer->CurrentLine, MainEditor.FileBuffer->ListHead);\r
   }\r
 \r
   if (Line == NULL) {\r
@@ -2672,28 +2674,27 @@ 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
+  IN CONST UINTN  NewFilePosRow,\r
+  IN CONST UINTN  NewFilePosCol\r
   )\r
 {\r
-  INTN    RowGap;\r
-  INTN    ColGap;\r
-  UINTN   Abs;\r
-  BOOLEAN Above;\r
-  BOOLEAN Under;\r
-  BOOLEAN Right;\r
-  BOOLEAN Left;\r
+  INTN     RowGap;\r
+  INTN     ColGap;\r
+  UINTN    Abs;\r
+  BOOLEAN  Above;\r
+  BOOLEAN  Under;\r
+  BOOLEAN  Right;\r
+  BOOLEAN  Left;\r
 \r
   //\r
   // CALCULATE gap between current file position and new file position\r
   //\r
-  RowGap  = NewFilePosRow - FileBuffer.FilePosition.Row;\r
-  ColGap  = NewFilePosCol - FileBuffer.FilePosition.Column;\r
+  RowGap = NewFilePosRow - FileBuffer.FilePosition.Row;\r
+  ColGap = NewFilePosCol - FileBuffer.FilePosition.Column;\r
 \r
-  Under   = UnderCurrentScreen (NewFilePosRow);\r
-  Above   = AboveCurrentScreen (NewFilePosRow);\r
+  Under = UnderCurrentScreen (NewFilePosRow);\r
+  Above = AboveCurrentScreen (NewFilePosRow);\r
   //\r
   // if is below current screen\r
   //\r
@@ -2720,7 +2721,7 @@ FileBufferMovePosition (
       //\r
       FileBuffer.FilePosition.Row = NewFilePosRow;\r
       if (RowGap < 0) {\r
-        Abs = (UINTN)ABS(RowGap);\r
+        Abs                             = (UINTN)ABS (RowGap);\r
         FileBuffer.DisplayPosition.Row -= Abs;\r
       } else {\r
         FileBuffer.DisplayPosition.Row += RowGap;\r
@@ -2728,10 +2729,10 @@ FileBufferMovePosition (
     }\r
   }\r
 \r
-  FileBuffer.LowVisibleRange.Row  = FileBuffer.FilePosition.Row - (FileBuffer.DisplayPosition.Row - 2);\r
+  FileBuffer.LowVisibleRange.Row = FileBuffer.FilePosition.Row - (FileBuffer.DisplayPosition.Row - 2);\r
 \r
   Right = RightCurrentScreen (NewFilePosCol);\r
-  Left = LeftCurrentScreen (NewFilePosCol);\r
+  Left  = LeftCurrentScreen (NewFilePosCol);\r
 \r
   //\r
   // if right to current screen\r
@@ -2760,7 +2761,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
@@ -2774,13 +2775,12 @@ FileBufferMovePosition (
   // let CurrentLine point to correct line;\r
   //\r
   FileBuffer.CurrentLine = MoveCurrentLine (RowGap);\r
-\r
 }\r
 \r
 /**\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,15 +2788,16 @@ 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
+  OUT EFI_EDITOR_LINE  **CutLine\r
   )\r
 {\r
-  EFI_EDITOR_LINE *Line;\r
-  EFI_EDITOR_LINE *NewLine;\r
-  UINTN           Row;\r
-  UINTN           Col;\r
+  EFI_EDITOR_LINE  *Line;\r
+  EFI_EDITOR_LINE  *NewLine;\r
+  UINTN            Row;\r
+  UINTN            Col;\r
+\r
+  *CutLine = NULL;\r
 \r
   if (FileBuffer.ReadOnly) {\r
     StatusBarSetStatusString (L"Read Only File Can Not Be Modified");\r
@@ -2808,17 +2809,19 @@ FileBufferCutLine (
   //\r
   // if is the last dummy line, SO CAN not cut\r
   //\r
-  if (StrCmp (Line->Buffer, L"\0") == 0 && Line->Link.ForwardLink == FileBuffer.ListHead\r
-  //\r
-  // last line\r
-  //\r
-  ) {\r
+  if ((StrCmp (Line->Buffer, L"\0") == 0) && (Line->Link.ForwardLink == FileBuffer.ListHead)\r
+      //\r
+      // last line\r
+      //\r
+      )\r
+  {\r
     //\r
     // LAST LINE AND NOTHING ON THIS LINE, SO CUT NOTHING\r
     //\r
     StatusBarSetStatusString (L"Nothing to Cut");\r
     return EFI_NOT_FOUND;\r
   }\r
+\r
   //\r
   // if is the last line, so create a dummy line\r
   //\r
@@ -2840,11 +2843,11 @@ FileBufferCutLine (
   // move home\r
   //\r
   FileBuffer.CurrentLine = CR (\r
-                            FileBuffer.CurrentLine->Link.ForwardLink,\r
-                            EFI_EDITOR_LINE,\r
-                            Link,\r
-                            LINE_LIST_SIGNATURE\r
-                            );\r
+                             FileBuffer.CurrentLine->Link.ForwardLink,\r
+                             EFI_EDITOR_LINE,\r
+                             Link,\r
+                             LINE_LIST_SIGNATURE\r
+                             );\r
 \r
   RemoveEntryList (&Line->Link);\r
 \r
@@ -2856,7 +2859,7 @@ FileBufferCutLine (
   FileBufferNeedRefresh         = TRUE;\r
   FileBufferOnlyLineNeedRefresh = FALSE;\r
 \r
-  *CutLine                      = Line;\r
+  *CutLine = Line;\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -2868,15 +2871,14 @@ FileBufferCutLine (
   @retval EFI_OUT_OF_RESOURCES    A memory allocation failed.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 FileBufferPasteLine (\r
   VOID\r
   )\r
 {\r
-  EFI_EDITOR_LINE *Line;\r
-  EFI_EDITOR_LINE *NewLine;\r
-  UINTN           Row;\r
-  UINTN           Col;\r
+  EFI_EDITOR_LINE  *Line;\r
+  EFI_EDITOR_LINE  *NewLine;\r
+  UINTN            Row;\r
+  UINTN            Col;\r
 \r
   //\r
   // if nothing is on clip board\r
@@ -2885,6 +2887,7 @@ FileBufferPasteLine (
   if (MainEditor.CutLine == NULL) {\r
     return EFI_SUCCESS;\r
   }\r
+\r
   //\r
   // read only file can not be pasted on\r
   //\r
@@ -2897,22 +2900,23 @@ FileBufferPasteLine (
   if (NewLine == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
+\r
   //\r
   // insert it above current line\r
   //\r
-  Line                    = FileBuffer.CurrentLine;\r
-  NewLine->Link.BackLink     = Line->Link.BackLink;\r
-  NewLine->Link.ForwardLink     = &Line->Link;\r
+  Line                      = FileBuffer.CurrentLine;\r
+  NewLine->Link.BackLink    = Line->Link.BackLink;\r
+  NewLine->Link.ForwardLink = &Line->Link;\r
 \r
   Line->Link.BackLink->ForwardLink = &NewLine->Link;\r
-  Line->Link.BackLink        = &NewLine->Link;\r
+  Line->Link.BackLink              = &NewLine->Link;\r
 \r
   FileBuffer.NumLines++;\r
-  FileBuffer.CurrentLine  = NewLine;\r
+  FileBuffer.CurrentLine = NewLine;\r
 \r
-  FileBuffer.Lines        = CR (FileBuffer.ListHead->ForwardLink, EFI_EDITOR_LINE, Link, LINE_LIST_SIGNATURE);\r
+  FileBuffer.Lines = CR (FileBuffer.ListHead->ForwardLink, EFI_EDITOR_LINE, Link, LINE_LIST_SIGNATURE);\r
 \r
-  Col                     = 1;\r
+  Col = 1;\r
   //\r
   // move home\r
   //\r
@@ -2940,22 +2944,22 @@ 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
+  IN CONST UINTN   Offset\r
   )\r
 {\r
-  CHAR16          *Current;\r
-  UINTN           Position;\r
-  UINTN           Row;\r
-  UINTN           Column;\r
-  EFI_EDITOR_LINE *Line;\r
-  CHAR16          *CharPos;\r
-  LIST_ENTRY      *Link;\r
-  BOOLEAN         Found;\r
+  CHAR16           *Current;\r
+  UINTN            Position;\r
+  UINTN            Row;\r
+  UINTN            Column;\r
+  EFI_EDITOR_LINE  *Line;\r
+  CHAR16           *CharPos;\r
+  LIST_ENTRY       *Link;\r
+  BOOLEAN          Found;\r
 \r
-  Column = 0;\r
+  Column   = 0;\r
+  Position = 0;\r
 \r
   //\r
   // search if in current line\r
@@ -2969,35 +2973,37 @@ FileBufferSearch (
     Current = FileBuffer.CurrentLine->Buffer + FileBuffer.CurrentLine->Size;\r
   }\r
 \r
-  CharPos  =  StrStr (Current, Str);\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
-    Column  = (Position - 1) + FileBuffer.FilePosition.Column + Offset;\r
-    Row     = FileBuffer.FilePosition.Row;\r
-    Found   = TRUE;\r
+  if (Found) {\r
+    Column = (Position - 1) + FileBuffer.FilePosition.Column + Offset;\r
+    Row    = FileBuffer.FilePosition.Row;\r
   } else {\r
     //\r
     // not found so find through next lines\r
     //\r
-    Link  = FileBuffer.CurrentLine->Link.ForwardLink;\r
+    Link = FileBuffer.CurrentLine->Link.ForwardLink;\r
 \r
-    Row   = FileBuffer.FilePosition.Row + 1;\r
+    Row = FileBuffer.FilePosition.Row + 1;\r
     while (Link != FileBuffer.ListHead) {\r
-      Line      = CR (Link, EFI_EDITOR_LINE, Link, LINE_LIST_SIGNATURE);\r
-//      Position  = StrStr (Line->Buffer, Str);\r
-      CharPos  =  StrStr (Line->Buffer, Str);\r
+      Line = CR (Link, EFI_EDITOR_LINE, Link, LINE_LIST_SIGNATURE);\r
+      //      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,10 +3049,9 @@ 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
+  IN CONST CHAR16  *Replace,\r
+  IN CONST UINTN   SearchLen\r
   )\r
 {\r
   UINTN   ReplaceLen;\r
@@ -3056,9 +3061,9 @@ FileBufferReplace (
   UINTN   OldSize;\r
   UINTN   Gap;\r
 \r
-  ReplaceLen  = StrLen (Replace);\r
+  ReplaceLen = StrLen (Replace);\r
 \r
-  OldSize     = FileBuffer.CurrentLine->Size + 1;\r
+  OldSize = FileBuffer.CurrentLine->Size + 1;\r
   //\r
   // include CHAR_NULL\r
   //\r
@@ -3070,21 +3075,22 @@ FileBufferReplace (
     //\r
     if (FileBuffer.CurrentLine->TotalSize + 1 <= NewSize) {\r
       FileBuffer.CurrentLine->Buffer = ReallocatePool (\r
-                                        2 * OldSize,\r
-                                        2 * NewSize,\r
-                                        FileBuffer.CurrentLine->Buffer\r
-                                        );\r
+                                         2 * OldSize,\r
+                                         2 * NewSize,\r
+                                         FileBuffer.CurrentLine->Buffer\r
+                                         );\r
       FileBuffer.CurrentLine->TotalSize = NewSize - 1;\r
     }\r
 \r
     if (FileBuffer.CurrentLine->Buffer == NULL) {\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
+\r
     //\r
     // the end CHAR_NULL character;\r
     //\r
-    Buffer  = FileBuffer.CurrentLine->Buffer + (NewSize - 1);\r
-    Gap     = ReplaceLen - SearchLen;\r
+    Buffer = FileBuffer.CurrentLine->Buffer + (NewSize - 1);\r
+    Gap    = ReplaceLen - SearchLen;\r
 \r
     //\r
     // keep the latter part\r
@@ -3093,24 +3099,25 @@ FileBufferReplace (
       *Buffer = *(Buffer - Gap);\r
       Buffer--;\r
     }\r
+\r
     //\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
     }\r
 \r
     Buffer += ReplaceLen;\r
-    Gap = SearchLen - ReplaceLen;\r
+    Gap     = SearchLen - ReplaceLen;\r
 \r
     //\r
     // set replace into it\r
@@ -3122,7 +3129,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
@@ -3132,7 +3139,7 @@ FileBufferReplace (
 \r
   FileBufferOnlyLineNeedRefresh = TRUE;\r
 \r
-  FileBuffer.FileModified       = TRUE;\r
+  FileBuffer.FileModified = TRUE;\r
 \r
   MainTitleBarRefresh (MainEditor.FileBuffer->FileName, MainEditor.FileBuffer->FileType, MainEditor.FileBuffer->ReadOnly, MainEditor.FileBuffer->FileModified, MainEditor.ScreenSize.Column, MainEditor.ScreenSize.Row, 0, 0);\r
   FileBufferRestorePosition ();\r
@@ -3148,16 +3155,15 @@ 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
+  IN CONST INT32  TextX,\r
+  IN CONST INT32  TextY\r
   )\r
 {\r
-  UINTN CoordinateX;\r
-  UINTN CoordinateY;\r
-  UINTN AbsX;\r
-  UINTN AbsY;\r
+  UINTN  CoordinateX;\r
+  UINTN  CoordinateY;\r
+  UINTN  AbsX;\r
+  UINTN  AbsY;\r
 \r
   //\r
   // TextX and TextY is mouse movement data returned by mouse driver\r
@@ -3167,8 +3173,8 @@ FileBufferAdjustMousePosition (
   // get absolute value\r
   //\r
 \r
-  AbsX = ABS(TextX);\r
-  AbsY = ABS(TextY);\r
+  AbsX = ABS (TextX);\r
+  AbsY = ABS (TextY);\r
 \r
   CoordinateX = FileBuffer.MousePosition.Column;\r
   CoordinateY = FileBuffer.MousePosition.Row;\r
@@ -3192,29 +3198,30 @@ FileBufferAdjustMousePosition (
       CoordinateY = 0;\r
     }\r
   }\r
+\r
   //\r
   // check whether new mouse column position is beyond screen\r
   // if not, adjust it\r
   //\r
-  if (CoordinateX >= 1 && CoordinateX <= MainEditor.ScreenSize.Column) {\r
+  if ((CoordinateX >= 1) && (CoordinateX <= MainEditor.ScreenSize.Column)) {\r
     FileBuffer.MousePosition.Column = CoordinateX;\r
   } else if (CoordinateX < 1) {\r
     FileBuffer.MousePosition.Column = 1;\r
   } else if (CoordinateX > MainEditor.ScreenSize.Column) {\r
     FileBuffer.MousePosition.Column = MainEditor.ScreenSize.Column;\r
   }\r
+\r
   //\r
   // 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
 \r
 /**\r
@@ -3225,30 +3232,29 @@ 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
-  IN UINTN  Offset\r
+  IN CHAR16  *SearchStr,\r
+  IN CHAR16  *ReplaceStr,\r
+  IN UINTN   Offset\r
   )\r
 {\r
-  CHAR16          *Buffer;\r
-  UINTN           Position;\r
-  UINTN           Column;\r
-  UINTN           ReplaceLen;\r
-  UINTN           SearchLen;\r
-  UINTN           Index;\r
-  UINTN           NewSize;\r
-  UINTN           OldSize;\r
-  UINTN           Gap;\r
-  EFI_EDITOR_LINE *Line;\r
-  LIST_ENTRY      *Link;\r
-  CHAR16          *CharPos;\r
-\r
-  SearchLen   = StrLen (SearchStr);\r
-  ReplaceLen  = StrLen (ReplaceStr);\r
-\r
-  Column      = FileBuffer.FilePosition.Column + Offset - 1;\r
+  CHAR16           *Buffer;\r
+  UINTN            Position;\r
+  UINTN            Column;\r
+  UINTN            ReplaceLen;\r
+  UINTN            SearchLen;\r
+  UINTN            Index;\r
+  UINTN            NewSize;\r
+  UINTN            OldSize;\r
+  UINTN            Gap;\r
+  EFI_EDITOR_LINE  *Line;\r
+  LIST_ENTRY       *Link;\r
+  CHAR16           *CharPos;\r
+\r
+  SearchLen  = StrLen (SearchStr);\r
+  ReplaceLen = StrLen (ReplaceStr);\r
+\r
+  Column = FileBuffer.FilePosition.Column + Offset - 1;\r
 \r
   if (Column > FileBuffer.CurrentLine->Size) {\r
     Column = FileBuffer.CurrentLine->Size;\r
@@ -3257,8 +3263,8 @@ FileBufferReplaceAll (
   Link = &(FileBuffer.CurrentLine->Link);\r
 \r
   while (Link != FileBuffer.ListHead) {\r
-    Line      = CR (Link, EFI_EDITOR_LINE, Link, LINE_LIST_SIGNATURE);\r
-    CharPos  =  StrStr (Line->Buffer + Column, SearchStr);\r
+    Line    = CR (Link, EFI_EDITOR_LINE, Link, LINE_LIST_SIGNATURE);\r
+    CharPos =  StrStr (Line->Buffer + Column, SearchStr);\r
     if (CharPos != NULL) {\r
       Position = CharPos - Line->Buffer;// + Column;\r
       //\r
@@ -3276,21 +3282,22 @@ FileBufferReplaceAll (
         //\r
         if (Line->TotalSize + 1 <= NewSize) {\r
           Line->Buffer = ReallocatePool (\r
-                          2 * OldSize,\r
-                          2 * NewSize,\r
-                          Line->Buffer\r
-                          );\r
+                           2 * OldSize,\r
+                           2 * NewSize,\r
+                           Line->Buffer\r
+                           );\r
           Line->TotalSize = NewSize - 1;\r
         }\r
 \r
         if (Line->Buffer == NULL) {\r
           return EFI_OUT_OF_RESOURCES;\r
         }\r
+\r
         //\r
         // the end CHAR_NULL character;\r
         //\r
-        Buffer  = Line->Buffer + (NewSize - 1);\r
-        Gap     = ReplaceLen - SearchLen;\r
+        Buffer = Line->Buffer + (NewSize - 1);\r
+        Gap    = ReplaceLen - SearchLen;\r
 \r
         //\r
         // keep the latter part\r
@@ -3299,18 +3306,18 @@ FileBufferReplaceAll (
           *Buffer = *(Buffer - Gap);\r
           Buffer--;\r
         }\r
-\r
-      } else if (ReplaceLen < SearchLen){\r
-        Buffer  = Line->Buffer + Position + ReplaceLen;\r
-        Gap     = SearchLen - ReplaceLen;\r
+      } else if (ReplaceLen < SearchLen) {\r
+        Buffer = Line->Buffer + Position + ReplaceLen;\r
+        Gap    = SearchLen - ReplaceLen;\r
 \r
         for (Index = 0; Index < (Line->Size - Position - ReplaceLen + 1); Index++) {\r
           *Buffer = *(Buffer + Gap);\r
           Buffer++;\r
         }\r
       } else {\r
-        ASSERT(ReplaceLen == SearchLen);\r
+        ASSERT (ReplaceLen == SearchLen);\r
       }\r
+\r
       //\r
       // set replace into it\r
       //\r
@@ -3320,15 +3327,16 @@ FileBufferReplaceAll (
       }\r
 \r
       Line->Size += (ReplaceLen - SearchLen);\r
-      Column += ReplaceLen;\r
+      Column     += ReplaceLen;\r
     } else {\r
       //\r
       // not found\r
       //\r
-      Column  = 0;\r
-      Link    = Link->ForwardLink;\r
+      Column = 0;\r
+      Link   = Link->ForwardLink;\r
     }\r
   }\r
+\r
   //\r
   // call refresh to fresh edit area\r
   //\r
@@ -3343,11 +3351,9 @@ FileBufferReplaceAll (
   Set the modified state to TRUE.\r
 **/\r
 VOID\r
-EFIAPI\r
 FileBufferSetModified (\r
   VOID\r
   )\r
 {\r
   FileBuffer.FileModified = TRUE;\r
 }\r
-\r