summaryrefslogtreecommitdiff
path: root/ShellPkg
diff options
context:
space:
mode:
authorjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>2011-06-30 22:58:53 +0000
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>2011-06-30 22:58:53 +0000
commitab94587a7d2cd89695f9190420daceae0d2b7446 (patch)
treed736759dc8ce225a8c7d1aa699703e6ca37a4a7e /ShellPkg
parentf1518f69703e1086f346a6e9d8e5a59855954178 (diff)
downloadedk2-platforms-ab94587a7d2cd89695f9190420daceae0d2b7446.tar.xz
This refactors 3 functions out of ShellCommandLib and puts them into a new library (but as 2 functions instead of 3). This allows for users outside of the shell itself to have access to these functions.
1) Remove the 3 functions out of the shell's internal library (ShellCommandLib) 2) Add a new library class (PathLib) 3) Add an instance of this class (BasePathLib) 4) Change all internal shell callers to use this new library class. signed-off-by: jcarsey reviewed-by: jljusten git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11936 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'ShellPkg')
-rw-r--r--ShellPkg/Application/Shell/FileHandleWrappers.c2
-rw-r--r--ShellPkg/Application/Shell/Shell.c2
-rw-r--r--ShellPkg/Application/Shell/Shell.h1
-rw-r--r--ShellPkg/Application/Shell/Shell.inf3
-rw-r--r--ShellPkg/Application/Shell/ShellProtocol.c12
-rw-r--r--ShellPkg/Include/Library/PathLib.h56
-rw-r--r--ShellPkg/Include/Library/ShellCommandLib.h45
-rw-r--r--ShellPkg/Library/BasePathLib/BasePathLib.c122
-rw-r--r--ShellPkg/Library/BasePathLib/BasePathLib.inf38
-rw-r--r--ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c106
-rw-r--r--ShellPkg/Library/UefiShellLevel1CommandsLib/If.c6
-rw-r--r--ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.inf1
-rw-r--r--ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c6
-rw-r--r--ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c4
-rw-r--r--ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c2
-rw-r--r--ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c4
-rw-r--r--ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c2
-rw-r--r--ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.h1
-rw-r--r--ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.inf1
-rw-r--r--ShellPkg/ShellPkg.dec3
-rw-r--r--ShellPkg/ShellPkg.dsc1
21 files changed, 245 insertions, 173 deletions
diff --git a/ShellPkg/Application/Shell/FileHandleWrappers.c b/ShellPkg/Application/Shell/FileHandleWrappers.c
index 3cadc41e0b..22e8c71d12 100644
--- a/ShellPkg/Application/Shell/FileHandleWrappers.c
+++ b/ShellPkg/Application/Shell/FileHandleWrappers.c
@@ -522,7 +522,7 @@ FileInterfaceStdInRead(
}
StrCat(TabStr, L"*");
FoundFileList = NULL;
-// TabStr = CleanPath(TabStr);
+// TabStr = PathCleanUpDirectories(TabStr);
Status = ShellInfoObject.NewEfiShellProtocol->FindFiles(TabStr, &FoundFileList);
for ( TempStr = CurrentString
; *TempStr == L' '
diff --git a/ShellPkg/Application/Shell/Shell.c b/ShellPkg/Application/Shell/Shell.c
index ae4c0606e3..452c65588b 100644
--- a/ShellPkg/Application/Shell/Shell.c
+++ b/ShellPkg/Application/Shell/Shell.c
@@ -859,7 +859,7 @@ DoStartupScript(
*TempSpot = CHAR_NULL;
}
FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, ((FILEPATH_DEVICE_PATH*)FilePath)->PathName, 0);
- ChopLastSlash(FileStringPath);
+ PathRemoveLastItem(FileStringPath);
FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, mStartupScript, 0);
Status = ShellInfoObject.NewEfiShellProtocol->OpenFileByName(FileStringPath, &FileHandle, EFI_FILE_MODE_READ);
FreePool(FileStringPath);
diff --git a/ShellPkg/Application/Shell/Shell.h b/ShellPkg/Application/Shell/Shell.h
index 51ec4f3a4b..e79c5481f3 100644
--- a/ShellPkg/Application/Shell/Shell.h
+++ b/ShellPkg/Application/Shell/Shell.h
@@ -44,6 +44,7 @@
#include <Library/HiiLib.h>
#include <Library/PrintLib.h>
#include <Library/HandleParsingLib.h>
+#include <Library/PathLib.h>
#include "ShellParametersProtocol.h"
#include "ShellProtocol.h"
diff --git a/ShellPkg/Application/Shell/Shell.inf b/ShellPkg/Application/Shell/Shell.inf
index f873fdaf6c..756e84137e 100644
--- a/ShellPkg/Application/Shell/Shell.inf
+++ b/ShellPkg/Application/Shell/Shell.inf
@@ -1,7 +1,7 @@
## @file
# This is the shell application
#
-# Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
@@ -69,6 +69,7 @@
HiiLib
SortLib
HandleParsingLib
+ PathLib
[Guids]
gShellVariableGuid # ALWAYS_CONSUMED
diff --git a/ShellPkg/Application/Shell/ShellProtocol.c b/ShellPkg/Application/Shell/ShellProtocol.c
index f0416ca937..e42f081834 100644
--- a/ShellPkg/Application/Shell/ShellProtocol.c
+++ b/ShellPkg/Application/Shell/ShellProtocol.c
@@ -529,7 +529,7 @@ EfiShellGetDevicePathFromFilePath(
StrCpy(NewPath, Cwd);
if (*Path == L'\\') {
Path++;
- while (ChopLastSlash(NewPath)) ;
+ while (PathRemoveLastItem(NewPath)) ;
}
StrCat(NewPath, Path);
DevicePathForReturn = EfiShellGetDevicePathFromFilePath(NewPath);
@@ -2232,7 +2232,7 @@ EfiShellFindFiles(
}
StrCpy(PatternCopy, FilePattern);
- PatternCopy = CleanPath(PatternCopy);
+ PatternCopy = PathCleanUpDirectories(PatternCopy);
Count = StrStr(PatternCopy, L":") - PatternCopy;
Count += 2;
@@ -2293,7 +2293,7 @@ EfiShellOpenFileList(
CONST CHAR16 *CurDir;
BOOLEAN Found;
- ShellCommandCleanPath(Path);
+ PathCleanUpDirectories(Path);
Path2Size = 0;
Path2 = NULL;
@@ -2315,7 +2315,7 @@ EfiShellOpenFileList(
StrnCatGrow(&Path2, &Path2Size, CurDir, 0);
if (*Path == L'\\') {
Path++;
- while (ChopLastSlash(Path2)) ;
+ while (PathRemoveLastItem(Path2)) ;
}
ASSERT((Path2 == NULL && Path2Size == 0) || (Path2 != NULL));
StrnCatGrow(&Path2, &Path2Size, Path, 0);
@@ -2324,7 +2324,7 @@ EfiShellOpenFileList(
StrnCatGrow(&Path2, NULL, Path, 0);
}
- CleanPath (Path2);
+ PathCleanUpDirectories (Path2);
//
// do the search
@@ -2677,7 +2677,7 @@ EfiShellSetCurDir(
DirectoryName = StrnCatGrow(&DirectoryName, NULL, Dir, 0);
ASSERT(DirectoryName != NULL);
- CleanPath(DirectoryName);
+ PathCleanUpDirectories(DirectoryName);
if (FileSystem == NULL) {
//
diff --git a/ShellPkg/Include/Library/PathLib.h b/ShellPkg/Include/Library/PathLib.h
new file mode 100644
index 0000000000..912b1f14b0
--- /dev/null
+++ b/ShellPkg/Include/Library/PathLib.h
@@ -0,0 +1,56 @@
+/** @file
+ Provides interface to path manipulation functions.
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+
+#ifndef _PATH_LIB_
+#define _PATH_LIB_
+
+#include <Base.h>
+#include <Library/BaseMemoryLib.h>
+
+/**
+ Removes the last directory or file entry in a path by changing the last
+ L'\' to a CHAR_NULL.
+
+ @param[in,out] Path The pointer to the path to modify.
+
+ @retval FALSE Nothing was found to remove.
+ @retval TRUE A directory or file was removed.
+**/
+BOOLEAN
+EFIAPI
+PathRemoveLastItem(
+ IN OUT CHAR16 *Path
+ );
+
+/**
+ Function to clean up paths.
+
+ - Single periods in the path are removed.
+ - Double periods in the path are removed along with a single parent directory.
+ - Forward slashes L'/' are converted to backward slashes L'\'.
+
+ This will be done inline and the existing buffer may be larger than required
+ upon completion.
+
+ @param[in] Path The pointer to the string containing the path.
+
+ @retval NULL An error occured.
+ @return Path in all other instances.
+**/
+CHAR16*
+EFIAPI
+PathCleanUpDirectories(
+ IN CHAR16 *Path
+ );
+
+#endif //_PATH_LIB_
diff --git a/ShellPkg/Include/Library/ShellCommandLib.h b/ShellPkg/Include/Library/ShellCommandLib.h
index 027c0caad5..e998ac51b9 100644
--- a/ShellPkg/Include/Library/ShellCommandLib.h
+++ b/ShellPkg/Include/Library/ShellCommandLib.h
@@ -573,20 +573,6 @@ ShellCommandCreateInitialMappingsAndPaths(
);
/**
- Function to standardize the directory indicators to \ characters.
-
- @param[in,out] Path The pointer to the path string to fix.
-
- @retval NULL The operation failed.
- @return The Path pointer.
-**/
-CHAR16*
-EFIAPI
-ShellCommandCleanPath (
- IN OUT CHAR16 *Path
- );
-
-/**
Converts a SHELL_FILE_HANDLE to an EFI_FILE_PROTOCOL*.
@param[in] Handle The SHELL_FILE_HANDLE to convert.
@@ -734,35 +720,4 @@ FreeBufferList (
IN BUFFER_LIST *List
);
-/**
- Chops off last directory or file entry in a path by changing the last '\' to a CHAR_NULL
-
- @param[in,out] PathToReturn The pointer to the path to modify.
-
- @retval FALSE No directory was found to chop off.
- @retval TRUE A directory was chopped off.
-**/
-BOOLEAN
-EFIAPI
-ChopLastSlash(
- IN OUT CHAR16 *PathToReturn
- );
-
-/**
- Function to clean up paths. Removes the following items:
- single periods in the path (no need for the current directory tag)
- double periods in the path and removes a single parent directory.
-
- This will be done inline and the resultant string may be be 'too big'.
-
- @param[in] PathToReturn The pointer to the string containing the path.
-
- @return PathToReturn is always returned.
-**/
-CHAR16*
-EFIAPI
-CleanPath(
- IN CHAR16 *PathToReturn
- );
-
#endif //_SHELL_COMMAND_LIB_
diff --git a/ShellPkg/Library/BasePathLib/BasePathLib.c b/ShellPkg/Library/BasePathLib/BasePathLib.c
new file mode 100644
index 0000000000..53a2a095b5
--- /dev/null
+++ b/ShellPkg/Library/BasePathLib/BasePathLib.c
@@ -0,0 +1,122 @@
+/** @file
+ Provides interface to path manipulation functions.
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+
+#include <Base.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/PathLib.h>
+#include <Library/BaseLib.h>
+
+/**
+ Removes the last directory or file entry in a path by changing the last
+ L'\' to a CHAR_NULL.
+
+ @param[in,out] Path The pointer to the path to modify.
+
+ @retval FALSE Nothing was found to remove.
+ @retval TRUE A directory or file was removed.
+**/
+BOOLEAN
+EFIAPI
+PathRemoveLastItem(
+ IN OUT CHAR16 *Path
+ )
+{
+ CHAR16 *Walker;
+ CHAR16 *LastSlash;
+ //
+ // get directory name from path... ('chop' off extra)
+ //
+ for ( Walker = Path, LastSlash = NULL
+ ; Walker != NULL && *Walker != CHAR_NULL
+ ; Walker++
+ ){
+ if (*Walker == L'\\' && *(Walker + 1) != CHAR_NULL) {
+ LastSlash = Walker+1;
+ }
+ }
+ if (LastSlash != NULL) {
+ *LastSlash = CHAR_NULL;
+ return (TRUE);
+ }
+ return (FALSE);
+}
+
+/**
+ Function to clean up paths.
+
+ - Single periods in the path are removed.
+ - Double periods in the path are removed along with a single parent directory.
+ - Forward slashes L'/' are converted to backward slashes L'\'.
+
+ This will be done inline and the existing buffer may be larger than required
+ upon completion.
+
+ @param[in] Path The pointer to the string containing the path.
+
+ @retval NULL An error occured.
+ @return Path in all other instances.
+**/
+CHAR16*
+EFIAPI
+PathCleanUpDirectories(
+ IN CHAR16 *Path
+ )
+{
+ CHAR16 *TempString;
+ UINTN TempSize;
+ if (Path==NULL) {
+ return(NULL);
+ }
+
+ //
+ // Fix up the / vs \
+ //
+ for (TempString = Path ; TempString != NULL && *TempString != CHAR_NULL ; TempString++) {
+ if (*TempString == L'/') {
+ *TempString = L'\\';
+ }
+ }
+
+ //
+ // Fix up the ..
+ //
+ while ((TempString = StrStr(Path, L"\\..\\")) != NULL) {
+ *TempString = CHAR_NULL;
+ TempString += 4;
+ PathRemoveLastItem(Path);
+ TempSize = StrSize(TempString);
+ CopyMem(Path+StrLen(Path), TempString, TempSize);
+ }
+ if ((TempString = StrStr(Path, L"\\..")) != NULL && *(TempString + 3) == CHAR_NULL) {
+ *TempString = CHAR_NULL;
+ PathRemoveLastItem(Path);
+ }
+
+ //
+ // Fix up the .
+ //
+ while ((TempString = StrStr(Path, L"\\.\\")) != NULL) {
+ *TempString = CHAR_NULL;
+ TempString += 2;
+ TempSize = StrSize(TempString);
+ CopyMem(Path+StrLen(Path), TempString, TempSize);
+ }
+ if ((TempString = StrStr(Path, L"\\.")) != NULL && *(TempString + 2) == CHAR_NULL) {
+ *TempString = CHAR_NULL;
+ }
+
+
+
+ return (Path);
+}
+
diff --git a/ShellPkg/Library/BasePathLib/BasePathLib.inf b/ShellPkg/Library/BasePathLib/BasePathLib.inf
new file mode 100644
index 0000000000..a9bd6a8e45
--- /dev/null
+++ b/ShellPkg/Library/BasePathLib/BasePathLib.inf
@@ -0,0 +1,38 @@
+## @file
+# Provides interface to path manipulation functions.
+#
+# Copyright (c) 2011, Intel Corporation. All rights reserved. <BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010006
+ BASE_NAME = BasePathLib
+ FILE_GUID = ED244F93-B97A-4a17-83E0-A03CF2A7F7B4
+ MODULE_TYPE = UEFI_DRIVER
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = PathLib|UEFI_APPLICATION UEFI_DRIVER
+
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+
+[Sources.common]
+ BasePathLib.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ ShellPkg/ShellPkg.dec
+
+
+[LibraryClasses]
+ BaseMemoryLib
+ BaseLib \ No newline at end of file
diff --git a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
index 82a9e78ed5..28b7dda51e 100644
--- a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
+++ b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
@@ -1123,30 +1123,6 @@ ShellCommandCreateInitialMappingsAndPaths(
}
/**
- Function to make sure all directory delimeters are backslashes.
-
- @param[in,out] Path The path to modify.
-
- @return Path.
-**/
-CHAR16*
-EFIAPI
-ShellCommandCleanPath (
- IN OUT CHAR16 *Path
- )
-{
- CHAR16 *Path2;
-
- for (Path2 = Path ; Path2 != NULL && *Path2 != CHAR_NULL ; Path2++) {
- if (*Path2 == L'/') {
- *Path2 = L'\\';
- }
- }
-
- return (Path);
-}
-
-/**
Converts a SHELL_FILE_HANDLE to an EFI_FILE_PROTOCOL*.
@param[in] Handle The SHELL_FILE_HANDLE to convert.
@@ -1489,85 +1465,3 @@ FreeBufferList (
}
}
-/**
- Chops off last directory or file entry in a path leaving the trailing slash
-
- @param[in,out] PathToReturn The path to modify.
-
- @retval FALSE No directory was found to chop off.
- @retval TRUE A directory was chopped off.
-**/
-BOOLEAN
-EFIAPI
-ChopLastSlash(
- IN OUT CHAR16 *PathToReturn
- )
-{
- CHAR16 *Walker;
- CHAR16 *LastSlash;
- //
- // get directory name from path... ('chop' off extra)
- //
- for ( Walker = PathToReturn, LastSlash = NULL
- ; Walker != NULL && *Walker != CHAR_NULL
- ; Walker++
- ){
- if (*Walker == L'\\' && *(Walker + 1) != CHAR_NULL) {
- LastSlash = Walker+1;
- }
- }
- if (LastSlash != NULL) {
- *LastSlash = CHAR_NULL;
- return (TRUE);
- }
- return (FALSE);
-}
-
-/**
- Function to clean up paths. Removes the following items:
- single periods in the path (no need for the current directory tag)
- double periods in the path and removes a single parent directory.
-
- This will be done inline and the resultant string may be be 'too big'.
-
- @param[in] PathToReturn The pointer to the string containing the path.
-
- @return PathToReturn is always returned.
-**/
-CHAR16*
-EFIAPI
-CleanPath(
- IN CHAR16 *PathToReturn
- )
-{
- CHAR16 *TempString;
- UINTN TempSize;
- if (PathToReturn==NULL) {
- return(NULL);
- }
- //
- // Fix up the directory name
- //
- while ((TempString = StrStr(PathToReturn, L"\\..\\")) != NULL) {
- *TempString = CHAR_NULL;
- TempString += 4;
- ChopLastSlash(PathToReturn);
- TempSize = StrSize(TempString);
- CopyMem(PathToReturn+StrLen(PathToReturn), TempString, TempSize);
- }
- if ((TempString = StrStr(PathToReturn, L"\\..")) != NULL && *(TempString + 3) == CHAR_NULL) {
- *TempString = CHAR_NULL;
- ChopLastSlash(PathToReturn);
- }
- while ((TempString = StrStr(PathToReturn, L"\\.\\")) != NULL) {
- *TempString = CHAR_NULL;
- TempString += 2;
- TempSize = StrSize(TempString);
- CopyMem(PathToReturn+StrLen(PathToReturn), TempString, TempSize);
- }
- if ((TempString = StrStr(PathToReturn, L"\\.")) != NULL && *(TempString + 2) == CHAR_NULL) {
- *TempString = CHAR_NULL;
- }
- return (PathToReturn);
-}
-
diff --git a/ShellPkg/Library/UefiShellLevel1CommandsLib/If.c b/ShellPkg/Library/UefiShellLevel1CommandsLib/If.c
index 62c713e589..b7f423ff4d 100644
--- a/ShellPkg/Library/UefiShellLevel1CommandsLib/If.c
+++ b/ShellPkg/Library/UefiShellLevel1CommandsLib/If.c
@@ -14,6 +14,7 @@
#include "UefiShellLevel1CommandsLib.h"
#include <Library/PrintLib.h>
+#include <Library/PathLib.h>
typedef enum {
EndTagOr,
@@ -95,10 +96,7 @@ IsValidProfile (
CONST CHAR16 *TempLocation;
ProfilesString = ShellGetEnvironmentVariable(L"profiles");
- //
- // According to the Shell spec this is a required environment variable.
- //
- ASSERT(ProfileString != NULL);
+ ASSERT(ProfilesString != NULL);
TempLocation = StrStr(ProfilesString, String);
if ((TempLocation != NULL) && (*(TempLocation-1) == L';') && (*(TempLocation+StrLen(String)) == L';')) {
return (TRUE);
diff --git a/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.inf b/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.inf
index 8b04b7d369..3a62cc3c8e 100644
--- a/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.inf
+++ b/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.inf
@@ -50,6 +50,7 @@
UefiBootServicesTableLib
SortLib
PrintLib
+ PathLib
[Pcd.common]
gEfiShellPkgTokenSpaceGuid.PcdShellSupportLevel # ALWAYS_CONSUMED
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c
index bee4b0ae43..82d1c39df0 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c
@@ -108,7 +108,7 @@ ShellCommandRunCd (
ShellStatus = SHELL_NOT_FOUND;
} else {
Drive = GetFullyQualifiedPath(Directory);
- ChopLastSlash(Drive);
+ PathRemoveLastItem(Drive);
}
if (ShellStatus == SHELL_SUCCESS && Drive != NULL) {
//
@@ -130,7 +130,7 @@ ShellCommandRunCd (
ShellStatus = SHELL_NOT_FOUND;
} else {
Drive = GetFullyQualifiedPath(Directory);
- while (ChopLastSlash(Drive)) ;
+ while (PathRemoveLastItem(Drive)) ;
}
if (ShellStatus == SHELL_SUCCESS && Drive != NULL) {
//
@@ -150,7 +150,7 @@ ShellCommandRunCd (
ASSERT((Drive == NULL && DriveSize == 0) || (Drive != NULL));
Drive = StrnCatGrow(&Drive, &DriveSize, ShellGetCurrentDir(NULL), 0);
if (*Param1 == L'\\') {
- while (ChopLastSlash(Drive)) ;
+ while (PathRemoveLastItem(Drive)) ;
Drive = StrnCatGrow(&Drive, &DriveSize, Param1+1, 0);
} else {
Drive = StrnCatGrow(&Drive, &DriveSize, Param1, 0);
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c
index 8b30ac3122..08f5514cf5 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c
@@ -416,7 +416,7 @@ ValidateAndCopyFiles(
break;
}
- CleanPath(DestPath);
+ PathCleanUpDirectories(DestPath);
ShellPrintEx(-1, -1, HiiOutput, Node->FullName, DestPath);
@@ -619,7 +619,7 @@ ShellCommandRunCp (
// now copy them all...
//
if (FileList != NULL && !IsListEmpty(&FileList->Link)) {
- ShellStatus = ProcessValidateAndCopyFiles(FileList, ShellCommandCleanPath((CHAR16*)ShellCommandLineGetRawValue(Package, ParamCount)), SilentMode, RecursiveMode);
+ ShellStatus = ProcessValidateAndCopyFiles(FileList, PathCleanUpDirectories((CHAR16*)ShellCommandLineGetRawValue(Package, ParamCount)), SilentMode, RecursiveMode);
Status = ShellCloseFileMetaArg(&FileList);
if (EFI_ERROR(Status) && ShellStatus == SHELL_SUCCESS) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_FILE), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, ParamCount), ShellStatus|MAX_BIT);
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c
index ac71350ef4..a93b54c429 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c
@@ -67,7 +67,7 @@ PrintLsOutput(
CorrectedPath = StrnCatGrow(&CorrectedPath, NULL, Path, 0);
ASSERT(CorrectedPath != NULL);
- ShellCommandCleanPath(CorrectedPath);
+ PathCleanUpDirectories(CorrectedPath);
Status = ShellOpenFileMetaArg((CHAR16*)CorrectedPath, EFI_FILE_MODE_READ, &ListHead);
if (EFI_ERROR(Status)) {
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c
index dc9ef64d7f..5afcea2310 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c
@@ -148,7 +148,7 @@ GetDestinationLocation(
return (SHELL_OUT_OF_RESOURCES);
}
StrCpy(DestPath, Cwd);
- while (ChopLastSlash(DestPath)) ;
+ while (PathRemoveLastItem(DestPath)) ;
*DestPathPointer = DestPath;
return (SHELL_SUCCESS);
}
@@ -268,7 +268,7 @@ ValidateAndMoveFiles(
if (ShellStatus != SHELL_SUCCESS) {
return (ShellStatus);
}
- DestPath = CleanPath(DestPath);
+ DestPath = PathCleanUpDirectories(DestPath);
HiiOutput = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_MV_OUTPUT), NULL);
HiiResultOk = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_GEN_RES_OK), NULL);
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c
index fed233c33a..ce3d87ba50 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c
@@ -196,7 +196,7 @@ GetFullyQualifiedPath(
}
StrnCatGrow(&PathToReturn, &Size, Path, 0);
- CleanPath(PathToReturn);
+ PathCleanUpDirectories(PathToReturn);
while (PathToReturn[StrLen(PathToReturn)-1] == L'*') {
PathToReturn[StrLen(PathToReturn)-1] = CHAR_NULL;
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.h b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.h
index 49e187fc7a..80f6d59ee9 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.h
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.h
@@ -46,6 +46,7 @@
#include <Library/HiiLib.h>
#include <Library/SortLib.h>
#include <Library/FileHandleLib.h>
+#include <Library/PathLib.h>
extern CONST CHAR16 mFileName[];
extern EFI_HANDLE gShellLevel2HiiHandle;
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.inf b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.inf
index 8b618b1f5f..52dc28feb2 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.inf
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.inf
@@ -64,6 +64,7 @@
PcdLib
HiiLib
HandleParsingLib
+ PathLib
[Protocols]
gEfiUnicodeCollation2ProtocolGuid # ALWAYS_CONSUMED
diff --git a/ShellPkg/ShellPkg.dec b/ShellPkg/ShellPkg.dec
index c8fd048334..e83b6cf504 100644
--- a/ShellPkg/ShellPkg.dec
+++ b/ShellPkg/ShellPkg.dec
@@ -41,6 +41,9 @@
## @libraryclass Provides advanced parsing functions
HandleParsingLib|Include/Library/HandleParsingLib.h
+
+ ## @libraryclass Provides path manipulation functions
+ PathLib|Include/Library/PathLib.h
[Guids]
gEfiShellEnvironment2ExtGuid = {0xd2c18636, 0x40e5, 0x4eb5, {0xa3, 0x1b, 0x36, 0x69, 0x5f, 0xd4, 0x2c, 0x87}}
diff --git a/ShellPkg/ShellPkg.dsc b/ShellPkg/ShellPkg.dsc
index 6ac336179c..6b641155f2 100644
--- a/ShellPkg/ShellPkg.dsc
+++ b/ShellPkg/ShellPkg.dsc
@@ -48,6 +48,7 @@
HandleParsingLib|ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.inf
PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf
+ PathLib|ShellPkg/Library/BasePathLib/BasePathLib.inf
[LibraryClasses.ARM]
#