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