2011-03-25 22:15:07 +01:00
|
|
|
/** @file
|
|
|
|
Implementation of various string and line routines
|
2018-06-27 15:13:38 +02:00
|
|
|
|
|
|
|
Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved. <BR>
|
2019-04-04 01:07:06 +02:00
|
|
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
2011-03-25 22:15:07 +01:00
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include "HexEditor.h"
|
|
|
|
|
|
|
|
extern BOOLEAN HEditorMouseAction;
|
|
|
|
|
2011-04-05 22:55:45 +02:00
|
|
|
/**
|
|
|
|
Free a line and it's internal buffer.
|
2018-06-27 15:13:38 +02:00
|
|
|
|
2011-04-05 22:55:45 +02:00
|
|
|
@param[in] Src The line to be freed.
|
|
|
|
**/
|
2011-03-25 22:15:07 +01:00
|
|
|
VOID
|
|
|
|
HLineFree (
|
|
|
|
IN HEFI_EDITOR_LINE *Src
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (Src == NULL) {
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
SHELL_FREE_NON_NULL (Src);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-04-05 22:55:45 +02:00
|
|
|
/**
|
|
|
|
Advance to the next Count lines.
|
|
|
|
|
|
|
|
@param[in] Count The line number to advance.
|
|
|
|
|
2020-08-01 02:52:32 +02:00
|
|
|
@retval NULL An error occurred.
|
2011-04-05 22:55:45 +02:00
|
|
|
@return A pointer to the line after advance.
|
|
|
|
**/
|
2011-03-25 22:15:07 +01:00
|
|
|
HEFI_EDITOR_LINE *
|
2011-04-05 22:55:45 +02:00
|
|
|
HLineAdvance (
|
2011-03-25 22:15:07 +01:00
|
|
|
IN UINTN Count
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINTN Index;
|
|
|
|
HEFI_EDITOR_LINE *Line;
|
|
|
|
|
|
|
|
Line = HMainEditor.BufferImage->CurrentLine;
|
|
|
|
if (Line == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Index = 0; Index < Count; Index++) {
|
|
|
|
//
|
|
|
|
// if already last line
|
|
|
|
//
|
|
|
|
if (Line->Link.ForwardLink == HMainEditor.BufferImage->ListHead) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Line = CR (Line->Link.ForwardLink, HEFI_EDITOR_LINE, Link, EFI_EDITOR_LINE_LIST);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Line;
|
|
|
|
}
|
|
|
|
|
2011-04-05 22:55:45 +02:00
|
|
|
/**
|
|
|
|
Retreat to the previous Count lines.
|
|
|
|
|
|
|
|
@param[in] Count The line number to retreat.
|
|
|
|
|
2020-08-01 02:52:32 +02:00
|
|
|
@retval NULL An error occurred.
|
2011-04-05 22:55:45 +02:00
|
|
|
@return A pointer to the line after retreat.
|
|
|
|
**/
|
2011-03-25 22:15:07 +01:00
|
|
|
HEFI_EDITOR_LINE *
|
2011-04-05 22:55:45 +02:00
|
|
|
HLineRetreat (
|
2011-03-25 22:15:07 +01:00
|
|
|
IN UINTN Count
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINTN Index;
|
|
|
|
HEFI_EDITOR_LINE *Line;
|
|
|
|
|
|
|
|
Line = HMainEditor.BufferImage->CurrentLine;
|
|
|
|
if (Line == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Index = 0; Index < Count; Index++) {
|
|
|
|
//
|
|
|
|
// already the first line
|
|
|
|
//
|
|
|
|
if (Line->Link.BackLink == HMainEditor.BufferImage->ListHead) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Line = CR (Line->Link.BackLink, HEFI_EDITOR_LINE, Link, EFI_EDITOR_LINE_LIST);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Line;
|
|
|
|
}
|
|
|
|
|
2011-04-05 22:55:45 +02:00
|
|
|
/**
|
|
|
|
Advance/Retreat lines.
|
|
|
|
|
|
|
|
@param[in] Count The line number to advance/retreat.
|
|
|
|
>0 : advance
|
2018-06-27 15:13:38 +02:00
|
|
|
<0: retreat
|
2011-04-05 22:55:45 +02:00
|
|
|
|
2020-08-01 02:52:32 +02:00
|
|
|
@retval NULL An error occurred.
|
2011-04-05 22:55:45 +02:00
|
|
|
@return A pointer to the line after move.
|
|
|
|
**/
|
2011-03-25 22:15:07 +01:00
|
|
|
HEFI_EDITOR_LINE *
|
|
|
|
HMoveLine (
|
|
|
|
IN INTN Count
|
|
|
|
)
|
|
|
|
{
|
|
|
|
HEFI_EDITOR_LINE *Line;
|
|
|
|
UINTN AbsCount;
|
|
|
|
|
|
|
|
//
|
|
|
|
// difference with MoveCurrentLine
|
|
|
|
// just return Line
|
|
|
|
// do not set currentline to Line
|
|
|
|
//
|
|
|
|
if (Count <= 0) {
|
2011-03-30 21:33:03 +02:00
|
|
|
AbsCount = (UINTN)ABS(Count);
|
2011-04-05 22:55:45 +02:00
|
|
|
Line = HLineRetreat (AbsCount);
|
2011-03-25 22:15:07 +01:00
|
|
|
} else {
|
2011-04-05 22:55:45 +02:00
|
|
|
Line = HLineAdvance ((UINTN)Count);
|
2011-03-25 22:15:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return Line;
|
|
|
|
}
|
|
|
|
|
2011-04-05 22:55:45 +02:00
|
|
|
/**
|
|
|
|
Advance/Retreat lines and set CurrentLine in BufferImage to it.
|
|
|
|
|
|
|
|
@param[in] Count The line number to advance/retreat.
|
|
|
|
>0 : advance
|
|
|
|
<0: retreat
|
|
|
|
|
2020-08-01 02:52:32 +02:00
|
|
|
@retval NULL An error occurred.
|
2011-04-05 22:55:45 +02:00
|
|
|
@return A pointer to the line after move.
|
|
|
|
**/
|
2011-03-25 22:15:07 +01:00
|
|
|
HEFI_EDITOR_LINE *
|
|
|
|
HMoveCurrentLine (
|
|
|
|
IN INTN Count
|
|
|
|
)
|
|
|
|
{
|
|
|
|
HEFI_EDITOR_LINE *Line;
|
|
|
|
UINTN AbsCount;
|
|
|
|
|
|
|
|
//
|
|
|
|
// <0: retreat
|
|
|
|
// >0: advance
|
|
|
|
//
|
|
|
|
if (Count <= 0) {
|
2011-03-30 21:33:03 +02:00
|
|
|
AbsCount = (UINTN)ABS(Count);
|
2011-04-05 22:55:45 +02:00
|
|
|
Line = HLineRetreat (AbsCount);
|
2011-03-25 22:15:07 +01:00
|
|
|
} else {
|
2011-04-05 22:55:45 +02:00
|
|
|
Line = HLineAdvance ((UINTN)Count);
|
2011-03-25 22:15:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Line == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
HMainEditor.BufferImage->CurrentLine = Line;
|
|
|
|
|
|
|
|
return Line;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-05 22:55:45 +02:00
|
|
|
/**
|
|
|
|
Free all the lines in HBufferImage.
|
2011-03-25 22:15:07 +01:00
|
|
|
Fields affected:
|
|
|
|
Lines
|
|
|
|
CurrentLine
|
|
|
|
NumLines
|
2018-06-27 15:13:38 +02:00
|
|
|
ListHead
|
2011-03-25 22:15:07 +01:00
|
|
|
|
2011-04-05 22:55:45 +02:00
|
|
|
@param[in] ListHead The list head.
|
|
|
|
@param[in] Lines The lines.
|
2011-03-25 22:15:07 +01:00
|
|
|
|
2011-04-05 22:55:45 +02:00
|
|
|
@retval EFI_SUCCESS The operation was successful.
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
HFreeLines (
|
|
|
|
IN LIST_ENTRY *ListHead,
|
|
|
|
IN HEFI_EDITOR_LINE *Lines
|
|
|
|
)
|
2011-03-25 22:15:07 +01:00
|
|
|
{
|
2011-04-05 22:55:45 +02:00
|
|
|
LIST_ENTRY *Link;
|
2011-03-25 22:15:07 +01:00
|
|
|
HEFI_EDITOR_LINE *Line;
|
|
|
|
|
|
|
|
//
|
|
|
|
// release all the lines
|
|
|
|
//
|
|
|
|
if (Lines != NULL) {
|
|
|
|
|
|
|
|
Line = Lines;
|
|
|
|
Link = &(Line->Link);
|
|
|
|
do {
|
|
|
|
Line = CR (Link, HEFI_EDITOR_LINE, Link, EFI_EDITOR_LINE_LIST);
|
|
|
|
Link = Link->ForwardLink;
|
|
|
|
HLineFree (Line);
|
|
|
|
} while (Link != ListHead);
|
|
|
|
}
|
|
|
|
|
|
|
|
ListHead->ForwardLink = ListHead;
|
|
|
|
ListHead->BackLink = ListHead;
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2011-04-05 22:55:45 +02:00
|
|
|
/**
|
|
|
|
Get the X information for the mouse.
|
2011-03-25 22:15:07 +01:00
|
|
|
|
2011-04-05 22:55:45 +02:00
|
|
|
@param[in] GuidX The change.
|
2011-03-25 22:15:07 +01:00
|
|
|
|
2011-04-05 22:55:45 +02:00
|
|
|
@return the new information.
|
|
|
|
**/
|
2011-03-25 22:15:07 +01:00
|
|
|
INT32
|
|
|
|
HGetTextX (
|
|
|
|
IN INT32 GuidX
|
|
|
|
)
|
|
|
|
{
|
|
|
|
INT32 Gap;
|
|
|
|
|
|
|
|
HMainEditor.MouseAccumulatorX += GuidX;
|
|
|
|
Gap = (HMainEditor.MouseAccumulatorX * (INT32) HMainEditor.ScreenSize.Column) / (INT32) (50 * (INT32) HMainEditor.MouseInterface->Mode->ResolutionX);
|
|
|
|
HMainEditor.MouseAccumulatorX = (HMainEditor.MouseAccumulatorX * (INT32) HMainEditor.ScreenSize.Column) % (INT32) (50 * (INT32) HMainEditor.MouseInterface->Mode->ResolutionX);
|
|
|
|
HMainEditor.MouseAccumulatorX = HMainEditor.MouseAccumulatorX / (INT32) HMainEditor.ScreenSize.Column;
|
|
|
|
return Gap;
|
|
|
|
}
|
|
|
|
|
2011-04-05 22:55:45 +02:00
|
|
|
/**
|
|
|
|
Get the Y information for the mouse.
|
|
|
|
|
|
|
|
@param[in] GuidY The change.
|
|
|
|
|
|
|
|
@return the new information.
|
|
|
|
**/
|
2011-03-25 22:15:07 +01:00
|
|
|
INT32
|
|
|
|
HGetTextY (
|
|
|
|
IN INT32 GuidY
|
|
|
|
)
|
|
|
|
{
|
|
|
|
INT32 Gap;
|
|
|
|
|
|
|
|
HMainEditor.MouseAccumulatorY += GuidY;
|
|
|
|
Gap = (HMainEditor.MouseAccumulatorY * (INT32) HMainEditor.ScreenSize.Row) / (INT32) (50 * (INT32) HMainEditor.MouseInterface->Mode->ResolutionY);
|
|
|
|
HMainEditor.MouseAccumulatorY = (HMainEditor.MouseAccumulatorY * (INT32) HMainEditor.ScreenSize.Row) % (INT32) (50 * (INT32) HMainEditor.MouseInterface->Mode->ResolutionY);
|
|
|
|
HMainEditor.MouseAccumulatorY = HMainEditor.MouseAccumulatorY / (INT32) HMainEditor.ScreenSize.Row;
|
|
|
|
|
|
|
|
return Gap;
|
|
|
|
}
|