]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
Refine comments and two code style.
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / Edit / FileBuffer.c
index 5843c7807d570817dcb5845ded56ec3fcd58f15a..7d8288432608ef8b158af815fe559aff86a1c63b 100644 (file)
@@ -53,7 +53,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
@@ -247,10 +247,10 @@ MoveLine (
   // if > 0, the advance\r
   //\r
   if (Count <= 0) {\r
-    AbsCount  = -Count;\r
+    AbsCount  = (UINTN)ABS(Count);\r
     Line      = InternalEditorMiscLineRetreat (AbsCount,MainEditor.FileBuffer->CurrentLine,MainEditor.FileBuffer->ListHead);\r
   } else {\r
-    Line = InternalEditorMiscLineAdvance (Count,MainEditor.FileBuffer->CurrentLine,MainEditor.FileBuffer->ListHead);\r
+    Line = InternalEditorMiscLineAdvance ((UINTN)Count,MainEditor.FileBuffer->CurrentLine,MainEditor.FileBuffer->ListHead);\r
   }\r
 \r
   return Line;\r
@@ -317,7 +317,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
@@ -357,7 +357,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
@@ -500,7 +500,7 @@ FileBufferPrintLine (
     Limit = 0;\r
   }\r
 \r
-  StrnCpy (PrintLine, Buffer, Limit > MainEditor.ScreenSize.Column ? MainEditor.ScreenSize.Column : Limit);\r
+  StrnCpy (PrintLine, Buffer, MIN(MIN(Limit,MainEditor.ScreenSize.Column), 200));\r
   for (; Limit < MainEditor.ScreenSize.Column; Limit++) {\r
     PrintLine[Limit] = L' ';\r
   }\r
@@ -627,11 +627,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
@@ -1367,7 +1367,7 @@ 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
@@ -1375,9 +1375,9 @@ GetNewLine (
 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
@@ -1446,7 +1446,7 @@ FileBufferSave (
   //\r
   // if is the old file\r
   //\r
-  if (StrCmp (FileName, FileBuffer.FileName) == 0) {\r
+  if (FileBuffer.FileName != NULL && StrCmp (FileName, FileBuffer.FileName) == 0) {\r
     //\r
     // file has not been modified\r
     //\r
@@ -1621,7 +1621,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
@@ -1685,8 +1685,8 @@ 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
@@ -1710,8 +1710,8 @@ 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
@@ -2300,8 +2300,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
@@ -2316,7 +2316,7 @@ FileBufferPageDown (
   //\r
   // if that line, is not that long, so move to the end of that line\r
   //\r
-  if (FCol > Line->Size) {\r
+  if (Line != NULL && FCol > Line->Size) {\r
     FCol = Line->Size + 1;\r
   }\r
 \r
@@ -2352,8 +2352,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
@@ -2372,7 +2372,7 @@ FileBufferPageUp (
   //\r
   // if that line is not that long, so move to the end of that line\r
   //\r
-  if (FCol > Line->Size) {\r
+  if (Line != NULL && FCol > Line->Size) {\r
     FCol = Line->Size + 1;\r
   }\r
 \r
@@ -2575,7 +2575,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
@@ -2650,10 +2650,10 @@ MoveCurrentLine (
   UINTN           AbsCount;\r
 \r
   if (Count <= 0) {\r
-    AbsCount  = -Count;\r
+    AbsCount  = (UINTN)ABS(Count);\r
     Line      = InternalEditorMiscLineRetreat (AbsCount,MainEditor.FileBuffer->CurrentLine,MainEditor.FileBuffer->ListHead);\r
   } else {\r
-    Line = InternalEditorMiscLineAdvance (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
@@ -2720,7 +2720,7 @@ FileBufferMovePosition (
       //\r
       FileBuffer.FilePosition.Row = NewFilePosRow;\r
       if (RowGap < 0) {\r
-        Abs = -RowGap;\r
+        Abs = (UINTN)ABS(RowGap);\r
         FileBuffer.DisplayPosition.Row -= Abs;\r
       } else {\r
         FileBuffer.DisplayPosition.Row += RowGap;\r
@@ -2760,7 +2760,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
@@ -2956,7 +2956,8 @@ FileBufferSearch (
   BOOLEAN         Found;\r
 \r
   Column = 0;\r
-\r
+  Position = 0;\r
+  \r
   //\r
   // search if in current line\r
   //\r
@@ -2969,20 +2970,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
-  }\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 +2996,11 @@ FileBufferSearch (
 //      Position  = StrStr (Line->Buffer, Str);\r
       CharPos  =  StrStr (Line->Buffer, Str);\r
       if (CharPos != NULL) {\r
-        Position = CharPos - Line->Buffer;\r
-      }\r
-      if (Position != 0) {\r
+        Position = CharPos - Line->Buffer + 1;\r
+        Found   = TRUE;\r
+      } \r
+      \r
+      if (Found) {\r
         //\r
         // found\r
         //\r
@@ -3096,14 +3099,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 +3125,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
@@ -3134,7 +3137,7 @@ FileBufferReplace (
 \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);\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
   FileBufferRefresh ();\r
 \r
@@ -3207,12 +3210,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