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