1 /* edit.h - main include file
2 
3    Copyright (C) 1996-2000 the Free Software Foundation
4 
5    Authors: 1996, 1997 Paul Sheer
6 
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.
11 
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.
16 
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.
21 */
22 
23 #ifndef __EDIT_H
24 #define __EDIT_H
25 
26 #ifdef MIDNIGHT
27 
28 #ifdef HAVE_SLANG
29 #define HAVE_SYNTAXH 1
30 #endif
31 
32 #    include <stdio.h>
33 #    include <stdarg.h>
34 #    include <sys/types.h>
35 #    ifdef HAVE_UNISTD_H
36 #    	 include <unistd.h>
37 #    endif
38 #    include <string.h>
39 #    include <ctype.h>
40 #    include <errno.h>
41 #    include "src/tty.h"
42 #    include <sys/stat.h>
43 #    include <errno.h>
44 
45 #    include <fcntl.h>
46 
47 #    include <stdlib.h>
48 #    include <malloc.h>
49 
50 #else       /* ! MIDNIGHT */
51 
52 #    include "global.h"
53 #    include <stdio.h>
54 #    include <stdarg.h>
55 #    include <sys/types.h>
56 #    ifdef HAVE_WCHAR_H
57 #    include <wchar.h>
58 #    endif
59 
60 #    	 ifdef HAVE_UNISTD_H
61 #    	     include <unistd.h>
62 #    	 endif
63 
64 #ifdef GTK
65 #    include <string.h>
66 #else
67 #    include <my_string.h>
68 #endif
69 #    include <ctype.h>
70 #    include <errno.h>
71 #    include <sys/stat.h>
72 
73 #    ifdef HAVE_FCNTL_H
74 #    	 include <fcntl.h>
75 #    endif
76 
77 #    include <stdlib.h>
78 #    include <stdarg.h>
79 
80 #    if TIME_WITH_SYS_TIME
81 #    	 include <sys/time.h>
82 #    	 include <time.h>
83 #    else
84 #    	 if HAVE_SYS_TIME_H
85 #    	     include <sys/time.h>
86 #    	 else
87 #    	     include <time.h>
88 #    	 endif
89 #    endif
90 
91 #    include "regex.h"
92 
93 #endif
94 
95 #ifndef MIDNIGHT
96 
97 #    include <signal.h>
98 #    include <X11/Xlib.h>
99 #    include <X11/Xutil.h>
100 #    include <X11/Xresource.h>
101 #    include "lkeysym.h"
102 #ifndef GTK
103 #    include "coolwidget.h"
104 #    include "app_glob.c"
105 #    include "coollocal.h"
106 #    include "stringtools.h"
107 #else
108 #    include "gtk/gtk.h"
109 #    include "gdk/gdkprivate.h"
110 #    include "gdk/gdk.h"
111 #    include "gtkedit.h"
112 #    include "editcmddef.h"
113 #    ifndef _
114 #        define _(x) x
115 #        define N_(x) x
116 #    endif
117 #endif
118 
119 #else
120 
121 #    include "src/global.h"
122 #    include "src/main.h"		/* for char *shell */
123 #    include "src/mad.h"
124 #    include "src/dlg.h"
125 #    include "src/widget.h"
126 #    include "src/color.h"
127 #    include "src/dialog.h"
128 #    include "src/mouse.h"
129 #    include "src/help.h"
130 #    include "src/key.h"
131 #    include "src/wtools.h"		/* for QuickWidgets */
132 #    include "src/win.h"
133 #    include "vfs/vfs.h"
134 #    include "src/menu.h"
135 #    include <regex.h>
136 #    define WANT_WIDGETS
137 
138 #    define WIDGET_COMMAND (WIDGET_USER + 10)
139 #    define N_menus 5
140 
141 #endif
142 
143 #ifdef GTK
144 /* unistd.h defines _POSIX_VERSION on POSIX.1 systems. */
145 #if defined(HAVE_DIRENT_H) || defined(_POSIX_VERSION)
146 #   include <dirent.h>
147 #   define NLENGTH(dirent) (strlen ((dirent)->d_name))
148 #else
149 #   define dirent direct
150 #   define NLENGTH(dirent) ((dirent)->d_namlen)
151 
152 #   ifdef HAVE_SYS_NDIR_H
153 #       include <sys/ndir.h>
154 #   endif /* HAVE_SYS_NDIR_H */
155 
156 #   ifdef HAVE_SYS_DIR_H
157 #       include <sys/dir.h>
158 #   endif /* HAVE_SYS_DIR_H */
159 
160 #   ifdef HAVE_NDIR_H
161 #       include <ndir.h>
162 #   endif /* HAVE_NDIR_H */
163 #endif /* not (HAVE_DIRENT_H or _POSIX_VERSION) */
164 #   ifndef _
165 #      define _(x) x
166 #      define N_(x) x
167 #   endif
168 #include "vfs/vfs.h"
169 #    define CDisplay gdk_display
170 #    define CRoot gdk_root_parent
171 #    define Window GtkEdit *
172 #endif
173 
174 #define SEARCH_DIALOG_OPTION_NO_SCANF	1
175 #define SEARCH_DIALOG_OPTION_NO_REGEX	2
176 #define SEARCH_DIALOG_OPTION_NO_CASE	4
177 #define SEARCH_DIALOG_OPTION_BACKWARDS	8
178 #define SEARCH_DIALOG_OPTION_BOOKMARK	16
179 
180 #define FILELIST_FILE "/.cedit/filelist"
181 #define SYNTAX_FILE "/.cedit/Syntax"
182 #define CLIP_FILE "/.cedit/cooledit.clip"
183 #define MACRO_FILE "/.cedit/cooledit.macros"
184 #define PARMESS_FILE "/.cedit/no_para_highlight_mess"
185 #define BLOCK_FILE "/.cedit/cooledit.block"
186 #define ERROR_FILE "/.cedit/cooledit.error"
187 #define TEMP_FILE "/.cedit/cooledit.temp"
188 #define SCRIPT_FILE "/.cedit/cooledit.script"
189 #define EDIT_DIR "/.cedit"
190 
191 #define EDIT_KEY_EMULATION_NORMAL 0
192 #define EDIT_KEY_EMULATION_EMACS  1
193 
194 #define REDRAW_LINE          (1 << 0)
195 #define REDRAW_LINE_ABOVE    (1 << 1)
196 #define REDRAW_LINE_BELOW    (1 << 2)
197 #define REDRAW_AFTER_CURSOR  (1 << 3)
198 #define REDRAW_BEFORE_CURSOR (1 << 4)
199 #define REDRAW_PAGE          (1 << 5)
200 #define REDRAW_IN_BOUNDS     (1 << 6)
201 #define REDRAW_CHAR_ONLY     (1 << 7)
202 #define REDRAW_COMPLETELY    (1 << 8)
203 
204 #define MOD_ABNORMAL		(1 << 0)
205 #define MOD_UNDERLINED		(1 << 1)
206 #define MOD_BOLD		(1 << 2)
207 #define MOD_HIGHLIGHTED		(1 << 3)
208 #define MOD_MARKED		(1 << 4)
209 #define MOD_ITALIC		(1 << 5)
210 #define MOD_CURSOR		(1 << 6)
211 #define MOD_INVERSE		(1 << 7)
212 #define MOD_TAB			(1 << 8)
213 #define MOD_PIXMAP		(1 << 9)
214 #define MOD_REVERSE		(1 << 10)
215 
216 #ifndef MIDNIGHT
217 #    ifdef GTK
218 #        define EDIT_TEXT_HORIZONTAL_OFFSET 0
219 #        define EDIT_TEXT_VERTICAL_OFFSET 0
220 #    else
221 #        define EDIT_TEXT_HORIZONTAL_OFFSET 4
222 #        define EDIT_TEXT_VERTICAL_OFFSET 3
223 #    endif
224 #else
225 #    define EDIT_TEXT_HORIZONTAL_OFFSET 0
226 #    define EDIT_TEXT_VERTICAL_OFFSET 1
227 #    define FONT_OFFSET_X 0
228 #    define FONT_OFFSET_Y 0
229 #endif
230 
231 #define EDIT_RIGHT_EXTREME option_edit_right_extreme
232 #define EDIT_LEFT_EXTREME option_edit_left_extreme
233 #define EDIT_TOP_EXTREME option_edit_top_extreme
234 #define EDIT_BOTTOM_EXTREME option_edit_bottom_extreme
235 
236 #define MAX_MACRO_LENGTH 1024
237 
238 /*there are a maximum of ... */
239 #define MAXBUFF 1024
240 /*... edit buffers, each of which is ... */
241 #define EDIT_BUF_SIZE 0x10000
242 /* ...bytes in size. */
243 
244 /*x / EDIT_BUF_SIZE equals x >> ... */
245 #define S_EDIT_BUF_SIZE 16
246 
247 /* x % EDIT_BUF_SIZE is equal to x && ... */
248 #define M_EDIT_BUF_SIZE 0xFFFF
249 
250 #define SIZE_LIMIT (EDIT_BUF_SIZE * (MAXBUFF - 2))
251 /* Note a 16k stack is 64k of data and enough to hold (usually) around 10
252    pages of undo info. */
253 
254 /* undo stack */
255 #define START_STACK_SIZE 32
256 
257 
258 /*some codes that may be pushed onto or returned from the undo stack: */
259 #define CURS_LEFT 601
260 #define CURS_RIGHT 602
261 #define ACT_DELETE 603
262 #define BACKSPACE 604
263 #define STACK_BOTTOM 605
264 #define CURS_LEFT_LOTS 606
265 #define CURS_RIGHT_LOTS 607
266 #define COLUMN_ON 608
267 #define COLUMN_OFF 609
268 #define MARK_1 1000
269 #define MARK_2 700000000
270 #define KEY_PRESS 1400000000
271 
272 /*Tabs spaces: (sofar only HALF_TAB_SIZE is used: */
273 #define TAB_SIZE		option_tab_spacing
274 #define HALF_TAB_SIZE		((int) option_tab_spacing / 2)
275 
276 struct macro {
277     int command;
278     long ch;
279 };
280 
281 /* this must be the same as struct edit_selection from rxvtlib.h */
282 struct selection {
283    unsigned char * text;
284    int len;
285 };
286 
287 struct mb_rule {
288     long ch;
289     char end;
290     mbstate_t shift_state;
291 };
292 
293 struct _mb_marker {
294     long offset;
295     struct mb_rule rule;
296     struct _mb_marker *next;
297 };
298 
299 #define wc_isgraph(c) (isgraph(c & 0xFF) && (unsigned long) c < 0x100UL)
300 #define wc_isprint(c) (isprint(c & 0xFF) && (unsigned long) c < 0x100UL)
301 #define wc_isspace(c) (isspace(c & 0xFF) && (unsigned long) c < 0x100UL)
302 
303 struct syntax_rule {
304     unsigned short keyword;
305     unsigned char end;
306     unsigned char context;
307     unsigned char _context;
308 #define RULE_ON_LEFT_BORDER 1
309 #define RULE_ON_RIGHT_BORDER 2
310     unsigned char border;
311 };
312 
313 #define MAX_WORDS_PER_CONTEXT	1024
314 #define MAX_CONTEXTS		128
315 
316 struct key_word {
317     char *keyword;
318     unsigned char first;
319     char *whole_word_chars_left;
320     char *whole_word_chars_right;
321     time_t time;
322 #define NO_COLOR 0x7FFFFFFF
323 #define SPELLING_ERROR 0x7EFEFEFE
324     int line_start;
325     int bg;
326     int fg;
327 };
328 
329 struct context_rule {
330     char *left;
331     unsigned char first_left;
332     char *right;
333     unsigned char first_right;
334     char line_start_left;
335     char line_start_right;
336     int single_char;
337     int between_delimiters;
338     char *whole_word_chars_left;
339     char *whole_word_chars_right;
340     char *keyword_first_chars;
341     int spelling;
342 /* first word is word[1] */
343     struct key_word **keyword;
344 };
345 
346 struct _syntax_marker {
347     long offset;
348     struct syntax_rule rule;
349     struct _syntax_marker *next;
350 };
351 
352 struct _book_mark {
353     int line;		/* line number */
354 #if 0
355 #define BOOK_MARK_COLOR ((0 << 8) | 26)		/* black on white */
356 #endif
357 #define BOOK_MARK_COLOR ((25 << 8) | 5)
358 #define BOOK_MARK_FOUND_COLOR ((26 << 8) | 4)
359     int c;		/* colour */
360     struct _book_mark *next;
361     struct _book_mark *prev;
362 };
363 
364 struct editor_widget {
365 #ifdef MIDNIGHT
366     Widget widget;
367 #elif defined(GTK)
368     GtkEdit *widget;
369 #else
370     struct cool_widget *widget;
371 #endif
372 #define from_here num_widget_lines
373     int num_widget_lines;
374     int num_widget_columns;
375 
376 #ifdef MIDNIGHT
377     int have_frame;
378 #else
379     int stopped;
380 #endif
381 
382     char *filename;		/* Name of the file */
383     char *dir;			/* current directory */
384 
385 /* dynamic buffers and cursor position for editor: */
386     long curs1;			/*position of the cursor from the beginning of the file. */
387     long curs2;			/*position from the end of the file */
388     unsigned char *buffers1[MAXBUFF + 1];	/*all data up to curs1 */
389     unsigned char *buffers2[MAXBUFF + 1];	/*all data from end of file down to curs2 */
390 
391 /* search variables */
392     long search_start;		/* First character to start searching from */
393     int found_len;		/* Length of found string or 0 if none was found */
394     long found_start;		/* the found word from a search - start position */
395 
396 /* display information */
397     long last_byte;		/* Last byte of file */
398     long start_display;		/* First char displayed */
399     long start_col;		/* First displayed column, negative */
400     long max_column;		/* The maximum cursor position ever reached used to calc hori scroll bar */
401     long curs_row;		/*row position of cursor on the screen */
402     long curs_col;		/*column position on screen */
403     int force;			/* how much of the screen do we redraw? */
404     int test_file_on_disk_for_changes;
405     time_t test_file_on_disk_for_changes_m_time;
406     unsigned char overwrite;
407     unsigned char modified;	/*has the file been changed?: 1 if char inserted or
408 				   deleted at all since last load or save */
409     unsigned char screen_modified;	/* has the file been changed since the last screen draw? */
410 #if defined(MIDNIGHT) || defined(GTK)
411     int delete_file;			/* has the file been created in edit_load_file? Delete
412 			           it at end of editing when it hasn't been modified
413 				   or saved */
414 #endif
415     unsigned char highlight;
416     long prev_col;		/*recent column position of the cursor - used when moving
417 				   up or down past lines that are shorter than the current line */
418     long curs_line;		/*line number of the cursor. */
419     long start_line;		/*line nummber of the top of the page */
420 
421 /* file info */
422     long total_lines;		/*total lines in the file */
423     long mark1;			/*position of highlight start */
424     long mark2;			/*position of highlight end */
425     int column1;			/*position of column highlight start */
426     int column2;			/*position of column highlight end */
427     long bracket;		/*position of a matching bracket */
428 
429 /* cache speedup for line lookups */
430 #define N_LINE_CACHES	32
431     int caches_valid;
432     int line_numbers[N_LINE_CACHES];
433     long line_offsets[N_LINE_CACHES];
434 
435     struct _book_mark *book_mark;
436 
437 /* undo stack and pointers */
438     unsigned long stack_pointer;
439     long *undo_stack;
440     unsigned long stack_size;
441     unsigned long stack_size_mask;
442     unsigned long stack_bottom;
443     struct stat stat;
444 
445 /* syntax higlighting */
446     struct _syntax_marker *syntax_marker;
447     struct context_rule **rules;
448     long last_get_rule;
449     struct syntax_rule rule;
450     int syntax_invalidate;
451     char *syntax_type;		/* description of syntax highlighting type being used */
452     int explicit_syntax;	/* have we forced the syntax hi. type in spite of the filename? */
453 
454     struct _mb_marker *mb_marker;
455     long last_get_mb_rule;
456     struct mb_rule mb_rule;
457     int mb_invalidate;
458 
459     struct shell_job {
460 	char *name;
461 	pid_t pid;
462 	int in, out, close_on_error;
463 	struct shell_job *next;
464     } *jobs;
465 
466     int to_here;		/* dummy marker */
467 
468 
469 /* macro stuff */
470     int macro_i;		/* -1 if not recording index to macro[] otherwise */
471     struct macro macro[MAX_MACRO_LENGTH];
472 };
473 
474 typedef struct editor_widget WEdit;
475 
476 int readall (int fd, char *buf, int len);
477 char *edit_get_write_filter (char *writename, const char *filename);
478 long edit_write_stream (WEdit * edit, FILE * f);
479 void edit_tab_cmd (WEdit * edit);
480 void edit_insert_wide (WEdit * edit, wchar_t wc);
481 
482 
483 #ifndef MIDNIGHT
484 
485 void edit_render_expose (WEdit * edit, XExposeEvent * xexpose);
486 #ifndef GTK
487 void edit_render_tidbits (struct cool_widget *w);
488 int eh_editor (CWidget * w, XEvent * xevent, CEvent * cwevent);
489 #endif
490 void edit_draw_menus (Window parent, int x, int y);
491 void edit_run_make (void);
492 void edit_change_directory (void);
493 int edit_man_page_cmd (WEdit * edit);
494 void edit_search_replace_dialog (Window parent, int x, int y, char **search_text, char **replace_text, char **arg_order, const char *heading, int option);
495 void edit_search_dialog (WEdit * edit, char **search_text);
496 long edit_find (long search_start, unsigned char *expr, int *len, long last_byte, int (*get_byte) (void *, long), void *data, void *d);
497 void edit_set_foreground_colors (unsigned long normal, unsigned long bold, unsigned long italic);
498 void edit_set_background_colors (unsigned long normal, unsigned long abnormal, unsigned long marked, unsigned long marked_abnormal, unsigned long highlighted);
499 void edit_set_cursor_color (unsigned long c);
500 void draw_options_dialog (Window parent, int x, int y);
501 void CRefreshEditor (WEdit * edit);
502 void edit_set_user_command (void (*func) (WEdit *, int));
503 void edit_draw_this_line_proportional (WEdit * edit, long b, int curs_row, int start_column, int end_column);
504 unsigned char get_international_character (unsigned char key_press);
505 void edit_set_user_key_function (int (*user_def_key_func) (unsigned int, unsigned int, KeySym keysym));
506 
507 #else
508 
509 int edit_drop_hotkey_menu (WEdit * e, int key);
510 void edit_menu_cmd (WEdit * e);
511 void edit_init_menu_emacs (void);
512 void edit_init_menu_normal (void);
513 void edit_done_menu (void);
514 int edit_raw_key_query (const char *heading, const char *query, int cancel);
515 char *strcasechr (const unsigned char *s, int c);
516 int edit (const char *_file, int line);
517 int edit_translate_key (WEdit * edit, unsigned int x_keycode, long x_key, int x_state, int *cmd, int *ch);
518 
519 #endif
520 
521 long edit_get_wide_byte (WEdit * edit, long byte_index);
522 struct mb_rule get_mb_rule (WEdit * edit, long byte_index);
523 #ifdef NO_INLINE_GETBYTE
524 int edit_get_byte (WEdit * edit, long byte_index);
525 #else
edit_get_byte(WEdit * edit,long byte_index)526 static inline int edit_get_byte (WEdit * edit, long byte_index)
527 {
528     unsigned long p;
529     if (byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0)
530 	return '\n';
531 
532     if (byte_index >= edit->curs1) {
533 	p = edit->curs1 + edit->curs2 - byte_index - 1;
534 	return edit->buffers2[p >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - (p & M_EDIT_BUF_SIZE) - 1];
535     } else {
536 	return edit->buffers1[byte_index >> S_EDIT_BUF_SIZE][byte_index & M_EDIT_BUF_SIZE];
537     }
538 }
539 #endif
540 
541 char *edit_get_buffer_as_text (WEdit * edit);
542 char *edit_get_current_line_as_text (WEdit * e, long *length, long *cursor);
543 int edit_count_lines (WEdit * edit, long current, int upto);
544 long edit_move_forward (WEdit * edit, long current, int lines, long upto);
545 long edit_move_forward3 (WEdit * edit, long current, int cols, long upto);
546 long edit_move_backward (WEdit * edit, long current, int lines);
547 void edit_scroll_screen_over_cursor (WEdit * edit);
548 void edit_render_keypress (WEdit * edit);
549 void edit_scroll_upward (WEdit * edit, unsigned long i);
550 void edit_scroll_downward (WEdit * edit, int i);
551 void edit_scroll_right (WEdit * edit, int i);
552 void edit_scroll_left (WEdit * edit, int i);
553 int edit_get_col (WEdit * edit);
554 long edit_bol (WEdit * edit, long current);
555 long edit_eol (WEdit * edit, long current);
556 void edit_update_curs_row (WEdit * edit);
557 void edit_update_curs_col (WEdit * edit);
558 
559 void edit_block_copy_cmd (WEdit * edit);
560 void edit_block_move_cmd (WEdit * edit);
561 int edit_block_delete_cmd (WEdit * edit);
562 int edit_block_delete (WEdit * edit);
563 void edit_delete_line (WEdit * edit);
564 
565 int edit_delete (WEdit * edit);
566 void edit_insert (WEdit * edit, int c);
567 int edit_cursor_move (WEdit * edit, long increment);
568 void edit_push_action (WEdit * edit, long c,...);
569 void edit_push_key_press (WEdit * edit);
570 void edit_insert_ahead (WEdit * edit, int c);
571 int edit_check_change_on_disk (WEdit * edit, int save_mode);
572 int edit_save_file (WEdit * edit, const char *filename);
573 int edit_save_cmd (WEdit * edit);
574 int edit_save_confirm_cmd (WEdit * edit);
575 int edit_save_as_cmd (WEdit * edit);
576 WEdit *edit_init (WEdit * edit, int lines, int columns, const char *filename, const char *text, const char *dir, unsigned long text_size);
577 int edit_clean (WEdit * edit);
578 int edit_renew (WEdit * edit);
579 int edit_new_cmd (WEdit * edit);
580 int edit_reload (WEdit * edit, const char *filename, const char *text, const char *dir, unsigned long text_size);
581 int edit_load_cmd (WEdit * edit);
582 void edit_mark_cmd (WEdit * edit, int unmark);
583 void edit_set_markers (WEdit * edit, long m1, long m2, int c1, int c2);
584 void edit_push_markers (WEdit * edit);
585 void edit_quit_cmd (WEdit * edit);
586 void edit_replace_cmd (WEdit * edit, int again);
587 void edit_search_cmd (WEdit * edit, int again);
588 int edit_save_block_cmd (WEdit * edit);
589 int edit_insert_file_cmd (WEdit * edit);
590 int edit_insert_file (WEdit * edit, const char *filename);
591 void edit_block_process_cmd (WEdit * edit, const char *shell_cmd, int block);
592 char *catstrs (const char *first,...);
593 void edit_refresh_cmd (WEdit * edit);
594 void edit_date_cmd (WEdit * edit);
595 void edit_goto_cmd (WEdit * edit);
596 int eval_marks (WEdit * edit, long *start_mark, long *end_mark);
597 void edit_status (WEdit * edit);
598 int edit_is_movement_command(int command);
599 int edit_execute_command (WEdit * edit, int command, int char_for_insertion);
600 int edit_execute_key_command (WEdit * edit, int command, long char_for_insertion);
601 void edit_update_screen (WEdit * edit);
602 int edit_printf (WEdit * e, const char *fmt,...);
603 int edit_print_string (WEdit * e, const char *s);
604 void edit_move_to_line (WEdit * e, long line);
605 void edit_move_display (WEdit * e, long line);
606 void edit_word_wrap (WEdit * edit);
607 unsigned char *edit_get_block (WEdit * edit, long start, long finish, int *l);
608 int edit_sort_cmd (WEdit * edit);
609 void edit_help_cmd (WEdit * edit);
610 void edit_left_word_move (WEdit * edit, int s);
611 void edit_right_word_move (WEdit * edit, int s);
612 void edit_get_selection (WEdit * edit);
613 char *edit_get_text_from_selection_history (Window parent, int x, int y, int cols, int lines, long *len);
614 
615 int edit_save_macro_cmd (WEdit * edit, struct macro macro[], int n);
616 int edit_load_macro_cmd (WEdit * edit, struct macro macro[], int *n, int k);
617 void edit_delete_macro_cmd (WEdit * edit);
618 
619 int edit_copy_to_X_buf_cmd (WEdit * edit);
620 int edit_cut_to_X_buf_cmd (WEdit * edit);
621 void edit_paste_from_X_buf_cmd (WEdit * edit);
622 
623 void edit_paste_from_history (WEdit *edit);
624 
625 void edit_split_filename (WEdit * edit, char *name);
626 
627 #ifdef MIDNIGHT
628 #define CWidget Widget
629 #elif defined(GTK)
630 #define CWidget GtkEdit
631 #endif
632 void edit_set_syntax_change_callback (void (*callback) (CWidget *));
633 void edit_load_syntax (WEdit * edit, char **names, char *type);
634 void edit_free_syntax_rules (WEdit * edit);
635 void edit_get_syntax_color (WEdit * edit, long byte_index, int *fg, int *bg);
636 int edit_check_spelling (WEdit * edit);
637 
638 
639 void book_mark_insert (WEdit * edit, int line, int c);
640 int book_mark_query_color (WEdit * edit, int line, int c);
641 int book_mark_query_all (WEdit * edit, int line, int *c);
642 struct _book_mark *book_mark_find (WEdit * edit, int line);
643 int book_mark_clear (WEdit * edit, int line, int c);
644 void book_mark_flush (WEdit * edit, int c);
645 void book_mark_inc (WEdit * edit, int line);
646 void book_mark_dec (WEdit * edit, int line);
647 
648 
649 #ifdef MIDNIGHT
650 
651 /* put OS2/NT/WIN95 defines here */
652 
653 #    ifdef USE_O_TEXT
654 #    	 define MY_O_TEXT O_TEXT
655 #    else
656 #    	 define MY_O_TEXT 0
657 #    endif
658 
659 #    define FONT_PIX_PER_LINE 1
660 #    define FONT_MEAN_WIDTH 1
661 
662 #    define get_sys_error(s) (s)
663 #    define open mc_open
664 #    define close(f) mc_close(f)
665 #    define read(f,b,c) mc_read(f,b,c)
666 #    define write(f,b,c) mc_write(f,b,c)
667 #    define stat(f,s) mc_stat(f,s)
668 #    define mkdir(s,m) mc_mkdir(s,m)
669 #    define itoa MY_itoa
670 
671 #    define edit_get_load_file(d,f,h) input_dialog (h, " Enter file name: ", f)
672 #    define edit_get_save_file(d,f,h) input_dialog (h, " Enter file name: ", f)
673 #    define CMalloc(x) malloc(x)
674 
675 #    define set_error_msg(s) edit_init_error_msg = strdup(s)
676 
677 #    ifdef _EDIT_C
678 
679 #         define edit_error_dialog(h,s) set_error_msg(s)
680 char *edit_init_error_msg = NULL;
681 
682 #    else				/* ! _EDIT_C */
683 
684 #    define edit_error_dialog(h,s) query_dialog (h, s, 0, 1, _("&Dismiss"))
685 #    define edit_message_dialog(h,s) query_dialog (h, s, 0, 1, _("&Ok"))
686 extern char *edit_init_error_msg;
687 
688 #    endif				/* ! _EDIT_C */
689 
690 
691 #    define get_error_msg(s) edit_init_error_msg
692 #    define edit_query_dialog2(h,t,a,b) query_dialog(h,t,0,2,a,b)
693 #    define edit_query_dialog3(h,t,a,b,c) query_dialog(h,t,0,3,a,b,c)
694 #    define edit_query_dialog4(h,t,a,b,c,d) query_dialog(h,t,0,4,a,b,c,d)
695 
696 #else				/* ! MIDNIGHT */
697 
698 #    ifdef GTK
699 #        define get_sys_error(s) (s)
700 
701 #        define open mc_open
702 #        define close(f) mc_close(f)
703 #        define read(f,b,c) mc_read(f,b,c)
704 #        define write(f,b,c) mc_write(f,b,c)
705 #        define stat(f,s) mc_stat(f,s)
706 #        define mkdir(s,m) mc_mkdir(s,m)
707 
708 #        define itoa MY_itoa
709 #        define CMalloc(x) malloc(x)
710 
711 #        define EDITOR_NO_FILE			(1<<3)
712 #        define EDITOR_NO_SCROLL		(1<<4)
713 #        define EDITOR_NO_TEXT			(1<<5)
714 #        define EDITOR_HORIZ_SCROLL		(1<<6)
715 
716 #include <gdk/gdkprivate.h>
717 #        define CWindowOf(w) (w)
718 #        define CHeightOf(w) ((w)->editable.widget.allocation.height)
719 #        define CWidthOf(w) ((w)->editable.widget.allocation.width)
720 #        define COptionsOf(w) ((w)->options)
721 
722 #        define cache_type unsigned int
723 
724 /* font dimensions */
725 #        define FONT_OVERHEAD		gtk_edit_option_text_line_spacing
726 #        define FONT_BASE_LINE		(FONT_OVERHEAD + gtk_edit_option_font_ascent)
727 #        define FONT_HEIGHT		(gtk_edit_option_font_ascent + gtk_edit_option_font_descent)
728 #        define FONT_PIX_PER_LINE	(FONT_OVERHEAD + FONT_HEIGHT)
729 #        define FONT_MEAN_WIDTH	gtk_edit_option_font_mean_width
730 
731 #        define EDIT_FRAME_H 3
732 #        define EDIT_FRAME_W 3
733 
734 #        define FONT_OFFSET_X 0
735 #        define FONT_OFFSET_Y		FONT_BASE_LINE
736 
737 #        define FONT_PER_CHAR gtk_edit_font_width_per_char
738 
739 #        ifndef _GTK_EDIT_C
740 extern guchar gtk_edit_font_width_per_char[256];
741 extern int gtk_edit_option_text_line_spacing;
742 extern int gtk_edit_option_font_ascent;
743 extern int gtk_edit_option_font_descent;
744 extern int gtk_edit_option_font_mean_width;
745 extern int gtk_edit_fixed_font;
746 #        endif
747 
748 /* start temporary */
749 
750 #        define COLOR_BLACK 0
751 #        define COLOR_WHITE 1
752 #        define CURSOR_TYPE_EDITOR 0
753 
754 #        define WIN_MESSAGES GTK_WINDOW_TOPLEVEL, 20, 20
755 #        define option_text_line_spacing 1
756 #        define fixed_font 0
757 
758 #define color_palette(x) win->color[x].pixel
759 
760 #define DndNotDnd	-1
761 #define DndUnknown	0
762 #define DndRawData	1
763 #define DndFile		2
764 #define DndFiles	3
765 #define DndText		4
766 #define DndDir		5
767 #define DndLink		6
768 #define DndExe		7
769 #define DndURL		8
770 #define DndMIME         9
771 
772 #define DndEND		10
773 
774 #define dnd_null_term_type(d) \
775 	((d) == DndFile || (d) == DndText || (d) == DndDir || \
776 	(d) == DndLink || (d) == DndExe || (d) == DndURL)
777 
778 
779 
780 /* end temporary */
781 
782 #    else
783 
784 #        define WIN_MESSAGES edit->widget ? edit->widget->mainid : CRoot, 20, 20
785 
786 #    endif
787 
788 #    define MY_O_TEXT 0
789 
790 #    ifdef GTK
791 
792 #        ifndef min
793 #            define min(x,y)     (((x) < (y)) ? (x) : (y))
794 #        endif
795 
796 #        ifndef max
797 #            define max(x,y)     (((x) > (y)) ? (x) : (y))
798 #        endif
799 
800 /*
801 extern Display             *gdk_display;
802 extern Window               gdk_root_window;
803 */
804 
805 enum {
806  match_file, match_normal
807 };
808 
809 #        define edit_get_load_file(d,f,h) gtk_edit_dialog_get_load_file(d,f,h)
810 #        define edit_get_save_file(d,f,h) gtk_edit_dialog_get_save_file(d,f,h)
811 #        define edit_error_dialog(h,t) gtk_edit_dialog_error(h,"%s",t)
812 #        define edit_message_dialog(h,t) gtk_edit_dialog_message(0,h,"%s",t)
813 #        define edit_query_dialog2(h,t,a,b) gtk_edit_dialog_query(h,t,a,b,0)
814 #        define edit_query_dialog3(h,t,a,b,c) gtk_edit_dialog_query(h,t,a,b,c,0)
815 #        define edit_query_dialog4(h,t,a,b,c,d) gtk_edit_dialog_query(h,t,a,b,c,d,0)
816 
817 #        define CError(x) printf("Error: %s\n",x)
818 #        define CIsDropAcknowledge(a,b) DndNotDnd
819 #        define CGetDrop(e,d,s,x,y) DndNotDnd
820 #        define CDropAcknowledge(x)
821 /* #        define edit_get_syntax_color(e,i,f,b)  */
822 #        define get_international_character(k) 0
823 #        define compose_key_pressed 0
824 
825 #    else
826 
827 #        define edit_get_load_file(d,f,h) CGetLoadFile(WIN_MESSAGES,d,f,h)
828 #        define edit_get_save_file(d,f,h) CGetSaveFile(WIN_MESSAGES,d,f,h)
829 #        define edit_error_dialog(h,t) CErrorDialog(WIN_MESSAGES,h,"%s",t)
830 #        define edit_message_dialog(h,t) CMessageDialog(WIN_MESSAGES,0,h,"%s",t)
831 #        define edit_query_dialog2(h,t,a,b) CQueryDialog(WIN_MESSAGES,h,t,a,b,NULL)
832 #        define edit_query_dialog3(h,t,a,b,c) CQueryDialog(WIN_MESSAGES,h,t,a,b,c,NULL)
833 #        define edit_query_dialog4(h,t,a,b,c,d) CQueryDialog(WIN_MESSAGES,h,t,a,b,c,d,NULL)
834 #    endif
835 
836 #endif				/* ! MIDNIGHT */
837 
838 extern char *home_dir;
839 
840 #define NUM_SELECTION_HISTORY 64
841 
842 #ifndef MAX_PATH_LEN
843 #ifdef PATH_MAX
844 #define MAX_PATH_LEN PATH_MAX
845 #else
846 #define MAX_PATH_LEN 1024
847 #endif
848 #endif
849 
850 #ifdef _EDIT_C
851 
852 struct selection selection =
853 {0, 0};
854 int current_selection = 0;
855 /* Note: selection.text = selection_history[current_selection].text */
856 struct selection selection_history[NUM_SELECTION_HISTORY] =
857 {
858     {0, 0},
859     {0, 0},
860     {0, 0},
861     {0, 0},
862     {0, 0},
863     {0, 0},
864     {0, 0},
865     {0, 0},
866     {0, 0},
867     {0, 0},
868 };
869 
870 #ifdef MIDNIGHT
871 /*
872    what editor are we going to emulate? one of EDIT_KEY_EMULATION_NORMAL
873    or EDIT_KEY_EMULATION_EMACS
874  */
875 int edit_key_emulation = EDIT_KEY_EMULATION_NORMAL;
876 #endif	/* ! MIDNIGHT */
877 
878 int option_word_wrap_line_length = 72;
879 int option_typewriter_wrap = 0;
880 int option_auto_para_formatting = 0;
881 int option_international_characters = 0;
882 int option_tab_spacing = 8;
883 int option_fill_tabs_with_spaces = 0;
884 int option_return_does_auto_indent = 1;
885 int option_backspace_through_tabs = 0;
886 int option_fake_half_tabs = 1;
887 int option_save_mode = 0;
888 int option_backup_ext_int = -1;
889 int option_find_bracket = 1;
890 int option_max_undo = 32768;
891 int option_typing_replaces_selection = 0;
892 
893 int option_editor_fg_normal = 26;
894 int option_editor_fg_bold = 8;
895 int option_editor_fg_italic = 10;
896 
897 int option_edit_right_extreme = 0;
898 int option_edit_left_extreme = 0;
899 int option_edit_top_extreme = 0;
900 int option_edit_bottom_extreme = 0;
901 
902 int option_editor_bg_normal = 0;
903 int option_editor_bg_abnormal = 1;
904 int option_editor_bg_marked = 2;
905 int option_editor_bg_marked_abnormal = 9;
906 int option_editor_bg_highlighted = 12;
907 int option_editor_fg_cursor = 18;
908 
909 char *option_whole_chars_search = "0123456789abcdefghijklmnopqrstuvwxyz_";
910 char *option_chars_move_whole_word = "!=&|<>^~ !:;, !'!`!.?!\"!( !) !Aa0 !+-*/= |<> ![ !] !\\#! ";
911 char *option_backup_ext = "~";
912 
913 #else				/* ! _EDIT_C */
914 
915 extern struct selection selection;
916 extern struct selection selection_history[];
917 extern int current_selection;
918 
919 #ifdef MIDNIGHT
920 /*
921    what editor are we going to emulate? one of EDIT_KEY_EMULATION_NORMAL
922    or EDIT_KEY_EMULATION_EMACS
923  */
924 extern int edit_key_emulation;
925 #endif	/* ! MIDNIGHT */
926 
927 extern int option_word_wrap_line_length;
928 extern int option_typewriter_wrap;
929 extern int option_auto_para_formatting;
930 extern int option_international_characters;
931 extern int option_tab_spacing;
932 extern int option_fill_tabs_with_spaces;
933 extern int option_return_does_auto_indent;
934 extern int option_backspace_through_tabs;
935 extern int option_fake_half_tabs;
936 extern int option_save_mode;
937 extern int option_backup_ext_int;
938 extern int option_find_bracket;
939 extern int option_max_undo;
940 extern int option_typing_replaces_selection;
941 
942 extern int option_editor_fg_normal;
943 extern int option_editor_fg_bold;
944 extern int option_editor_fg_italic;
945 
946 extern int option_edit_right_extreme;
947 extern int option_edit_left_extreme;
948 extern int option_edit_top_extreme;
949 extern int option_edit_bottom_extreme;
950 
951 extern int option_editor_bg_normal;
952 extern int option_editor_bg_abnormal;
953 extern int option_editor_bg_marked;
954 extern int option_editor_bg_marked_abnormal;
955 extern int option_editor_bg_highlighted;
956 extern int option_editor_fg_cursor;
957 
958 extern char *option_whole_chars_search;
959 extern char *option_chars_move_whole_word;
960 extern char *option_backup_ext;
961 
962 extern int edit_confirm_save;
963 
964 #endif				/* ! _EDIT_C */
965 #endif 				/* __EDIT_H */
966