updating headers from code review.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9449 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
jcarsey 2009-11-18 21:36:50 +00:00
parent b594c46658
commit 125c2cf4f1
13 changed files with 585 additions and 209 deletions

View File

@ -17,7 +17,7 @@
[Defines] [Defines]
INF_VERSION = 0x00010005 INF_VERSION = 0x00010005
BASE_NAME = SimpleApplication BASE_NAME = ShellLibTestApp
FILE_GUID = 10C75C00-3052-4467-9ED8-7196CAAF610F FILE_GUID = 10C75C00-3052-4467-9ED8-7196CAAF610F
MODULE_TYPE = UEFI_APPLICATION MODULE_TYPE = UEFI_APPLICATION
VERSION_STRING = 1.0 VERSION_STRING = 1.0

View File

@ -24,6 +24,8 @@
SHELL_PARAM_ITEM ParamList[] = { SHELL_PARAM_ITEM ParamList[] = {
{L"/Param1", TypeFlag}, {L"/Param1", TypeFlag},
{L"/Param2", TypeValue}, {L"/Param2", TypeValue},
{L"/Param3", TypeDoubleValue},
{L"/Param4", TypeMaxValue},
{NULL, TypeMax}}; {NULL, TypeMax}};
/** /**
@ -46,26 +48,47 @@ UefiMain (
EFI_FILE_HANDLE FileHandle; EFI_FILE_HANDLE FileHandle;
EFI_STATUS Status; EFI_STATUS Status;
CHAR16 FileName[100]; CHAR16 FileName[100];
UINTN BufferSize; // UINTN BufferSize;
UINT64 Position; // UINT64 Position;
UINT8 Buffer[200]; // UINT8 Buffer[200];
EFI_FILE_INFO *pFileInfo; EFI_FILE_INFO *pFileInfo;
UINT64 Size; UINT64 Size;
BOOLEAN NoFile; BOOLEAN NoFile;
EFI_SHELL_FILE_INFO *pShellFileInfo; EFI_SHELL_FILE_INFO *pShellFileInfo;
LIST_ENTRY *List; LIST_ENTRY *List;
CONST CHAR16 *Tester;
FileHandle = NULL; FileHandle = NULL;
StrCpy(FileName, L"testfile.txt"); StrCpy(FileName, L"testfile.txt");
Position = 0; // Position = 0;
pFileInfo = NULL; pFileInfo = NULL;
Size = 0; Size = 0;
NoFile = FALSE; NoFile = FALSE;
pShellFileInfo = NULL; pShellFileInfo = NULL;
List = NULL; List = NULL;
// command line param functions
Status = ShellCommandLineParse(ParamList, &List, NULL, FALSE);
// if you put an invalid parameter you SHOULD hit this assert.
ASSERT_EFI_ERROR(Status);
if (List) {
ASSERT(ShellCommandLineGetFlag(List, L"/Param5") == FALSE);
ASSERT(ShellCommandLineGetFlag(List, L"/Param1") != FALSE);
ASSERT(StrCmp(ShellCommandLineGetValue(List, L"/Param2"), L"Val1")==0);
ASSERT(StrCmp(ShellCommandLineGetRawValue(List, 0), L"SimpleApplication.efi")==0);
Tester = ShellCommandLineGetValue(List, L"/Param3");
Tester = ShellCommandLineGetValue(List, L"/Param4");
ShellCommandLineFreeVarList(List);
} else {
Print(L"param checking skipped.\r\n");
}
return (EFI_SUCCESS);
/*
ASSERT(ShellGetExecutionBreakFlag() == FALSE); ASSERT(ShellGetExecutionBreakFlag() == FALSE);
ASSERT(StrCmp(ShellGetCurrentDir(NULL), L"f8:\\") == 0); ASSERT(StrCmp(ShellGetCurrentDir(NULL), L"f10:\\") == 0);
Print(L"execution break and get cur dir - pass\r\n"); Print(L"execution break and get cur dir - pass\r\n");
ShellSetPageBreakMode(TRUE); ShellSetPageBreakMode(TRUE);
@ -253,7 +276,7 @@ UefiMain (
// get environment variable // get environment variable
// made for testing under nt32 // made for testing under nt32
ASSERT(StrCmp(ShellGetEnvironmentVariable(L"path"), L".;f8:\\efi\\tools;f8:\\efi\\boot;f8:\\;f9:\\efi\\tools;f9:\\efi\\boot;f9:\\") == 0); ASSERT(StrCmp(ShellGetEnvironmentVariable(L"path"), L".;f10:\\efi\\tools;f10:\\efi\\boot;f10:\\;f9:\\efi\\tools;f9:\\efi\\boot;f9:\\") == 0);
Print(L"ShellGetEnvironmentVariable - pass\r\n"); Print(L"ShellGetEnvironmentVariable - pass\r\n");
// set environment variable // set environment variable
@ -267,21 +290,6 @@ UefiMain (
// the pass printout for this is performed by EmptyApplication // the pass printout for this is performed by EmptyApplication
Print(L"\r\n"); Print(L"\r\n");
// command line param functions
Status = ShellCommandLineParse(ParamList, &List, NULL, FALSE);
// if you put an invalid parameter you SHOULD hit this assert.
ASSERT_EFI_ERROR(Status);
if (List) {
ASSERT(ShellCommandLineGetFlag(List, L"/Param5") == FALSE);
ASSERT(ShellCommandLineGetFlag(List, L"/Param1") != FALSE);
ASSERT(StrCmp(ShellCommandLineGetValue(List, L"/Param2"), L"Val1")==0);
ASSERT(StrCmp(ShellCommandLineGetRawValue(List, 0), L"SimpleApplication.efi")==0);
ShellCommandLineFreeVarList(List);
} else {
Print(L"param checking skipped.\r\n");
}
// page break mode (done last so we can see the results) // page break mode (done last so we can see the results)
// we set this true at the begining of the program // we set this true at the begining of the program
// this is enough lines to trigger the page... // this is enough lines to trigger the page...
@ -290,6 +298,7 @@ UefiMain (
Print(L"1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22\r\n23\r\n24\r\n25\r\n26\r\n27\r\n28\r\n29\r\n30\r\n31\r\n32\r\n33\r\n34\r\n35\r\n36\r\n37\r\n38\r\n39\r\n40\r\n41\r\n42\r\n43\r\n44\r\n45\r\n46\r\n47\r\n48\r\n49\r\n50\r\n51\r\n52\r\n53\r\n54\r\n55\r\n56\r\n57\r\n58\r\n59\r\n60\r\n"); Print(L"1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22\r\n23\r\n24\r\n25\r\n26\r\n27\r\n28\r\n29\r\n30\r\n31\r\n32\r\n33\r\n34\r\n35\r\n36\r\n37\r\n38\r\n39\r\n40\r\n41\r\n42\r\n43\r\n44\r\n45\r\n46\r\n47\r\n48\r\n49\r\n50\r\n51\r\n52\r\n53\r\n54\r\n55\r\n56\r\n57\r\n58\r\n59\r\n60\r\n");
return EFI_SUCCESS; return EFI_SUCCESS;
*/
} }

