]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c
This refactors 3 functions out of ShellCommandLib and puts them into a new library...
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel2CommandsLib / Cd.c
index 78403c22748bae815907aed756d1dd99a02a9047..82d1c39df0cdffea0b5bf35db0bbf4bc7e0139e7 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main file for attrib shell level 2 function.\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
@@ -108,7 +108,7 @@ ShellCommandRunCd (
           ShellStatus = SHELL_NOT_FOUND;\r
         } else {\r
           Drive = GetFullyQualifiedPath(Directory);\r
-          ChopLastSlash(Drive);\r
+          PathRemoveLastItem(Drive);\r
         }\r
         if (ShellStatus == SHELL_SUCCESS && Drive != NULL) {\r
           //\r
@@ -130,7 +130,7 @@ ShellCommandRunCd (
           ShellStatus = SHELL_NOT_FOUND;\r
         } else {\r
           Drive = GetFullyQualifiedPath(Directory);\r
-          while (ChopLastSlash(Drive)) ;\r
+          while (PathRemoveLastItem(Drive)) ;\r
         }\r
         if (ShellStatus == SHELL_SUCCESS && Drive != NULL) {\r
           //\r
@@ -150,7 +150,7 @@ ShellCommandRunCd (
           ASSERT((Drive == NULL && DriveSize == 0) || (Drive != NULL));\r
           Drive = StrnCatGrow(&Drive, &DriveSize, ShellGetCurrentDir(NULL), 0);\r
           if (*Param1 == L'\\') {\r
-            while (ChopLastSlash(Drive)) ;\r
+            while (PathRemoveLastItem(Drive)) ;\r
             Drive = StrnCatGrow(&Drive, &DriveSize, Param1+1, 0);\r
           } else {\r
             Drive = StrnCatGrow(&Drive, &DriveSize, Param1, 0);\r
@@ -186,17 +186,33 @@ ShellCommandRunCd (
         // change directory on other drive letter\r
         //\r
         Drive = AllocateZeroPool(StrSize(Param1));\r
-        Drive = StrCpy(Drive, Param1);\r
-        Path = StrStr(Drive, L":");\r
-        *(++Path) = CHAR_NULL;\r
-        Status = gEfiShellProtocol->SetCurDir(Drive, ++Path);\r
-\r
-        if (Status == EFI_NOT_FOUND) {\r
-          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r
-          Status = SHELL_NOT_FOUND;\r
-        } else if (EFI_ERROR(Status)) {\r
-          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, Param1);\r
-          Status = SHELL_NOT_FOUND;\r
+        if (Drive == NULL) {\r
+          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellLevel2HiiHandle);\r
+          ShellStatus = SHELL_OUT_OF_RESOURCES;\r
+        } else {\r
+          Drive = StrCpy(Drive, Param1);\r
+          Path = StrStr(Drive, L":");\r
+          ASSERT(Path != NULL);\r
+          if (*(Path+1) == CHAR_NULL) {\r
+            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r
+            ShellStatus = SHELL_NOT_FOUND;\r
+          } else {\r
+            *(Path+1) = CHAR_NULL;\r
+            if (Path == Drive + StrLen(Drive)) {\r
+              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r
+              ShellStatus = SHELL_NOT_FOUND;\r
+            } else {\r
+              Status = gEfiShellProtocol->SetCurDir(Drive, Path+2);\r
+              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_PRINT), gShellLevel2HiiHandle, ShellGetCurrentDir(Drive));\r
+            }\r
+          }\r
+          if (Status == EFI_NOT_FOUND) {\r
+            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r
+            Status = SHELL_NOT_FOUND;\r
+          } else if (EFI_ERROR(Status)) {\r
+            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, Param1);\r
+            Status = SHELL_NOT_FOUND;\r
+          }\r
         }\r
       }\r
     }\r