*** empty log message ***
[midnight-commander.git] / edit / edit.h
blob496d8511a4badfe9d4d64ed568032e5a31361811
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 #define HAVE_SYNTAXH 1
28 #include <stdio.h>
29 #include <stdarg.h>
30 #include <sys/types.h>
31 #ifdef HAVE_UNISTD_H
32 # include <unistd.h>
33 #endif
34 #include <string.h>
35 #include <ctype.h>
36 #include <errno.h>
37 #include <sys/stat.h>
38 #include <errno.h>
40 #include <fcntl.h>
42 #include <stdlib.h>
43 #if !defined(STDC_HEADERS) && defined(HAVE_MALLOC_H)
44 # include <malloc.h>
45 #endif
47 #include "src/global.h"
48 #include "src/tty.h"
49 #include "src/main.h" /* for char *shell */
50 #include "src/dlg.h"
51 #include "src/widget.h"
52 #include "src/color.h"
53 #include "src/dialog.h"
54 #include "src/mouse.h"
55 #include "src/help.h"
56 #include "src/key.h"
57 #include "src/wtools.h" /* for QuickWidgets */
58 #include "src/cmd.h" /* for menu_edit_cmd */
59 #include "src/win.h"
60 #include "vfs/vfs.h"
61 #include "src/menu.h"
62 #include "edit-widget.h"
63 #include "src/user.h" /* for user_menu_cmd, must be after edit-widget.h */
65 # define WANT_WIDGETS
67 # define WIDGET_COMMAND (WIDGET_USER + 10)
68 # define N_menus 5
70 #define SEARCH_DIALOG_OPTION_NO_SCANF 1
71 #define SEARCH_DIALOG_OPTION_NO_REGEX 2
72 #define SEARCH_DIALOG_OPTION_NO_CASE 4
73 #define SEARCH_DIALOG_OPTION_BACKWARDS 8
74 #define SEARCH_DIALOG_OPTION_BOOKMARK 16
76 #define EDIT_KEY_EMULATION_NORMAL 0
77 #define EDIT_KEY_EMULATION_EMACS 1
79 #define REDRAW_LINE (1 << 0)
80 #define REDRAW_LINE_ABOVE (1 << 1)
81 #define REDRAW_LINE_BELOW (1 << 2)
82 #define REDRAW_AFTER_CURSOR (1 << 3)
83 #define REDRAW_BEFORE_CURSOR (1 << 4)
84 #define REDRAW_PAGE (1 << 5)
85 #define REDRAW_IN_BOUNDS (1 << 6)
86 #define REDRAW_CHAR_ONLY (1 << 7)
87 #define REDRAW_COMPLETELY (1 << 8)
89 #define MOD_ABNORMAL (1 << 0)
90 #define MOD_UNDERLINED (1 << 1)
91 #define MOD_BOLD (1 << 2)
92 #define MOD_HIGHLIGHTED (1 << 3)
93 #define MOD_MARKED (1 << 4)
94 #define MOD_ITALIC (1 << 5)
95 #define MOD_CURSOR (1 << 6)
96 #define MOD_INVERSE (1 << 7)
98 #define EDIT_TEXT_HORIZONTAL_OFFSET 0
99 #define EDIT_TEXT_VERTICAL_OFFSET 1
100 #define FONT_OFFSET_X 0
101 #define FONT_OFFSET_Y 0
103 #define EDIT_RIGHT_EXTREME option_edit_right_extreme
104 #define EDIT_LEFT_EXTREME option_edit_left_extreme
105 #define EDIT_TOP_EXTREME option_edit_top_extreme
106 #define EDIT_BOTTOM_EXTREME option_edit_bottom_extreme
108 /*there are a maximum of ... */
109 /*... edit buffers, each of which is ... */
110 #define EDIT_BUF_SIZE 0x10000
111 /* ...bytes in size. */
113 /*x / EDIT_BUF_SIZE equals x >> ... */
114 #define S_EDIT_BUF_SIZE 16
116 /* x % EDIT_BUF_SIZE is equal to x && ... */
117 #define M_EDIT_BUF_SIZE 0xFFFF
119 #define SIZE_LIMIT (EDIT_BUF_SIZE * (MAXBUFF - 2))
120 /* Note a 16k stack is 64k of data and enough to hold (usually) around 10
121 pages of undo info. */
123 /* undo stack */
124 #define START_STACK_SIZE 32
127 /*some codes that may be pushed onto or returned from the undo stack: */
128 #define CURS_LEFT 601
129 #define CURS_RIGHT 602
130 #define DELCHAR 603
131 #define BACKSPACE 604
132 #define STACK_BOTTOM 605
133 #define CURS_LEFT_LOTS 606
134 #define CURS_RIGHT_LOTS 607
135 #define COLUMN_ON 608
136 #define COLUMN_OFF 609
137 #define MARK_1 1000
138 #define MARK_2 700000000
139 #define KEY_PRESS 1400000000
141 /*Tabs spaces: (sofar only HALF_TAB_SIZE is used: */
142 #define TAB_SIZE option_tab_spacing
143 #define HALF_TAB_SIZE ((int) option_tab_spacing / 2)
145 struct selection {
146 unsigned char * text;
147 int len;
150 #define MAX_WORDS_PER_CONTEXT 1024
151 #define MAX_CONTEXTS 128
153 struct key_word {
154 char *keyword;
155 unsigned char first;
156 char *whole_word_chars_left;
157 char *whole_word_chars_right;
158 time_t time;
159 #define NO_COLOR 0x7FFFFFFF
160 #define SPELLING_ERROR 0x7EFEFEFE
161 int line_start;
162 int color;
165 struct context_rule {
166 char *left;
167 unsigned char first_left;
168 char *right;
169 unsigned char first_right;
170 char line_start_left;
171 char line_start_right;
172 #if 0
173 int single_char;
174 #endif
175 int between_delimiters;
176 char *whole_word_chars_left;
177 char *whole_word_chars_right;
178 char *keyword_first_chars;
179 int spelling;
180 /* first word is word[1] */
181 struct key_word **keyword;
184 int edit_drop_hotkey_menu (WEdit * e, int key);
185 void edit_menu_cmd (WEdit * e);
186 void edit_init_menu_emacs (void);
187 void edit_init_menu_normal (void);
188 void edit_done_menu (void);
189 void menu_save_mode_cmd (void);
190 int edit_raw_key_query (char *heading, char *query, int cancel);
191 char *strcasechr (const unsigned char *s, int c);
192 int edit (const char *_file, int line);
193 int edit_translate_key (WEdit * edit, unsigned int x_keycode, long x_key, int x_state, int *cmd, int *ch);
195 #ifndef NO_INLINE_GETBYTE
196 int edit_get_byte (WEdit * edit, long byte_index);
197 #else
198 static inline int edit_get_byte (WEdit * edit, long byte_index)
200 unsigned long p;
201 if (byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0)
202 return '\n';
204 if (byte_index >= edit->curs1) {
205 p = edit->curs1 + edit->curs2 - byte_index - 1;
206 return edit->buffers2[p >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - (p & M_EDIT_BUF_SIZE) - 1];
207 } else {
208 return edit->buffers1[byte_index >> S_EDIT_BUF_SIZE][byte_index & M_EDIT_BUF_SIZE];
211 #endif
213 char *edit_get_buffer_as_text (WEdit * edit);
214 int edit_count_lines (WEdit * edit, long current, int upto);
215 long edit_move_forward (WEdit * edit, long current, int lines, long upto);
216 long edit_move_forward3 (WEdit * edit, long current, int cols, long upto);
217 long edit_move_backward (WEdit * edit, long current, int lines);
218 void edit_scroll_screen_over_cursor (WEdit * edit);
219 void edit_render_keypress (WEdit * edit);
220 void edit_scroll_upward (WEdit * edit, unsigned long i);
221 void edit_scroll_downward (WEdit * edit, int i);
222 void edit_scroll_right (WEdit * edit, int i);
223 void edit_scroll_left (WEdit * edit, int i);
224 int edit_get_col (WEdit * edit);
225 long edit_bol (WEdit * edit, long current);
226 long edit_eol (WEdit * edit, long current);
227 void edit_update_curs_row (WEdit * edit);
228 void edit_update_curs_col (WEdit * edit);
230 void edit_block_copy_cmd (WEdit * edit);
231 void edit_block_move_cmd (WEdit * edit);
232 int edit_block_delete_cmd (WEdit * edit);
233 int edit_block_delete (WEdit * edit);
234 void edit_delete_line (WEdit * edit);
236 int edit_delete (WEdit * edit);
237 void edit_insert (WEdit * edit, int c);
238 int edit_cursor_move (WEdit * edit, long increment);
239 void edit_push_action (WEdit * edit, long c, ...);
240 void edit_push_key_press (WEdit * edit);
241 void edit_insert_ahead (WEdit * edit, int c);
242 int edit_save_file (WEdit * edit, const char *filename);
243 long edit_write_stream (WEdit * edit, FILE * f);
244 char *edit_get_write_filter (char *writename, const char *filename);
245 int edit_save_cmd (WEdit * edit);
246 int edit_save_confirm_cmd (WEdit * edit);
247 int edit_save_as_cmd (WEdit * edit);
248 WEdit *edit_init (WEdit * edit, int lines, int columns, const char *filename, const char *text, const char *dir, unsigned long text_size);
249 int edit_clean (WEdit * edit);
250 int edit_renew (WEdit * edit);
251 int edit_new_cmd (WEdit * edit);
252 int edit_reload (WEdit * edit, const char *filename, const char *text, const char *dir, unsigned long text_size);
253 int edit_load_cmd (WEdit * edit);
254 void edit_mark_cmd (WEdit * edit, int unmark);
255 void edit_set_markers (WEdit * edit, long m1, long m2, int c1, int c2);
256 void edit_push_markers (WEdit * edit);
257 void edit_quit_cmd (WEdit * edit);
258 void edit_replace_cmd (WEdit * edit, int again);
259 void edit_search_cmd (WEdit * edit, int again);
260 void edit_complete_word_cmd (WEdit * edit);
261 int edit_save_block (WEdit * edit, const char *filename, long start, long finish);
262 int edit_save_block_cmd (WEdit * edit);
263 int edit_insert_file_cmd (WEdit * edit);
264 int edit_insert_file (WEdit * edit, const char *filename);
265 void edit_block_process_cmd (WEdit * edit, const char *shell_cmd, int block);
266 char *catstrs (const char *first, ...);
267 void freestrs (void);
268 void edit_refresh_cmd (WEdit * edit);
269 void edit_date_cmd (WEdit * edit);
270 void edit_goto_cmd (WEdit * edit);
271 int eval_marks (WEdit * edit, long *start_mark, long *end_mark);
272 void edit_status (WEdit * edit);
273 int edit_execute_command (WEdit * edit, int command, int char_for_insertion);
274 int edit_execute_key_command (WEdit * edit, int command, int char_for_insertion);
275 void edit_update_screen (WEdit * edit);
276 int edit_printf (WEdit * e, const char *fmt, ...)
277 __attribute__ ((format (printf, 2, 3)));
278 int edit_print_string (WEdit * e, const char *s);
279 void edit_move_to_line (WEdit * e, long line);
280 void edit_move_display (WEdit * e, long line);
281 void edit_word_wrap (WEdit * edit);
282 unsigned char *edit_get_block (WEdit * edit, long start, long finish, int *l);
283 int edit_sort_cmd (WEdit * edit);
284 void edit_help_cmd (WEdit * edit);
285 void edit_left_word_move (WEdit * edit, int s);
286 void edit_right_word_move (WEdit * edit, int s);
287 void edit_get_selection (WEdit * edit);
289 int edit_save_macro_cmd (WEdit * edit, struct macro macro[], int n);
290 int edit_load_macro_cmd (WEdit * edit, struct macro macro[], int *n, int k);
291 void edit_delete_macro_cmd (WEdit * edit);
293 int edit_copy_to_X_buf_cmd (WEdit * edit);
294 int edit_cut_to_X_buf_cmd (WEdit * edit);
295 void edit_paste_from_X_buf_cmd (WEdit * edit);
297 void edit_paste_from_history (WEdit *edit);
299 void edit_split_filename (WEdit * edit, const char *name);
301 #define CWidget Widget
302 void edit_set_syntax_change_callback (void (*callback) (CWidget *));
303 void edit_load_syntax (WEdit * edit, char **names, char *type);
304 void edit_free_syntax_rules (WEdit * edit);
305 void edit_get_syntax_color (WEdit * edit, long byte_index, int *color);
306 int edit_check_spelling (WEdit * edit);
309 void book_mark_insert (WEdit * edit, int line, int c);
310 int book_mark_query_color (WEdit * edit, int line, int c);
311 int book_mark_query_all (WEdit * edit, int line, int *c);
312 struct _book_mark *book_mark_find (WEdit * edit, int line);
313 int book_mark_clear (WEdit * edit, int line, int c);
314 void book_mark_flush (WEdit * edit, int c);
315 void book_mark_inc (WEdit * edit, int line);
316 void book_mark_dec (WEdit * edit, int line);
318 void user_menu (WEdit *edit);
320 /* either command or char_for_insertion must be passed as -1 */
321 int edit_execute_cmd (WEdit * edit, int command, int char_for_insertion);
323 #define CPushFont(x,y)
324 #define CPopFont()
325 #define FIXED_FONT 1
327 /* put OS2/NT/WIN95 defines here */
329 #ifdef USE_O_TEXT
330 # define MY_O_TEXT O_TEXT
331 #else
332 # define MY_O_TEXT 0
333 #endif
335 #define FONT_PIX_PER_LINE 1
336 #define FONT_MEAN_WIDTH 1
338 #define get_sys_error(s) (s)
339 #define itoa MY_itoa
341 #define edit_get_load_file(d,f,h) input_dialog (h, _(" Enter file name: "), f)
342 #define edit_get_save_file(d,f,h) input_dialog (h, _(" Enter file name: "), f)
343 #define CMalloc(x) malloc(x)
345 #define edit_error_dialog(h,s) query_dialog (h, s, 0, 1, _("&Dismiss"))
347 #define edit_message_dialog(h,s) query_dialog (h, s, 0, 1, _("&Ok"))
348 #define edit_query_dialog2(h,t,a,b) query_dialog(h,t,0,2,a,b)
349 #define edit_query_dialog3(h,t,a,b,c) query_dialog(h,t,0,3,a,b,c)
350 #define edit_query_dialog4(h,t,a,b,c,d) query_dialog(h,t,0,4,a,b,c,d)
352 #define color_palette(x) win->color[x].pixel
354 extern char *home_dir;
356 #define NUM_SELECTION_HISTORY 64
358 #ifndef MAX_PATH_LEN
359 #ifdef PATH_MAX
360 #define MAX_PATH_LEN PATH_MAX
361 #else
362 #define MAX_PATH_LEN 1024
363 #endif
364 #endif
367 what editor are we going to emulate? one of EDIT_KEY_EMULATION_NORMAL
368 or EDIT_KEY_EMULATION_EMACS
370 extern int edit_key_emulation;
371 extern WEdit *wedit;
372 extern Menu EditMenuBar[];
373 extern Dlg_head *edit_dlg;
374 extern WMenu *edit_menubar;
376 extern int option_word_wrap_line_length;
377 extern int option_typewriter_wrap;
378 extern int option_auto_para_formatting;
379 extern int option_tab_spacing;
380 extern int option_fill_tabs_with_spaces;
381 extern int option_return_does_auto_indent;
382 extern int option_backspace_through_tabs;
383 extern int option_fake_half_tabs;
384 extern int option_save_mode;
385 extern int option_backup_ext_int;
386 extern int option_max_undo;
387 extern int option_syntax_highlighting;
389 extern int option_edit_right_extreme;
390 extern int option_edit_left_extreme;
391 extern int option_edit_top_extreme;
392 extern int option_edit_bottom_extreme;
394 extern char *option_whole_chars_search;
395 extern char *option_backup_ext;
397 extern int edit_confirm_save;
398 extern int column_highlighting;
400 #endif /* __EDIT_H */