*** empty log message ***
[midnight-commander.git] / edit / edit.h
blob0078345d67467240e0a032fe2767b4138be4ff6d
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 __attribute__ ((format (printf, 2, 3)));
283 int edit_print_string (WEdit * e, const char *s);
284 void edit_move_to_line (WEdit * e, long line);
285 void edit_move_display (WEdit * e, long line);
286 void edit_word_wrap (WEdit * edit);
287 unsigned char *edit_get_block (WEdit * edit, long start, long finish, int *l);
288 int edit_sort_cmd (WEdit * edit);
289 void edit_help_cmd (WEdit * edit);
290 void edit_left_word_move (WEdit * edit, int s);
291 void edit_right_word_move (WEdit * edit, int s);
292 void edit_get_selection (WEdit * edit);
294 int edit_save_macro_cmd (WEdit * edit, struct macro macro[], int n);
295 int edit_load_macro_cmd (WEdit * edit, struct macro macro[], int *n, int k);
296 void edit_delete_macro_cmd (WEdit * edit);
298 int edit_copy_to_X_buf_cmd (WEdit * edit);
299 int edit_cut_to_X_buf_cmd (WEdit * edit);
300 void edit_paste_from_X_buf_cmd (WEdit * edit);
302 void edit_paste_from_history (WEdit *edit);
304 void edit_split_filename (WEdit * edit, const char *name);
306 #define CWidget Widget
307 void edit_set_syntax_change_callback (void (*callback) (CWidget *));
308 void edit_load_syntax (WEdit * edit, char **names, char *type);
309 void edit_free_syntax_rules (WEdit * edit);
310 void edit_get_syntax_color (WEdit * edit, long byte_index, int *fg, int *bg);
311 int edit_check_spelling (WEdit * edit);
314 void book_mark_insert (WEdit * edit, int line, int c);
315 int book_mark_query_color (WEdit * edit, int line, int c);
316 int book_mark_query_all (WEdit * edit, int line, int *c);
317 struct _book_mark *book_mark_find (WEdit * edit, int line);
318 int book_mark_clear (WEdit * edit, int line, int c);
319 void book_mark_flush (WEdit * edit, int c);
320 void book_mark_inc (WEdit * edit, int line);
321 void book_mark_dec (WEdit * edit, int line);
323 void user_menu (WEdit *edit);
325 #define CPushFont(x,y)
326 #define CPopFont()
327 #define FIXED_FONT 1
329 /* put OS2/NT/WIN95 defines here */
331 #ifdef USE_O_TEXT
332 # define MY_O_TEXT O_TEXT
333 #else
334 # define MY_O_TEXT 0
335 #endif
337 #define FONT_PIX_PER_LINE 1
338 #define FONT_MEAN_WIDTH 1
340 #define get_sys_error(s) (s)
341 #define open mc_open
342 #define close(f) mc_close(f)
343 #define read(f,b,c) mc_read(f,b,c)
344 #define write(f,b,c) mc_write(f,b,c)
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 edit_error_dialog(h,s) query_dialog (h, s, 0, 1, _("&Dismiss"))
354 #define edit_message_dialog(h,s) query_dialog (h, s, 0, 1, _("&Ok"))
355 #define edit_query_dialog2(h,t,a,b) query_dialog(h,t,0,2,a,b)
356 #define edit_query_dialog3(h,t,a,b,c) query_dialog(h,t,0,3,a,b,c)
357 #define edit_query_dialog4(h,t,a,b,c,d) query_dialog(h,t,0,4,a,b,c,d)
359 #define color_palette(x) win->color[x].pixel
361 extern char *home_dir;
363 #define NUM_SELECTION_HISTORY 64
365 #ifndef MAX_PATH_LEN
366 #ifdef PATH_MAX
367 #define MAX_PATH_LEN PATH_MAX
368 #else
369 #define MAX_PATH_LEN 1024
370 #endif
371 #endif
374 what editor are we going to emulate? one of EDIT_KEY_EMULATION_NORMAL
375 or EDIT_KEY_EMULATION_EMACS
377 extern int edit_key_emulation;
378 extern WEdit *wedit;
380 extern int option_word_wrap_line_length;
381 extern int option_typewriter_wrap;
382 extern int option_auto_para_formatting;
383 extern int option_tab_spacing;
384 extern int option_fill_tabs_with_spaces;
385 extern int option_return_does_auto_indent;
386 extern int option_backspace_through_tabs;
387 extern int option_fake_half_tabs;
388 extern int option_save_mode;
389 extern int option_backup_ext_int;
390 extern int option_max_undo;
392 extern int option_edit_right_extreme;
393 extern int option_edit_left_extreme;
394 extern int option_edit_top_extreme;
395 extern int option_edit_bottom_extreme;
397 extern char *option_whole_chars_search;
398 extern char *option_backup_ext;
400 extern int edit_confirm_save;
402 #endif /* __EDIT_H */