/** @file\r
Provides interface to shell functionality for shell commands and applications.\r
\r
-Copyright (c) 2006 - 2009, Intel Corporation\r
+Copyright (c) 2006 - 2009, Intel Corporation<BR>\r
All rights reserved. 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
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_SUCCESS);\r
}\r
\r
+/**\r
+ Internal worker function to output a string.\r
+\r
+ This function will output a string to the correct StdOut.\r
+\r
+ @param[in] String The string to print out.\r
+\r
+ @retval EFI_SUCCESS The operation was sucessful.\r
+ @retval !EFI_SUCCESS The operation failed.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InternalPrintTo (\r
+ IN CONST CHAR16 *String\r
+ )\r
+{\r
+ UINTN Size;\r
+ Size = StrSize(String) - sizeof(CHAR16);\r
+ if (mEfiShellParametersProtocol != NULL) {\r
+ return (mEfiShellParametersProtocol->StdOut->Write(mEfiShellParametersProtocol->StdOut, &Size, (VOID*)String));\r
+ }\r
+ if (mEfiShellInterface != NULL) {\r
+ return ( mEfiShellInterface->StdOut->Write(mEfiShellInterface->StdOut, &Size, (VOID*)String));\r
+ }\r
+ ASSERT(FALSE);\r
+ return (EFI_UNSUPPORTED);\r
+}\r
+\r
/**\r
Print at a specific location on the screen.\r
\r
CHAR16 *ResumeLocation;\r
CHAR16 *FormatWalker;\r
\r
- BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);\r
+ BufferSize = PcdGet16 (PcdShellLibMaxPrintBufferSize);\r
+ ASSERT(PcdGet16 (PcdShellLibMaxPrintBufferSize) < PcdGet32 (PcdMaximumUnicodeStringLength));\r
PostReplaceFormat = AllocateZeroPool (BufferSize);\r
ASSERT (PostReplaceFormat != NULL);\r
PostReplaceFormat2 = AllocateZeroPool (BufferSize);\r
//\r
// print the current FormatWalker string\r
//\r
- Status = gST->ConOut->OutputString(gST->ConOut, FormatWalker);\r
+ Status = InternalPrintTo(FormatWalker);\r
ASSERT_EFI_ERROR(Status);\r
//\r
// update the attribute\r
gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_GREEN, ((NormalAttribute&(BIT4|BIT5|BIT6))>>4)));\r
break;\r
default:\r
- ASSERT(FALSE);\r
+ //\r
+ // Print a simple '%' symbol\r
+ //\r
+ Status = InternalPrintTo(L"%");\r
+ ASSERT_EFI_ERROR(Status);\r
+ ResumeLocation = ResumeLocation - 1;\r
break;\r
}\r
} else {\r
/**\r
Print at a specific location on the screen.\r
\r
- This function will move the cursor to a given screen location and print the specified string\r
+ This function will move the cursor to a given screen location and print the specified string.\r
\r
If -1 is specified for either the Row or Col the current screen location for BOTH \r
will be used.\r
\r
- if either Row or Col is out of range for the current console, then ASSERT\r
- if Format is NULL, then ASSERT\r
+ If either Row or Col is out of range for the current console, then ASSERT.\r
+ If Format is NULL, then ASSERT.\r
\r
In addition to the standard %-based flags as supported by UefiLib Print() this supports \r
the following additional flags:\r
) \r
{\r
VA_LIST Marker;\r
+ EFI_STATUS Status;\r
VA_START (Marker, Format);\r
- return (InternalShellPrintWorker(Col, Row, Format, Marker));\r
+ Status = InternalShellPrintWorker(Col, Row, Format, Marker);\r
+ VA_END(Marker);\r
+ return(Status);\r
}\r
\r
/**\r
Print at a specific location on the screen.\r
\r
- This function will move the cursor to a given screen location, print the specified string, \r
- and return the cursor to the original locaiton. \r
+ This function will move the cursor to a given screen location and print the specified string.\r
\r
If -1 is specified for either the Row or Col the current screen location for BOTH \r
- will be used and the cursor's position will not be moved back to an original location.\r
+ will be used.\r
\r
- if either Row or Col is out of range for the current console, then ASSERT\r
- if Format is NULL, then ASSERT\r
+ If either Row or Col is out of range for the current console, then ASSERT.\r
+ If Format is NULL, then ASSERT.\r
\r
In addition to the standard %-based flags as supported by UefiLib Print() this supports \r
the following additional flags:\r
RetVal = InternalShellPrintWorker(Col, Row, HiiFormatString, Marker);\r
\r
FreePool(HiiFormatString);\r
+ VA_END(Marker);\r
\r
return (RetVal);\r
}\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