]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
move a function to the correct library.
[mirror_edk2.git] / ShellPkg / Library / UefiShellCommandLib / UefiShellCommandLib.c
index 2dd39ef3cf453b091903b3c72d44e0e501c58625..b91ba27af04d9375356bb7c6f9a392ea49490113 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Provides interface to shell internal functions for shell commands.\r
 \r
-  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 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
@@ -17,7 +17,7 @@
 /// The tag for use in identifying UNICODE files.\r
 /// If the file is UNICODE, the first 16 bits of the file will equal this value.\r
 enum {\r
-  UnicodeFileTag = 0xFEFF\r
+  gUnicodeFileTag = 0xFEFF\r
 };\r
 \r
 // STATIC local variables\r
@@ -207,6 +207,12 @@ ShellCommandLibDestructor (
     FreePool(mProfileList);\r
   }\r
 \r
+  gEfiShellProtocol            = NULL;\r
+  gEfiShellParametersProtocol  = NULL;\r
+  gUnicodeCollation            = NULL;\r
+  gDevPathToText               = NULL;\r
+  gShellCurDir                 = NULL;\r
+\r
   return (RETURN_SUCCESS);\r
 }\r
 \r
@@ -374,9 +380,9 @@ ShellCommandRegisterCommandName (
   //\r
   // allocate memory for new struct\r
   //\r
-  Node = AllocatePool(sizeof(SHELL_COMMAND_INTERNAL_LIST_ENTRY));\r
+  Node = AllocateZeroPool(sizeof(SHELL_COMMAND_INTERNAL_LIST_ENTRY));\r
   ASSERT(Node != NULL);\r
-  Node->CommandString = AllocatePool(StrSize(CommandString));\r
+  Node->CommandString = AllocateZeroPool(StrSize(CommandString));\r
   ASSERT(Node->CommandString != NULL);\r
 \r
   //\r
@@ -440,8 +446,6 @@ ShellCommandGetProfileList (
   information will be returned. If Sections is NULL, then all help text information\r
   available will be returned.\r
 \r
-  @param          Sections          pointer to string representing which section to get help on.\r
-\r
   @param[in]  CommandString         Pointer to the command name.  This is the name\r
                                     found on the command line in the shell.\r
   @param[in,out] RetVal             Pointer to the return vaule from the command handler.\r
@@ -546,13 +550,19 @@ ShellCommandGetManFileNameHandler (
   (via LIST_ENTRY structure).  enumerate through it using the BaseLib linked\r
   list functions.  do not modify the values.\r
 \r
+  @param[in] Sort       TRUE to alphabetically sort the values first.  FALSE otherwise.\r
+\r
   @return a Linked list of all available shell commands.\r
 **/\r
 CONST COMMAND_LIST*\r
 EFIAPI\r
 ShellCommandGetCommandList (\r
+  IN CONST BOOLEAN Sort\r
   )\r
 {\r
+//  if (!Sort) {\r
+//    return ((COMMAND_LIST*)(&mCommandList));\r
+//  }\r
   return ((COMMAND_LIST*)(&mCommandList));\r
 }\r
 \r
@@ -587,10 +597,10 @@ ShellCommandRegisterAlias (
   //\r
   // allocate memory for new struct\r
   //\r
-  Node = AllocatePool(sizeof(ALIAS_LIST));\r
+  Node = AllocateZeroPool(sizeof(ALIAS_LIST));\r
   ASSERT(Node != NULL);\r
-  Node->CommandString = AllocatePool(StrSize(Command));\r
-  Node->Alias = AllocatePool(StrSize(Alias));\r
+  Node->CommandString = AllocateZeroPool(StrSize(Command));\r
+  Node->Alias = AllocateZeroPool(StrSize(Alias));\r
   ASSERT(Node->CommandString != NULL);\r
   ASSERT(Node->Alias != NULL);\r
 \r
@@ -625,7 +635,7 @@ ShellCommandGetInitAliasList (
 }\r
 \r
 /**\r
-  Determine if a given alias is on the list of built in alias'\r
+  Determine if a given alias is on the list of built in alias'.\r
 \r
   @param[in] Alias              The alias to test for\r
 \r
@@ -694,6 +704,8 @@ ShellCommandGetEchoState(
 \r
   If State is TRUE, Echo will be enabled.\r
   If State is FALSE, Echo will be disabled.\r
+\r
+  @param[in] State      How to set echo.\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -1040,7 +1052,7 @@ ShellCommandCreateInitialMappingsAndPaths(
     //\r
     // Get all Device Paths\r
     //\r
-    DevicePathList = AllocatePool(sizeof(EFI_DEVICE_PATH_PROTOCOL*) * Count);\r
+    DevicePathList = AllocateZeroPool(sizeof(EFI_DEVICE_PATH_PROTOCOL*) * Count);\r
     ASSERT(DevicePathList != NULL);\r
 \r
     for (Count = 0 ; HandleList[Count] != NULL ; Count++) {\r
@@ -1097,7 +1109,7 @@ ShellCommandCreateInitialMappingsAndPaths(
     //\r
     // Get all Device Paths\r
     //\r
-    DevicePathList = AllocatePool(sizeof(EFI_DEVICE_PATH_PROTOCOL*) * Count);\r
+    DevicePathList = AllocateZeroPool(sizeof(EFI_DEVICE_PATH_PROTOCOL*) * Count);\r
     ASSERT(DevicePathList != NULL);\r
 \r
     for (Count = 0 ; HandleList[Count] != NULL ; Count++) {\r
@@ -1132,6 +1144,13 @@ ShellCommandCreateInitialMappingsAndPaths(
   return (EFI_SUCCESS);\r
 }\r
 \r
+/**\r
+  Function to make sure all directory delimeters are backslashes.\r
+\r
+  @param[in,out] Path     The path to modify.\r
+\r
+  @return Path.\r
+**/\r
 CHAR16*\r
 EFIAPI\r
 ShellCommandCleanPath (\r
@@ -1189,7 +1208,7 @@ ConvertEfiFileProtocolToShellHandle(
     if (Buffer == NULL) {\r
       return (NULL);\r
     }\r
-    NewNode             = AllocatePool(sizeof(BUFFER_LIST));\r
+    NewNode             = AllocateZeroPool(sizeof(BUFFER_LIST));\r
     if (NewNode == NULL) {\r
       return (NULL);\r
     }\r
@@ -1232,7 +1251,7 @@ ShellFileHandleGetPath(
 }\r
 \r
 /**\r
-  Remove a SHELL_FILE_HANDLE frmo the list of SHELL_FILE_HANDLES.\r
+  Remove a SHELL_FILE_HANDLE from the list of SHELL_FILE_HANDLES.\r
 \r
   @param[in] Handle     The SHELL_FILE_HANDLE to remove.\r
 \r
@@ -1340,7 +1359,7 @@ ShellFileHandleReturnLine(
 \r
   Status = ShellFileHandleReadLine(Handle, RetVal, &Size, FALSE, Ascii);\r
   if (Status == EFI_BUFFER_TOO_SMALL) {\r
-    RetVal = AllocatePool(Size);\r
+    RetVal = AllocateZeroPool(Size);\r
     Status = ShellFileHandleReadLine(Handle, RetVal, &Size, FALSE, Ascii);\r
   }\r
   ASSERT_EFI_ERROR(Status);\r
@@ -1409,7 +1428,7 @@ ShellFileHandleReadLine(
     CharSize = sizeof(CHAR16);\r
     Status = gEfiShellProtocol->ReadFile(Handle, &CharSize, &CharBuffer);\r
     ASSERT_EFI_ERROR(Status);\r
-    if (CharBuffer == UnicodeFileTag) {\r
+    if (CharBuffer == gUnicodeFileTag) {\r
       *Ascii = FALSE;\r
     } else {\r
       *Ascii = TRUE;\r
@@ -1462,6 +1481,8 @@ ShellFileHandleReadLine(
 }\r
 /**\r
   Frees any BUFFER_LIST defined type.\r
+\r
+  @param[in] List     The BUFFER_LIST object to free.\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -1493,7 +1514,7 @@ FreeBufferList (
 /**\r
   Chops off last directory or file entry in a path leaving the trailing slash\r
 \r
-  @param[in,out] Path\r
+  @param[in,out] PathToReturn The path to modify.\r
 \r
   @retval FALSE     No directory was found to chop off.\r
   @retval TRUE      A directory was chopped off.\r
@@ -1505,11 +1526,11 @@ ChopLastSlash(
   )\r
 {\r
   CHAR16        *Walker;\r
-  CHAR16        *LastSlash = NULL;\r
+  CHAR16        *LastSlash;\r
   //\r
   // get directory name from path... ('chop' off extra)\r
   //\r
-  for ( Walker = PathToReturn\r
+  for ( Walker = PathToReturn, LastSlash = NULL\r
       ; Walker != NULL && *Walker != CHAR_NULL\r
       ; Walker++\r
      ){\r
@@ -1524,3 +1545,51 @@ ChopLastSlash(
   return (FALSE);\r
 }\r
 \r
+/**\r
+  Function to clean up paths.  Removes the following items:\r
+    single periods in the path (no need for the current directory tag)\r
+    double periods in the path and removes a single parent directory.\r
+\r
+  This will be done inline and the resultant string may be be 'too big'.\r
+\r
+  @param[in] PathToReturn  The pointer to the string containing the path.\r
+\r
+  @return PathToReturn is always returned.\r
+**/\r
+CHAR16*\r
+EFIAPI\r
+CleanPath(\r
+  IN CHAR16 *PathToReturn\r
+  )\r
+{\r
+  CHAR16  *TempString;\r
+  UINTN   TempSize;\r
+  if (PathToReturn==NULL) {\r
+    return(NULL);\r
+  }\r
+  //\r
+  // Fix up the directory name\r
+  //\r
+  while ((TempString = StrStr(PathToReturn, L"\\..\\")) != NULL) {\r
+    *TempString = CHAR_NULL;\r
+    TempString  += 4;\r
+    ChopLastSlash(PathToReturn);\r
+    TempSize = StrSize(TempString);\r
+    CopyMem(PathToReturn+StrLen(PathToReturn), TempString, TempSize);\r
+  }\r
+  if ((TempString = StrStr(PathToReturn, L"\\..")) != NULL && *(TempString + 3) == CHAR_NULL) {\r
+    *TempString = CHAR_NULL;\r
+    ChopLastSlash(PathToReturn);\r
+  }\r
+  while ((TempString = StrStr(PathToReturn, L"\\.\\")) != NULL) {\r
+    *TempString = CHAR_NULL;\r
+    TempString  += 2;\r
+    TempSize = StrSize(TempString);\r
+    CopyMem(PathToReturn+StrLen(PathToReturn), TempString, TempSize);\r
+  }\r
+  if ((TempString = StrStr(PathToReturn, L"\\.")) != NULL && *(TempString + 2) == CHAR_NULL) {\r
+    *TempString = CHAR_NULL;\r
+  }\r
+  return (PathToReturn);\r
+}\r
+\r