Ticket #2689 (fix fallocate detection for xBSD)
[midnight-commander.git] / src / editor / edit-impl.h
blobf9d3efee371e6d863aa9ba1b792ab5779902de92
1 /*
2 editor private API
3 */
5 /** \file edit-impl.h
6 * \brief Header: editor low level data handling and cursor fundamentals
7 * \author Paul Sheer
8 * \date 1996, 1997
9 */
11 #ifndef MC__EDIT_IMPL_H
12 #define MC__EDIT_IMPL_H
14 #include <stdio.h>
16 #include "lib/search.h" /* mc_search_type_t */
17 #include "lib/widget.h" /* cb_ret_t */
19 #include "edit.h"
21 /*** typedefs(not structures) and defined constants **********************************************/
23 #define REDRAW_LINE (1 << 0)
24 #define REDRAW_LINE_ABOVE (1 << 1)
25 #define REDRAW_LINE_BELOW (1 << 2)
26 #define REDRAW_AFTER_CURSOR (1 << 3)
27 #define REDRAW_BEFORE_CURSOR (1 << 4)
28 #define REDRAW_PAGE (1 << 5)
29 #define REDRAW_IN_BOUNDS (1 << 6)
30 #define REDRAW_CHAR_ONLY (1 << 7)
31 #define REDRAW_COMPLETELY (1 << 8)
33 #define EDIT_TEXT_HORIZONTAL_OFFSET 0
34 #define EDIT_TEXT_VERTICAL_OFFSET 0
36 #define EDIT_RIGHT_EXTREME option_edit_right_extreme
37 #define EDIT_LEFT_EXTREME option_edit_left_extreme
38 #define EDIT_TOP_EXTREME option_edit_top_extreme
39 #define EDIT_BOTTOM_EXTREME option_edit_bottom_extreme
42 * The editor keeps data in two arrays of buffers.
43 * All buffers have the same size, which must be a power of 2.
46 /* Configurable: log2 of the buffer size in bytes */
47 #ifndef S_EDIT_BUF_SIZE
48 #define S_EDIT_BUF_SIZE 16
49 #endif
51 /* Size of the buffer */
52 #define EDIT_BUF_SIZE (((off_t) 1) << S_EDIT_BUF_SIZE)
54 /* Buffer mask (used to find cursor position relative to the buffer) */
55 #define M_EDIT_BUF_SIZE (EDIT_BUF_SIZE - 1)
58 * Configurable: Maximal allowed number of buffers in each buffer array.
59 * This number can be increased for systems with enough physical memory.
61 #ifndef MAXBUFF
62 #define MAXBUFF 1024
63 #endif
65 /* Maximal length of file that can be opened */
66 #define SIZE_LIMIT (EDIT_BUF_SIZE * (MAXBUFF - 2))
68 /* Initial size of the undo stack, in bytes */
69 #define START_STACK_SIZE 32
71 /* Some codes that may be pushed onto or returned from the undo stack */
72 #define CURS_LEFT 601
73 #define CURS_RIGHT 602
74 #define DELCHAR 603
75 #define BACKSPACE 604
76 #define STACK_BOTTOM 605
77 #define CURS_LEFT_LOTS 606
78 #define CURS_RIGHT_LOTS 607
79 #define COLUMN_ON 608
80 #define COLUMN_OFF 609
81 #define DELCHAR_BR 610
82 #define BACKSPACE_BR 611
83 #define MARK_1 1000
84 #define MARK_2 500000000
85 #define MARK_CURS 1000000000
86 #define KEY_PRESS 1500000000
88 /* Tabs spaces: (sofar only HALF_TAB_SIZE is used: */
89 #define TAB_SIZE option_tab_spacing
90 #define HALF_TAB_SIZE ((int) option_tab_spacing / 2)
92 /* max count stack files */
93 #define MAX_HISTORY_MOVETO 50
94 #define LINE_STATE_WIDTH 8
96 #define LB_NAMES (LB_MAC + 1)
98 #define get_sys_error(s) (s)
100 #define edit_error_dialog(h,s) query_dialog (h, s, D_ERROR, 1, _("&Dismiss"))
102 #define edit_query_dialog2(h,t,a,b) query_dialog (h, t, D_NORMAL, 2, a, b)
103 #define edit_query_dialog3(h,t,a,b,c) query_dialog (h, t, D_NORMAL, 3, a, b, c)
105 /*** enums ***************************************************************************************/
107 /* type for file which is currently being edited */
108 typedef enum
110 EDIT_FILE_COMMON = 0,
111 EDIT_FILE_SYNTAX = 1,
112 EDIT_FILE_MENU = 2
113 } edit_current_file_t;
115 /* line breaks */
116 typedef enum
118 LB_ASIS = 0,
119 LB_UNIX,
120 LB_WIN,
121 LB_MAC
122 } LineBreaks;
124 typedef enum
126 EDIT_QUICK_SAVE = 0,
127 EDIT_SAFE_SAVE,
128 EDIT_DO_BACKUP
129 } edit_save_mode_t;
131 /*** structures declarations (and typedefs of structures)*****************************************/
133 /* search/replace options */
134 typedef struct edit_search_options_t
136 mc_search_type_t type;
137 gboolean case_sens;
138 gboolean backwards;
139 gboolean only_in_selection;
140 gboolean whole_words;
141 gboolean all_codepages;
142 } edit_search_options_t;
144 typedef struct edit_stack_type
146 long line;
147 char *filename;
148 } edit_stack_type;
150 struct Widget;
151 struct WMenuBar;
153 /*** global variables defined in .c file *********************************************************/
155 extern const char VERTICAL_MAGIC[5];
156 /* if enable_show_tabs_tws ==1 then use visible_tab visible_tws */
157 extern int enable_show_tabs_tws;
159 extern edit_search_options_t edit_search_options;
161 extern int edit_stack_iterator;
162 extern edit_stack_type edit_history_moveto[MAX_HISTORY_MOVETO];
164 extern int option_line_state_width;
166 extern int option_max_undo;
167 extern int option_auto_syntax;
169 extern int option_edit_right_extreme;
170 extern int option_edit_left_extreme;
171 extern int option_edit_top_extreme;
172 extern int option_edit_bottom_extreme;
174 extern const char *option_whole_chars_search;
175 extern gboolean search_create_bookmark;
177 /*** declarations of public functions ************************************************************/
179 int edit_drop_hotkey_menu (WEdit * e, int key);
180 void edit_menu_cmd (WEdit * e);
181 void user_menu (WEdit * edit, const char *menu_file, int selected_entry);
182 void edit_init_menu (struct WMenuBar *menubar);
183 void menu_save_mode_cmd (void);
184 int edit_translate_key (WEdit * edit, long x_key, int *cmd, int *ch);
185 int edit_get_byte (WEdit * edit, long byte_index);
186 int edit_get_utf (WEdit * edit, long byte_index, int *char_width);
187 long edit_count_lines (WEdit * edit, long current, long upto);
188 long edit_move_forward (WEdit * edit, long current, long lines, long upto);
189 long edit_move_forward3 (WEdit * edit, long current, int cols, long upto);
190 long edit_move_backward (WEdit * edit, long current, long lines);
191 void edit_scroll_screen_over_cursor (WEdit * edit);
192 void edit_render_keypress (WEdit * edit);
193 void edit_scroll_upward (WEdit * edit, unsigned long i);
194 void edit_scroll_downward (WEdit * edit, int i);
195 void edit_scroll_right (WEdit * edit, int i);
196 void edit_scroll_left (WEdit * edit, int i);
197 void edit_move_up (WEdit * edit, unsigned long i, int scroll);
198 void edit_move_down (WEdit * edit, unsigned long i, int scroll);
199 void edit_move_to_prev_col (WEdit * edit, long p);
200 int edit_get_col (WEdit * edit);
201 long edit_bol (WEdit * edit, long current);
202 long edit_eol (WEdit * edit, long current);
203 void edit_update_curs_row (WEdit * edit);
204 void edit_update_curs_col (WEdit * edit);
205 void edit_find_bracket (WEdit * edit);
206 int edit_reload_line (WEdit * edit, const char *filename, long line);
207 void edit_set_codeset (WEdit * edit);
209 void edit_block_copy_cmd (WEdit * edit);
210 void edit_block_move_cmd (WEdit * edit);
211 int edit_block_delete_cmd (WEdit * edit);
212 void edit_delete_line (WEdit * edit);
214 int edit_delete (WEdit * edit, const int byte_delete);
215 void edit_insert (WEdit * edit, int c);
216 void edit_cursor_move (WEdit * edit, long increment);
217 void edit_push_undo_action (WEdit * edit, long c, ...);
218 void edit_push_redo_action (WEdit * edit, long c, ...);
219 void edit_push_key_press (WEdit * edit);
220 void edit_insert_ahead (WEdit * edit, int c);
221 long edit_write_stream (WEdit * edit, FILE * f);
222 char *edit_get_write_filter (const char *writename, const char *filename);
223 int edit_save_confirm_cmd (WEdit * edit);
224 int edit_save_as_cmd (WEdit * edit);
225 WEdit *edit_init (WEdit * edit, int y, int x, int lines, int cols, const char *filename, long line);
226 int edit_clean (WEdit * edit);
227 gboolean edit_ok_to_exit (WEdit * edit);
228 int edit_renew (WEdit * edit);
229 int edit_new_cmd (WEdit * edit);
230 int edit_reload (WEdit * edit, const char *filename);
231 int edit_load_cmd (WEdit * edit, edit_current_file_t what);
232 void edit_mark_cmd (WEdit * edit, int unmark);
233 void edit_mark_current_word_cmd (WEdit * edit);
234 void edit_mark_current_line_cmd (WEdit * edit);
235 void edit_set_markers (WEdit * edit, long m1, long m2, int c1, int c2);
236 void edit_push_markers (WEdit * edit);
237 void edit_replace_cmd (WEdit * edit, int again);
238 void edit_search_cmd (WEdit * edit, gboolean again);
239 int edit_search_cmd_callback (const void *user_data, gsize char_offset);
240 void edit_complete_word_cmd (WEdit * edit);
241 void edit_get_match_keyword_cmd (WEdit * edit);
242 int edit_save_block (WEdit * edit, const char *filename, long start, long finish);
243 int edit_save_block_cmd (WEdit * edit);
244 int edit_insert_file_cmd (WEdit * edit);
245 void edit_insert_over (WEdit * edit);
246 int edit_insert_column_of_text_from_file (WEdit * edit, int file,
247 long *start_pos, long *end_pos, int *col1, int *col2);
248 long edit_insert_file (WEdit * edit, const char *filename);
249 int edit_load_back_cmd (WEdit * edit);
250 int edit_load_forward_cmd (WEdit * edit);
251 void edit_block_process_cmd (WEdit * edit, int macro_number);
252 void edit_refresh_cmd (WEdit * edit);
253 void edit_date_cmd (WEdit * edit);
254 void edit_goto_cmd (WEdit * edit);
255 int eval_marks (WEdit * edit, long *start_mark, long *end_mark);
256 void edit_status (WEdit * edit);
257 void edit_execute_key_command (WEdit * edit, unsigned long command, int char_for_insertion);
258 void edit_update_screen (WEdit * edit);
259 void edit_move_to_line (WEdit * e, long line);
260 void edit_move_display (WEdit * e, long line);
261 void edit_word_wrap (WEdit * edit);
262 int edit_sort_cmd (WEdit * edit);
263 int edit_ext_cmd (WEdit * edit);
264 void edit_help_cmd (WEdit * edit);
266 int edit_store_macro_cmd (WEdit * edit);
267 gboolean edit_load_macro_cmd (WEdit * edit);
268 void edit_delete_macro_cmd (WEdit * edit);
269 gboolean edit_repeat_macro_cmd (WEdit * edit);
271 int edit_copy_to_X_buf_cmd (WEdit * edit);
272 int edit_cut_to_X_buf_cmd (WEdit * edit);
273 void edit_paste_from_X_buf_cmd (WEdit * edit);
275 void edit_select_codepage_cmd (WEdit * edit);
276 void edit_insert_literal_cmd (WEdit * edit);
277 gboolean edit_execute_macro (WEdit * edit, int hotkey);
278 void edit_begin_end_macro_cmd (WEdit * edit);
279 void edit_begin_end_repeat_cmd (WEdit * edit);
281 void edit_paste_from_history (WEdit * edit);
283 void edit_set_filename (WEdit * edit, const char *name);
285 void edit_load_syntax (WEdit * edit, char ***pnames, const char *type);
286 void edit_free_syntax_rules (WEdit * edit);
287 void edit_get_syntax_color (WEdit * edit, long byte_index, int *color);
289 void book_mark_insert (WEdit * edit, size_t line, int c);
290 int book_mark_query_color (WEdit * edit, int line, int c);
291 int book_mark_query_all (WEdit * edit, int line, int *c);
292 struct _book_mark *book_mark_find (WEdit * edit, int line);
293 int book_mark_clear (WEdit * edit, int line, int c);
294 void book_mark_flush (WEdit * edit, int c);
295 void book_mark_inc (WEdit * edit, int line);
296 void book_mark_dec (WEdit * edit, int line);
297 void book_mark_serialize (WEdit * edit, int color);
298 void book_mark_restore (WEdit * edit, int color);
300 int line_is_blank (WEdit * edit, long line);
301 int edit_indent_width (WEdit * edit, long p);
302 void edit_insert_indent (WEdit * edit, int indent);
303 void edit_options_dialog (WEdit * edit);
304 void edit_syntax_dialog (WEdit * edit);
305 void edit_mail_dialog (WEdit * edit);
306 void format_paragraph (WEdit * edit, int force);
308 unsigned int edit_unlock_file (WEdit * edit);
309 unsigned int edit_lock_file (WEdit * edit);
311 /* either command or char_for_insertion must be passed as -1 */
312 void edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion);
314 /*** inline functions ****************************************************************************/
316 #endif /* MC__EDIT_IMPL_H */