}\r
StrCat(TabStr, L"*");\r
FoundFileList = NULL;\r
-// TabStr = CleanPath(TabStr);\r
+// TabStr = PathCleanUpDirectories(TabStr);\r
Status = ShellInfoObject.NewEfiShellProtocol->FindFiles(TabStr, &FoundFileList);\r
for ( TempStr = CurrentString\r
; *TempStr == L' '\r
*TempSpot = CHAR_NULL;\r
}\r
FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, ((FILEPATH_DEVICE_PATH*)FilePath)->PathName, 0);\r
- ChopLastSlash(FileStringPath);\r
+ PathRemoveLastItem(FileStringPath);\r
FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, mStartupScript, 0);\r
Status = ShellInfoObject.NewEfiShellProtocol->OpenFileByName(FileStringPath, &FileHandle, EFI_FILE_MODE_READ);\r
FreePool(FileStringPath);\r
#include <Library/HiiLib.h>\r
#include <Library/PrintLib.h>\r
#include <Library/HandleParsingLib.h>\r
+#include <Library/PathLib.h>\r
\r
#include "ShellParametersProtocol.h"\r
#include "ShellProtocol.h"\r
## @file\r
# This is the shell application\r
#\r
-# Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
#\r
# This program and the accompanying materials\r
# are licensed and made available under the terms and conditions of the BSD License\r
HiiLib\r
SortLib\r
HandleParsingLib\r
+ PathLib\r
\r
[Guids]\r
gShellVariableGuid # ALWAYS_CONSUMED\r
StrCpy(NewPath, Cwd);\r
if (*Path == L'\\') {\r
Path++;\r
- while (ChopLastSlash(NewPath)) ;\r
+ while (PathRemoveLastItem(NewPath)) ;\r
}\r
StrCat(NewPath, Path);\r
DevicePathForReturn = EfiShellGetDevicePathFromFilePath(NewPath);\r
}\r
StrCpy(PatternCopy, FilePattern);\r
\r
- PatternCopy = CleanPath(PatternCopy);\r
+ PatternCopy = PathCleanUpDirectories(PatternCopy);\r
\r
Count = StrStr(PatternCopy, L":") - PatternCopy;\r
Count += 2;\r
CONST CHAR16 *CurDir;\r
BOOLEAN Found;\r
\r
- ShellCommandCleanPath(Path);\r
+ PathCleanUpDirectories(Path);\r
\r
Path2Size = 0;\r
Path2 = NULL;\r
StrnCatGrow(&Path2, &Path2Size, CurDir, 0);\r
if (*Path == L'\\') {\r
Path++;\r
- while (ChopLastSlash(Path2)) ;\r
+ while (PathRemoveLastItem(Path2)) ;\r
}\r
ASSERT((Path2 == NULL && Path2Size == 0) || (Path2 != NULL));\r
StrnCatGrow(&Path2, &Path2Size, Path, 0);\r
StrnCatGrow(&Path2, NULL, Path, 0);\r
}\r
\r
- CleanPath (Path2);\r
+ PathCleanUpDirectories (Path2);\r
\r
//\r
// do the search\r
DirectoryName = StrnCatGrow(&DirectoryName, NULL, Dir, 0);\r
ASSERT(DirectoryName != NULL);\r
\r
- CleanPath(DirectoryName);\r
+ PathCleanUpDirectories(DirectoryName);\r
\r
if (FileSystem == NULL) {\r
//\r
--- /dev/null
+/** @file\r
+ Provides interface to path manipulation functions.\r
+\r
+ Copyright (c) 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
+**/\r
+\r
+#ifndef _PATH_LIB_\r
+#define _PATH_LIB_\r
+\r
+#include <Base.h>\r
+#include <Library/BaseMemoryLib.h>\r
+\r
+/**\r
+ Removes the last directory or file entry in a path by changing the last\r
+ L'\' to a CHAR_NULL.\r
+\r
+ @param[in,out] Path The pointer to the path to modify.\r
+\r
+ @retval FALSE Nothing was found to remove.\r
+ @retval TRUE A directory or file was removed.\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+PathRemoveLastItem(\r
+ IN OUT CHAR16 *Path\r
+ );\r
+\r
+/**\r
+ Function to clean up paths. \r
+ \r
+ - Single periods in the path are removed.\r
+ - Double periods in the path are removed along with a single parent directory.\r
+ - Forward slashes L'/' are converted to backward slashes L'\'.\r
+\r
+ This will be done inline and the existing buffer may be larger than required \r
+ upon completion.\r
+\r
+ @param[in] Path The pointer to the string containing the path.\r
+\r
+ @retval NULL An error occured.\r
+ @return Path in all other instances.\r
+**/\r
+CHAR16*\r
+EFIAPI\r
+PathCleanUpDirectories(\r
+ IN CHAR16 *Path\r
+ );\r
+\r
+#endif //_PATH_LIB_\r
VOID\r
);\r
\r
-/**\r
- Function to standardize the directory indicators to \ characters.\r
-\r
- @param[in,out] Path The pointer to the path string to fix.\r
-\r
- @retval NULL The operation failed.\r
- @return The Path pointer.\r
-**/\r
-CHAR16*\r
-EFIAPI\r
-ShellCommandCleanPath (\r
- IN OUT CHAR16 *Path\r
- );\r
-\r
/**\r
Converts a SHELL_FILE_HANDLE to an EFI_FILE_PROTOCOL*.\r
\r
IN BUFFER_LIST *List\r
);\r
\r
-/**\r
- Chops off last directory or file entry in a path by changing the last '\' to a CHAR_NULL\r
-\r
- @param[in,out] PathToReturn The pointer to the path to modify.\r
-\r
- @retval FALSE No directory was found to chop off.\r
- @retval TRUE A directory was chopped off.\r
-**/\r
-BOOLEAN\r
-EFIAPI\r
-ChopLastSlash(\r
- IN OUT CHAR16 *PathToReturn\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
#endif //_SHELL_COMMAND_LIB_\r
--- /dev/null
+/** @file\r
+ Provides interface to path manipulation functions.\r
+\r
+ Copyright (c) 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
+**/\r
+\r
+#include <Base.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/PathLib.h>\r
+#include <Library/BaseLib.h>\r
+\r
+/**\r
+ Removes the last directory or file entry in a path by changing the last\r
+ L'\' to a CHAR_NULL.\r
+\r
+ @param[in,out] Path The pointer to the path to modify.\r
+\r
+ @retval FALSE Nothing was found to remove.\r
+ @retval TRUE A directory or file was removed.\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+PathRemoveLastItem(\r
+ IN OUT CHAR16 *Path\r
+ )\r
+{\r
+ CHAR16 *Walker;\r
+ CHAR16 *LastSlash;\r
+ //\r
+ // get directory name from path... ('chop' off extra)\r
+ //\r
+ for ( Walker = Path, LastSlash = NULL\r
+ ; Walker != NULL && *Walker != CHAR_NULL\r
+ ; Walker++\r
+ ){\r
+ if (*Walker == L'\\' && *(Walker + 1) != CHAR_NULL) {\r
+ LastSlash = Walker+1;\r
+ }\r
+ }\r
+ if (LastSlash != NULL) {\r
+ *LastSlash = CHAR_NULL;\r
+ return (TRUE);\r
+ }\r
+ return (FALSE);\r
+}\r
+\r
+/**\r
+ Function to clean up paths. \r
+ \r
+ - Single periods in the path are removed.\r
+ - Double periods in the path are removed along with a single parent directory.\r
+ - Forward slashes L'/' are converted to backward slashes L'\'.\r
+\r
+ This will be done inline and the existing buffer may be larger than required \r
+ upon completion.\r
+\r
+ @param[in] Path The pointer to the string containing the path.\r
+\r
+ @retval NULL An error occured.\r
+ @return Path in all other instances.\r
+**/\r
+CHAR16*\r
+EFIAPI\r
+PathCleanUpDirectories(\r
+ IN CHAR16 *Path\r
+ )\r
+{\r
+ CHAR16 *TempString;\r
+ UINTN TempSize;\r
+ if (Path==NULL) {\r
+ return(NULL);\r
+ }\r
+\r
+ //\r
+ // Fix up the / vs \\r
+ //\r
+ for (TempString = Path ; TempString != NULL && *TempString != CHAR_NULL ; TempString++) {\r
+ if (*TempString == L'/') {\r
+ *TempString = L'\\';\r
+ }\r
+ }\r
+\r
+ //\r
+ // Fix up the ..\r
+ //\r
+ while ((TempString = StrStr(Path, L"\\..\\")) != NULL) {\r
+ *TempString = CHAR_NULL;\r
+ TempString += 4;\r
+ PathRemoveLastItem(Path);\r
+ TempSize = StrSize(TempString);\r
+ CopyMem(Path+StrLen(Path), TempString, TempSize);\r
+ }\r
+ if ((TempString = StrStr(Path, L"\\..")) != NULL && *(TempString + 3) == CHAR_NULL) {\r
+ *TempString = CHAR_NULL;\r
+ PathRemoveLastItem(Path);\r
+ }\r
+\r
+ //\r
+ // Fix up the .\r
+ //\r
+ while ((TempString = StrStr(Path, L"\\.\\")) != NULL) {\r
+ *TempString = CHAR_NULL;\r
+ TempString += 2;\r
+ TempSize = StrSize(TempString);\r
+ CopyMem(Path+StrLen(Path), TempString, TempSize);\r
+ }\r
+ if ((TempString = StrStr(Path, L"\\.")) != NULL && *(TempString + 2) == CHAR_NULL) {\r
+ *TempString = CHAR_NULL;\r
+ }\r
+\r
+\r
+\r
+ return (Path);\r
+}\r
+\r
--- /dev/null
+## @file\r
+# Provides interface to path manipulation functions.\r
+#\r
+# Copyright (c) 2011, Intel Corporation. All rights reserved. <BR>\r
+#\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
+# 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
+#\r
+#\r
+##\r
+\r
+[Defines]\r
+ INF_VERSION = 0x00010006\r
+ BASE_NAME = BasePathLib\r
+ FILE_GUID = ED244F93-B97A-4a17-83E0-A03CF2A7F7B4\r
+ MODULE_TYPE = UEFI_DRIVER\r
+ VERSION_STRING = 1.0\r
+ LIBRARY_CLASS = PathLib|UEFI_APPLICATION UEFI_DRIVER\r
+\r
+#\r
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources.common]\r
+ BasePathLib.c\r
+\r
+[Packages]\r
+ MdePkg/MdePkg.dec\r
+ ShellPkg/ShellPkg.dec\r
+ \r
+\r
+[LibraryClasses]\r
+ BaseMemoryLib\r
+ BaseLib
\ No newline at end of file
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
- IN OUT CHAR16 *Path\r
- )\r
-{\r
- CHAR16 *Path2;\r
-\r
- for (Path2 = Path ; Path2 != NULL && *Path2 != CHAR_NULL ; Path2++) {\r
- if (*Path2 == L'/') {\r
- *Path2 = L'\\';\r
- }\r
- }\r
-\r
- return (Path);\r
-}\r
-\r
/**\r
Converts a SHELL_FILE_HANDLE to an EFI_FILE_PROTOCOL*.\r
\r
}\r
}\r
\r
-/**\r
- Chops off last directory or file entry in a path leaving the trailing slash\r
-\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
-**/\r
-BOOLEAN\r
-EFIAPI\r
-ChopLastSlash(\r
- IN OUT CHAR16 *PathToReturn\r
- )\r
-{\r
- CHAR16 *Walker;\r
- CHAR16 *LastSlash;\r
- //\r
- // get directory name from path... ('chop' off extra)\r
- //\r
- for ( Walker = PathToReturn, LastSlash = NULL\r
- ; Walker != NULL && *Walker != CHAR_NULL\r
- ; Walker++\r
- ){\r
- if (*Walker == L'\\' && *(Walker + 1) != CHAR_NULL) {\r
- LastSlash = Walker+1;\r
- }\r
- }\r
- if (LastSlash != NULL) {\r
- *LastSlash = CHAR_NULL;\r
- return (TRUE);\r
- }\r
- 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
\r
#include "UefiShellLevel1CommandsLib.h"\r
#include <Library/PrintLib.h>\r
+#include <Library/PathLib.h>\r
\r
typedef enum {\r
EndTagOr,\r
CONST CHAR16 *TempLocation;\r
\r
ProfilesString = ShellGetEnvironmentVariable(L"profiles");\r
- //\r
- // According to the Shell spec this is a required environment variable.\r
- //\r
- ASSERT(ProfileString != NULL);\r
+ ASSERT(ProfilesString != NULL);\r
TempLocation = StrStr(ProfilesString, String);\r
if ((TempLocation != NULL) && (*(TempLocation-1) == L';') && (*(TempLocation+StrLen(String)) == L';')) {\r
return (TRUE);\r
UefiBootServicesTableLib\r
SortLib\r
PrintLib\r
+ PathLib\r
\r
[Pcd.common]\r
gEfiShellPkgTokenSpaceGuid.PcdShellSupportLevel # ALWAYS_CONSUMED\r
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
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
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
break;\r
}\r
\r
- CleanPath(DestPath);\r
+ PathCleanUpDirectories(DestPath);\r
\r
ShellPrintEx(-1, -1, HiiOutput, Node->FullName, DestPath);\r
\r
// now copy them all...\r
//\r
if (FileList != NULL && !IsListEmpty(&FileList->Link)) {\r
- ShellStatus = ProcessValidateAndCopyFiles(FileList, ShellCommandCleanPath((CHAR16*)ShellCommandLineGetRawValue(Package, ParamCount)), SilentMode, RecursiveMode);\r
+ ShellStatus = ProcessValidateAndCopyFiles(FileList, PathCleanUpDirectories((CHAR16*)ShellCommandLineGetRawValue(Package, ParamCount)), SilentMode, RecursiveMode);\r
Status = ShellCloseFileMetaArg(&FileList);\r
if (EFI_ERROR(Status) && ShellStatus == SHELL_SUCCESS) {\r
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_FILE), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, ParamCount), ShellStatus|MAX_BIT);\r
\r
CorrectedPath = StrnCatGrow(&CorrectedPath, NULL, Path, 0);\r
ASSERT(CorrectedPath != NULL);\r
- ShellCommandCleanPath(CorrectedPath);\r
+ PathCleanUpDirectories(CorrectedPath);\r
\r
Status = ShellOpenFileMetaArg((CHAR16*)CorrectedPath, EFI_FILE_MODE_READ, &ListHead);\r
if (EFI_ERROR(Status)) {\r
return (SHELL_OUT_OF_RESOURCES);\r
}\r
StrCpy(DestPath, Cwd);\r
- while (ChopLastSlash(DestPath)) ;\r
+ while (PathRemoveLastItem(DestPath)) ;\r
*DestPathPointer = DestPath;\r
return (SHELL_SUCCESS);\r
}\r
if (ShellStatus != SHELL_SUCCESS) {\r
return (ShellStatus);\r
}\r
- DestPath = CleanPath(DestPath);\r
+ DestPath = PathCleanUpDirectories(DestPath);\r
\r
HiiOutput = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_MV_OUTPUT), NULL);\r
HiiResultOk = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_GEN_RES_OK), NULL);\r
}\r
StrnCatGrow(&PathToReturn, &Size, Path, 0);\r
\r
- CleanPath(PathToReturn);\r
+ PathCleanUpDirectories(PathToReturn);\r
\r
while (PathToReturn[StrLen(PathToReturn)-1] == L'*') {\r
PathToReturn[StrLen(PathToReturn)-1] = CHAR_NULL;\r
#include <Library/HiiLib.h>\r
#include <Library/SortLib.h>\r
#include <Library/FileHandleLib.h>\r
+#include <Library/PathLib.h>\r
\r
extern CONST CHAR16 mFileName[];\r
extern EFI_HANDLE gShellLevel2HiiHandle;\r
PcdLib\r
HiiLib\r
HandleParsingLib\r
+ PathLib\r
\r
[Protocols]\r
gEfiUnicodeCollation2ProtocolGuid # ALWAYS_CONSUMED\r
\r
## @libraryclass Provides advanced parsing functions\r
HandleParsingLib|Include/Library/HandleParsingLib.h\r
+ \r
+ ## @libraryclass Provides path manipulation functions\r
+ PathLib|Include/Library/PathLib.h\r
\r
[Guids]\r
gEfiShellEnvironment2ExtGuid = {0xd2c18636, 0x40e5, 0x4eb5, {0xa3, 0x1b, 0x36, 0x69, 0x5f, 0xd4, 0x2c, 0x87}}\r
HandleParsingLib|ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.inf\r
\r
PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf\r
+ PathLib|ShellPkg/Library/BasePathLib/BasePathLib.inf\r
\r
[LibraryClasses.ARM]\r
#\r