]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c
ShellPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / UefiShellDebug1CommandsLib.c
index 9ab5d89748a82bd62aea26a355fa8fc2b40f39cd..ddce3bef5a3022cf4c9461df19ac517bad52e0b3 100644 (file)
@@ -1,18 +1,13 @@
 /** @file\r
   Main file for NULL named library for debug1 profile shell command functions.\r
 \r
-  Copyright (c) 2010 - 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) 2010 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 #include "UefiShellDebug1CommandsLib.h"\r
+#include <Library/BcfgCommandLib.h>\r
 \r
 STATIC CONST CHAR16 mFileName[] = L"Debug1Commands";\r
 EFI_HANDLE gShellDebug1HiiHandle = NULL;\r
@@ -84,18 +79,10 @@ UefiShellDebug1CommandsLibConstructor (
   ShellCommandRegisterCommandName(L"edit",          ShellCommandRunEdit               , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_EDIT)         );\r
   ShellCommandRegisterCommandName(L"hexedit",       ShellCommandRunHexEdit            , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_HEXEDIT)      );\r
 \r
-  //\r
-  // check install profile bit of the profiles mask is set\r
-  //\r
-  if ((PcdGet8(PcdShellProfileMask) & BIT2) == 0) {\r
-    ShellCommandRegisterCommandName(L"bcfg",        ShellCommandRunBcfg               , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_BCFG)         );\r
-  }\r
-\r
-\r
-\r
-\r
   ShellCommandRegisterAlias(L"dmem", L"mem");\r
 \r
+  BcfgLibraryRegisterBcfgCommand(ImageHandle, SystemTable, L"Debug1");\r
+\r
   return (EFI_SUCCESS);\r
 }\r
 \r
@@ -115,108 +102,11 @@ UefiShellDebug1CommandsLibDestructor (
   if (gShellDebug1HiiHandle != NULL) {\r
     HiiRemovePackages(gShellDebug1HiiHandle);\r
   }\r
-  return (EFI_SUCCESS);\r
-}\r
-\r
-STATIC CONST CHAR8 Hex[] = {\r
-  '0',\r
-  '1',\r
-  '2',\r
-  '3',\r
-  '4',\r
-  '5',\r
-  '6',\r
-  '7',\r
-  '8',\r
-  '9',\r
-  'A',\r
-  'B',\r
-  'C',\r
-  'D',\r
-  'E',\r
-  'F'\r
-};\r
-\r
-/**\r
-  Dump some hexadecimal data to the screen.\r
-\r
-  @param[in] Indent     How many spaces to indent the output.\r
-  @param[in] Offset     The offset of the printing.\r
-  @param[in] DataSize   The size in bytes of UserData.\r
-  @param[in] UserData   The data to print out.\r
-**/\r
-VOID\r
-DumpHex (\r
-  IN UINTN        Indent,\r
-  IN UINTN        Offset,\r
-  IN UINTN        DataSize,\r
-  IN VOID         *UserData\r
-  )\r
-{\r
-  UINT8 *Data;\r
-\r
-  CHAR8 Val[50];\r
-\r
-  CHAR8 Str[20];\r
-\r
-  UINT8 TempByte;\r
-  UINTN Size;\r
-  UINTN Index;\r
 \r
-  Data = UserData;\r
-  while (DataSize != 0) {\r
-    Size = 16;\r
-    if (Size > DataSize) {\r
-      Size = DataSize;\r
-    }\r
-\r
-    for (Index = 0; Index < Size; Index += 1) {\r
-      TempByte            = Data[Index];\r
-      Val[Index * 3 + 0]  = Hex[TempByte >> 4];\r
-      Val[Index * 3 + 1]  = Hex[TempByte & 0xF];\r
-      Val[Index * 3 + 2]  = (CHAR8) ((Index == 7) ? '-' : ' ');\r
-      Str[Index]          = (CHAR8) ((TempByte < ' ' || TempByte > 'z') ? '.' : TempByte);\r
-    }\r
-\r
-    Val[Index * 3]  = 0;\r
-    Str[Index]      = 0;\r
-    ShellPrintEx(-1, -1, L"%*a%02X: %-.48a *%a*\r\n", Indent, "", Offset, Val, Str);\r
-\r
-    Data += Size;\r
-    Offset += Size;\r
-    DataSize -= Size;\r
-  }\r
+  BcfgLibraryUnregisterBcfgCommand(ImageHandle, SystemTable);\r
+  return (EFI_SUCCESS);\r
 }\r
 \r
