\r
If CheckPackage is NULL, then return NULL.\r
\r
- @param CheckPackage The package of parsed command line arguments.\r
- @param KeyString The Key of the command line argument to check for.\r
+ @param[in] CheckPackage The package of parsed command line arguments.\r
+ @param[in] KeyString The Key of the command line argument to check for.\r
\r
@retval NULL The flag is not on the command line.\r
@retval !=NULL Pointer to unicode string of the value.\r
\r
Raw value parameters are in the form of "value" in a specific position in the list.\r
\r
- If CheckPackage is NULL, then return NULL;\r
+ If CheckPackage is NULL, then return NULL.\r
\r
- @param CheckPackage The package of parsed command line arguments.\r
- @param Position The position of the value.\r
+ @param[in] CheckPackage The package of parsed command line arguments.\r
+ @param[in] Position The position of the value.\r
\r
@retval NULL The flag is not on the command line.\r
@retval !=NULL Pointer to unicode string of the value.\r
VOID\r
);\r
\r
+/**\r
+ Determins if a parameter is duplicated.\r
+\r
+ If Param is not NULL then it will point to a callee allocated string buffer \r
+ with the parameter value if a duplicate is found.\r
+\r
+ If CheckPackage is NULL, then ASSERT.\r
+\r
+ @param[in] CheckPackage The package of parsed command line arguments.\r
+ @param[out] Param Upon finding one, a pointer to the duplicated parameter.\r
+\r
+ @retval EFI_SUCCESS No parameters were duplicated.\r
+ @retval EFI_DEVICE_ERROR A duplicate was found.\r
+ **/\r
+EFI_STATUS\r
+EFIAPI\r
+ShellCommandLineCheckDuplicate (\r
+ IN CONST LIST_ENTRY *CheckPackage,\r
+ OUT CHAR16 **Param\r
+ );\r
+\r
/**\r
This function causes the shell library to initialize itself. If the shell library\r
is already initialized it will de-initialize all the current protocol poitners and\r
}\r
\r
typedef struct _EFI_SHELL_PARAMETERS_PROTOCOL {\r
-///\r
-/// Points to an Argc-element array of points to null-terminated strings containing\r
-/// the command-line parameters. The first entry in the array is always the full file\r
-/// path of the executable. Any quotation marks that were used to preserve\r
-/// whitespace have been removed.\r
-///\r
+ ///\r
+ /// Points to an Argc-element array of points to null-terminated strings containing\r
+ /// the command-line parameters. The first entry in the array is always the full file\r
+ /// path of the executable. Any quotation marks that were used to preserve\r
+ /// whitespace have been removed.\r
+ ///\r
CHAR16 **Argv;\r
\r
-///\r
-/// The number of elements in the Argv array.\r
-/// \r
+ ///\r
+ /// The number of elements in the Argv array.\r
+ /// \r
UINTN Argc;\r
\r
-///\r
-/// The file handle for the standard input for this executable. This may be different\r
-/// from the ConInHandle in the EFI_SYSTEM_TABLE.\r
-///\r
+ ///\r
+ /// The file handle for the standard input for this executable. This may be different\r
+ /// from the ConInHandle in the EFI_SYSTEM_TABLE.\r
+ ///\r
EFI_FILE_HANDLE StdIn;\r
\r
-///\r
-/// The file handle for the standard output for this executable. This may be different\r
-/// from the ConOutHandle in the EFI_SYSTEM_TABLE.\r
-///\r
+ ///\r
+ /// The file handle for the standard output for this executable. This may be different\r
+ /// from the ConOutHandle in the EFI_SYSTEM_TABLE.\r
+ ///\r
EFI_FILE_HANDLE StdOut;\r
\r
-///\r
-/// The file handle for the standard error output for this executable. This may be\r
-/// different from the StdErrHandle in the EFI_SYSTEM_TABLE.\r
-///\r
+ ///\r
+ /// The file handle for the standard error output for this executable. This may be\r
+ /// different from the StdErrHandle in the EFI_SYSTEM_TABLE.\r
+ ///\r
EFI_FILE_HANDLE StdErr;\r
} EFI_SHELL_PARAMETERS_PROTOCOL;\r
\r
CHAR16 *RetVal;\r
CHAR16 *TestPath;\r
CONST CHAR16 *Walker;\r
+ UINTN Size;\r
\r
RetVal = NULL;\r
\r
Path = ShellGetEnvironmentVariable(L"cwd");\r
if (Path != NULL) {\r
- TestPath = AllocateZeroPool((StrSize(Path) + StrSize(FileName)));\r
+ Size = StrSize(Path);\r
+ Size += StrSize(FileName);\r
+ TestPath = AllocateZeroPool(Size);\r
StrCpy(TestPath, Path);\r
StrCat(TestPath, FileName);\r
Status = ShellOpenFileByName(TestPath, &Handle, EFI_FILE_MODE_READ, 0);\r
}\r
Path = ShellGetEnvironmentVariable(L"path");\r
if (Path != NULL) {\r
- TestPath = AllocateZeroPool((StrSize(Path)+StrSize(FileName)));\r
+ Size = StrSize(Path);\r
+ Size += StrSize(FileName);\r
+ TestPath = AllocateZeroPool(Size);\r
Walker = (CHAR16*)Path; \r
do {\r
CopyMem(TestPath, Walker, StrSize(Walker));\r
return (mTotalParameterCount);\r
}\r
\r
+/**\r
+ Determins if a parameter is duplicated.\r
+\r
+ If Param is not NULL then it will point to a callee allocated string buffer \r
+ with the parameter value if a duplicate is found.\r
+\r
+ If CheckPackage is NULL, then ASSERT.\r
+\r
+ @param[in] CheckPackage The package of parsed command line arguments.\r
+ @param[out] Param Upon finding one, a pointer to the duplicated parameter.\r
+\r
+ @retval EFI_SUCCESS No parameters were duplicated.\r
+ @retval EFI_DEVICE_ERROR A duplicate was found.\r
+ **/\r
+EFI_STATUS\r
+EFIAPI\r
+ShellCommandLineCheckDuplicate (\r
+ IN CONST LIST_ENTRY *CheckPackage,\r
+ OUT CHAR16 **Param\r
+ )\r
+{\r
+ LIST_ENTRY *Node1;\r
+ LIST_ENTRY *Node2;\r
+ \r
+ ASSERT(CheckPackage != NULL);\r
+\r
+ for ( Node1 = GetFirstNode(CheckPackage) \r
+ ; !IsNull (CheckPackage, Node1) \r
+ ; Node1 = GetNextNode(CheckPackage, Node1) \r
+ ){\r
+ for ( Node2 = GetNextNode(CheckPackage, Node1) \r
+ ; !IsNull (CheckPackage, Node2) \r
+ ; Node2 = GetNextNode(CheckPackage, Node2) \r
+ ){\r
+ if (StrCmp(((SHELL_PARAM_PACKAGE*)Node1)->Name, ((SHELL_PARAM_PACKAGE*)Node2)->Name) == 0) {\r
+ if (Param != NULL) {\r
+ *Param = NULL;\r
+ *Param = StrnCatGrow(Param, NULL, ((SHELL_PARAM_PACKAGE*)Node1)->Name, 0);\r
+ }\r
+ return (EFI_DEVICE_ERROR);\r
+ }\r
+ }\r
+ }\r
+ return (EFI_SUCCESS);\r
+}\r
+\r
/**\r
This is a find and replace function. it will return the NewString as a copy of \r
SourceString with each instance of FindTarget replaced with ReplaceWith.\r
return (EFI_NOT_FOUND);\r
}\r
\r
+/**\r
+ Function to determine if a given filename represents a file.\r
+\r
+ @param[in] Name Path to file to test.\r
+\r
+ @retval EFI_SUCCESS The Path represents a file.\r
+ @retval EFI_NOT_FOUND The Path does not represent a file.\r
+ @retval other The path failed to open.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ShellIsFile(\r
+ IN CONST CHAR16 *Name\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_FILE_HANDLE Handle;\r
+\r
+ Handle = NULL;\r
+\r
+ Status = ShellOpenFileByName(Name, &Handle, EFI_FILE_MODE_READ, 0);\r
+ if (EFI_ERROR(Status)) {\r
+ return (Status);\r
+ }\r
+\r
+ if (FileHandleIsDirectory(Handle) != EFI_SUCCESS) {\r
+ ShellCloseFile(&Handle);\r
+ return (EFI_SUCCESS);\r
+ }\r
+ ShellCloseFile(&Handle);\r
+ return (EFI_NOT_FOUND);\r
+}\r
+\r
/**\r
Function to determine whether a string is decimal or hex representation of a number \r
and return the number converted from the string.\r