edk2/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/BufferImage.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

263 lines
6.8 KiB
C

/** @file
Defines BufferImage - the view of the file that is visible at any point,
as well as the event handlers for editing the file
Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved. <BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#pragma once
#include "HexEditor.h"
/**
Initialization function for HBufferImage
@retval EFI_SUCCESS The operation was successful.
@retval EFI_LOAD_ERROR A load error occurred.
**/
EFI_STATUS
HBufferImageInit (
VOID
);
/**
Cleanup function for HBufferImage
@retval EFI_SUCCESS The operation was successful.
**/
EFI_STATUS
HBufferImageCleanup (
VOID
);
/**
Refresh function for HBufferImage.
@retval EFI_SUCCESS The operation was successful.
@retval EFI_LOAD_ERROR A Load error occurred.
**/
EFI_STATUS
HBufferImageRefresh (
VOID
);
/**
Dispatch input to different handler
@param[in] Key The input key:
the keys can be:
ASCII KEY
Backspace/Delete
Direction key: up/down/left/right/pgup/pgdn
Home/End
INS
@retval EFI_SUCCESS The operation was successful.
@retval EFI_LOAD_ERROR A load error occurred.
@retval EFI_OUT_OF_RESOURCES A Memory allocation failed.
**/
EFI_STATUS
HBufferImageHandleInput (
IN EFI_INPUT_KEY *Key
);
/**
Backup function for HBufferImage. Only a few fields need to be backup.
This is for making the file buffer refresh as few as possible.
@retval EFI_SUCCESS The operation was successful.
**/
EFI_STATUS
HBufferImageBackup (
VOID
);
/**
Read an image into a buffer friom a source.
@param[in] FileName Pointer to the file name. OPTIONAL and ignored if not FileTypeFileBuffer.
@param[in] DiskName Pointer to the disk name. OPTIONAL and ignored if not FileTypeDiskBuffer.
@param[in] DiskOffset Offset into the disk. OPTIONAL and ignored if not FileTypeDiskBuffer.
@param[in] DiskSize Size of the disk buffer. OPTIONAL and ignored if not FileTypeDiskBuffer.
@param[in] MemOffset Offset into the Memory. OPTIONAL and ignored if not FileTypeMemBuffer.
@param[in] MemSize Size of the Memory buffer. OPTIONAL and ignored if not FileTypeMemBuffer.
@param[in] BufferType The type of buffer to save. IGNORED.
@param[in] Recover TRUE for recovermode, FALSE otherwise.
@return EFI_SUCCESS The operation was successful.
**/
EFI_STATUS
HBufferImageRead (
IN CONST CHAR16 *FileName,
IN CONST CHAR16 *DiskName,
IN UINTN DiskOffset,
IN UINTN DiskSize,
IN UINTN MemOffset,
IN UINTN MemSize,
IN EDIT_FILE_TYPE BufferType,
IN BOOLEAN Recover
);
/**
Save the current image.
@param[in] FileName Pointer to the file name. OPTIONAL and ignored if not FileTypeFileBuffer.
@param[in] DiskName Pointer to the disk name. OPTIONAL and ignored if not FileTypeDiskBuffer.
@param[in] DiskOffset Offset into the disk. OPTIONAL and ignored if not FileTypeDiskBuffer.
@param[in] DiskSize Size of the disk buffer. OPTIONAL and ignored if not FileTypeDiskBuffer.
@param[in] MemOffset Offset into the Memory. OPTIONAL and ignored if not FileTypeMemBuffer.
@param[in] MemSize Size of the Memory buffer. OPTIONAL and ignored if not FileTypeMemBuffer.
@param[in] BufferType The type of buffer to save. IGNORED.
@return EFI_SUCCESS The operation was successful.
**/
EFI_STATUS
HBufferImageSave (
IN CHAR16 *FileName,
IN CHAR16 *DiskName,
IN UINTN DiskOffset,
IN UINTN DiskSize,
IN UINTN MemOffset,
IN UINTN MemSize,
IN EDIT_FILE_TYPE BufferType
);
/**
According to cursor's file position, adjust screen display.
@param[in] NewFilePosRow Row of file position ( start from 1 ).
@param[in] NewFilePosCol Column of file position ( start from 1 ).
@param[in] HighBits Cursor will on high4 bits or low4 bits.
**/
VOID
HBufferImageMovePosition (
IN UINTN NewFilePosRow,
IN UINTN NewFilePosCol,
IN BOOLEAN HighBits
);
/**
Create a new line and append it to the line list.
Fields affected:
NumLines
Lines
@retval NULL create line failed.
@return the line created.
**/
HEFI_EDITOR_LINE *
HBufferImageCreateLine (
VOID
);
/**
Free the current image.
@retval EFI_SUCCESS The operation was successful.
**/
EFI_STATUS
HBufferImageFree (
VOID
);
/**
Delete character from buffer.
@param[in] Pos Position, Pos starting from 0.
@param[in] Count The Count of characters to delete.
@param[out] DeleteBuffer The DeleteBuffer.
@retval EFI_SUCCESS Success
**/
EFI_STATUS
HBufferImageDeleteCharacterFromBuffer (
IN UINTN Pos,
IN UINTN Count,
OUT UINT8 *DeleteBuffer
);
/**
Add character to buffer, add before pos.
@param[in] Pos Position, Pos starting from 0.
@param[in] Count Count of characters to add.
@param[in] AddBuffer Add buffer.
@retval EFI_SUCCESS Success.
**/
EFI_STATUS
HBufferImageAddCharacterToBuffer (
IN UINTN Pos,
IN UINTN Count,
IN UINT8 *AddBuffer
);
/**
Change the raw buffer to a list of lines for the UI.
@param[in] Buffer The pointer to the buffer to fill.
@param[in] Bytes The size of the buffer in bytes.
@retval EFI_SUCCESS The operation was successful.
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.
**/
EFI_STATUS
HBufferImageBufferToList (
IN VOID *Buffer,
IN UINTN Bytes
);
/**
Change the list of lines from the UI to a raw buffer.
@param[in] Buffer The pointer to the buffer to fill.
@param[in] Bytes The size of the buffer in bytes.
@retval EFI_SUCCESS The operation was successful.
**/
EFI_STATUS
HBufferImageListToBuffer (
IN VOID *Buffer,
IN UINTN Bytes
);
/**
Move the mouse in the image buffer.
@param[in] TextX The x-coordinate.
@param[in] TextY The y-coordinate.
**/
VOID
HBufferImageAdjustMousePosition (
IN INT32 TextX,
IN INT32 TextY
);
/**
Function to decide if a column number is stored in the high bits.
@param[in] Column The column to examine.
@param[out] FCol The actual column number.
@retval TRUE The actual column was in high bits and is now in FCol.
@retval FALSE There was not a column number in the high bits.
**/
BOOLEAN
HBufferImageIsAtHighBits (
IN UINTN Column,
OUT UINTN *FCol
);
/**
Get the size of the open buffer.
@retval The size in bytes.
**/
UINTN
HBufferImageGetTotalSize (
VOID
);