]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EmbeddedPkg/Ebl/Command.c
EmbeddedPkg: Fix mispellings
[mirror_edk2.git] / EmbeddedPkg / Ebl / Command.c
index f0db375cefd67027244a489b9f7d8b899f684b13..78ddcd19367e20a57e2310a914fc981424ceb846 100644 (file)
@@ -1,10 +1,10 @@
 /** @file\r
   Basic commands and command processing infrastructure for EBL\r
 \r
-  Copyright (c) 2007, Intel Corporation<BR>\r
-  Portions copyright (c) 2008-2009, Apple Inc. All rights reserved.\r
+  Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>\r
+  Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
 \r
-  All rights reserved. This program and the accompanying materials\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
@@ -46,7 +46,7 @@ AsciiToUpper (
 \r
 \r
 /**\r
-  Case insensitve comparison of two Null-terminated Unicode strings with maximum\r
+  Case insensitive comparison of two Null-terminated Unicode strings with maximum\r
   lengths, and returns the difference between the first mismatched Unicode\r
   characters.\r
   This function compares the Null-terminated Unicode string FirstString to the\r
@@ -94,9 +94,9 @@ AsciiStrniCmp (
 /**\r
   Add a command to the mCmdTable. If there is no free space in the command \r
   table ASSERT. The mCmdTable is maintained in alphabetical order and the \r
-  new entry is inserted into its sorted possition.\r
+  new entry is inserted into its sorted position.\r
 \r
-  @param  Entry   Commnad Entry to add to the CmdTable\r
+  @param  Entry   Command Entry to add to the CmdTable\r
 \r
 **/\r
 VOID\r
