Updated italian translatio
[midnight-commander.git] / edit / edit.h
blobd36e3618c8be5d07b3dcb4a49121b9eb6147b261
1 /* edit.h - main include file
3 Copyright (C) 1996, 1997 the Free Software Foundation
5 Authors: 1996, 1997 Paul Sheer
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307, USA.
23 #ifndef __EDIT_H
24 #define __EDIT_H
26 #include <stdio.h>
27 #include <stdarg.h>
28 #include <sys/types.h>
29 #ifdef HAVE_UNISTD_H
30 # include <unistd.h>
31 #endif
32 #include <string.h>
33 #include <ctype.h>
34 #include <errno.h>
35 #include <sys/stat.h>
36 #include <errno.h>
38 #include <stdlib.h>
40 #include "../src/global.h"
42 #define N_menus 5
44 #define SEARCH_DIALOG_OPTION_NO_SCANF 1
45 #define SEARCH_DIALOG_OPTION_NO_REGEX 2
46 #define SEARCH_DIALOG_OPTION_NO_CASE 4
47 #define SEARCH_DIALOG_OPTION_BACKWARDS 8
48 #define SEARCH_DIALOG_OPTION_BOOKMARK 16
50 #define EDIT_KEY_EMULATION_NORMAL 0
51 #define EDIT_KEY_EMULATION_EMACS 1
53 #define REDRAW_LINE (1 << 0)
54 #define REDRAW_LINE_ABOVE (1 << 1)
55 #define REDRAW_LINE_BELOW (1 << 2)
56 #define REDRAW_AFTER_CURSOR (1 << 3)
57 #define REDRAW_BEFORE_CURSOR (1 << 4)
58 #define REDRAW_PAGE (1 << 5)
59 #define REDRAW_IN_BOUNDS (1 << 6)
60 #define REDRAW_CHAR_ONLY (1 << 7)
61 #define REDRAW_COMPLETELY (1 << 8)
63 #define EDIT_TEXT_HORIZONTAL_OFFSET 0
64 #define EDIT_TEXT_VERTICAL_OFFSET 1
66 #define EDIT_RIGHT_EXTREME option_edit_right_extreme
67 #define EDIT_LEFT_EXTREME option_edit_left_extreme
68 #define EDIT_TOP_EXTREME option_edit_top_extreme
69 #define EDIT_BOTTOM_EXTREME option_edit_bottom_extreme
72 * The editor keeps data in two arrays of buffers.
73 * All buffers have the same size, which must be a power of 2.
76 /* Configurable: log2 of the buffer size in bytes */
77 #ifndef S_EDIT_BUF_SIZE
78 #define S_EDIT_BUF_SIZE 16
79 #endif
81 /* Size of the buffer */
82 #define EDIT_BUF_SIZE (((off_t) 1) << S_EDIT_BUF_SIZE)
84 /* Buffer mask (used to find cursor position relative to the buffer) */
85 #define M_EDIT_BUF_SIZE (EDIT_BUF_SIZE - 1)
88 * Configurable: Maximal allowed number of buffers in each buffer array.
89 * This number can be increased for systems with enough physical memory.
91 #ifndef MAXBUFF
92 #define MAXBUFF 1024
93 #endif
95 /* Maximal length of file that can be opened */
96 #define SIZE_LIMIT (EDIT_BUF_SIZE * (MAXBUFF - 2))
98 /* Initial size of the undo stack, in bytes */
99 #define START_STACK_SIZE 32
101 /* Some codes that may be pushed onto or returned from the undo stack */
102 #define CURS_LEFT 601
103 #define CURS_RIGHT 602
104 #define DELCHAR 603
105 #define BACKSPACE 604
106 #define STACK_BOTTOM 605
107 #define CURS_LEFT_LOTS 606
108 #define CURS_RIGHT_LOTS 607
109 #define COLUMN_ON 608
110 #define COLUMN_OFF 609
111 #define MARK_1 1000
112 #define MARK_2 700000000
113 #define KEY_PRESS 1400000000
115 /* Tabs spaces: (sofar only HALF_TAB_SIZE is used: */
116 #define TAB_SIZE option_tab_spacing
117 #define HALF_TAB_SIZE ((int) option_tab_spacing / 2)
119 struct macro {
120 short command;
121 short ch;
124 struct WEdit;
125 typedef struct WEdit WEdit;
127 int edit_drop_hotkey_menu (WEdit *e, int key);
128 void edit_menu_cmd (WEdit *e);
129 void edit_init_menu_emacs (void);
130 void edit_init_menu_normal (void);
131 void edit_done_menu (void);
132 void menu_save_mode_cmd (void);
133 int edit_raw_key_query (char *heading, char *query, int cancel);
134 int edit (const char *_file, int line);
135 int edit_translate_key (WEdit *edit, long x_key, int *cmd, int *ch);
137 #ifndef NO_INLINE_GETBYTE
138 int edit_get_byte (WEdit * edit, long byte_index);
139 #else
140 static inline int edit_get_byte (WEdit * edit, long byte_index)
142 unsigned long p;
143 if (byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0)
144 return '\n';
146 if (byte_index >= edit->curs1) {
147 p = edit->curs1 + edit->curs2 - byte_index - 1;
148 return edit->buffers2[p >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - (p & M_EDIT_BUF_SIZE) - 1];
149 } else {
150 return edit->buffers1[byte_index >> S_EDIT_BUF_SIZE][byte_index & M_EDIT_BUF_SIZE];
153 #endif
155 int edit_count_lines (WEdit * edit, long current, int upto);
156 long edit_move_forward (WEdit * edit, long current, int lines, long upto);
157 long edit_move_forward3 (WEdit * edit, long current, int cols, long upto);
158 long edit_move_backward (WEdit * edit, long current, int lines);
159 void edit_scroll_screen_over_cursor (WEdit * edit);
160 void edit_render_keypress (WEdit * edit);
161 void edit_scroll_upward (WEdit * edit, unsigned long i);
162 void edit_scroll_downward (WEdit * edit, int i);
163 void edit_scroll_right (WEdit * edit, int i);
164 void edit_scroll_left (WEdit * edit, int i);
165 void edit_move_up (WEdit * edit, unsigned long i, int scroll);
166 void edit_move_down (WEdit * edit, int i, int scroll);
167 int edit_get_col (WEdit * edit);
168 long edit_bol (WEdit * edit, long current);
169 long edit_eol (WEdit * edit, long current);
170 void edit_update_curs_row (WEdit * edit);
171 void edit_update_curs_col (WEdit * edit);
173 void edit_block_copy_cmd (WEdit * edit);
174 void edit_block_move_cmd (WEdit * edit);
175 int edit_block_delete_cmd (WEdit * edit);
176 void edit_delete_line (WEdit * edit);
178 int edit_delete (WEdit * edit);
179 void edit_insert (WEdit * edit, int c);
180 int edit_cursor_move (WEdit * edit, long increment);
181 void edit_push_action (WEdit * edit, long c, ...);
182 void edit_push_key_press (WEdit * edit);
183 void edit_insert_ahead (WEdit * edit, int c);
184 long edit_write_stream (WEdit * edit, FILE * f);
185 char *edit_get_write_filter (const char *writename, const char *filename);
186 int edit_save_confirm_cmd (WEdit * edit);
187 int edit_save_as_cmd (WEdit * edit);
188 WEdit *edit_init (WEdit *edit, int lines, int columns,
189 const char *filename, long line);
190 int edit_clean (WEdit * edit);
191 int edit_ok_to_exit (WEdit *edit);
192 int edit_renew (WEdit * edit);
193 int edit_new_cmd (WEdit * edit);
194 int edit_reload (WEdit *edit, const char *filename);
195 int edit_load_cmd (WEdit * edit);
196 void edit_mark_cmd (WEdit * edit, int unmark);
197 void edit_set_markers (WEdit * edit, long m1, long m2, int c1, int c2);
198 void edit_push_markers (WEdit * edit);
199 void edit_replace_cmd (WEdit * edit, int again);
200 void edit_search_cmd (WEdit * edit, int again);
201 void edit_complete_word_cmd (WEdit * edit);
202 int edit_save_block (WEdit * edit, const char *filename, long start, long finish);
203 int edit_save_block_cmd (WEdit * edit);
204 int edit_insert_file_cmd (WEdit * edit);
205 int edit_insert_file (WEdit * edit, const char *filename);
206 void edit_block_process_cmd (WEdit * edit, const char *shell_cmd, int block);
207 char *catstrs (const char *first, ...);
208 void freestrs (void);
209 void edit_refresh_cmd (WEdit * edit);
210 void edit_date_cmd (WEdit * edit);
211 void edit_goto_cmd (WEdit * edit);
212 int eval_marks (WEdit * edit, long *start_mark, long *end_mark);
213 void edit_status (WEdit * edit);
214 int edit_execute_key_command (WEdit * edit, int command, int char_for_insertion);
215 void edit_update_screen (WEdit * edit);
216 int edit_print_string (WEdit * e, const char *s);
217 void edit_move_to_line (WEdit * e, long line);
218 void edit_move_display (WEdit * e, long line);
219 void edit_word_wrap (WEdit * edit);
220 int edit_sort_cmd (WEdit * edit);
221 int edit_ext_cmd (WEdit * edit);
222 void edit_help_cmd (WEdit * edit);
224 int edit_save_macro_cmd (WEdit * edit, struct macro macro[], int n);
225 int edit_load_macro_cmd (WEdit * edit, struct macro macro[], int *n, int k);
226 void edit_delete_macro_cmd (WEdit * edit);
228 int edit_copy_to_X_buf_cmd (WEdit * edit);
229 int edit_cut_to_X_buf_cmd (WEdit * edit);
230 void edit_paste_from_X_buf_cmd (WEdit * edit);
232 void edit_paste_from_history (WEdit *edit);
234 void edit_set_filename (WEdit *edit, const char *name);
236 void edit_load_syntax (WEdit * edit, char **names, char *type);
237 void edit_free_syntax_rules (WEdit * edit);
238 void edit_get_syntax_color (WEdit * edit, long byte_index, int *color);
241 void book_mark_insert (WEdit * edit, int line, int c);
242 int book_mark_query_color (WEdit * edit, int line, int c);
243 int book_mark_query_all (WEdit * edit, int line, int *c);
244 struct _book_mark *book_mark_find (WEdit * edit, int line);
245 int book_mark_clear (WEdit * edit, int line, int c);
246 void book_mark_flush (WEdit * edit, int c);
247 void book_mark_inc (WEdit * edit, int line);
248 void book_mark_dec (WEdit * edit, int line);
250 int line_is_blank (WEdit *edit, long line);
251 int edit_indent_width (WEdit *edit, long p);
252 void edit_insert_indent (WEdit *edit, int indent);
253 void edit_options_dialog (void);
254 void edit_mail_dialog (WEdit *edit);
255 void format_paragraph (WEdit *edit, int force);
257 /* either command or char_for_insertion must be passed as -1 */
258 int edit_execute_cmd (WEdit * edit, int command, int char_for_insertion);
260 #define get_sys_error(s) (s)
262 #define edit_error_dialog(h,s) query_dialog (h, s, 0, 1, _("&Dismiss"))
264 #define edit_message_dialog(h,s) query_dialog (h, s, 0, 1, _("&OK"))
265 #define edit_query_dialog2(h,t,a,b) query_dialog(h,t,0,2,a,b)
266 #define edit_query_dialog3(h,t,a,b,c) query_dialog(h,t,0,3,a,b,c)
267 #define edit_query_dialog4(h,t,a,b,c,d) query_dialog(h,t,0,4,a,b,c,d)
269 #define color_palette(x) win->color[x].pixel
271 #define NUM_SELECTION_HISTORY 64
273 #ifndef MAX_PATH_LEN
274 #ifdef PATH_MAX
275 #define MAX_PATH_LEN PATH_MAX
276 #else
277 #define MAX_PATH_LEN 1024
278 #endif
279 #endif
282 what editor are we going to emulate? one of EDIT_KEY_EMULATION_NORMAL
283 or EDIT_KEY_EMULATION_EMACS
285 extern int edit_key_emulation;
287 extern WEdit *wedit;
288 struct Menu;
289 extern struct Menu *EditMenuBar[];
290 struct WMenu;
291 extern struct WMenu *edit_menubar;
293 extern int option_word_wrap_line_length;
294 extern int option_typewriter_wrap;
295 extern int option_auto_para_formatting;
296 extern int option_tab_spacing;
297 extern int option_fill_tabs_with_spaces;
298 extern int option_return_does_auto_indent;
299 extern int option_backspace_through_tabs;
300 extern int option_fake_half_tabs;
302 typedef enum {
303 EDIT_QUICK_SAVE = 0,
304 EDIT_SAFE_SAVE,
305 EDIT_DO_BACKUP
306 } edit_save_mode_t;
308 extern int option_save_mode;
309 extern int option_save_position;
310 extern int option_backup_ext_int;
311 extern int option_max_undo;
312 extern int option_syntax_highlighting;
313 extern int editor_option_check_nl_at_eof;
315 extern int option_edit_right_extreme;
316 extern int option_edit_left_extreme;
317 extern int option_edit_top_extreme;
318 extern int option_edit_bottom_extreme;
320 extern char *option_whole_chars_search;
321 extern char *option_backup_ext;
323 extern int edit_confirm_save;
324 extern int column_highlighting;
326 /* File names */
327 #define EDIT_DIR PATH_SEP_STR ".mc" PATH_SEP_STR "cedit"
328 #define SYNTAX_FILE EDIT_DIR PATH_SEP_STR "Syntax"
329 #define CLIP_FILE EDIT_DIR PATH_SEP_STR "cooledit.clip"
330 #define MACRO_FILE EDIT_DIR PATH_SEP_STR "cooledit.macros"
331 #define BLOCK_FILE EDIT_DIR PATH_SEP_STR "cooledit.block"
332 #define TEMP_FILE EDIT_DIR PATH_SEP_STR "cooledit.temp"
334 #endif /* __EDIT_H */