TianoCore EDK2 master
Loading...
Searching...
No Matches
ShellParametersProtocol.c File Reference
#include "Shell.h"

Go to the source code of this file.

Functions

CONST CHAR16 * FindEndOfParameter (IN CONST CHAR16 *String)
 
EFI_STATUS GetNextParameter (IN OUT CHAR16 **Walker, IN OUT CHAR16 **TempParameter, IN CONST UINTN Length, IN BOOLEAN StripQuotation)
 
EFI_STATUS ParseCommandLineToArgs (IN CONST CHAR16 *CommandLine, IN BOOLEAN StripQuotation, IN OUT CHAR16 ***Argv, IN OUT UINTN *Argc)
 
EFI_STATUS CreatePopulateInstallShellParametersProtocol (IN OUT EFI_SHELL_PARAMETERS_PROTOCOL **NewShellParameters, IN OUT BOOLEAN *RootShellInstance)
 
EFI_STATUS CleanUpShellParametersProtocol (IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *NewShellParameters)
 
EFI_STATUS IsUnicodeFile (IN CONST CHAR16 *FileName)
 
VOID StripQuotes (IN OUT CHAR16 *TheString)
 
VOID CalculateEfiHdrCrc (IN OUT EFI_TABLE_HEADER *Hdr)
 
CHAR16 * FixFileName (IN CHAR16 *FileName)
 
CHAR16 * FixVarName (IN CHAR16 *FileName)
 
EFI_STATUS WriteFileTag (IN SHELL_FILE_HANDLE FileHandle)
 
EFI_STATUS UpdateStdInStdOutStdErr (IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters, IN CHAR16 *NewCommandLine, OUT SHELL_FILE_HANDLE *OldStdIn, OUT SHELL_FILE_HANDLE *OldStdOut, OUT SHELL_FILE_HANDLE *OldStdErr, OUT SYSTEM_TABLE_INFO *SystemTableInfo)
 
EFI_STATUS RestoreStdInStdOutStdErr (IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters, IN SHELL_FILE_HANDLE *OldStdIn, IN SHELL_FILE_HANDLE *OldStdOut, IN SHELL_FILE_HANDLE *OldStdErr, IN SYSTEM_TABLE_INFO *SystemTableInfo)
 
EFI_STATUS UpdateArgcArgv (IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters, IN CONST CHAR16 *NewCommandLine, IN SHELL_OPERATION_TYPES Type, OUT CHAR16 ***OldArgv OPTIONAL, OUT UINTN *OldArgc OPTIONAL)
 
VOID RestoreArgcArgv (IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters, IN CHAR16 ***OldArgv, IN UINTN *OldArgc)
 

Variables

BOOLEAN AsciiRedirection = FALSE
 

Detailed Description

Member functions of EFI_SHELL_PARAMETERS_PROTOCOL and functions for creation, manipulation, and initialization of EFI_SHELL_PARAMETERS_PROTOCOL.

(C) Copyright 2016 Hewlett Packard Enterprise Development LP
Copyright (C) 2014, Red Hat, Inc. (C) Copyright 2013 Hewlett-Packard Development Company, L.P.
Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file ShellParametersProtocol.c.

Function Documentation

◆ CalculateEfiHdrCrc()

VOID CalculateEfiHdrCrc ( IN OUT EFI_TABLE_HEADER Hdr)

Calculate the 32-bit CRC in a EFI table using the service provided by the gRuntime service.

Parameters
HdrPointer to an EFI standard header

Definition at line 564 of file ShellParametersProtocol.c.

◆ CleanUpShellParametersProtocol()

EFI_STATUS CleanUpShellParametersProtocol ( IN OUT EFI_SHELL_PARAMETERS_PROTOCOL NewShellParameters)

frees all memory used by creation and installation of shell parameters protocol and if there was an old version installed it will restore that one.

Parameters
NewShellParametersthe interface of EFI_SHELL_PARAMETERS_PROTOCOL that is being cleaned up.
Return values
EFI_SUCCESSthe cleanup was successful
Returns
other the cleanup failed
See also
ReinstallProtocolInterface
UninstallProtocolInterface

Definition at line 447 of file ShellParametersProtocol.c.

◆ CreatePopulateInstallShellParametersProtocol()

EFI_STATUS CreatePopulateInstallShellParametersProtocol ( IN OUT EFI_SHELL_PARAMETERS_PROTOCOL **  NewShellParameters,
IN OUT BOOLEAN *  RootShellInstance 
)