-/**\r
-  Convert a Unicode character to upper case only if\r
-  it maps to a valid small-case ASCII character.\r
-\r
-  This internal function only deal with Unicode character\r
-  which maps to a valid small-case ASCII character, i.e.\r
-  L'a' to L'z'. For other Unicode character, the input character\r
-  is returned directly.\r
-\r
-  @param  Char  The character to convert.\r
-\r
-  @retval LowerCharacter   If the Char is with range L'a' to L'z'.\r
-  @retval Unchanged        Otherwise.\r
-\r
-\r
-  //Stolen from MdePkg Baselib\r
-**/\r
-CHAR16\r
-EFIAPI\r
-CharToUpper (\r
-  IN      CHAR16                    Char\r
-  )\r
-{\r
-  if (Char >= L'a' && Char <= L'z') {\r
-    return (CHAR16) (Char - (L'a' - L'A'));\r
-  }\r
-\r
-  return Char;\r
-}\r
 \r
 /**\r
   Function returns a system configuration table that is stored in the\r
@@ -229,7 +119,6 @@ CharToUpper (
   @retval EFI_NOT_FOUND    A configuration table matching TableGuid was not found.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 GetSystemConfigurationTable (\r
   IN EFI_GUID *TableGuid,\r
   IN OUT VOID **Table\r
@@ -248,137 +137,21 @@ GetSystemConfigurationTable (
   return EFI_NOT_FOUND;\r
 }\r
 \r
-/**\r
-  Convert a Unicode character to numerical value.\r
-\r
-  This internal function only deal with Unicode character\r
-  which maps to a valid hexadecimal ASII character, i.e.\r
-  L'0' to L'9', L'a' to L'f' or L'A' to L'F'. For other\r
-  Unicode character, the value returned does not make sense.\r
-\r
-  @param  Char  The character to convert.\r
-\r
-  @return The numerical value converted.\r
-\r
-**/\r
-UINTN\r
-EFIAPI\r
-HexCharToUintn (\r
-  IN      CHAR16                    Char\r
-  )\r
-{\r
-  if (Char >= L'0' && Char <= L'9') {\r
-    return Char - L'0';\r
-  }\r
-\r
-  return (UINTN) (10 + CharToUpper (Char) - L'A');\r
-}\r
-\r
-/**\r
-  Convert a string representation of a guid to a Guid value.\r
-\r
-  @param[in] StringGuid    The pointer to the string of a guid.\r
-  @param[in, out] Guid     The pointer to the GUID structure to populate.\r
-\r
-  @retval EFI_INVALID_PARAMETER   A parameter was invalid.\r
-  @retval EFI_SUCCESS             The conversion was successful.\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-ConvertStringToGuid (\r
-  IN CONST CHAR16 *StringGuid,\r
-  IN OUT EFI_GUID *Guid\r
-  )\r
-{\r
-  CHAR16  *TempCopy;\r
-  CHAR16  *TempSpot;\r
-  CHAR16  *Walker;\r
-  UINT64  TempVal;\r
-  EFI_STATUS Status;\r
-\r
-  if (StringGuid == NULL) {\r
-    return (EFI_INVALID_PARAMETER);\r
-  } else if (StrLen(StringGuid) != 36) {\r
-    return (EFI_INVALID_PARAMETER);\r
-  } \r
-  TempCopy = NULL;\r
-  TempCopy = StrnCatGrow(&TempCopy, NULL, StringGuid, 0);\r
-  Walker   = TempCopy;\r
-  TempSpot = StrStr(Walker, L"-");\r
-  if (TempSpot != NULL) {\r
-    *TempSpot = CHAR_NULL;\r
-  }\r
-  Status = ShellConvertStringToUint64(Walker, &TempVal, TRUE, FALSE);\r
-  if (EFI_ERROR(Status)) {\r
-    FreePool(TempCopy);\r
-    return (Status);\r
-  }\r
-  Guid->Data1 = (UINT32)TempVal;\r
-  Walker += 9;\r
-  TempSpot = StrStr(Walker, L"-");\r
-  if (TempSpot != NULL) {\r
-    *TempSpot = CHAR_NULL;\r
-  }\r
-  Status = ShellConvertStringToUint64(Walker, &TempVal, TRUE, FALSE);\r
-  if (EFI_ERROR(Status)) {\r
-    FreePool(TempCopy);\r
-    return (Status);\r
-  }\r
-  Guid->Data2 = (UINT16)TempVal;\r
-  Walker += 5;\r
-  TempSpot = StrStr(Walker, L"-");\r
-  if (TempSpot != NULL) {\r
-    *TempSpot = CHAR_NULL;\r
-  }\r
-  Status = ShellConvertStringToUint64(Walker, &TempVal, TRUE, FALSE);\r
-  if (EFI_ERROR(Status)) {\r
-    FreePool(TempCopy);\r
-    return (Status);\r
-  }\r
-  Guid->Data3 = (UINT16)TempVal;\r
-  Walker += 5;\r
-  Guid->Data4[0] = (UINT8)(HexCharToUintn(Walker[0]) * 16);\r
-  Guid->Data4[0] = (UINT8)(Guid->Data4[0]+ (UINT8)HexCharToUintn(Walker[1]));\r
-  Walker += 2;\r
-  Guid->Data4[1] = (UINT8)(HexCharToUintn(Walker[0]) * 16);\r
-  Guid->Data4[1] = (UINT8)(Guid->Data4[1] + (UINT8)HexCharToUintn(Walker[1]));\r
-  Walker += 3;\r
-  Guid->Data4[2] = (UINT8)(HexCharToUintn(Walker[0]) * 16);\r
-  Guid->Data4[2] = (UINT8)(Guid->Data4[2] + (UINT8)HexCharToUintn(Walker[1]));\r
-  Walker += 2;\r
-  Guid->Data4[3] = (UINT8)(HexCharToUintn(Walker[0]) * 16);\r
-  Guid->Data4[3] = (UINT8)(Guid->Data4[3] + (UINT8)HexCharToUintn(Walker[1]));\r
-  Walker += 2;\r
-  Guid->Data4[4] = (UINT8)(HexCharToUintn(Walker[0]) * 16);\r
-  Guid->Data4[4] = (UINT8)(Guid->Data4[4] + (UINT8)HexCharToUintn(Walker[1]));\r
-  Walker += 2;\r
-  Guid->Data4[5] = (UINT8)(HexCharToUintn(Walker[0]) * 16);\r
-  Guid->Data4[5] = (UINT8)(Guid->Data4[5] + (UINT8)HexCharToUintn(Walker[1]));\r
-  Walker += 2;\r
-  Guid->Data4[6] = (UINT8)(HexCharToUintn(Walker[0]) * 16);\r
-  Guid->Data4[6] = (UINT8)(Guid->Data4[6] + (UINT8)HexCharToUintn(Walker[1]));\r
-  Walker += 2;\r
-  Guid->Data4[7] = (UINT8)(HexCharToUintn(Walker[0]) * 16);\r
-  Guid->Data4[7] = (UINT8)(Guid->Data4[7] + (UINT8)HexCharToUintn(Walker[1]));\r
-  FreePool(TempCopy);\r
-  return (EFI_SUCCESS);\r
-}\r
-\r
 /**\r
   Clear the line at the specified Row.\r
-  \r
+\r
   @param[in] Row                The row number to be cleared ( start from 1 )\r
   @param[in] LastCol            The last printable column.\r
   @param[in] LastRow            The last printable row.\r
 **/\r
 VOID\r
