Files
edk2-upstream/ShellPkg/Application/Shell/ShellManParser.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

75 lines
3.2 KiB
C

/** @file
Provides interface to shell MAN file parser.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#pragma once
/**
This function returns the help information for the specified command. The help text
will be parsed from a UEFI Shell manual page. (see UEFI Shell 2.0 Appendix B)
If Sections is specified, then each section name listed will be compared in a casesensitive
manner, to the section names described in Appendix B. If the section exists,
it will be appended to the returned help text. If the section does not exist, no
information will be returned. If Sections is NULL, then all help text information
available will be returned.
if BriefDesc is NULL, then the breif description will not be savedd separately,
but placed first in the main HelpText.
@param[in] ManFileName Points to the NULL-terminated UEFI Shell MAN file name.
@param[in] Command Points to the NULL-terminated UEFI Shell command name.
@param[in] Sections Points to the NULL-terminated comma-delimited
section names to return. If NULL, then all
sections will be returned.
@param[out] BriefDesc On return, points to a callee-allocated buffer
containing brief description text.
@param[out] HelpText On return, points to a callee-allocated buffer
containing all specified help text.
@retval EFI_SUCCESS The help text was returned.
@retval EFI_OUT_OF_RESOURCES The necessary buffer could not be allocated to hold the
returned help text.
@retval EFI_INVALID_PARAMETER HelpText is NULL
@retval EFI_NOT_FOUND There is no help text available for Command.
**/
EFI_STATUS
ProcessManFile (
IN CONST CHAR16 *ManFileName,
IN CONST CHAR16 *Command,
IN CONST CHAR16 *Sections OPTIONAL,
OUT CHAR16 **BriefDesc,
OUT CHAR16 **HelpText
);
/**
parses through the MAN file specified by SHELL_FILE_HANDLE and returns the
detailed help for any sub section specified in the comma separated list of
sections provided. If the end of the file or a .TH section is found then
return.
Upon a successful return the caller is responsible to free the memory in *HelpText
@param[in] Handle FileHandle to read from
@param[in] Sections name of command's sub sections to find
@param[out] HelpText pointer to pointer to string where text goes.
@param[out] HelpSize pointer to size of allocated HelpText (may be updated)
@param[in] Ascii TRUE if the file is ASCII, FALSE otherwise.
@retval EFI_OUT_OF_RESOURCES a memory allocation failed.
@retval EFI_SUCCESS the section was found and its description stored in
an allocated buffer.
**/
EFI_STATUS
ManFileFindSections (
IN SHELL_FILE_HANDLE Handle,
IN CONST CHAR16 *Sections,
OUT CHAR16 **HelpText,
OUT UINTN *HelpSize,
IN BOOLEAN Ascii
);