creates a new EFI_SHELL_PARAMETERS_PROTOCOL instance and populates it and then installs it on our handle and if there is an existing version of the protocol that one is cached for removal later.

Parameters
[in,out]NewShellParameterson a successful return, a pointer to pointer to the newly installed interface.
[in,out]RootShellInstanceon a successful return, pointer to boolean. TRUE if this is the root shell instance.
Return values
EFI_SUCCESSthe operation completed successfully.
Returns
other the operation failed.
See also
ReinstallProtocolInterface
InstallProtocolInterface
ParseCommandLineToArgs

Definition at line 293 of file ShellParametersProtocol.c.

◆ FindEndOfParameter()

CONST CHAR16 * FindEndOfParameter ( IN CONST CHAR16 *  String)

Return the next parameter's end from a command line string.

Parameters
[in]Stringthe string to parse

Definition at line 23 of file ShellParametersProtocol.c.

◆ FixFileName()

CHAR16 * FixFileName ( IN CHAR16 *  FileName)

Fix a string to only have the file name, removing starting at the first space of whatever is quoted.

Parameters
[in]FileNameThe filename to start with.
Return values
NULLFileName was invalid.
Returns
The modified FileName.

Definition at line 590 of file ShellParametersProtocol.c.

◆ FixVarName()

CHAR16 * FixVarName ( IN CHAR16 *  FileName)

Fix a string to only have the environment variable name, removing starting at the first space of whatever is quoted and removing the leading and trailing %.

Parameters
[in]FileNameThe filename to start with.
Return values
NULLFileName was invalid.
Returns
The modified FileName.

Definition at line 633 of file ShellParametersProtocol.c.

◆ GetNextParameter()

EFI_STATUS GetNextParameter ( IN OUT CHAR16 **  Walker,
IN OUT CHAR16 **  TempParameter,
IN CONST UINTN  Length,
IN BOOLEAN  StripQuotation 
)

Return the next parameter from a command line string.

This function moves the next parameter from Walker into TempParameter and moves Walker up past that parameter for recursive calling. When the final parameter is moved *Walker will be set to NULL;

Temp Parameter must be large enough to hold the parameter before calling this function.

This will also remove all remaining ^ characters after processing.

Parameters
[in,out]Walkerpointer to string of command line. Adjusted to remaining command line on return
[in,out]TempParameterpointer to string of command line item extracted.
[in]Lengthbuffer size of TempParameter.
[in]StripQuotationif TRUE then strip the quotation marks surrounding the parameters.
Returns
EFI_INVALID_PARAMETER A required parameter was NULL or pointed to a NULL or empty string.
EFI_NOT_FOUND A closing " could not be found on the specified string

Definition at line 82 of file ShellParametersProtocol.c.

◆ IsUnicodeFile()

EFI_STATUS IsUnicodeFile ( IN CONST CHAR16 *  FileName)

Determine if a file name represents a unicode file.

Parameters
[in]FileNamePointer to the filename to open.
Return values
EFI_SUCCESSThe file is a unicode file.
Returns
An error upon failure.

Definition at line 503 of file ShellParametersProtocol.c.

◆ ParseCommandLineToArgs()

EFI_STATUS ParseCommandLineToArgs ( IN CONST CHAR16 *  CommandLine,
IN BOOLEAN  StripQuotation,
IN OUT CHAR16 ***  Argv,
IN OUT UINTN Argc 
)

Function to populate Argc and Argv.

This function parses the CommandLine and divides it into standard C style Argc/Argv parameters for inclusion in EFI_SHELL_PARAMETERS_PROTOCOL. this supports space delimited and quote surrounded parameter definition.

