• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2   Implementation of various string and line routines
3 
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
9 
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.
12 
13 **/
14 
15 #include "HexEditor.h"
16 
17 extern BOOLEAN  HEditorMouseAction;
18 
19 /**
20   Free a line and it's internal buffer.
21 
22   @param[in] Src    The line to be freed.
23 **/
24 VOID
HLineFree(IN HEFI_EDITOR_LINE * Src)25 HLineFree (
26   IN  HEFI_EDITOR_LINE *Src
27   )
28 {
29   if (Src == NULL) {
30     return ;
31   }
32 
33   SHELL_FREE_NON_NULL (Src);
34 
35 }
36 
37 /**
38   Advance to the next Count lines.
39 
40   @param[in] Count      The line number to advance.
41 
42   @retval NULL An error occured.
43   @return A pointer to the line after advance.
44 **/
45 HEFI_EDITOR_LINE *
HLineAdvance(IN UINTN Count)46 HLineAdvance (
47   IN  UINTN Count
48   )
49 {
50   UINTN             Index;
51   HEFI_EDITOR_LINE  *Line;
52 
53   Line = HMainEditor.BufferImage->CurrentLine;
54   if (Line == NULL) {
55     return NULL;
56   }
57 
58   for (Index = 0; Index < Count; Index++) {
59     //
60     // if already last line
61     //
62     if (Line->Link.ForwardLink == HMainEditor.BufferImage->ListHead) {
63       return NULL;
64     }
65 
66     Line = CR (Line->Link.ForwardLink, HEFI_EDITOR_LINE, Link, EFI_EDITOR_LINE_LIST);
67   }
68 
69   return Line;
70 }
71 
72 /**
73   Retreat to the previous Count lines.
74 
75   @param[in] Count    The line number to retreat.
76 
77   @retval NULL An error occured.
78   @return A pointer to the line after retreat.
79 **/
80 HEFI_EDITOR_LINE *
HLineRetreat(IN UINTN Count)81 HLineRetreat (
82   IN  UINTN Count
83   )
84 {
85   UINTN             Index;
86   HEFI_EDITOR_LINE  *Line;
87 
88   Line = HMainEditor.BufferImage->CurrentLine;
89   if (Line == NULL) {
90     return NULL;
91   }
92 
93   for (Index = 0; Index < Count; Index++) {
94     //
95     // already the first line
96     //
97     if (Line->Link.BackLink == HMainEditor.BufferImage->ListHead) {
98       return NULL;
99     }
100 
101     Line = CR (Line->Link.BackLink, HEFI_EDITOR_LINE, Link, EFI_EDITOR_LINE_LIST);
102   }
103 
104   return Line;
105 }
106 
107 /**
108   Advance/Retreat lines.
109 
110   @param[in] Count      The line number to advance/retreat.
111                             >0 : advance
112                             <0: retreat
113 
114   @retval NULL An error occured.
115   @return A pointer to the line after move.
116 **/
117 HEFI_EDITOR_LINE *
HMoveLine(IN INTN Count)118 HMoveLine (
119   IN  INTN Count
120   )
121 {
122   HEFI_EDITOR_LINE  *Line;
123   UINTN             AbsCount;
124 
125   //
126   // difference with MoveCurrentLine
127   //     just return Line
128   //     do not set currentline to Line
129   //
130   if (Count <= 0) {
131     AbsCount  = (UINTN)ABS(Count);
132     Line      = HLineRetreat (AbsCount);
133   } else {
134     Line = HLineAdvance ((UINTN)Count);
135   }
136 
137   return Line;
138 }
139 
140 /**
141   Advance/Retreat lines and set CurrentLine in BufferImage to it.
142 
143   @param[in] Count    The line number to advance/retreat.
144                           >0 : advance
145                           <0: retreat
146 
147   @retval NULL An error occured.
148   @return A pointer to the line after move.
149 **/
150 HEFI_EDITOR_LINE *
HMoveCurrentLine(IN INTN Count)151 HMoveCurrentLine (
152   IN  INTN Count
153   )
154 {
155   HEFI_EDITOR_LINE  *Line;
156   UINTN             AbsCount;
157 
158   //
159   // <0: retreat
160   // >0: advance
161   //
162   if (Count <= 0) {
163     AbsCount  = (UINTN)ABS(Count);
164     Line      = HLineRetreat (AbsCount);
165   } else {
166     Line = HLineAdvance ((UINTN)Count);
167   }
168 
169   if (Line == NULL) {
170     return NULL;
171   }
172 
173   HMainEditor.BufferImage->CurrentLine = Line;
174 
175   return Line;
176 }
177 
178 
179 /**
180   Free all the lines in HBufferImage.
181     Fields affected:
182     Lines
183     CurrentLine
184     NumLines
185     ListHead
186 
187   @param[in] ListHead     The list head.
188   @param[in] Lines        The lines.
189 
190   @retval EFI_SUCCESS     The operation was successful.
191 **/
192 EFI_STATUS
HFreeLines(IN LIST_ENTRY * ListHead,IN HEFI_EDITOR_LINE * Lines)193 HFreeLines (
194   IN LIST_ENTRY   *ListHead,
195   IN HEFI_EDITOR_LINE *Lines
196   )
197 {
198   LIST_ENTRY        *Link;
199   HEFI_EDITOR_LINE  *Line;
200 
201   //
202   // release all the lines
203   //
204   if (Lines != NULL) {
205 
206     Line  = Lines;
207     Link  = &(Line->Link);
208     do {
209       Line  = CR (Link, HEFI_EDITOR_LINE, Link, EFI_EDITOR_LINE_LIST);
210       Link  = Link->ForwardLink;
211       HLineFree (Line);
212     } while (Link != ListHead);
213   }
214 
215   ListHead->ForwardLink = ListHead;
216   ListHead->BackLink = ListHead;
217 
218   return EFI_SUCCESS;
219 }
220 
221 /**
222   Get the X information for the mouse.
223 
224   @param[in] GuidX      The change.
225 
226   @return the new information.
227 **/
228 INT32
HGetTextX(IN INT32 GuidX)229 HGetTextX (
230   IN INT32 GuidX
231   )
232 {
233   INT32 Gap;
234 
235   HMainEditor.MouseAccumulatorX += GuidX;
236   Gap = (HMainEditor.MouseAccumulatorX * (INT32) HMainEditor.ScreenSize.Column) / (INT32) (50 * (INT32) HMainEditor.MouseInterface->Mode->ResolutionX);
237   HMainEditor.MouseAccumulatorX = (HMainEditor.MouseAccumulatorX * (INT32) HMainEditor.ScreenSize.Column) % (INT32) (50 * (INT32) HMainEditor.MouseInterface->Mode->ResolutionX);
238   HMainEditor.MouseAccumulatorX = HMainEditor.MouseAccumulatorX / (INT32) HMainEditor.ScreenSize.Column;
239   return Gap;
240 }
241 
242 /**
243   Get the Y information for the mouse.
244 
245   @param[in] GuidY      The change.
246 
247   @return the new information.
248 **/
249 INT32
HGetTextY(IN INT32 GuidY)250 HGetTextY (
251   IN INT32 GuidY
252   )
253 {
254   INT32 Gap;
255 
256   HMainEditor.MouseAccumulatorY += GuidY;
257   Gap = (HMainEditor.MouseAccumulatorY * (INT32) HMainEditor.ScreenSize.Row) / (INT32) (50 * (INT32) HMainEditor.MouseInterface->Mode->ResolutionY);
258   HMainEditor.MouseAccumulatorY = (HMainEditor.MouseAccumulatorY * (INT32) HMainEditor.ScreenSize.Row) % (INT32) (50 * (INT32) HMainEditor.MouseInterface->Mode->ResolutionY);
259   HMainEditor.MouseAccumulatorY = HMainEditor.MouseAccumulatorY / (INT32) HMainEditor.ScreenSize.Row;
260 
261   return Gap;
262 }
263