@@ -139,7 +139,7 @@ EblAddCommand (
   array of commands.\r
 \r
   @param  EntryArray   Pointer to array of command entries\r
-  @param  ArrayCount   Number of commnad entries to add\r
+  @param  ArrayCount   Number of command entries to add\r
 \r
 **/\r
 VOID\r
@@ -168,8 +168,8 @@ EBL_ADD_COMMAND_PROTOCOL gEblAddCommand = {
 \r
 /**\r
   Return the best matching command for the passed in command name. The match \r
-  does not have to be exact, it just needs to be unqiue. This enables commands\r
-  to be shortend to the smallest set of starting characters that is unique.\r
+  does not have to be exact, it just needs to be unique. This enables commands\r
+  to be shortened to the smallest set of starting characters that is unique.\r
 \r
   @param  CommandName   Name of command to search for\r
 \r
@@ -186,8 +186,16 @@ EblGetCommand (
   UINTN               BestMatchCount;\r
   UINTN               Length;\r
   EBL_COMMAND_TABLE   *Match;\r
+  CHAR8               *Str;\r
 \r
   Length = AsciiStrLen (CommandName);\r
+  Str = AsciiStrStr (CommandName, ".");\r
+  if (Str != NULL) {\r
+    // If the command includes a trailing . command extension skip it for the match.\r
+    // Example: hexdump.4\r
+    Length = (UINTN)(Str - CommandName); \r
+  }\r
+  \r
   for (Index = 0, BestMatchCount = 0, Match = NULL; Index < mCmdTableNextFreeIndex; Index++) {\r
     if (AsciiStriCmp (mCmdTable[Index]->Name,  CommandName) == 0) {\r
       // match a command exactly\r
@@ -212,6 +220,26 @@ EblGetCommand (
 }\r
 \r
 \r
+UINTN\r
+CountNewLines (\r
+  IN CHAR8  *Str\r
+  )\r
+{\r
+  UINTN Count;\r
+  \r
+  if (Str == NULL) {\r
+    return 0;\r
+  }\r
+  \r
+  for (Count = 0; *Str != '\0'; Str++) {\r
+    if (Str[Count] == '\n') {\r
+      Count++;\r
+    }\r
+  }\r
+  \r
+  return Count;\r
+}\r
+\r
 \r
 /**\r
   List out help information on all the commands or print extended information \r
@@ -222,7 +250,7 @@ EblGetCommand (
 \r
   @param  Argc   Number of command arguments in Argv\r
   @param  Argv   Array of strings that represent the parsed command line. \r
-                 Argv[0] is the comamnd name\r
+                 Argv[0] is the command name\r
 \r
   @return EFI_SUCCESS\r
 \r
@@ -235,16 +263,22 @@ EblHelpCmd (
 {\r
   UINTN   Index;\r
   CHAR8   *Ptr;\r
-  UINTN   CurrentRow;\r
+  UINTN   CurrentRow = 0;\r
 \r
   if (Argc == 1) {\r
     // Print all the commands\r
     AsciiPrint ("Embedded Boot Loader (EBL) commands (help command for more info):\n");\r
+    CurrentRow++;\r
     for (Index = 0; Index < mCmdTableNextFreeIndex; Index++) {\r
       EblSetTextColor (EFI_YELLOW);\r
       AsciiPrint (" %a", mCmdTable[Index]->Name);\r
       EblSetTextColor (0);\r
       AsciiPrint ("%a\n", mCmdTable[Index]->HelpSummary);\r
+      // Handle multi line help summaries\r
+      CurrentRow += CountNewLines (mCmdTable[Index]->HelpSummary);\r
+      if (EblAnyKeyToContinueQtoQuit (&CurrentRow, FALSE)) {\r
+        break;\r
+      }\r
     }\r
   } else if (Argv[1] != NULL) {\r
     // Print specific help \r
@@ -252,6 +286,8 @@ EblHelpCmd (
       if (AsciiStriCmp (Argv[1], mCmdTable[Index]->Name) == 0) {\r
         Ptr = (mCmdTable[Index]->Help == NULL) ? mCmdTable[Index]->HelpSummary : mCmdTable[Index]->Help;\r
         AsciiPrint ("%a%a\n", Argv[1], Ptr);\r
+        // Handle multi line help summaries\r
+        CurrentRow += CountNewLines (Ptr);\r
         if (EblAnyKeyToContinueQtoQuit (&CurrentRow, FALSE)) {\r
           break;\r
         }\r
@@ -264,14 +300,14 @@ EblHelpCmd (
 \r
 \r
 /**\r
-  Exit the EBL. If the commnad processor sees EFI_ABORTED return status it will\r
+  Exit the EBL. If the command processor sees EFI_ABORTED return status it will\r
   exit the EBL.\r
 \r
   Argv[0] - "exit"\r
 \r
   @param  Argc   Number of command arguments in Argv\r
   @param  Argv   Array of strings that represent the parsed command line. \r
-                 Argv[0] is the comamnd name\r
+                 Argv[0] is the command name\r
 \r
   @return EFI_ABORTED\r
 \r
@@ -352,7 +388,7 @@ EblExitCmd (
   This AsciiPrint has to match the AsciiPrint in \r
   EblPauseCmd. \r
 \r
-  @param  ElaspedTime   Current timout value remaining\r
+  @param  ElaspedTime   Current timeout value remaining\r
 \r
 **/\r
 VOID\r
@@ -375,10 +411,10 @@ EblPauseCallback (
 \r
   @param  Argc   Number of command arguments in Argv\r
   @param  Argv   Array of strings that represent the parsed command line. \r
-                 Argv[0] is the comamnd name\r
+                 Argv[0] is the command name\r
 \r
   @return EFI_SUCCESS  Timeout expired with no input\r
-  @return EFI_TIMEOUT  Stop procesing other commands on the same command line\r
+  @return EFI_TIMEOUT  Stop processing other commands on the same command line\r
 \r
 **/\r
 EFI_STATUS\r
@@ -397,8 +433,8 @@ EblPauseCmd (
   Status = EblGetCharKey (&Key, Delay, EblPauseCallback);\r
   AsciiPrint ("\n");\r
 \r
-  // If we timeout then the pause succeded thus return success\r
-  // If we get a key return timout to stop other commnad on this cmd line\r
+  // If we timeout then the pause succeeded thus return success\r
+  // If we get a key return timeout to stop other command on this cmd line\r
   return (Status == EFI_SUCCESS) ? EFI_TIMEOUT : EFI_SUCCESS;;\r
 }\r
 \r
@@ -410,7 +446,7 @@ EblPauseCmd (
 \r
   @param  Argc   Number of command arguments in Argv\r
   @param  Argv   Array of strings that represent the parsed command line. \r
-                 Argv[0] is the comamnd name\r
+                 Argv[0] is the command name\r
 \r
   @return EFI_SUCCESS\r
 \r
@@ -436,7 +472,7 @@ EblBreakPointCmd (
 \r
   @param  Argc   Number of command arguments in Argv\r
   @param  Argv   Array of strings that represent the parsed command line. \r
-                 Argv[0] is the comamnd name\r
+                 Argv[0] is the command name\r
 \r
   @return EFI_SUCCESS\r
 \r
@@ -476,7 +512,7 @@ EblResetCmd (
 \r
   @param  Argc   Number of command arguments in Argv\r
   @param  Argv   Array of strings that represent the parsed command line. \r
-                 Argv[0] is the comamnd name\r
+                 Argv[0] is the command name\r
 \r
   @return EFI_SUCCESS\r
 \r
@@ -650,8 +686,60 @@ OutputData (
   return EFI_SUCCESS;\r
 }\r
 \r
+\r
+/**\r
+  See if command contains .# where # is a number. Return # as the Width\r
+  or 1 as the default Width for commands. \r
+  \r
+  Example hexdump.4 returns a width of 4.\r
+\r
+  @param  Argv   Argv[0] is the command name\r
+\r
+  @return Width of command\r
+\r
+**/\r
+UINTN\r
+WidthFromCommandName (\r
+  IN CHAR8  *Argv,\r
+  IN UINTN  Default\r
+  )\r
+{\r
+  CHAR8         *Str;\r
+  UINTN         Width;\r
+  \r
+  //Hexdump.2 HexDump.4 mean use a different width\r
+  Str = AsciiStrStr (Argv, ".");\r
+  if (Str != NULL) {\r
+    Width = AsciiStrDecimalToUintn (Str + 1);\r
+    if (Width == 0) {\r
+      Width = Default;\r
+    }\r
+  } else {\r
+    // Default answer\r
+    return Default;\r
+  }\r
+\r
+  return Width;\r
+}\r
+\r
 #define HEXDUMP_CHUNK 1024\r
 \r
+/**\r
+  Toggle page break global. This turns on and off prompting to Quit or hit any\r
+  key to continue when a command is about to scroll the screen with its output\r
+\r
+  Argv[0] - "hexdump"[.#]  # is optional 1,2, or 4 for width  \r
+  Argv[1] - Device or File to dump. \r
+  Argv[2] - Optional offset to start dumping\r
+  Argv[3] - Optional number of bytes to dump\r
+\r
+  @param  Argc   Number of command arguments in Argv\r
+  @param  Argv   Array of strings that represent the parsed command line. \r
+                 Argv[0] is the command name\r
+\r
+  @return EFI_SUCCESS\r
+\r
+**/\r
 EFI_STATUS\r
 EblHexdumpCmd (\r
   IN UINTN  Argc,\r
@@ -661,19 +749,16 @@ EblHexdumpCmd (
   EFI_OPEN_FILE *File;\r
   VOID          *Location;\r
   UINTN         Size;\r
-  UINTN         Width = 1;\r
+  UINTN         Width;\r
   UINTN         Offset = 0;\r
   EFI_STATUS    Status;\r
   UINTN         Chunk = HEXDUMP_CHUNK;\r
 \r
-  if ((Argc < 2) || (Argc > 3)) {\r
+  if ((Argc < 2) || (Argc > 4)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
   \r
-  if (Argc == 3) {\r
-      Width = AsciiStrDecimalToUintn(Argv[2]);\r
-  }\r
-  \r
+  Width = WidthFromCommandName (Argv[0], 1);\r
   if ((Width != 1) && (Width != 2) && (Width != 4)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -684,14 +769,26 @@ EblHexdumpCmd (
   }\r
 \r
   Location = AllocatePool (Chunk);\r
-  Size     = EfiTell(File, NULL);\r
+  Size     = (Argc > 3) ? AsciiStrHexToUintn (Argv[3]) : EfiTell (File, NULL);\r
+\r
+  Offset = 0;\r
+  if (Argc > 2) {\r
+    Offset = AsciiStrHexToUintn (Argv[2]);\r
+    if (Offset > 0) {\r
+      // Make sure size includes the part of the file we have skipped\r
+      Size += Offset;\r
+    }\r
+  } \r
 \r
-  for (Offset = 0; Offset + HEXDUMP_CHUNK <= Size; Offset += Chunk) {\r
+  Status = EfiSeek (File, Offset, EfiSeekStart);\r
+  if (EFI_ERROR (Status)) {\r
+    goto Exit;\r
+  }\r
+  \r
+  for (; Offset + HEXDUMP_CHUNK <= Size; Offset += Chunk) {\r
     Chunk = HEXDUMP_CHUNK;\r
-    \r
     Status = EfiRead (File, Location, &Chunk);\r
-    if (EFI_ERROR(Status))\r
-    {\r
+    if (EFI_ERROR(Status)) {\r
       AsciiPrint ("Error reading file content\n");\r
       goto Exit;\r
     }\r
@@ -778,7 +875,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED const EBL_COMMAND_TABLE mCmdTemplate[] =
   },\r
   {\r
     "hexdump",\r
-    " filename ; dump a file as hex bytes",\r
+    "[.{1|2|4}] filename [Offset] [Size]; dump a file as hex .width",\r
     NULL,\r
     EblHexdumpCmd\r
   }\r