View File

@ -48,7 +48,8 @@ EFIAPI
ShellAppMain ( ShellAppMain (
IN UINTN Argc, IN UINTN Argc,
IN CHAR16 **Argv IN CHAR16 **Argv
){ )
{
INTN Array[10] = {2,3,4,1,5,6,7,8,1,5}; INTN Array[10] = {2,3,4,1,5,6,7,8,1,5};
Print(L"Array = %d, %d, %d, %d, %d, %d, %d, %d, %d, %d\r\n", Array[0],Array[1],Array[2],Array[3],Array[4],Array[5],Array[6],Array[7],Array[8],Array[9]); Print(L"Array = %d, %d, %d, %d, %d, %d, %d, %d, %d, %d\r\n", Array[0],Array[1],Array[2],Array[3],Array[4],Array[5],Array[6],Array[7],Array[8],Array[9]);
PerformQuickSort(Array, 10, sizeof(INTN), Test); PerformQuickSort(Array, 10, sizeof(INTN), Test);

View File

@ -1,5 +1,5 @@
/** @file /** @file
GUID for ShellPkg PCD Token Space GUID for ShellPkg PCD Token Space.
Copyright (c) 2009, Intel Corporation Copyright (c) 2009, Intel Corporation
All rights reserved. This program and the accompanying materials All rights reserved. This program and the accompanying materials
@ -15,10 +15,10 @@
#ifndef _SHELLPKG_TOKEN_SPACE_GUID_H_ #ifndef _SHELLPKG_TOKEN_SPACE_GUID_H_
#define _SHELLPKG_TOKEN_SPACE_GUID_H_ #define _SHELLPKG_TOKEN_SPACE_GUID_H_
#define SHELLPKG_TOKEN_SPACE_GUID \ #define EFI_SHELLPKG_TOKEN_SPACE_GUID \
{ \ { \
0x171e9188, 0x31d3, 0x40f5, { 0xb1, 0xc, 0x53, 0x9b, 0x2d, 0xb9, 0x40, 0xcd } \ 0x171e9188, 0x31d3, 0x40f5, { 0xb1, 0xc, 0x53, 0x9b, 0x2d, 0xb9, 0x40, 0xcd } \
}; }
extern EFI_GUID gEfiShellPkgTokenSpaceGuid; extern EFI_GUID gEfiShellPkgTokenSpaceGuid;

View File

@ -17,14 +17,14 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
specified and store it in allocated pool memory. specified and store it in allocated pool memory.
This function allocates a buffer to store the file's information. It is the This function allocates a buffer to store the file's information. It is the
caller's responsibility to free the buffer caller's responsibility to free the buffer.
@param FileHandle The file handle of the file for which information is @param FileHandle The file handle of the file for which information is
being requested. being requested.
@retval NULL information could not be retrieved. @retval NULL information could not be retrieved.
@return the information about the file @retval !NULL the information about the file
**/ **/
EFI_FILE_INFO* EFI_FILE_INFO*
EFIAPI EFIAPI
@ -37,12 +37,12 @@ FileHandleGetInfo (
specified. specified.
@param FileHandle The file handle of the file for which information @param FileHandle The file handle of the file for which information
is being set is being set.
@param FileInfo The infotmation to set. @param FileInfo The information to set.
@retval EFI_SUCCESS The information was set. @retval EFI_SUCCESS The information was set.
@retval EFI_UNSUPPORTED The InformationType is not known. @retval EFI_UNSUPPORTED The FileHandle does not support FileInfo.
@retval EFI_NO_MEDIA The device has no medium. @retval EFI_NO_MEDIA The device has no medium.
@retval EFI_DEVICE_ERROR The device reported an error. @retval EFI_DEVICE_ERROR The device reported an error.
@retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
@ -73,10 +73,10 @@ FileHandleSetInfo (
are no more directory entries, the read returns a zero-length buffer. are no more directory entries, the read returns a zero-length buffer.
EFI_FILE_INFO is the structure returned as the directory entry. EFI_FILE_INFO is the structure returned as the directory entry.
@param FileHandle the opened file handle @param FileHandle The opened file handle.
@param BufferSize on input the size of buffer in bytes. on return @param BufferSize On input the size of buffer in bytes. on return
the number of bytes written. the number of bytes written.
@param Buffer the buffer to put read data into. @param Buffer The buffer to put read data into.
@retval EFI_SUCCESS Data was read. @retval EFI_SUCCESS Data was read.
@retval EFI_NO_MEDIA The device has no media. @retval EFI_NO_MEDIA The device has no media.
@ -105,9 +105,9 @@ FileHandleRead(
opened directories are not supported. opened directories are not supported.
@param FileHandle The opened file for writing @param FileHandle The opened file for writing
@param BufferSize on input the number of bytes in Buffer. On output @param BufferSize On input the number of bytes in Buffer. On output
the number of bytes written. the number of bytes written.
@param Buffer the buffer containing data to write is stored. @param Buffer The buffer containing data to write is stored.
@retval EFI_SUCCESS Data was written. @retval EFI_SUCCESS Data was written.
@retval EFI_UNSUPPORTED Writes to an open directory are not supported. @retval EFI_UNSUPPORTED Writes to an open directory are not supported.
@ -133,9 +133,9 @@ FileHandleWrite(
flushed to the device, and the file is closed. In all cases the handle is flushed to the device, and the file is closed. In all cases the handle is
closed. closed.
@param FileHandle the file handle to close. @param FileHandle The file handle to close.
@retval EFI_SUCCESS the file handle was closed sucessfully. @retval EFI_SUCCESS The file handle was closed sucessfully.
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
@ -144,15 +144,15 @@ FileHandleClose (
); );
/** /**
Delete a file and close the handle Delete a file and close the handle.
This function closes and deletes a file. In all cases the file handle is closed. This function closes and deletes a file. In all cases the file handle is closed.
If the file cannot be deleted, the warning code EFI_WARN_DELETE_FAILURE is If the file cannot be deleted, the warning code EFI_WARN_DELETE_FAILURE is
returned, but the handle is still closed. returned, but the handle is still closed.
@param FileHandle the file handle to delete @param FileHandle The file handle to delete.
@retval EFI_SUCCESS the file was closed sucessfully @retval EFI_SUCCESS The file was closed sucessfully.
@retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not @retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not
deleted deleted
@retval INVALID_PARAMETER One of the parameters has an invalid value. @retval INVALID_PARAMETER One of the parameters has an invalid value.
@ -190,7 +190,7 @@ FileHandleSetPosition (
); );
/** /**
Gets a file's current position Gets a file's current position.
This function retrieves the current file position for the file handle. For This function retrieves the current file position for the file handle. For
directories, the current file position has no meaning outside of the file directories, the current file position has no meaning outside of the file
@ -211,11 +211,11 @@ FileHandleGetPosition (
OUT UINT64 *Position OUT UINT64 *Position
); );
/** /**
Flushes data on a file Flushes data on a file.
This function flushes all modified data associated with a file to a device. This function flushes all modified data associated with a file to a device.
@param FileHandle The file handle on which to flush data @param FileHandle The file handle on which to flush data.
@retval EFI_SUCCESS The data was flushed. @retval EFI_SUCCESS The data was flushed.
@retval EFI_NO_MEDIA The device has no media. @retval EFI_NO_MEDIA The device has no media.
@ -231,14 +231,14 @@ FileHandleFlush (
); );
/** /**
function to determine if a given handle is a directory handle Function to determine if a given handle is a directory handle.
if DirHandle is NULL then ASSERT() If DirHandle is NULL then ASSERT().
open the file information on the DirHandle and verify that the Attribute Open the file information on the DirHandle and verify that the Attribute
includes EFI_FILE_DIRECTORY bit set. includes EFI_FILE_DIRECTORY bit set.
@param DirHandle Handle to open file @param DirHandle Handle to open file.
@retval EFI_SUCCESS DirHandle is a directory @retval EFI_SUCCESS DirHandle is a directory
@retval EFI_INVALID_PARAMETER DirHandle did not have EFI_FILE_INFO available @retval EFI_INVALID_PARAMETER DirHandle did not have EFI_FILE_INFO available
@ -251,7 +251,7 @@ FileHandleIsDirectory (
); );
/** /**
Retrieves the first file from a directory Retrieves the first file from a directory.
This function opens a directory and gets the first file's info in the This function opens a directory and gets the first file's info in the
directory. Caller can use FileHandleFindNextFile() to get other files. When directory. Caller can use FileHandleFindNextFile() to get other files. When
@ -304,14 +304,14 @@ FileHandleFindNextFile(
/** /**
Retrieve the size of a file. Retrieve the size of a file.
if FileHandle is NULL then ASSERT() If FileHandle is NULL then ASSERT()
if Size is NULL then ASSERT() If Size is NULL then ASSERT()
This function extracts the file size info from the FileHandle's EFI_FILE_INFO This function extracts the file size info from the FileHandle's EFI_FILE_INFO
data. data.
@param FileHandle file handle from which size is retrieved @param FileHandle The file handle from which size is retrieved.
@param Size pointer to size @param Size pointer to size.
@retval EFI_SUCCESS operation was completed sucessfully @retval EFI_SUCCESS operation was completed sucessfully
@retval EFI_DEVICE_ERROR cannot access the file @retval EFI_DEVICE_ERROR cannot access the file
@ -327,10 +327,8 @@ FileHandleGetSize (
Function to get a full filename given a EFI_FILE_HANDLE somewhere lower on the Function to get a full filename given a EFI_FILE_HANDLE somewhere lower on the
directory 'stack'. directory 'stack'.
if Handle is NULL, return EFI_INVALID_PARAMETER
@param[in] Handle Handle to the Directory or File to create path to. @param[in] Handle Handle to the Directory or File to create path to.
@param[out] FullFileName pointer to pointer to generated full file name. It @param[out] FullFileName Pointer to pointer to generated full file name. It
is the responsibility of the caller to free this memory is the responsibility of the caller to free this memory
with a call to FreePool(). with a call to FreePool().
@retval EFI_SUCCESS the operation was sucessful and the FullFileName is valid. @retval EFI_SUCCESS the operation was sucessful and the FullFileName is valid.
@ -346,16 +344,16 @@ FileHandleGetFileName (
); );
/** /**
Function to read a single line (up to but not including the \n) from a file. Function to read a single line from a file. The \n is not included in the returned buffer.
@param[in] Handle FileHandle to read from @param[in] Handle FileHandle to read from.
@param[in,out] Buffer pointer to buffer to read into @param[in,out] Buffer Pointer to buffer to read into
@param[in,out] Size pointer to number of bytes in buffer @param[in,out] Size Pointer to number of bytes in buffer
@param[in[ Truncate if TRUE then allows for truncation of the line to fit. @param[in] Truncate If TRUE then allows for truncation of the line to fit.
if FALSE will reset the position to the begining of the If FALSE will reset the position to the begining of the
line if the buffer is not large enough. line if the buffer is not large enough.
@retval EFI_SUCCESS the operation was sucessful. the line is stored in @retval EFI_SUCCESS The operation was sucessful. the line is stored in
Buffer. (Size was NOT updated) Buffer. (Size was NOT updated)
@retval EFI_INVALID_PARAMETER Handle was NULL. @retval EFI_INVALID_PARAMETER Handle was NULL.
@retval EFI_INVALID_PARAMETER Buffer was NULL. @retval EFI_INVALID_PARAMETER Buffer was NULL.
@ -368,19 +366,19 @@ EFI_STATUS
EFIAPI EFIAPI
FileHandleReadLine( FileHandleReadLine(
IN EFI_FILE_HANDLE Handle, IN EFI_FILE_HANDLE Handle,
IN OUT VOID *Buffer, IN OUT CHAR16 *Buffer,
IN OUT UINTN *Size, IN OUT UINTN *Size,
IN BOOLEAN Truncate IN BOOLEAN Truncate
); );
/** /**
function to write a line of unicode text to a file. Function to write a line of unicode text to a file.
if Handle is NULL, ASSERT. If Handle is NULL, ASSERT.
if Buffer is NULL, do nothing. (return SUCCESS)
@param[in] Handle FileHandle to write to @param[in] Handle FileHandle to write to
@param[in] Buffer Buffer to write @param[in] Buffer Buffer to write, if NULL the function will
take no action and return EFI_SUCCESS.
@retval EFI_SUCCESS the data was written. @retval EFI_SUCCESS the data was written.
@retval other failure. @retval other failure.
@ -393,3 +391,39 @@ FileHandleWriteLine(
IN EFI_FILE_HANDLE Handle, IN EFI_FILE_HANDLE Handle,
IN CHAR16 *Buffer IN CHAR16 *Buffer
); );
/**
function to take a formatted argument and print it to a file.
@param[in] Handle the file handle for the file to write to
@param[in] Format the format argument (see printlib for format specifier)
@param[in] ... the variable arguments for the format
@retval EFI_SUCCESS the operation was sucessful
@return other a return value from FileHandleWriteLine
@sa FileHandleWriteLine
**/
EFI_STATUS
EFIAPI
FileHandlePrintLine(
IN EFI_FILE_HANDLE Handle,
IN CONST CHAR16 *Format,
...
);
/**
Function to determine if a FILE_HANDLE is at the end of the file.
This will NOT work on directories.
@param[in] Handle the file handle
@retval TRUE the position is at the end of the file
@retval FALSE the position is not at the end of the file
**/
BOOLEAN
EFIAPI
FileHandleEof(
IN EFI_FILE_HANDLE Handle
);

View File

@ -69,7 +69,7 @@ ShellSetFileInfo (
This function opens a file with the open mode according to the file path. The This function opens a file with the open mode according to the file path. The
Attributes is valid only for EFI_FILE_MODE_CREATE. Attributes is valid only for EFI_FILE_MODE_CREATE.
@param FilePath on input the device path to the file. On output @param FilePath On input the device path to the file. On output
the remaining device path. the remaining device path.
@param DeviceHandle pointer to the system device handle. @param DeviceHandle pointer to the system device handle.
@param FileHandle pointer to the file handle. @param FileHandle pointer to the file handle.
@ -148,8 +148,8 @@ ShellOpenFileByName(
otherwise, the Filehandle is NULL. If the directory already existed, this otherwise, the Filehandle is NULL. If the directory already existed, this
function opens the existing directory. function opens the existing directory.
@param DirectoryName pointer to Directory name @param DirectoryName Pointer to Directory name.
@param FileHandle pointer to the file handle. @param FileHandle Pointer to the file handle.
@retval EFI_SUCCESS The information was set. @retval EFI_SUCCESS The information was set.
@retval EFI_INVALID_PARAMETER One of the parameters has an invalid value. @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
@ -191,12 +191,10 @@ ShellCreateDirectory(
are no more directory entries, the read returns a zero-length buffer. are no more directory entries, the read returns a zero-length buffer.
EFI_FILE_INFO is the structure returned as the directory entry. EFI_FILE_INFO is the structure returned as the directory entry.
@param FileHandle the opened file handle @param FileHandle The opened file handle.
@param ReadSize On input the size of buffer in bytes. On return
@param ReadSize on input the size of buffer in bytes. on return
the number of bytes written. the number of bytes written.
@param Buffer The buffer to put read data into.
@param Buffer the buffer to put read data into.
@retval EFI_SUCCESS Data was read. @retval EFI_SUCCESS Data was read.
@retval EFI_NO_MEDIA The device has no media. @retval EFI_NO_MEDIA The device has no media.
@ -224,12 +222,12 @@ ShellReadFile(
The file is automatically grown to hold the data if required. Direct writes to The file is automatically grown to hold the data if required. Direct writes to
opened directories are not supported. opened directories are not supported.
@param FileHandle The opened file for writing @param FileHandle The opened file for writing.
@param BufferSize on input the number of bytes in Buffer. On output @param BufferSize On input the number of bytes in Buffer. On output
the number of bytes written. the number of bytes written.
@param Buffer the buffer containing data to write is stored. @param Buffer The buffer containing data to write is stored.
@retval EFI_SUCCESS Data was written. @retval EFI_SUCCESS Data was written.
@retval EFI_UNSUPPORTED Writes to an open directory are not supported. @retval EFI_UNSUPPORTED Writes to an open directory are not supported.
@ -255,9 +253,9 @@ ShellWriteFile(
flushed to the device, and the file is closed. In all cases the handle is flushed to the device, and the file is closed. In all cases the handle is
closed. closed.
@param FileHandle the file handle to close. @param FileHandle The file handle to close.
@retval EFI_SUCCESS the file handle was closed sucessfully. @retval EFI_SUCCESS The file handle was closed sucessfully.
@retval INVALID_PARAMETER One of the parameters has an invalid value. @retval INVALID_PARAMETER One of the parameters has an invalid value.
**/ **/
EFI_STATUS EFI_STATUS
@ -273,11 +271,11 @@ ShellCloseFile (
If the file cannot be deleted, the warning code EFI_WARN_DELETE_FAILURE is If the file cannot be deleted, the warning code EFI_WARN_DELETE_FAILURE is
returned, but the handle is still closed. returned, but the handle is still closed.
@param FileHandle the file handle to delete @param FileHandle The file handle to delete.
@retval EFI_SUCCESS the file was closed sucessfully @retval EFI_SUCCESS The file was closed sucessfully.
@retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not @retval EFI_WARN_DELETE_FAILURE The handle was closed, but the file was not
deleted deleted.
@retval INVALID_PARAMETER One of the parameters has an invalid value. @retval INVALID_PARAMETER One of the parameters has an invalid value.
**/ **/
EFI_STATUS EFI_STATUS
@ -414,11 +412,11 @@ ShellFindNextFile(
This function extracts the file size info from the FileHandle's EFI_FILE_INFO This function extracts the file size info from the FileHandle's EFI_FILE_INFO
data. data.
@param FileHandle file handle from which size is retrieved @param FileHandle The file handle from which size is retrieved.
@param Size pointer to size @param Size Pointer to size.
@retval EFI_SUCCESS operation was completed sucessfully @retval EFI_SUCCESS The operation was completed sucessfully.
@retval EFI_DEVICE_ERROR cannot access the file @retval EFI_DEVICE_ERROR cannot access the file.
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
@ -442,15 +440,15 @@ ShellGetExecutionBreakFlag(
); );
/** /**
return the value of an environment variable Return the value of an environment variable.
this function gets the value of the environment variable set by the This function gets the value of the environment variable set by the
ShellSetEnvironmentVariable function ShellSetEnvironmentVariable function.
@param EnvKey The key name of the environment variable. @param EnvKey The key name of the environment variable.
@retval NULL the named environment variable does not exist. @retval NULL the named environment variable does not exist.
@return != NULL pointer to the value of the environment variable @return != NULL pointer to the value of the environment variable.
**/ **/
CONST CHAR16* CONST CHAR16*
EFIAPI EFIAPI
@ -487,7 +485,7 @@ ShellSetEnvironmentVariable (
); );
/** /**
cause the shell to parse and execute a command line. Cause the shell to parse and execute a command line.
This function creates a nested instance of the shell and executes the specified This function creates a nested instance of the shell and executes the specified
command (CommandLine) with the specified environment (Environment). Upon return, command (CommandLine) with the specified environment (Environment). Upon return,
@ -543,9 +541,9 @@ ShellGetCurrentDir (
); );
/** /**
sets (enabled or disabled) the page break mode Sets (enabled or disabled) the page break mode.
when page break mode is enabled the screen will stop scrolling When page break mode is enabled the screen will stop scrolling
and wait for operator input before scrolling a subsequent screen. and wait for operator input before scrolling a subsequent screen.
@param CurrentState TRUE to enable and FALSE to disable @param CurrentState TRUE to enable and FALSE to disable
@ -563,21 +561,19 @@ ShellSetPageBreakMode (
file has a SHELL_FILE_ARG structure to record the file information. These file has a SHELL_FILE_ARG structure to record the file information. These
structures are placed on the list ListHead. Users can get the SHELL_FILE_ARG structures are placed on the list ListHead. Users can get the SHELL_FILE_ARG
structures from ListHead to access each file. This function supports wildcards structures from ListHead to access each file. This function supports wildcards
and will process '?' and '*' as such. the list must be freed with a call to and will process '?' and '*' as such. The list must be freed with a call to
ShellCloseFileMetaArg(). ShellCloseFileMetaArg().
If you are NOT appending to an existing list *ListHead must be NULL. If If you are NOT appending to an existing list *ListHead must be NULL. If
*ListHead is NULL then it must be callee freed. *ListHead is NULL then it must be callee freed.
@param Arg pointer to path string @param Arg Pointer to path string.
@param OpenMode mode to open files with @param OpenMode Mode to open files with.
@param ListHead head of linked list of results @param ListHead Head of linked list of results.
@retval EFI_SUCCESS the operation was sucessful and the list head @retval EFI_SUCCESS The operation was sucessful and the list head
contains the list of opened files contains the list of opened files.
#retval EFI_UNSUPPORTED a previous ShellOpenFileMetaArg must be closed first. @return != EFI_SUCCESS The operation failed.
*ListHead is set to NULL.
@return != EFI_SUCCESS the operation failed
@sa InternalShellConvertFileListType @sa InternalShellConvertFileListType
**/ **/
@ -603,11 +599,31 @@ ShellCloseFileMetaArg (
IN OUT EFI_SHELL_FILE_INFO **ListHead IN OUT EFI_SHELL_FILE_INFO **ListHead
); );
/**
Find a file by searching the CWD and then the path.
if FileName is NULL then ASSERT.
if the return value is not NULL then the memory must be caller freed.
@param FileName Filename string.
@retval NULL the file was not found
@return !NULL the path to the file.
**/
CHAR16 *
EFIAPI
ShellFindFilePath (
IN CONST CHAR16 *FileName
);
typedef enum { typedef enum {
TypeFlag = 0, TypeFlag = 0, /// a flag that is present or not present only. (IE "-a")
TypeValue, TypeValue, /// a flag that has some data following it with a space (IE "-a 1")
TypePosition, TypePosition, /// some data that did not follow a parameter (IE "filename.txt")
TypeStart, TypeStart, /// a flag that has variable value appended to the end (IE "-ad", "-afd", "-adf", etc...
TypeDoubleValue, /// a flag that has 2 space seperated value data following it. (IE "-a 1 2")
TypeMaxValue, /// a flag followed by all the command line data before the next flag.
TypeMax, TypeMax,
} ParamType; } ParamType;
@ -626,11 +642,11 @@ extern SHELL_PARAM_ITEM EmptyParamList[];
If no initialization is required, then return RETURN_SUCCESS. If no initialization is required, then return RETURN_SUCCESS.
@param CheckList pointer to list of parameters to check @param CheckList Pointer to list of parameters to check.
@param CheckPackage Package of checked values @param CheckPackage Package of checked values.
@param ProblemParam optional pointer to pointer to unicode string for @param ProblemParam Pptional pointer to pointer to unicode string for
the paramater that caused failure. the paramater that caused failure.
@param AutoPageBreak will automatically set PageBreakEnabled @param AutoPageBreak Will automatically set PageBreakEnabled.
@retval EFI_SUCCESS The operation completed sucessfully. @retval EFI_SUCCESS The operation completed sucessfully.
@retval EFI_OUT_OF_RESOURCES A memory allocation failed @retval EFI_OUT_OF_RESOURCES A memory allocation failed
@ -638,10 +654,10 @@ extern SHELL_PARAM_ITEM EmptyParamList[];
@retval EFI_VOLUME_CORRUPTED the command line was corrupt. an argument was @retval EFI_VOLUME_CORRUPTED the command line was corrupt. an argument was
duplicated. the duplicated command line argument duplicated. the duplicated command line argument
was returned in ProblemParam if provided. was returned in ProblemParam if provided.
@retval EFI_DEVICE_ERROR the commands contained 2 opposing arguments. one @retval EFI_DEVICE_ERROR The commands contained 2 opposing arguments. one
of the command line arguments was returned in of the command line arguments was returned in
ProblemParam if provided. ProblemParam if provided.
@retval EFI_NOT_FOUND a argument required a value that was missing. @retval EFI_NOT_FOUND A argument required a value that was missing.
the invalid command line argument was returned in the invalid command line argument was returned in
ProblemParam if provided. ProblemParam if provided.
**/ **/
@ -767,6 +783,7 @@ ShellCommandLineGetCount(
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
ShellInitialize ( ShellInitialize (
VOID
); );
/** /**
@ -861,5 +878,59 @@ ShellIsDirectory(
IN CONST CHAR16 *DirName IN CONST CHAR16 *DirName
); );
/**
Function to determine whether a string is decimal or hex representation of a number
and return the number converted from the string.
@param[in] String String representation of a number
@retval all the number
**/
UINTN
EFIAPI
ShellStrToUintn(
IN CONST CHAR16 *String
);
/**
Safely append with automatic string resizing given length of Destination and
desired length of copy from Source.
append the first D characters of Source to the end of Destination, where D is
the lesser of Count and the StrLen() of Source. If appending those D characters
will fit within Destination (whose Size is given as CurrentSize) and
still leave room for a null terminator, then those characters are appended,
starting at the original terminating null of Destination, and a new terminating
null is appended.
If appending D characters onto Destination will result in a overflow of the size
given in CurrentSize the string will be grown such that the copy can be performed
and CurrentSize will be updated to the new size.
If Source is NULL, there is nothing to append, just return the current buffer in
Destination.
if Destination is NULL, then ASSERT()
if Destination's current length (including NULL terminator) is already more then
CurrentSize, then ASSERT()
@param[in,out] Destination The String to append onto
@param[in,out] CurrentSize on call the number of bytes in Destination. On
return possibly the new size (still in bytes). if NULL
then allocate whatever is needed.
@param[in] Source The String to append from
@param[in] Count Maximum number of characters to append. if 0 then
all are appended.
@return Destination return the resultant string.
**/
CHAR16*
EFIAPI
StrnCatGrow (
IN OUT CHAR16 **Destination,
IN OUT UINTN *CurrentSize,
IN CONST CHAR16 *Source,
IN UINTN Count
);
#endif // __SHELL_LIB__ #endif // __SHELL_LIB__

View File

@ -1,5 +1,5 @@
/** @file /** @file
Library used for sorting routines. Library used for sorting and comparison routines.
Copyright (c) 2009, Intel Corporation Copyright (c) 2009, Intel Corporation
All rights reserved. This program and the accompanying materials All rights reserved. This program and the accompanying materials
@ -59,4 +59,20 @@ PerformQuickSort (
IN SORT_COMPARE CompareFunction IN SORT_COMPARE CompareFunction
); );
/**
Function to compare 2 device paths for use as CompareFunction.
@param[in] Buffer1 pointer to Device Path to compare
@param[in] Buffer2 pointer to second DevicePath to compare
@retval 0 Buffer1 equal to Buffer2
@return < 0 Buffer1 is less than Buffer2
@return > 0 Buffer1 is greater than Buffer2
**/
INTN
DevicePathCompare (
IN VOID *Buffer1,
IN VOID *Buffer2
);
#endif //__SORT_LIB_H__ #endif //__SORT_LIB_H__

View File

@ -26,12 +26,12 @@
// replaced EFI_LIST_ENTRY with LIST_ENTRY for simplicity. // replaced EFI_LIST_ENTRY with LIST_ENTRY for simplicity.
// they are identical outside of the name. // they are identical outside of the name.
typedef struct { typedef struct {
LIST_ENTRY Link; LIST_ENTRY Link; /// Linked list members
EFI_STATUS Status; EFI_STATUS Status; /// Status of opening the file. Valid only if Handle != NULL.
CONST CHAR16 *FullName; CONST CHAR16 *FullName; /// Fully qualified filename.
CONST CHAR16 *FileName; CONST CHAR16 *FileName; /// name of this file.
EFI_FILE_HANDLE Handle; EFI_FILE_HANDLE Handle; /// Handle for interacting with the opened file or NULL if closed.
EFI_FILE_INFO *Info; EFI_FILE_INFO *Info; /// Pointer to the FileInfo struct for this file or NULL.
} EFI_SHELL_FILE_INFO; } EFI_SHELL_FILE_INFO;
/** /**
Returns whether any script files are currently being processed. Returns whether any script files are currently being processed.
@ -85,7 +85,7 @@ EFI_STATUS
@retval EFI_SUCCESS The file was opened. FileHandle points to the new file's handle. @retval EFI_SUCCESS The file was opened. FileHandle points to the new file's handle.
@retval EFI_INVALID_PARAMETER One of the parameters has an invalid value. @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
@retval EFI_UNSUPPORTED could not open the file path @retval EFI_UNSUPPORTED could not open the file path
@retval EFI_NOT_FOUND the specified file could not be found on the devide, or could not @retval EFI_NOT_FOUND The specified file could not be found on the device, or could not
file the file system on the device. file the file system on the device.
@retval EFI_NO_MEDIA the device has no medium. @retval EFI_NO_MEDIA the device has no medium.
@retval EFI_MEDIA_CHANGED The device has a different medium in it or the medium is no @retval EFI_MEDIA_CHANGED The device has a different medium in it or the medium is no

View File

@ -12,6 +12,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/ **/
#if !defined(__SHELL_BASE__)
#define __SHELL_BASE__
typedef enum { typedef enum {
/// ///
/// The operation completed successfully. /// The operation completed successfully.
@ -140,3 +143,4 @@ SHELL_SECURITY_VIOLATION = 26,
SHELL_CRC_ERROR = 27 SHELL_CRC_ERROR = 27
}SHELL_STATUS; }SHELL_STATUS;
#endif //__SHELL_BASE__

View File

@ -17,7 +17,7 @@
INF_VERSION = 0x00010006 INF_VERSION = 0x00010006
BASE_NAME = BaseFileHandleLib BASE_NAME = BaseFileHandleLib
FILE_GUID = 9495D344-9D8A-41f3-8D17-E2FD238C4E71 FILE_GUID = 9495D344-9D8A-41f3-8D17-E2FD238C4E71
MODULE_TYPE = UEFI_DRIVER MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0 VERSION_STRING = 1.0
LIBRARY_CLASS = FileHandleLib|DXE_DRIVER UEFI_APPLICATION UEFI_DRIVER LIBRARY_CLASS = FileHandleLib|DXE_DRIVER UEFI_APPLICATION UEFI_DRIVER
@ -33,17 +33,18 @@
ShellPkg/ShellPkg.dec ShellPkg/ShellPkg.dec
[LibraryClasses] [LibraryClasses]
UefiBootServicesTableLib
MemoryAllocationLib MemoryAllocationLib
DevicePathLib
BaseLib BaseLib
BaseMemoryLib BaseMemoryLib
DebugLib DebugLib
PrintLib
PcdLib
[Protocols] [Protocols]
gEfiSimpleFileSystemProtocolGuid # ALWAYS_USED
[Guids] [Guids]
gEfiFileInfoGuid # ALWAYS_CONSUMED gEfiFileInfoGuid # ALWAYS_CONSUMED
[Pcd.common] [Pcd.common]
gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize # ALWAYS_CONSUMED

View File

@ -50,7 +50,8 @@ QuickSortWorker (
IN CONST UINTN ElementSize, IN CONST UINTN ElementSize,
IN SORT_COMPARE CompareFunction, IN SORT_COMPARE CompareFunction,
IN VOID *Buffer IN VOID *Buffer
){ )
{
VOID *Pivot; VOID *Pivot;
UINTN LoopCount; UINTN LoopCount;
UINTN NextSwapLocation; UINTN NextSwapLocation;
@ -149,7 +150,8 @@ PerformQuickSort (
IN CONST UINTN Count, IN CONST UINTN Count,
IN CONST UINTN ElementSize, IN CONST UINTN ElementSize,
IN SORT_COMPARE CompareFunction IN SORT_COMPARE CompareFunction
){ )
{
VOID *Buffer; VOID *Buffer;
ASSERT(BufferToSort != NULL); ASSERT(BufferToSort != NULL);
@ -168,3 +170,18 @@ PerformQuickSort (
FreePool(Buffer); FreePool(Buffer);
return; return;
} }
/**
Not supported in Base version.
ASSERT and return 0.
**/
INTN
DevicePathCompare (
IN VOID *Buffer1,
IN VOID *Buffer2
)
{
ASSERT(FALSE);
return 0;
}

View File

@ -1249,7 +1249,8 @@ EFIAPI
InternalShellConvertFileListType ( InternalShellConvertFileListType (
IN LIST_ENTRY *FileList, IN LIST_ENTRY *FileList,
IN OUT LIST_ENTRY *ListHead IN OUT LIST_ENTRY *ListHead
){ )
{
SHELL_FILE_ARG *OldInfo; SHELL_FILE_ARG *OldInfo;
LIST_ENTRY *Link; LIST_ENTRY *Link;
EFI_SHELL_FILE_INFO_NO_CONST *NewInfo; EFI_SHELL_FILE_INFO_NO_CONST *NewInfo;
@ -1464,6 +1465,74 @@ ShellCloseFileMetaArg (
} }
} }
/**
Find a file by searching the CWD and then the path.
if FileName is NULL then ASSERT.
if the return value is not NULL then the memory must be caller freed.
@param FileName Filename string.
@retval NULL the file was not found
@return !NULL the full path to the file.
**/
CHAR16 *
EFIAPI
ShellFindFilePath (
IN CONST CHAR16 *FileName
)
{
CONST CHAR16 *Path;
EFI_FILE_HANDLE Handle;
EFI_STATUS Status;
CHAR16 *RetVal;
CHAR16 *TestPath;
CONST CHAR16 *Walker;
RetVal = NULL;
Path = ShellGetEnvironmentVariable(L"cwd");
if (Path != NULL) {
TestPath = AllocateZeroPool(StrSize(Path) + StrSize(FileName));
StrCpy(TestPath, Path);
StrCat(TestPath, FileName);
Status = ShellOpenFileByName(TestPath, &Handle, EFI_FILE_MODE_READ, 0);
if (!EFI_ERROR(Status)){
RetVal = StrnCatGrow(&RetVal, NULL, TestPath, 0);
ShellCloseFile(&Handle);
FreePool(TestPath);
return (RetVal);
}
FreePool(TestPath);
}
Path = ShellGetEnvironmentVariable(L"path");
if (Path != NULL) {
TestPath = AllocateZeroPool(StrSize(Path)+StrSize(FileName) );
Walker = (CHAR16*)Path;
do {
CopyMem(TestPath, Walker, StrSize(Walker));
if (StrStr(TestPath, L";") != NULL) {
*(StrStr(TestPath, L";")) = CHAR_NULL;
}
StrCat(TestPath, FileName);
if (StrStr(Walker, L";") != NULL) {
Walker = StrStr(Walker, L";") + 1;
} else {
Walker = NULL;
}
Status = ShellOpenFileByName(TestPath, &Handle, EFI_FILE_MODE_READ, 0);
if (!EFI_ERROR(Status)){
RetVal = StrnCatGrow(&RetVal, NULL, TestPath, 0);
ShellCloseFile(&Handle);
break;
}
} while (Walker != NULL && Walker[0] != CHAR_NULL);
FreePool(TestPath);
}
return (RetVal);
}
typedef struct { typedef struct {
LIST_ENTRY Link; LIST_ENTRY Link;
CHAR16 *Name; CHAR16 *Name;
@ -1609,11 +1678,13 @@ InternalCommandLineParse (
UINTN LoopCounter; UINTN LoopCounter;
ParamType CurrentItemType; ParamType CurrentItemType;
SHELL_PARAM_PACKAGE *CurrentItemPackage; SHELL_PARAM_PACKAGE *CurrentItemPackage;
BOOLEAN GetItemValue; UINTN GetItemValue;
UINTN ValueSize;
CurrentItemPackage = NULL; CurrentItemPackage = NULL;
mTotalParameterCount = 0; mTotalParameterCount = 0;
GetItemValue = FALSE; GetItemValue = 0;
ValueSize = 0;
// //
// If there is only 1 item we dont need to do anything // If there is only 1 item we dont need to do anything
@ -1647,8 +1718,8 @@ InternalCommandLineParse (
// //
// We might have leftover if last parameter didnt have optional value // We might have leftover if last parameter didnt have optional value
// //
if (GetItemValue == TRUE) { if (GetItemValue != 0) {
GetItemValue = FALSE; GetItemValue = 0;
InsertHeadList(*CheckPackage, &CurrentItemPackage->Link); InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);
} }
// //
@ -1666,27 +1737,48 @@ InternalCommandLineParse (
// //
// Does this flag require a value // Does this flag require a value
// //
if (CurrentItemPackage->Type == TypeValue) { switch (CurrentItemPackage->Type) {
// //
// trigger the next loop to populate the value of this item // possibly trigger the next loop(s) to populate the value of this item
// //
GetItemValue = TRUE; case TypeValue:
} else { GetItemValue = 1;
ValueSize = 0;
break;
case TypeDoubleValue:
GetItemValue = 2;
ValueSize = 0;
break;
case TypeMaxValue:
GetItemValue = (UINTN)(-1);
ValueSize = 0;
break;
default:
// //
// this item has no value expected; we are done // this item has no value expected; we are done
// //
InsertHeadList(*CheckPackage, &CurrentItemPackage->Link); InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);
ASSERT(GetItemValue == 0);
break;
} }
} else if (GetItemValue == TRUE && InternalIsFlag(Argv[LoopCounter], AlwaysAllowNumbers) == FALSE) { } else if (GetItemValue != 0 && InternalIsFlag(Argv[LoopCounter], AlwaysAllowNumbers) == FALSE) {
ASSERT(CurrentItemPackage != NULL); ASSERT(CurrentItemPackage != NULL);
// //
// get the item VALUE for the previous flag // get the item VALUE for a previous flag
// //
GetItemValue = FALSE; CurrentItemPackage->Value = ReallocatePool(ValueSize, ValueSize + StrSize(Argv[LoopCounter]) + sizeof(CHAR16), CurrentItemPackage->Value);
CurrentItemPackage->Value = AllocateZeroPool(StrSize(Argv[LoopCounter]));
ASSERT(CurrentItemPackage->Value != NULL); ASSERT(CurrentItemPackage->Value != NULL);
if (ValueSize == 0) {
StrCpy(CurrentItemPackage->Value, Argv[LoopCounter]); StrCpy(CurrentItemPackage->Value, Argv[LoopCounter]);
} else {
StrCat(CurrentItemPackage->Value, L" ");
StrCat(CurrentItemPackage->Value, Argv[LoopCounter]);
}
ValueSize += StrSize(Argv[LoopCounter]) + sizeof(CHAR16);
GetItemValue--;
if (GetItemValue == 0) {
InsertHeadList(*CheckPackage, &CurrentItemPackage->Link); InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);
}
} else if (InternalIsFlag(Argv[LoopCounter], AlwaysAllowNumbers) == FALSE) { } else if (InternalIsFlag(Argv[LoopCounter], AlwaysAllowNumbers) == FALSE) {
// //
// add this one as a non-flag // add this one as a non-flag
@ -1716,6 +1808,10 @@ InternalCommandLineParse (
return (EFI_VOLUME_CORRUPTED); return (EFI_VOLUME_CORRUPTED);
} }
} }
if (GetItemValue != 0) {
GetItemValue = 0;
InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);
}
// //
// support for AutoPageBreak // support for AutoPageBreak
// //
@ -2028,7 +2124,8 @@ UINTN
EFIAPI EFIAPI
ShellCommandLineGetCount( ShellCommandLineGetCount(
VOID VOID
){ )
{
return (mTotalParameterCount); return (mTotalParameterCount);
} }
@ -2362,3 +2459,126 @@ ShellIsDirectory(
return (EFI_NOT_FOUND); 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.
@param[in] String String representation of a number
@retval all the number
**/
UINTN
EFIAPI
ShellStrToUintn(
IN CONST CHAR16 *String
)
{
CONST CHAR16 *Walker;
for (Walker = String; Walker != NULL && *Walker != CHAR_NULL && *Walker == L' '; Walker = Walker + 1);
if (StrnCmp(Walker, L"0x", 2) == 0 || StrnCmp(Walker, L"0X", 2) == 0){
return (StrHexToUintn(Walker));
}
return (StrDecimalToUintn(Walker));
}
/**
Safely append with automatic string resizing given length of Destination and
desired length of copy from Source.
append the first D characters of Source to the end of Destination, where D is
the lesser of Count and the StrLen() of Source. If appending those D characters
will fit within Destination (whose Size is given as CurrentSize) and
still leave room for a null terminator, then those characters are appended,
starting at the original terminating null of Destination, and a new terminating
null is appended.
If appending D characters onto Destination will result in a overflow of the size
given in CurrentSize the string will be grown such that the copy can be performed
and CurrentSize will be updated to the new size.
If Source is NULL, there is nothing to append, just return the current buffer in
Destination.
if Destination is NULL, then ASSERT()
if Destination's current length (including NULL terminator) is already more then
CurrentSize, then ASSERT()
@param[in,out] Destination The String to append onto
@param[in,out] CurrentSize on call the number of bytes in Destination. On
return possibly the new size (still in bytes). if NULL
then allocate whatever is needed.
@param[in] Source The String to append from
@param[in] Count Maximum number of characters to append. if 0 then
all are appended.
@return Destination return the resultant string.
**/
CHAR16*
EFIAPI
StrnCatGrow (
IN OUT CHAR16 **Destination,
IN OUT UINTN *CurrentSize,
IN CONST CHAR16 *Source,
IN UINTN Count
)
{
UINTN DestinationStartSize;
UINTN NewSize;
//
// ASSERTs
//
ASSERT(Destination != NULL);
//
// If there's nothing to do then just return Destination
//
if (Source == NULL) {
return (*Destination);
}
//
// allow for un-initialized pointers, based on size being 0
//
if (CurrentSize != NULL && *CurrentSize == 0) {
*Destination = NULL;
}
//
// allow for NULL pointers address as Destination
//
if (*Destination != NULL) {
ASSERT(CurrentSize != 0);
DestinationStartSize = StrSize(*Destination);
ASSERT(DestinationStartSize <= *CurrentSize);
} else {
DestinationStartSize = 0;
// ASSERT(*CurrentSize == 0);
}
//
// Append all of Source?
//
if (Count == 0) {
Count = StrLen(Source);
}
//
// Test and grow if required
//
if (CurrentSize != NULL) {
NewSize = *CurrentSize;
while (NewSize < (DestinationStartSize + (Count*sizeof(CHAR16)))) {
NewSize += 2 * Count * sizeof(CHAR16);
}
*Destination = ReallocatePool(*CurrentSize, NewSize, *Destination);
*CurrentSize = NewSize;
} else {
*Destination = AllocateZeroPool((Count+1)*sizeof(CHAR16));
}
//
// Now use standard StrnCat on a big enough buffer
//
return StrnCat(*Destination, Source, Count);
}

View File

@ -55,7 +55,8 @@ QuickSortWorker (
IN CONST UINTN ElementSize, IN CONST UINTN ElementSize,
IN SORT_COMPARE CompareFunction, IN SORT_COMPARE CompareFunction,
IN VOID *Buffer IN VOID *Buffer
){ )
{
VOID *Pivot; VOID *Pivot;
UINTN LoopCount; UINTN LoopCount;
UINTN NextSwapLocation; UINTN NextSwapLocation;
@ -154,7 +155,8 @@ PerformQuickSort (
IN CONST UINTN Count, IN CONST UINTN Count,
IN CONST UINTN ElementSize, IN CONST UINTN ElementSize,
IN SORT_COMPARE CompareFunction IN SORT_COMPARE CompareFunction
){ )
{
VOID *Buffer; VOID *Buffer;
ASSERT(BufferToSort != NULL); ASSERT(BufferToSort != NULL);
@ -188,7 +190,8 @@ INTN
DevicePathCompare ( DevicePathCompare (
IN VOID *Buffer1, IN VOID *Buffer1,
IN VOID *Buffer2 IN VOID *Buffer2
){ )
{
EFI_DEVICE_PATH_PROTOCOL *DevicePath1; EFI_DEVICE_PATH_PROTOCOL *DevicePath1;
EFI_DEVICE_PATH_PROTOCOL *DevicePath2; EFI_DEVICE_PATH_PROTOCOL *DevicePath2;
CHAR16 *TextPath1; CHAR16 *TextPath1;