-EFIAPI\r
 EditorClearLine (\r
   IN UINTN Row,\r
   IN UINTN LastCol,\r
   IN UINTN LastRow\r
   )\r
 {\r
+  UINTN  Col;\r
   CHAR16 Line[200];\r
 \r
   if (Row == 0) {\r
@@ -387,22 +160,28 @@ EditorClearLine (
 \r
   //\r
   // prepare a blank line\r
+  // If max column is larger, split to multiple prints.\r
   //\r
-  SetMem16(Line, LastCol*sizeof(CHAR16), L' ');\r
+  SetMem16 (Line, sizeof (Line), L' ');\r
+  Line[ARRAY_SIZE (Line) - 1] = CHAR_NULL;\r
+\r
+  for (Col = 1; Col <= LastCol; Col += ARRAY_SIZE (Line) - 1) {\r
+    if (Col + ARRAY_SIZE (Line) - 1 > LastCol) {\r
+      if (Row == LastRow) {\r
+        //\r
+        // if CHAR_NULL is still at position LastCol, it will cause first line error\r
+        //\r
+        Line[(LastCol - 1) % (ARRAY_SIZE (Line) - 1)] = CHAR_NULL;\r
+      } else {\r
+        Line[LastCol % (ARRAY_SIZE (Line) - 1)] = CHAR_NULL;\r
+      }\r
+    }\r
 \r
-  if (Row == LastRow) {\r
     //\r
-    // if CHAR_NULL is still at position 80, it will cause first line error\r
+    // print out the blank line\r
     //\r
-    Line[LastCol - 1] = CHAR_NULL;\r
-  } else {\r
-    Line[LastCol] = CHAR_NULL;\r
+    ShellPrintEx ((INT32) Col - 1, (INT32) Row - 1, Line);\r
   }\r
-\r
-  //\r
-  // print out the blank line\r
-  //\r
-  ShellPrintEx (0, ((INT32)Row) - 1, Line);\r
 }\r
 \r
 /**\r
@@ -414,7 +193,6 @@ EditorClearLine (
   @retval FALSE     The character is not valid.\r
 **/\r
 BOOLEAN\r
-EFIAPI\r
 IsValidFileNameChar (\r
   IN CONST CHAR16 Ch\r
   )\r
@@ -422,7 +200,7 @@ IsValidFileNameChar (
   //\r
   // See if there are any illegal characters within the name\r
   //\r
-  if (Ch < 0x20 || Ch == L'\"' || Ch == L'*' || Ch == L'/' || Ch == L'<' || Ch == L'>' || Ch == L'?' || Ch == L'|' || Ch == L' ') {\r
+  if (Ch < 0x20 || Ch == L'\"' || Ch == L'*' || Ch == L'/' || Ch == L'<' || Ch == L'>' || Ch == L'?' || Ch == L'|') {\r
     return FALSE;\r
   }\r
 \r
@@ -431,14 +209,13 @@ IsValidFileNameChar (
 \r
 /**\r
   Check if file name has illegal characters.\r
-  \r
+\r
   @param Name       The filename to check.\r
 \r
   @retval TRUE      The filename is ok.\r
   @retval FALSE     The filename is not ok.\r
 **/\r
 BOOLEAN\r
-EFIAPI\r
 IsValidFileName (\r
   IN CONST CHAR16 *Name\r
   )\r
@@ -480,18 +257,15 @@ IsValidFileName (
   @return the valid filename.\r
 **/\r
 CHAR16 *\r
-EFIAPI\r
 EditGetDefaultFileName (\r
   IN CONST CHAR16 *Extension\r
   )\r
 {\r
   EFI_STATUS         Status;\r
   UINTN              Suffix;\r
-  BOOLEAN            FoundNewFile;\r
   CHAR16             *FileNameTmp;\r
 \r
   Suffix       = 0;\r
-  FoundNewFile = FALSE;\r
 \r
   do {\r
     FileNameTmp = CatSPrint (NULL, L"NewFile%d.%s", Suffix, Extension);\r
@@ -515,18 +289,18 @@ EditGetDefaultFileName (
 }\r
 \r
 /**\r
-  Read a file into an allocated buffer.  The buffer is the responsibility \r
+  Read a file into an allocated buffer.  The buffer is the responsibility\r
   of the caller to free.\r
 \r
   @param[in]  FileName          The filename of the file to open.\r
-  @param[out] Buffer            Upon successful return, the pointer to the \r
-                                address of the allocated buffer.                                  \r
+  @param[out] Buffer            Upon successful return, the pointer to the\r
+                                address of the allocated buffer.\r
   @param[out] BufferSize        If not NULL, then the pointer to the size\r
                                 of the allocated buffer.\r
   @param[out] ReadOnly          Upon successful return TRUE if the file is\r
                                 read only.  FALSE otherwise.\r
 \r
-  @retval EFI_NOT_FOUND         The filename did not represent a file in the \r
+  @retval EFI_NOT_FOUND         The filename did not represent a file in the\r
                                 file system.\r
   @retval EFI_SUCCESS           The file was read into the buffer.\r
   @retval EFI_OUT_OF_RESOURCES  A memory allocation failed.\r
@@ -536,7 +310,6 @@ EditGetDefaultFileName (
   @retval EFI_INVALID_PARAMETER FileName was a directory.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 ReadFileIntoBuffer (\r
   IN CONST CHAR16 *FileName,\r
   OUT VOID        **Buffer,\r
@@ -574,7 +347,7 @@ ReadFileIntoBuffer (
     }\r
 \r
     Info = ShellGetFileInfo(FileHandle);\r
-    \r
+\r
     if (Info->Attribute & EFI_FILE_DIRECTORY) {\r
       FreePool (Info);\r
       return EFI_INVALID_PARAMETER;\r