2 Implementation of various string and line routines
4 Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "HexEditor.h"
17 extern BOOLEAN HEditorMouseAction
;
31 Row -- row number to be cleared ( start from 1 )
44 if (HEditorMouseAction
) {
48 Limit
= HMainEditor
.ScreenSize
.Column
;
52 // prepare a blank line
54 for (Index
= 0; Index
< Limit
; Index
++) {
58 if (Row
== HMainEditor
.ScreenSize
.Row
&& Limit
== HMainEditor
.ScreenSize
.Column
) {
60 // if '\0' is still at position 80, it will cause first line error
62 Line
[Limit
- 1] = '\0';
67 // print out the blank line
69 ShellPrintEx ((INT32
)StartCol
- 1, (INT32
)Row
- 1, Line
);
74 IN HEFI_EDITOR_LINE
*Src
84 Src -- line to be duplicated
89 Not NULL -- line created
93 HEFI_EDITOR_LINE
*Dest
;
96 // allocate for the line structure
98 Dest
= AllocateZeroPool (sizeof (HEFI_EDITOR_LINE
));
103 Dest
->Signature
= EFI_EDITOR_LINE_LIST
;
104 Dest
->Size
= Src
->Size
;
106 CopyMem (Dest
->Buffer
, Src
->Buffer
, 0x10);
108 Dest
->Link
= Src
->Link
;
115 IN HEFI_EDITOR_LINE
*Src
121 Free a line and it's internal buffer
125 Src -- line to be freed
137 SHELL_FREE_NON_NULL (Src
);
149 Advance to the next Count lines
153 Count -- line number to advance
158 Not NULL -- line after advance
163 HEFI_EDITOR_LINE
*Line
;
165 Line
= HMainEditor
.BufferImage
->CurrentLine
;
170 for (Index
= 0; Index
< Count
; Index
++) {
172 // if already last line
174 if (Line
->Link
.ForwardLink
== HMainEditor
.BufferImage
->ListHead
) {
178 Line
= CR (Line
->Link
.ForwardLink
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
192 Retreat to the previous Count lines
196 Count -- line number to retreat
201 Not NULL -- line after retreat
206 HEFI_EDITOR_LINE
*Line
;
208 Line
= HMainEditor
.BufferImage
->CurrentLine
;
213 for (Index
= 0; Index
< Count
; Index
++) {
215 // already the first line
217 if (Line
->Link
.BackLink
== HMainEditor
.BufferImage
->ListHead
) {
221 Line
= CR (Line
->Link
.BackLink
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
235 Advance/Retreat lines
239 Count -- line number to advance/retreat
246 Not NULL -- line after advance
250 HEFI_EDITOR_LINE
*Line
;
254 // difference with MoveCurrentLine
256 // do not set currentline to Line
259 AbsCount
= (UINTN
)ABS(Count
);
260 Line
= _HLineRetreat (AbsCount
);
262 Line
= _HLineAdvance ((UINTN
)Count
);
276 Advance/Retreat lines and set CurrentLine in BufferImage to it
280 Count -- line number to advance/retreat
287 Not NULL -- line after advance
292 HEFI_EDITOR_LINE
*Line
;
300 AbsCount
= (UINTN
)ABS(Count
);
301 Line
= _HLineRetreat (AbsCount
);
303 Line
= _HLineAdvance ((UINTN
)Count
);
310 HMainEditor
.BufferImage
->CurrentLine
= Line
;
318 IN LIST_ENTRY
*ListHead
,
319 IN HEFI_EDITOR_LINE
*Lines
325 Free all the lines in HBufferImage
334 ListHead - The list head
344 HEFI_EDITOR_LINE
*Line
;
347 // release all the lines
352 Link
= &(Line
->Link
);
354 Line
= CR (Link
, HEFI_EDITOR_LINE
, Link
, EFI_EDITOR_LINE_LIST
);
355 Link
= Link
->ForwardLink
;
357 } while (Link
!= ListHead
);
360 ListHead
->ForwardLink
= ListHead
;
361 ListHead
->BackLink
= ListHead
;
380 Pat -- search pattern
386 >= 1 : found position + 1
397 // this function copies from some lib
402 Failure
= AllocateZeroPool ((UINTN
)(Lenp
* sizeof (INTN
)));
403 if (Failure
== NULL
) {
407 for (j
= 1; j
< Lenp
; j
++) {
409 while ((Pat
[j
] != Pat
[i
+ 1]) && (i
>= 0)) {
413 if (Pat
[j
] == Pat
[i
+ 1]) {
422 while (i
< Lens
&& j
< Lenp
) {
423 if (Str
[i
] == Pat
[j
]) {
429 j
= Failure
[j
- 1] + 1;
437 // >=1 : found position + 1
439 return ((j
== Lenp
) ? (i
- Lenp
) : -1) + 1;
450 HMainEditor
.MouseAccumulatorX
+= GuidX
;
451 Gap
= (HMainEditor
.MouseAccumulatorX
* (INT32
) HMainEditor
.ScreenSize
.Column
) / (INT32
) (50 * (INT32
) HMainEditor
.MouseInterface
->Mode
->ResolutionX
);
452 HMainEditor
.MouseAccumulatorX
= (HMainEditor
.MouseAccumulatorX
* (INT32
) HMainEditor
.ScreenSize
.Column
) % (INT32
) (50 * (INT32
) HMainEditor
.MouseInterface
->Mode
->ResolutionX
);
453 HMainEditor
.MouseAccumulatorX
= HMainEditor
.MouseAccumulatorX
/ (INT32
) HMainEditor
.ScreenSize
.Column
;
464 HMainEditor
.MouseAccumulatorY
+= GuidY
;
465 Gap
= (HMainEditor
.MouseAccumulatorY
* (INT32
) HMainEditor
.ScreenSize
.Row
) / (INT32
) (50 * (INT32
) HMainEditor
.MouseInterface
->Mode
->ResolutionY
);
466 HMainEditor
.MouseAccumulatorY
= (HMainEditor
.MouseAccumulatorY
* (INT32
) HMainEditor
.ScreenSize
.Row
) % (INT32
) (50 * (INT32
) HMainEditor
.MouseInterface
->Mode
->ResolutionY
);
467 HMainEditor
.MouseAccumulatorY
= HMainEditor
.MouseAccumulatorY
/ (INT32
) HMainEditor
.ScreenSize
.Row
;
480 convert hex string to uint
496 Size
= sizeof (UINTN
);
499 // skip leading white space
501 while (*Str
&& *Str
== ' ') {
505 if (StrLen (Str
) > Size
* 2) {
506 return EFI_LOAD_ERROR
;
509 // convert hex digits
523 if (!((c
>= 'a' && c
<= 'f') || (c
>= 'A' && c
<= 'F') || (c
>= '0' && c
<= '9') || (c
== '\0'))) {
524 return EFI_LOAD_ERROR
;
527 if (c
>= 'a' && c
<= 'f') {
531 if ((c
>= '0' && c
<= '9') || (c
>= 'A' && c
<= 'F')) {
532 u
= LShiftU64 (u
, 4) + (c
- (c
>= 'A' ? 'A' - 10 : '0'));