All special character processing (alias, environment variable, redirection, etc... must be complete before calling this API.

Parameters
[in]CommandLineString of command line to parse
[in]StripQuotationif TRUE then strip the quotation marks surrounding the parameters.
[in,out]Argvpointer to array of strings; one for each parameter
[in,out]Argcpointer to number of strings in Argv array
Returns
EFI_SUCCESS the operation was successful
EFI_INVALID_PARAMETER some parameters are invalid
EFI_OUT_OF_RESOURCES a memory allocation failed.

Definition at line 191 of file ShellParametersProtocol.c.

◆ RestoreArgcArgv()

VOID RestoreArgcArgv ( IN OUT EFI_SHELL_PARAMETERS_PROTOCOL ShellParameters,
IN CHAR16 ***  OldArgv,
IN UINTN OldArgc 
)

Function will replace the current Argc and Argv in the ShellParameters protocol structure with Argv and Argc. The current values are de-allocated and the OldArgv must not be deallocated by the caller.

Parameters
[in,out]ShellParameterspointer to parameter structure to modify
[in]OldArgvpointer to old list of parameters
[in]OldArgcpointer to old number of items in Argv list

Definition at line 1499 of file ShellParametersProtocol.c.

◆ RestoreStdInStdOutStdErr()

EFI_STATUS RestoreStdInStdOutStdErr ( IN OUT EFI_SHELL_PARAMETERS_PROTOCOL ShellParameters,
IN SHELL_FILE_HANDLE *  OldStdIn,
IN SHELL_FILE_HANDLE *  OldStdOut,
IN SHELL_FILE_HANDLE *  OldStdErr,
IN SYSTEM_TABLE_INFO SystemTableInfo 
)

Function will replace the current StdIn and StdOut in the ShellParameters protocol structure with StdIn and StdOut. The current values are de-allocated.

Parameters
[in,out]ShellParametersPointer to parameter structure to modify.
[in]OldStdInPointer to old StdIn.
[in]OldStdOutPointer to old StdOut.
[in]OldStdErrPointer to old StdErr.
[in]SystemTableInfoPointer to old system table information.

Definition at line 1368 of file ShellParametersProtocol.c.

◆ StripQuotes()

VOID StripQuotes ( IN OUT CHAR16 *  TheString)

Strips out quotes sections of a string.

All of the characters between quotes is replaced with spaces.

Parameters
[in,out]TheStringA pointer to the string to update.

Definition at line 539 of file ShellParametersProtocol.c.

◆ UpdateArgcArgv()

EFI_STATUS UpdateArgcArgv ( IN OUT EFI_SHELL_PARAMETERS_PROTOCOL ShellParameters,
IN CONST CHAR16 *  NewCommandLine,
IN SHELL_OPERATION_TYPES  Type,
OUT CHAR16 ***OldArgv  OPTIONAL,
OUT UINTN *OldArgc  OPTIONAL 
)

Function will replace the current Argc and Argv in the ShellParameters protocol structure by parsing NewCommandLine. The current values are returned to the user.

If OldArgv or OldArgc is NULL then that value is not returned.

Parameters
[in,out]ShellParametersPointer to parameter structure to modify.
[in]NewCommandLineThe new command line to parse and use.
[in]TypeThe type of operation.
[out]OldArgvPointer to old list of parameters.
[out]OldArgcPointer to old number of items in Argv list.
Return values
EFI_SUCCESSOperation was successful, Argv and Argc are valid.
Returns
EFI_INVALID_PARAMETER Some parameters are invalid.
Return values
EFI_OUT_OF_RESOURCESA memory allocation failed.

Definition at line 1456 of file ShellParametersProtocol.c.

◆ UpdateStdInStdOutStdErr()

EFI_STATUS UpdateStdInStdOutStdErr ( IN OUT EFI_SHELL_PARAMETERS_PROTOCOL ShellParameters,
IN CHAR16 *  NewCommandLine,
OUT SHELL_FILE_HANDLE *  OldStdIn,
OUT SHELL_FILE_HANDLE *  OldStdOut,
OUT SHELL_FILE_HANDLE *  OldStdErr,
OUT SYSTEM_TABLE_INFO SystemTableInfo 
)

Function will replace the current StdIn and StdOut in the ShellParameters protocol structure by parsing NewCommandLine. The current values are returned to the user.

This will also update the system table.

Parameters
[in,out]ShellParametersPointer to parameter structure to modify.
[in]NewCommandLineThe new command line to parse and use.
[out]OldStdInPointer to old StdIn.
[out]OldStdOutPointer to old StdOut.
[out]OldStdErrPointer to old StdErr.
[out]SystemTableInfoPointer to old system table information.
Return values
EFI_SUCCESSOperation was successful, Argv and Argc are valid.
EFI_OUT_OF_RESOURCESA memory allocation failed.

Definition at line 701 of file ShellParametersProtocol.c.

◆ WriteFileTag()

EFI_STATUS WriteFileTag ( IN SHELL_FILE_HANDLE  FileHandle)

Write the unicode file tag to the specified file.

It is the caller's responsibility to ensure that ShellInfoObject.NewEfiShellProtocol has been initialized before calling this function.

Parameters
[in]FileHandleThe file to write the unicode file tag to.
Returns
Status code from ShellInfoObject.NewEfiShellProtocol->WriteFile.

Definition at line 664 of file ShellParametersProtocol.c.

Variable Documentation

◆ AsciiRedirection

BOOLEAN AsciiRedirection = FALSE

Definition at line 15 of file ShellParametersProtocol.c.