* textconf.h: Remove status_using_ncurses - it's useless now.
[midnight-commander.git] / edit / edit.h
blob39610826a28b73a9fb8bccf3bd6ac485f356d550
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 #ifdef HAVE_SLANG
27 # define HAVE_SYNTAXH 1
28 #endif
30 #include <stdio.h>
31 #include <stdarg.h>
32 #include <sys/types.h>
33 #ifdef HAVE_UNISTD_H
34 # include <unistd.h>
35 #endif
36 #include <string.h>
37 #include <ctype.h>
38 #include <errno.h>
39 #include <sys/stat.h>
40 #include <errno.h>
42 #include <fcntl.h>
44 #include <stdlib.h>
45 #if !defined(STDC_HEADERS) && defined(HAVE_MALLOC_H)
46 # include <malloc.h>
47 #endif
49 #if defined(HAVE_RX_H) && defined(HAVE_REGCOMP)
50 # include <rx.h>
51 #else
52 # include <regex.h>
53 #endif
55 #include "src/global.h"
56 #include "src/tty.h"
57 #include "src/main.h" /* for char *shell */
58 #include "src/mad.h"
59 #include "src/dlg.h"
60 #include "src/widget.h"
61 #include "src/color.h"
62 #include "src/dialog.h"
63 #include "src/mouse.h"
64 #include "src/help.h"
65 #include "src/key.h"
66 #include "src/wtools.h" /* for QuickWidgets */
67 #include "src/cmd.h" /* for menu_edit_cmd */
68 #include "src/win.h"
69 #include "vfs/vfs.h"
70 #include "src/menu.h"
71 #include "edit-widget.h"
72 #include "src/user.h" /* for user_menu_cmd, must be after edit-widget.h */
74 # define WANT_WIDGETS
76 # define WIDGET_COMMAND (WIDGET_USER + 10)
77 # define N_menus 5
79 #define SEARCH_DIALOG_OPTION_NO_SCANF 1
80 #define SEARCH_DIALOG_OPTION_NO_REGEX 2
81 #define SEARCH_DIALOG_OPTION_NO_CASE 4
82 #define SEARCH_DIALOG_OPTION_BACKWARDS 8
83 #define SEARCH_DIALOG_OPTION_BOOKMARK 16
85 #define EDIT_KEY_EMULATION_NORMAL 0
86 #define EDIT_KEY_EMULATION_EMACS 1
88 #define REDRAW_LINE (1 << 0)
89 #define REDRAW_LINE_ABOVE (1 << 1)
90 #define REDRAW_LINE_BELOW (1 << 2)
91 #define REDRAW_AFTER_CURSOR (1 << 3)
92 #define REDRAW_BEFORE_CURSOR (1 << 4)
93 #define REDRAW_PAGE (1 << 5)
94 #define REDRAW_IN_BOUNDS (1 << 6)
95 #define REDRAW_CHAR_ONLY (1 << 7)
96 #define REDRAW_COMPLETELY (1 << 8)
98 #define MOD_ABNORMAL (1 << 0)
99 #define MOD_UNDERLINED (1 << 1)
100 #define MOD_BOLD (1 << 2)
101 #define MOD_HIGHLIGHTED (1 << 3)
102 #define MOD_MARKED (1 << 4)
103 #define MOD_ITALIC (1 << 5)
104 #define MOD_CURSOR (1 << 6)
105 #define MOD_INVERSE (1 << 7)
107 #define EDIT_TEXT_HORIZONTAL_OFFSET 0
108 #define EDIT_TEXT_VERTICAL_OFFSET 1
109 #define FONT_OFFSET_X 0
110 #define FONT_OFFSET_Y 0
112 #define EDIT_RIGHT_EXTREME option_edit_right_extreme
113 #define EDIT_LEFT_EXTREME option_edit_left_extreme
114 #define EDIT_TOP_EXTREME option_edit_top_extreme
115 #define EDIT_BOTTOM_EXTREME option_edit_bottom_extreme
117 /*there are a maximum of ... */
118 /*... edit buffers, each of which is ... */
119 #define EDIT_BUF_SIZE 0x10000
120 /* ...bytes in size. */
122 /*x / EDIT_BUF_SIZE equals x >> ... */
123 #define S_EDIT_BUF_SIZE 16
125 /* x % EDIT_BUF_SIZE is equal to x && ... */
126 #define M_EDIT_BUF_SIZE 0xFFFF
128 #define SIZE_LIMIT (EDIT_BUF_SIZE * (MAXBUFF - 2))
129 /* Note a 16k stack is 64k of data and enough to hold (usually) around 10
130 pages of undo info. */
132 /* undo stack */
133 #define START_STACK_SIZE 32
136 /*some codes that may be pushed onto or returned from the undo stack: */
137 #define CURS_LEFT 601
138 #define CURS_RIGHT 602
139 #define DELETE 603
140 #define BACKSPACE 604
141 #define STACK_BOTTOM 605
142 #define CURS_LEFT_LOTS 606
143 #define CURS_RIGHT_LOTS 607
144 #define COLUMN_ON 608
145 #define COLUMN_OFF 609
146 #define MARK_1 1000
147 #define MARK_2 700000000
148 #define KEY_PRESS 1400000000
150 /*Tabs spaces: (sofar only HALF_TAB_SIZE is used: */
151 #define TAB_SIZE option_tab_spacing
152 #define HALF_TAB_SIZE ((int) option_tab_spacing / 2)
154 struct selection {
155 unsigned char * text;
156 int len;
159 #define MAX_WORDS_PER_CONTEXT 1024
160 #define MAX_CONTEXTS 128
162 struct key_word {
163 char *keyword;
164 unsigned char first;
165 char *whole_word_chars_left;
166 char *whole_word_chars_right;
167 time_t time;
168 #define NO_COLOR 0x7FFFFFFF
169 #define SPELLING_ERROR 0x7EFEFEFE
170 int line_start;
171 int bg;
172 int fg;
175 struct context_rule {
176 char *left;
177 unsigned char first_left;
178 char *right;
179 unsigned char first_right;
180 char line_start_left;
181 char line_start_right;
182 int single_char;
183 int between_delimiters;
184 char *whole_word_chars_left;
185 char *whole_word_chars_right;
186 char *keyword_first_chars;
187 int spelling;
188 /* first word is word[1] */
189 struct key_word **keyword;
192 int edit_drop_hotkey_menu (WEdit * e, int key);
193 void edit_menu_cmd (WEdit * e);
194 void edit_init_menu_emacs (void);
195 void edit_init_menu_normal (void);
196 void edit_done_menu (void);
197 int edit_raw_key_query (char *heading, char *query, int cancel);
198 char *strcasechr (const unsigned char *s, int c);
199 int edit (const char *_file, int line);
200 int edit_translate_key (WEdit * edit, unsigned int x_keycode, long x_key, int x_state, int *cmd, int *ch);
202 #ifndef NO_INLINE_GETBYTE
203 int edit_get_byte (WEdit * edit, long byte_index);
204 #else
205 static inline int edit_get_byte (WEdit * edit, long byte_index)
207 unsigned long p;
208 if (byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0)
209 return '\n';
211 if (byte_index >= edit->curs1) {
212 p = edit->curs1 + edit->curs2 - byte_index - 1;
213 return edit->buffers2[p >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - (p & M_EDIT_BUF_SIZE) - 1];
214 } else {
215 return edit->buffers1[byte_index >> S_EDIT_BUF_SIZE][byte_index & M_EDIT_BUF_SIZE];
218 #endif
220 char *edit_get_buffer_as_text (WEdit * edit);
221 int edit_count_lines (WEdit * edit, long current, int upto);
222 long edit_move_forward (WEdit * edit, long current, int lines, long upto);
223 long edit_move_forward3 (WEdit * edit, long current, int cols, long upto);
224 long edit_move_backward (WEdit * edit, long current, int lines);
225 void edit_scroll_screen_over_cursor (WEdit * edit);
226 void edit_render_keypress (WEdit * edit);
227 void edit_scroll_upward (WEdit * edit, unsigned long i);
228 void edit_scroll_downward (WEdit * edit, int i);
229 void edit_scroll_right (WEdit * edit, int i);
230 void edit_scroll_left (WEdit * edit, int i);
231 int edit_get_col (WEdit * edit);
232 long edit_bol (WEdit * edit, long current);
233 long edit_eol (WEdit * edit, long current);
234 void edit_update_curs_row (WEdit * edit);
235 void edit_update_curs_col (WEdit * edit);
237 void edit_block_copy_cmd (WEdit * edit);
238 void edit_block_move_cmd (WEdit * edit);
239 int edit_block_delete_cmd (WEdit * edit);
240 int edit_block_delete (WEdit * edit);
241 void edit_delete_line (WEdit * edit);
243 int edit_delete (WEdit * edit);
244 void edit_insert (WEdit * edit, int c);
245 int edit_cursor_move (WEdit * edit, long increment);
246 void edit_push_action (WEdit * edit, long c,...);
247 void edit_push_key_press (WEdit * edit);
248 void edit_insert_ahead (WEdit * edit, int c);
249 int edit_save_file (WEdit * edit, const char *filename);
250 long edit_write_stream (WEdit * edit, FILE * f);
251 char *edit_get_write_filter (char *writename, const char *filename);
252 int edit_save_cmd (WEdit * edit);
253 int edit_save_confirm_cmd (WEdit * edit);
254 int edit_save_as_cmd (WEdit * edit);
255 WEdit *edit_init (WEdit * edit, int lines, int columns, const char *filename, const char *text, const char *dir, unsigned long text_size);
256 int edit_clean (WEdit * edit);
257 int edit_renew (WEdit * edit);
258 int edit_new_cmd (WEdit * edit);
259 int edit_reload (WEdit * edit, const char *filename, const char *text, const char *dir, unsigned long text_size);
260 int edit_load_cmd (WEdit * edit);
261 void edit_mark_cmd (WEdit * edit, int unmark);
262 void edit_set_markers (WEdit * edit, long m1, long m2, int c1, int c2);
263 void edit_push_markers (WEdit * edit);
264 void edit_quit_cmd (WEdit * edit);
265 void edit_replace_cmd (WEdit * edit, int again);
266 void edit_search_cmd (WEdit * edit, int again);
267 int edit_save_block (WEdit * edit, const char *filename, long start, long finish);
268 int edit_save_block_cmd (WEdit * edit);
269 int edit_insert_file_cmd (WEdit * edit);
270 int edit_insert_file (WEdit * edit, const char *filename);
271 void edit_block_process_cmd (WEdit * edit, const char *shell_cmd, int block);
272 char *catstrs (const char *first,...);
273 void edit_refresh_cmd (WEdit * edit);
274 void edit_date_cmd (WEdit * edit);
275 void edit_goto_cmd (WEdit * edit);
276 int eval_marks (WEdit * edit, long *start_mark, long *end_mark);
277 void edit_status (WEdit * edit);
278 int edit_execute_command (WEdit * edit, int command, int char_for_insertion);
279 int edit_execute_key_command (WEdit * edit, int command, int char_for_insertion);
280 void edit_update_screen (WEdit * edit);
281 int edit_printf (WEdit * e, const char *fmt,...);
282 int edit_print_string (WEdit * e, const char *s);
283 void edit_move_to_line (WEdit * e, long line);
284 void edit_move_display (WEdit * e, long line);
285 void edit_word_wrap (WEdit * edit);
286 unsigned char *edit_get_block (WEdit * edit, long start, long finish, int *l);
287 int edit_sort_cmd (WEdit * edit);
288 void edit_help_cmd (WEdit * edit);
289 void edit_left_word_move (WEdit * edit, int s);
290 void edit_right_word_move (WEdit * edit, int s);
291 void edit_get_selection (WEdit * edit);
293 int edit_save_macro_cmd (WEdit * edit, struct macro macro[], int n);
294 int edit_load_macro_cmd (WEdit * edit, struct macro macro[], int *n, int k);
295 void edit_delete_macro_cmd (WEdit * edit);
297 int edit_copy_to_X_buf_cmd (WEdit * edit);
298 int edit_cut_to_X_buf_cmd (WEdit * edit);
299 void edit_paste_from_X_buf_cmd (WEdit * edit);
301 void edit_paste_from_history (WEdit *edit);
303 void edit_split_filename (WEdit * edit, const char *name);
305 #define CWidget Widget
306 void edit_set_syntax_change_callback (void (*callback) (CWidget *));
307 void edit_load_syntax (WEdit * edit, char **names, char *type);
308 void edit_free_syntax_rules (WEdit * edit);
309 void edit_get_syntax_color (WEdit * edit, long byte_index, int *fg, int *bg);
310 int edit_check_spelling (WEdit * edit);
313 void book_mark_insert (WEdit * edit, int line, int c);
314 int book_mark_query_color (WEdit * edit, int line, int c);
315 int book_mark_query_all (WEdit * edit, int line, int *c);
316 struct _book_mark *book_mark_find (WEdit * edit, int line);
317 int book_mark_clear (WEdit * edit, int line, int c);
318 void book_mark_flush (WEdit * edit, int c);
319 void book_mark_inc (WEdit * edit, int line);
320 void book_mark_dec (WEdit * edit, int line);
322 void user_menu (WEdit *edit);
324 #define CPushFont(x,y)
325 #define CPopFont()
326 #define FIXED_FONT 1
328 /* put OS2/NT/WIN95 defines here */
330 #ifdef USE_O_TEXT
331 # define MY_O_TEXT O_TEXT
332 #else
333 # define MY_O_TEXT 0
334 #endif
336 #define FONT_PIX_PER_LINE 1
337 #define FONT_MEAN_WIDTH 1
339 #define get_sys_error(s) (s)
340 #define open mc_open
341 #define close(f) mc_close(f)
342 #define read(f,b,c) mc_read(f,b,c)
343 #define write(f,b,c) mc_write(f,b,c)
344 #define stat(f,s) mc_stat(f,s)
345 #define mkdir(s,m) mc_mkdir(s,m)
346 #define itoa MY_itoa
348 #define edit_get_load_file(d,f,h) input_dialog (h, " Enter file name: ", f)
349 #define edit_get_save_file(d,f,h) input_dialog (h, " Enter file name: ", f)
350 #define CMalloc(x) malloc(x)
352 #define set_error_msg(s) edit_init_error_msg = strdup(s)
354 #ifdef _EDIT_C
356 #define edit_error_dialog(h,s) set_error_msg(s)
357 char *edit_init_error_msg = NULL;
359 #else /* ! _EDIT_C */
361 #define edit_error_dialog(h,s) query_dialog (h, s, 0, 1, _("&Dismiss"))
362 #define edit_message_dialog(h,s) query_dialog (h, s, 0, 1, _("&Ok"))
363 extern char *edit_init_error_msg;
365 #endif /* ! _EDIT_C */
368 #define get_error_msg(s) edit_init_error_msg
369 #define edit_query_dialog2(h,t,a,b) query_dialog(h,t,0,2,a,b)
370 #define edit_query_dialog3(h,t,a,b,c) query_dialog(h,t,0,3,a,b,c)
371 #define edit_query_dialog4(h,t,a,b,c,d) query_dialog(h,t,0,4,a,b,c,d)
373 #define color_palette(x) win->color[x].pixel
375 extern char *home_dir;
377 #define NUM_SELECTION_HISTORY 64
379 #ifndef MAX_PATH_LEN
380 #ifdef PATH_MAX
381 #define MAX_PATH_LEN PATH_MAX
382 #else
383 #define MAX_PATH_LEN 1024
384 #endif
385 #endif
387 #ifdef _EDIT_C
389 struct selection selection =
390 {0, 0};
391 int current_selection = 0;
392 /* Note: selection.text = selection_history[current_selection].text */
393 struct selection selection_history[NUM_SELECTION_HISTORY] =
395 {0, 0},
396 {0, 0},
397 {0, 0},
398 {0, 0},
399 {0, 0},
400 {0, 0},
401 {0, 0},
402 {0, 0},
403 {0, 0},
404 {0, 0}
408 what editor are we going to emulate? one of EDIT_KEY_EMULATION_NORMAL
409 or EDIT_KEY_EMULATION_EMACS
411 int edit_key_emulation = EDIT_KEY_EMULATION_NORMAL;
413 int option_word_wrap_line_length = 72;
414 int option_typewriter_wrap = 0;
415 int option_auto_para_formatting = 0;
416 int option_international_characters = 0;
417 int option_tab_spacing = 8;
418 int option_fill_tabs_with_spaces = 0;
419 int option_return_does_auto_indent = 1;
420 int option_backspace_through_tabs = 0;
421 int option_fake_half_tabs = 1;
422 int option_save_mode = 0;
423 int option_backup_ext_int = -1;
424 int option_find_bracket = 1;
425 int option_max_undo = 32768;
427 int option_editor_fg_normal = 26;
428 int option_editor_fg_bold = 8;
429 int option_editor_fg_italic = 10;
431 int option_edit_right_extreme = 0;
432 int option_edit_left_extreme = 0;
433 int option_edit_top_extreme = 0;
434 int option_edit_bottom_extreme = 0;
436 int option_editor_bg_normal = 1;
437 int option_editor_bg_abnormal = 0;
438 int option_editor_bg_marked = 2;
439 int option_editor_bg_marked_abnormal = 9;
440 int option_editor_bg_highlighted = 12;
441 int option_editor_fg_cursor = 18;
443 char *option_whole_chars_search = "0123456789abcdefghijklmnopqrstuvwxyz_";
444 char *option_chars_move_whole_word = "!=&|<>^~ !:;, !'!`!.?!\"!( !) !Aa0 !+-*/= |<> ![ !] !\\#! ";
445 char *option_backup_ext = "~";
447 #else /* ! _EDIT_C */
449 extern struct selection selection;
450 extern struct selection selection_history[];
451 extern int current_selection;
454 what editor are we going to emulate? one of EDIT_KEY_EMULATION_NORMAL
455 or EDIT_KEY_EMULATION_EMACS
457 extern int edit_key_emulation;
458 extern WEdit *wedit;
460 extern int option_word_wrap_line_length;
461 extern int option_typewriter_wrap;
462 extern int option_auto_para_formatting;
463 extern int option_international_characters;
464 extern int option_tab_spacing;
465 extern int option_fill_tabs_with_spaces;
466 extern int option_return_does_auto_indent;
467 extern int option_backspace_through_tabs;
468 extern int option_fake_half_tabs;
469 extern int option_save_mode;
470 extern int option_backup_ext_int;
471 extern int option_find_bracket;
472 extern int option_max_undo;
474 extern int option_editor_fg_normal;
475 extern int option_editor_fg_bold;
476 extern int option_editor_fg_italic;
478 extern int option_edit_right_extreme;
479 extern int option_edit_left_extreme;
480 extern int option_edit_top_extreme;
481 extern int option_edit_bottom_extreme;
483 extern int option_editor_bg_normal;
484 extern int option_editor_bg_abnormal;
485 extern int option_editor_bg_marked;
486 extern int option_editor_bg_marked_abnormal;
487 extern int option_editor_bg_highlighted;
488 extern int option_editor_fg_cursor;
490 extern char *option_whole_chars_search;
491 extern char *option_chars_move_whole_word;
492 extern char *option_backup_ext;
494 extern int edit_confirm_save;
496 #endif /* ! _EDIT_C */
497 #endif /* __EDIT_H */