Files
edk2-upstream/ShellPkg/Application/Shell/ShellParametersProtocol.h
Michael Kubacki 8472271dae ShellPkg: Replace include guards with #pragma once
Replace traditional `#ifndef`/`#define`/`#endif` include guards with
`#pragma` once.

`#pragma once` is a widely supported preprocessor directive that
prevents header files from being included multiple times. It is
supported by all toolchains used to build edk2: GCC, Clang/LLVM, and
MSVC.

Compared to macro-based include guards, `#pragma once`:

- Eliminates the risk of macro name collisions or copy/paste errors
  where two headers inadvertently use the same guard macro.
- Eliminate inconsistency in the way include guard macros are named
  (e.g., some files use `__FILE_H__`, others use `FILE_H_`, etc.).
- Reduces boilerplate (three lines replaced by one).
- Avoids polluting the macro namespace with guard symbols.
- Can improve build times as the preprocessor can skip re-opening the
  file entirely, rather than re-reading it to find the matching
  `#endif` ("multiple-include optimization").
  - Note that some compilers may already optimize traditional include
    guards, by recognzining the idiomatic pattern.

This change is made acknowledging that overall portability of the
code will technically be reduced, as `#pragma once` is not part of the
C/C++ standards.

However, this is considered acceptable given:

1. edk2 already defines a subset of supported compilers in
   BaseTools/Conf/tools_def.template, all of which have supported
   `#pragma once` for over two decades.
2. There have been concerns raised to the project about inconsistent
   include guard naming and potential macro collisions.

Approximate compiler support dates:

- MSVC: Supported since Visual C++ 4.2 (1996)
- GCC: Supported since 3.4 (2004)
  (http://gnu.ist.utl.pt/software/gcc/gcc-3.4/changes.html)
- Clang (LLVM based): Since initial release in 2007

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
2026-02-23 21:01:28 +00:00

208 lines
8.1 KiB
C

/** @file
Member functions of EFI_SHELL_PARAMETERS_PROTOCOL and functions for creation,
manipulation, and initialization of EFI_SHELL_PARAMETERS_PROTOCOL.
Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#pragma once
#include "Shell.h"
typedef enum {
Internal_Command,
Script_File_Name,
Efi_Application,
File_Sys_Change,
Unknown_Invalid
} SHELL_OPERATION_TYPES;
/**
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.
@param[in, out] NewShellParameters on a successful return, a pointer to pointer
to the newly installed interface.
@param[in, out] RootShellInstance on a successful return, pointer to boolean.
TRUE if this is the root shell instance.
@retval EFI_SUCCESS the operation completed successfully.
@return other the operation failed.
@sa ReinstallProtocolInterface
@sa InstallProtocolInterface
@sa ParseCommandLineToArgs
**/
EFI_STATUS
CreatePopulateInstallShellParametersProtocol (
IN OUT EFI_SHELL_PARAMETERS_PROTOCOL **NewShellParameters,
IN OUT BOOLEAN *RootShellInstance
);
/**
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.
@param NewShellParameters the interface of EFI_SHELL_PARAMETERS_PROTOCOL that is
being cleaned up.
@retval EFI_SUCCESS the cleanup was successful
@return other the cleanup failed
@sa ReinstallProtocolInterface
@sa UninstallProtocolInterface
**/
EFI_STATUS
CleanUpShellParametersProtocol (
IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *NewShellParameters
);
/**
Function will replace the current Argc and Argv in the ShellParameters protocol
structure by parsing NewCommandLine. The current values are returned to the
user.
@param[in, out] ShellParameters pointer to parameter structure to modify
@param[in] NewCommandLine the new command line to parse and use
@param[in] Type the type of operation.
@param[out] OldArgv pointer to old list of parameters
@param[out] OldArgc pointer to old number of items in Argv list
@retval EFI_SUCCESS operation was successful, Argv and Argc are valid
@return EFI_INVALID_PARAMETER some parameters are invalid
@retval EFI_OUT_OF_RESOURCES a memory allocation failed.
**/
EFI_STATUS
UpdateArgcArgv (
IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,
IN CONST CHAR16 *NewCommandLine,
IN SHELL_OPERATION_TYPES Type,
OUT CHAR16 ***OldArgv,
OUT 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.
@param[in, out] ShellParameters pointer to parameter structure to modify
@param[in] OldArgv pointer to old list of parameters
@param[in] OldArgc pointer to old number of items in Argv list
**/
VOID
RestoreArgcArgv (
IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,
IN CHAR16 ***OldArgv,
IN UINTN *OldArgc
);
typedef struct {
EFI_SIMPLE_TEXT_INPUT_PROTOCOL *ConIn;
EFI_HANDLE ConInHandle;
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut;
EFI_HANDLE ConOutHandle;
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ErrOut;
EFI_HANDLE ErrOutHandle;
} SYSTEM_TABLE_INFO;
/**
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.
@param[in, out] ShellParameters Pointer to parameter structure to modify.
@param[in] NewCommandLine The new command line to parse and use.
@param[out] OldStdIn Pointer to old StdIn.
@param[out] OldStdOut Pointer to old StdOut.
@param[out] OldStdErr Pointer to old StdErr.
@param[out] SystemTableInfo Pointer to old system table information.
@retval EFI_SUCCESS Operation was successful, Argv and Argc are valid.
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.
**/
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 with StdIn and StdOut. The current values are de-allocated.
@param[in, out] ShellParameters Pointer to parameter structure to modify.
@param[in] OldStdIn Pointer to old StdIn.
@param[in] OldStdOut Pointer to old StdOut.
@param[in] OldStdErr Pointer to old StdErr.
@param[in] SystemTableInfo Pointer to old system table information.
**/
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 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.
@param[in] CommandLine String of command line to parse
@param[in] StripQuotation if TRUE then strip the quotation marks surrounding
the parameters.
@param[in, out] Argv pointer to array of strings; one for each parameter
@param[in, out] Argc pointer to number of strings in Argv array
@return EFI_SUCCESS the operation was successful
@return EFI_INVALID_PARAMETER some parameters are invalid
@return EFI_OUT_OF_RESOURCES a memory allocation failed.
**/
EFI_STATUS
ParseCommandLineToArgs (
IN CONST CHAR16 *CommandLine,
IN BOOLEAN StripQuotation,
IN OUT CHAR16 ***Argv,
IN OUT UINTN *Argc
);
/**
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.
@param[in, out] Walker pointer to string of command line. Adjusted to
remaining command line on return
@param[in, out] TempParameter pointer to string of command line item extracted.
@param[in] Length Length of (*TempParameter) in bytes
@param[in] StripQuotation if TRUE then strip the quotation marks surrounding
the parameters.
@return EFI_INVALID_PARAMETER A required parameter was NULL or pointed to a NULL or empty string.
@return EFI_NOT_FOUND A closing " could not be found on the specified string
**/
EFI_STATUS
GetNextParameter (
IN OUT CHAR16 **Walker,
IN OUT CHAR16 **TempParameter,
IN CONST UINTN Length,
IN BOOLEAN StripQuotation
);