summaryrefslogtreecommitdiff
path: root/ShellPkg
diff options
context:
space:
mode:
Diffstat (limited to 'ShellPkg')
-rw-r--r--ShellPkg/Include/Library/ShellLib.h31
-rw-r--r--ShellPkg/Include/Protocol/EfiShell.h2
-rw-r--r--ShellPkg/Include/Protocol/EfiShellParameters.h42
-rw-r--r--ShellPkg/Library/UefiShellLib/UefiShellLib.c88
4 files changed, 134 insertions, 29 deletions
diff --git a/ShellPkg/Include/Library/ShellLib.h b/ShellPkg/Include/Library/ShellLib.h
index 617d90b692..96ec2648a1 100644
--- a/ShellPkg/Include/Library/ShellLib.h
+++ b/ShellPkg/Include/Library/ShellLib.h
@@ -718,8 +718,8 @@ ShellCommandLineGetFlag (
If CheckPackage is NULL, then return NULL.
- @param CheckPackage The package of parsed command line arguments.
- @param KeyString The Key of the command line argument to check for.
+ @param[in] CheckPackage The package of parsed command line arguments.
+ @param[in] KeyString The Key of the command line argument to check for.
@retval NULL The flag is not on the command line.
@retval !=NULL Pointer to unicode string of the value.
@@ -736,10 +736,10 @@ ShellCommandLineGetValue (
Raw value parameters are in the form of "value" in a specific position in the list.
- If CheckPackage is NULL, then return NULL;
+ If CheckPackage is NULL, then return NULL.
- @param CheckPackage The package of parsed command line arguments.
- @param Position The position of the value.
+ @param[in] CheckPackage The package of parsed command line arguments.
+ @param[in] Position The position of the value.
@retval NULL The flag is not on the command line.
@retval !=NULL Pointer to unicode string of the value.
@@ -766,6 +766,27 @@ ShellCommandLineGetCount(
);
/**
+ Determins if a parameter is duplicated.
+
+ If Param is not NULL then it will point to a callee allocated string buffer
+ with the parameter value if a duplicate is found.
+
+ If CheckPackage is NULL, then ASSERT.
+
+ @param[in] CheckPackage The package of parsed command line arguments.
+ @param[out] Param Upon finding one, a pointer to the duplicated parameter.
+
+ @retval EFI_SUCCESS No parameters were duplicated.
+ @retval EFI_DEVICE_ERROR A duplicate was found.
+ **/
+EFI_STATUS
+EFIAPI
+ShellCommandLineCheckDuplicate (
+ IN CONST LIST_ENTRY *CheckPackage,
+ OUT CHAR16 **Param
+ );
+
+/**
This function causes the shell library to initialize itself. If the shell library
is already initialized it will de-initialize all the current protocol poitners and
re-populate them again.
diff --git a/ShellPkg/Include/Protocol/EfiShell.h b/ShellPkg/Include/Protocol/EfiShell.h
index 92bb03fa5e..82d228187d 100644
--- a/ShellPkg/Include/Protocol/EfiShell.h
+++ b/ShellPkg/Include/Protocol/EfiShell.h
@@ -791,7 +791,7 @@ EFI_STATUS
If Alias is NULL, ReturnedData points to a ‘;’
delimited list of alias (e.g.
ReturnedData = “dir;del;copy;mfp”) that is null-terminated.
- @retval NULL an error ocurred.
+ @retval NULL An error ocurred.
@retval NULL Alias was not a valid Alias.
**/
typedef
diff --git a/ShellPkg/Include/Protocol/EfiShellParameters.h b/ShellPkg/Include/Protocol/EfiShellParameters.h
index 8f6658b6b5..dcf4b72ad3 100644
--- a/ShellPkg/Include/Protocol/EfiShellParameters.h
+++ b/ShellPkg/Include/Protocol/EfiShellParameters.h
@@ -21,35 +21,35 @@
}
typedef struct _EFI_SHELL_PARAMETERS_PROTOCOL {
-///
-/// Points to an Argc-element array of points to null-terminated strings containing
-/// the command-line parameters. The first entry in the array is always the full file
-/// path of the executable. Any quotation marks that were used to preserve
-/// whitespace have been removed.
-///
+ ///
+ /// Points to an Argc-element array of points to null-terminated strings containing
+ /// the command-line parameters. The first entry in the array is always the full file
+ /// path of the executable. Any quotation marks that were used to preserve
+ /// whitespace have been removed.
+ ///
CHAR16 **Argv;
-///
-/// The number of elements in the Argv array.
-///
+ ///
+ /// The number of elements in the Argv array.
+ ///
UINTN Argc;
-///
-/// The file handle for the standard input for this executable. This may be different
-/// from the ConInHandle in the EFI_SYSTEM_TABLE.
-///
+ ///
+ /// The file handle for the standard input for this executable. This may be different
+ /// from the ConInHandle in the EFI_SYSTEM_TABLE.
+ ///
EFI_FILE_HANDLE StdIn;
-///
-/// The file handle for the standard output for this executable. This may be different
-/// from the ConOutHandle in the EFI_SYSTEM_TABLE.
-///
+ ///
+ /// The file handle for the standard output for this executable. This may be different
+ /// from the ConOutHandle in the EFI_SYSTEM_TABLE.
+ ///
EFI_FILE_HANDLE StdOut;
-///
-/// The file handle for the standard error output for this executable. This may be
-/// different from the StdErrHandle in the EFI_SYSTEM_TABLE.
-///
+ ///
+ /// The file handle for the standard error output for this executable. This may be
+ /// different from the StdErrHandle in the EFI_SYSTEM_TABLE.
+ ///
EFI_FILE_HANDLE StdErr;
} EFI_SHELL_PARAMETERS_PROTOCOL;
diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.c b/ShellPkg/Library/UefiShellLib/UefiShellLib.c
index e52d1e7627..b1128ffc14 100644
--- a/ShellPkg/Library/UefiShellLib/UefiShellLib.c
+++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.c
@@ -1489,12 +1489,15 @@ ShellFindFilePath (
CHAR16 *RetVal;
CHAR16 *TestPath;
CONST CHAR16 *Walker;
+ UINTN Size;
RetVal = NULL;
Path = ShellGetEnvironmentVariable(L"cwd");
if (Path != NULL) {
- TestPath = AllocateZeroPool((StrSize(Path) + StrSize(FileName)));
+ Size = StrSize(Path);
+ Size += StrSize(FileName);
+ TestPath = AllocateZeroPool(Size);
StrCpy(TestPath, Path);
StrCat(TestPath, FileName);
Status = ShellOpenFileByName(TestPath, &Handle, EFI_FILE_MODE_READ, 0);
@@ -1508,7 +1511,9 @@ ShellFindFilePath (
}
Path = ShellGetEnvironmentVariable(L"path");
if (Path != NULL) {
- TestPath = AllocateZeroPool((StrSize(Path)+StrSize(FileName)));
+ Size = StrSize(Path);
+ Size += StrSize(FileName);
+ TestPath = AllocateZeroPool(Size);
Walker = (CHAR16*)Path;
do {
CopyMem(TestPath, Walker, StrSize(Walker));
@@ -2130,6 +2135,52 @@ ShellCommandLineGetCount(
}
/**
+ Determins if a parameter is duplicated.
+
+ If Param is not NULL then it will point to a callee allocated string buffer
+ with the parameter value if a duplicate is found.
+
+ If CheckPackage is NULL, then ASSERT.
+
+ @param[in] CheckPackage The package of parsed command line arguments.
+ @param[out] Param Upon finding one, a pointer to the duplicated parameter.
+
+ @retval EFI_SUCCESS No parameters were duplicated.
+ @retval EFI_DEVICE_ERROR A duplicate was found.
+ **/
+EFI_STATUS
+EFIAPI
+ShellCommandLineCheckDuplicate (
+ IN CONST LIST_ENTRY *CheckPackage,
+ OUT CHAR16 **Param
+ )
+{
+ LIST_ENTRY *Node1;
+ LIST_ENTRY *Node2;
+
+ ASSERT(CheckPackage != NULL);
+
+ for ( Node1 = GetFirstNode(CheckPackage)
+ ; !IsNull (CheckPackage, Node1)
+ ; Node1 = GetNextNode(CheckPackage, Node1)
+ ){
+ for ( Node2 = GetNextNode(CheckPackage, Node1)
+ ; !IsNull (CheckPackage, Node2)
+ ; Node2 = GetNextNode(CheckPackage, Node2)
+ ){
+ if (StrCmp(((SHELL_PARAM_PACKAGE*)Node1)->Name, ((SHELL_PARAM_PACKAGE*)Node2)->Name) == 0) {
+ if (Param != NULL) {
+ *Param = NULL;
+ *Param = StrnCatGrow(Param, NULL, ((SHELL_PARAM_PACKAGE*)Node1)->Name, 0);
+ }
+ return (EFI_DEVICE_ERROR);
+ }
+ }
+ }
+ return (EFI_SUCCESS);
+}
+
+/**
This is a find and replace function. it will return the NewString as a copy of
SourceString with each instance of FindTarget replaced with ReplaceWith.
@@ -2460,6 +2511,39 @@ ShellIsDirectory(
}
/**
+ Function to determine if a given filename represents a file.
+
+ @param[in] Name Path to file to test.
+
+ @retval EFI_SUCCESS The Path represents a file.
+ @retval EFI_NOT_FOUND The Path does not represent a file.
+ @retval other The path failed to open.
+**/
+EFI_STATUS
+EFIAPI
+ShellIsFile(
+ IN CONST CHAR16 *Name
+ )
+{
+ EFI_STATUS Status;
+ EFI_FILE_HANDLE Handle;
+
+ Handle = NULL;
+
+ Status = ShellOpenFileByName(Name, &Handle, EFI_FILE_MODE_READ, 0);
+ if (EFI_ERROR(Status)) {
+ return (Status);
+ }
+
+ if (FileHandleIsDirectory(Handle) != EFI_SUCCESS) {
+ ShellCloseFile(&Handle);
+ return (EFI_SUCCESS);
+ }
+ ShellCloseFile(&Handle);
+ return (EFI_NOT_FOUND);
+}
+
+/**
Function to determine whether a string is decimal or hex representation of a number
and return the number converted from the string.