1 /** @file
2   Declares filebuffer interface functions.
3 
4   Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved. <BR>
5   SPDX-License-Identifier: BSD-2-Clause-Patent
6 
7 **/
8 
9 #ifndef _LIB_FILE_BUFFER_H_
10 #define _LIB_FILE_BUFFER_H_
11 
12 #include "TextEditorTypes.h"
13 
14 /**
15   Initialization function for FileBuffer.
16 
17   @param EFI_SUCCESS            The initialization was successful.
18   @param EFI_LOAD_ERROR         A default name could not be created.
19   @param EFI_OUT_OF_RESOURCES   A memory allocation failed.
20 **/
21 EFI_STATUS
22 FileBufferInit (
23   VOID
24   );
25 
26 /**
27   Cleanup function for FileBuffer.
28 
29   @retval EFI_SUCCESS   The cleanup was successful.
30 **/
31 EFI_STATUS
32 FileBufferCleanup (
33   VOID
34   );
35 
36 /**
37   Refresh the screen with whats in the buffer.
38 
39   @retval EFI_SUCCESS     The refresh was successful.
40   @retval EFI_LOAD_ERROR  There was an error finding what to write.
41 **/
42 EFI_STATUS
43 FileBufferRefresh (
44   VOID
45   );
46 
47 /**
48   Dispatch input to different handler
49   @param[in] Key                The input key.  One of:
50                                     ASCII KEY
51                                     Backspace/Delete
52                                     Return
53                                     Direction key: up/down/left/right/pgup/pgdn
54                                     Home/End
55                                     INS
56 
57   @retval EFI_SUCCESS           The dispatch was done successfully.
58   @retval EFI_LOAD_ERROR        The dispatch was not successful.
59   @retval EFI_OUT_OF_RESOURCES  A memory allocation failed.
60 **/
61 EFI_STATUS
62 FileBufferHandleInput (
63   IN CONST EFI_INPUT_KEY * Key
64   );
65 
66 /**
67   Backup function for FileBuffer.  Only backup the following items:
68       Mouse/Cursor position
69       File Name, Type, ReadOnly, Modified
70       Insert Mode
71 
72   This is for making the file buffer refresh as few as possible.
73 
74   @retval EFI_SUCCESS           The backup operation was successful.
75 **/
76 EFI_STATUS
77 FileBufferBackup (
78   VOID
79   );
80 
81 /**
82   Set the cursor position according to FileBuffer.DisplayPosition.
83 
84   @retval EFI_SUCCESS           The operation was successful.
85 **/
86 EFI_STATUS
87 FileBufferRestorePosition (
88   VOID
89   );
90 
91 /**
92   Set FileName field in FileBuffer.
93 
94   @param Str                    The file name to set.
95 
96   @retval EFI_SUCCESS           The filename was successfully set.
97   @retval EFI_OUT_OF_RESOURCES  A memory allocation failed.
98   @retval EFI_INVALID_PARAMETER Str is not a valid filename.
99 **/
100 EFI_STATUS
101 FileBufferSetFileName (
102   IN CONST CHAR16 *Str
103   );
104 
105 /**
106   Read a file from disk into the FileBuffer.
107 
108   @param[in] FileName           The filename to read.
109   @param[in] Recover            TRUE if is for recover mode, no information printouts.
110 
111   @retval EFI_SUCCESS            The load was successful.
112   @retval EFI_LOAD_ERROR         The load failed.
113   @retval EFI_OUT_OF_RESOURCES   A memory allocation failed.
114   @retval EFI_INVALID_PARAMETER  FileName is a directory.
115 **/
116 EFI_STATUS
117 FileBufferRead (
118   IN CONST CHAR16  *FileName,
119   IN CONST BOOLEAN Recover
120   );
121 
122 /**
123   Save lines in FileBuffer to disk
124 
125   @param[in] FileName           The file name for writing.
126 
127   @retval EFI_SUCCESS           Data was written.
128   @retval EFI_LOAD_ERROR
129   @retval EFI_OUT_OF_RESOURCES  There were not enough resources to write the file.
130 **/
131 EFI_STATUS
132 FileBufferSave (
133   CONST CHAR16 *FileName
134   );
135 
136 /**
137   According to cursor's file position, adjust screen display
138 
139   @param[in] NewFilePosRow    The row of file position ( start from 1 ).
140   @param[in] NewFilePosCol    The column of file position ( start from 1 ).
141 **/
142 VOID
143 FileBufferMovePosition (
144   IN CONST UINTN NewFilePosRow,
145   IN CONST UINTN NewFilePosCol
146   );
147 
148 /**
149   Cut current line out and return a pointer to it.
150 
151   @param[out] CutLine    Upon a successful return pointer to the pointer to
152                         the allocated cut line.
153 
154   @retval EFI_SUCCESS             The cut was successful.
155   @retval EFI_NOT_FOUND           There was no selection to cut.
156   @retval EFI_OUT_OF_RESOURCES    A memory allocation failed.
157 **/
158 EFI_STATUS
159 FileBufferCutLine (
160   OUT EFI_EDITOR_LINE **CutLine
161   );
162 
163 /**
164   Paste a line into line list.
165 
166   @retval EFI_SUCCESS             The paste was successful.
167   @retval EFI_OUT_OF_RESOURCES    A memory allocation failed.
168 **/
169 EFI_STATUS
170 FileBufferPasteLine (
171   VOID
172   );
173 
174 /**
175   Search string from current position on in file
176 
177   @param[in] Str    The search string.
178   @param[in] Offset The offset from current position.
179 
180   @retval EFI_SUCCESS       The operation was successful.
181   @retval EFI_NOT_FOUND     The string Str was not found.
182 **/
183 EFI_STATUS
184 FileBufferSearch (
185   IN CONST CHAR16  *Str,
186   IN CONST UINTN Offset
187   );
188 
189 /**
190   Replace SearchLen characters from current position on with Replace.
191 
192   This will modify the current buffer at the current position.
193 
194   @param[in] Replace    The string to replace.
195   @param[in] SearchLen  Search string's length.
196 
197   @retval EFI_SUCCESS             The operation was successful.
198   @retval EFI_OUT_OF_RESOURCES    A memory allocation failed.
199 **/
200 EFI_STATUS
201 FileBufferReplace (
202   IN CONST CHAR16   *Replace,
203   IN CONST UINTN    SearchLen
204   );
205 
206 /**
207   Search and replace operation.
208 
209   @param[in] SearchStr    The string to search for.
210   @param[in] ReplaceStr   The string to replace with.
211   @param[in] Offset       The column to start at.
212 **/
213 EFI_STATUS
214 FileBufferReplaceAll (
215   IN CHAR16 *SearchStr,
216   IN CHAR16 *ReplaceStr,
217   IN UINTN  Offset
218   );
219 
220 /**
221   Move the mouse cursor position.
222 
223   @param[in] TextX      The new x-coordinate.
224   @param[in] TextY      The new y-coordinate.
225 **/
226 VOID
227 FileBufferAdjustMousePosition (
228   IN CONST INT32 TextX,
229   IN CONST INT32 TextY
230   );
231 
232 /**
233   Set the modified state to TRUE.
234 **/
235 VOID
236 FileBufferSetModified (
237   VOID
238   );
239 
240 #endif
241