edit.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. /* edit.h - main include file
  2. Copyright (C) 1996, 1997 the Free Software Foundation
  3. Authors: 1996, 1997 Paul Sheer
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307, USA.
  16. */
  17. #ifndef __EDIT_H
  18. #define __EDIT_H
  19. #define HAVE_SYNTAXH 1
  20. #include <stdio.h>
  21. #include <stdarg.h>
  22. #include <sys/types.h>
  23. #ifdef HAVE_UNISTD_H
  24. # include <unistd.h>
  25. #endif
  26. #include <string.h>
  27. #include <ctype.h>
  28. #include <errno.h>
  29. #include <sys/stat.h>
  30. #include <errno.h>
  31. #include <fcntl.h>
  32. #include <stdlib.h>
  33. #if !defined(STDC_HEADERS) && defined(HAVE_MALLOC_H)
  34. # include <malloc.h>
  35. #endif
  36. #include "src/global.h"
  37. #include "src/tty.h"
  38. #include "src/main.h" /* for char *shell */
  39. #include "src/dlg.h"
  40. #include "src/widget.h"
  41. #include "src/color.h"
  42. #include "src/dialog.h"
  43. #include "src/mouse.h"
  44. #include "src/help.h"
  45. #include "src/key.h"
  46. #include "src/wtools.h" /* for QuickWidgets */
  47. #include "src/cmd.h" /* for menu_edit_cmd */
  48. #include "src/win.h"
  49. #include "vfs/vfs.h"
  50. #include "src/menu.h"
  51. #include "edit-widget.h"
  52. #include "src/user.h" /* for user_menu_cmd, must be after edit-widget.h */
  53. # define WANT_WIDGETS
  54. # define WIDGET_COMMAND (WIDGET_USER + 10)
  55. # define N_menus 5
  56. #define SEARCH_DIALOG_OPTION_NO_SCANF 1
  57. #define SEARCH_DIALOG_OPTION_NO_REGEX 2
  58. #define SEARCH_DIALOG_OPTION_NO_CASE 4
  59. #define SEARCH_DIALOG_OPTION_BACKWARDS 8
  60. #define SEARCH_DIALOG_OPTION_BOOKMARK 16
  61. #define EDIT_KEY_EMULATION_NORMAL 0
  62. #define EDIT_KEY_EMULATION_EMACS 1
  63. #define REDRAW_LINE (1 << 0)
  64. #define REDRAW_LINE_ABOVE (1 << 1)
  65. #define REDRAW_LINE_BELOW (1 << 2)
  66. #define REDRAW_AFTER_CURSOR (1 << 3)
  67. #define REDRAW_BEFORE_CURSOR (1 << 4)
  68. #define REDRAW_PAGE (1 << 5)
  69. #define REDRAW_IN_BOUNDS (1 << 6)
  70. #define REDRAW_CHAR_ONLY (1 << 7)
  71. #define REDRAW_COMPLETELY (1 << 8)
  72. #define MOD_ABNORMAL (1 << 0)
  73. #define MOD_UNDERLINED (1 << 1)
  74. #define MOD_BOLD (1 << 2)
  75. #define MOD_HIGHLIGHTED (1 << 3)
  76. #define MOD_MARKED (1 << 4)
  77. #define MOD_ITALIC (1 << 5)
  78. #define MOD_CURSOR (1 << 6)
  79. #define MOD_INVERSE (1 << 7)
  80. #define EDIT_TEXT_HORIZONTAL_OFFSET 0
  81. #define EDIT_TEXT_VERTICAL_OFFSET 1
  82. #define FONT_OFFSET_X 0
  83. #define FONT_OFFSET_Y 0
  84. #define EDIT_RIGHT_EXTREME option_edit_right_extreme
  85. #define EDIT_LEFT_EXTREME option_edit_left_extreme
  86. #define EDIT_TOP_EXTREME option_edit_top_extreme
  87. #define EDIT_BOTTOM_EXTREME option_edit_bottom_extreme
  88. /*there are a maximum of ... */
  89. /*... edit buffers, each of which is ... */
  90. #define EDIT_BUF_SIZE 0x10000
  91. /* ...bytes in size. */
  92. /*x / EDIT_BUF_SIZE equals x >> ... */
  93. #define S_EDIT_BUF_SIZE 16
  94. /* x % EDIT_BUF_SIZE is equal to x && ... */
  95. #define M_EDIT_BUF_SIZE 0xFFFF
  96. #define SIZE_LIMIT (EDIT_BUF_SIZE * (MAXBUFF - 2))
  97. /* Note a 16k stack is 64k of data and enough to hold (usually) around 10
  98. pages of undo info. */
  99. /* undo stack */
  100. #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
  114. /*Tabs spaces: (sofar only HALF_TAB_SIZE is used: */
  115. #define TAB_SIZE option_tab_spacing
  116. #define HALF_TAB_SIZE ((int) option_tab_spacing / 2)
  117. struct selection {
  118. unsigned char * text;
  119. int len;
  120. };
  121. #define MAX_WORDS_PER_CONTEXT 1024
  122. #define MAX_CONTEXTS 128
  123. struct key_word {
  124. char *keyword;
  125. unsigned char first;
  126. char *whole_word_chars_left;
  127. char *whole_word_chars_right;
  128. time_t time;
  129. #define NO_COLOR 0x7FFFFFFF
  130. #define SPELLING_ERROR 0x7EFEFEFE
  131. int line_start;
  132. int color;
  133. };
  134. struct context_rule {
  135. char *left;
  136. unsigned char first_left;
  137. char *right;
  138. unsigned char first_right;
  139. char line_start_left;
  140. char line_start_right;
  141. #if 0
  142. int single_char;
  143. #endif
  144. int between_delimiters;
  145. char *whole_word_chars_left;
  146. char *whole_word_chars_right;
  147. char *keyword_first_chars;
  148. int spelling;
  149. /* first word is word[1] */
  150. struct key_word **keyword;
  151. };
  152. int edit_drop_hotkey_menu (WEdit * e, int key);
  153. void edit_menu_cmd (WEdit * e);
  154. void edit_init_menu_emacs (void);
  155. void edit_init_menu_normal (void);
  156. void edit_done_menu (void);
  157. void menu_save_mode_cmd (void);
  158. int edit_raw_key_query (char *heading, char *query, int cancel);
  159. char *strcasechr (const unsigned char *s, int c);
  160. int edit (const char *_file, int line);
  161. int edit_translate_key (WEdit * edit, unsigned int x_keycode, long x_key, int x_state, int *cmd, int *ch);
  162. #ifndef NO_INLINE_GETBYTE
  163. int edit_get_byte (WEdit * edit, long byte_index);
  164. #else
  165. static inline int edit_get_byte (WEdit * edit, long byte_index)
  166. {
  167. unsigned long p;
  168. if (byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0)
  169. return '\n';
  170. if (byte_index >= edit->curs1) {
  171. p = edit->curs1 + edit->curs2 - byte_index - 1;
  172. return edit->buffers2[p >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - (p & M_EDIT_BUF_SIZE) - 1];
  173. } else {
  174. return edit->buffers1[byte_index >> S_EDIT_BUF_SIZE][byte_index & M_EDIT_BUF_SIZE];
  175. }
  176. }
  177. #endif
  178. char *edit_get_buffer_as_text (WEdit * edit);
  179. int edit_count_lines (WEdit * edit, long current, int upto);
  180. long edit_move_forward (WEdit * edit, long current, int lines, long upto);
  181. long edit_move_forward3 (WEdit * edit, long current, int cols, long upto);
  182. long edit_move_backward (WEdit * edit, long current, int lines);
  183. void edit_scroll_screen_over_cursor (WEdit * edit);
  184. void edit_render_keypress (WEdit * edit);
  185. void edit_scroll_upward (WEdit * edit, unsigned long i);
  186. void edit_scroll_downward (WEdit * edit, int i);
  187. void edit_scroll_right (WEdit * edit, int i);
  188. void edit_scroll_left (WEdit * edit, int i);
  189. int edit_get_col (WEdit * edit);
  190. long edit_bol (WEdit * edit, long current);
  191. long edit_eol (WEdit * edit, long current);
  192. void edit_update_curs_row (WEdit * edit);
  193. void edit_update_curs_col (WEdit * edit);
  194. void edit_block_copy_cmd (WEdit * edit);
  195. void edit_block_move_cmd (WEdit * edit);
  196. int edit_block_delete_cmd (WEdit * edit);
  197. int edit_block_delete (WEdit * edit);
  198. void edit_delete_line (WEdit * edit);
  199. int edit_delete (WEdit * edit);
  200. void edit_insert (WEdit * edit, int c);
  201. int edit_cursor_move (WEdit * edit, long increment);
  202. void edit_push_action (WEdit * edit, long c, ...);
  203. void edit_push_key_press (WEdit * edit);
  204. void edit_insert_ahead (WEdit * edit, int c);
  205. int edit_save_file (WEdit * edit, const char *filename);
  206. long edit_write_stream (WEdit * edit, FILE * f);
  207. char *edit_get_write_filter (char *writename, const char *filename);
  208. int edit_save_cmd (WEdit * edit);
  209. int edit_save_confirm_cmd (WEdit * edit);
  210. int edit_save_as_cmd (WEdit * edit);
  211. WEdit *edit_init (WEdit * edit, int lines, int columns, const char *filename, const char *text, const char *dir, unsigned long text_size);
  212. int edit_clean (WEdit * edit);
  213. int edit_renew (WEdit * edit);
  214. int edit_new_cmd (WEdit * edit);
  215. int edit_reload (WEdit * edit, const char *filename, const char *text, const char *dir, unsigned long text_size);
  216. int edit_load_cmd (WEdit * edit);
  217. void edit_mark_cmd (WEdit * edit, int unmark);
  218. void edit_set_markers (WEdit * edit, long m1, long m2, int c1, int c2);
  219. void edit_push_markers (WEdit * edit);
  220. void edit_quit_cmd (WEdit * edit);
  221. void edit_replace_cmd (WEdit * edit, int again);
  222. void edit_search_cmd (WEdit * edit, int again);
  223. void edit_complete_word_cmd (WEdit * edit);
  224. int edit_save_block (WEdit * edit, const char *filename, long start, long finish);
  225. int edit_save_block_cmd (WEdit * edit);
  226. int edit_insert_file_cmd (WEdit * edit);
  227. int edit_insert_file (WEdit * edit, const char *filename);
  228. void edit_block_process_cmd (WEdit * edit, const char *shell_cmd, int block);
  229. char *catstrs (const char *first, ...);
  230. void freestrs (void);
  231. void edit_refresh_cmd (WEdit * edit);
  232. void edit_date_cmd (WEdit * edit);
  233. void edit_goto_cmd (WEdit * edit);
  234. int eval_marks (WEdit * edit, long *start_mark, long *end_mark);
  235. void edit_status (WEdit * edit);
  236. int edit_execute_command (WEdit * edit, int command, int char_for_insertion);
  237. int edit_execute_key_command (WEdit * edit, int command, int char_for_insertion);
  238. void edit_update_screen (WEdit * edit);
  239. int edit_printf (WEdit * e, const char *fmt, ...)
  240. __attribute__ ((format (printf, 2, 3)));
  241. int edit_print_string (WEdit * e, const char *s);
  242. void edit_move_to_line (WEdit * e, long line);
  243. void edit_move_display (WEdit * e, long line);
  244. void edit_word_wrap (WEdit * edit);
  245. unsigned char *edit_get_block (WEdit * edit, long start, long finish, int *l);
  246. int edit_sort_cmd (WEdit * edit);
  247. void edit_help_cmd (WEdit * edit);
  248. void edit_left_word_move (WEdit * edit, int s);
  249. void edit_right_word_move (WEdit * edit, int s);
  250. void edit_get_selection (WEdit * edit);
  251. int edit_save_macro_cmd (WEdit * edit, struct macro macro[], int n);
  252. int edit_load_macro_cmd (WEdit * edit, struct macro macro[], int *n, int k);
  253. void edit_delete_macro_cmd (WEdit * edit);
  254. int edit_copy_to_X_buf_cmd (WEdit * edit);
  255. int edit_cut_to_X_buf_cmd (WEdit * edit);
  256. void edit_paste_from_X_buf_cmd (WEdit * edit);
  257. void edit_paste_from_history (WEdit *edit);
  258. void edit_split_filename (WEdit * edit, const char *name);
  259. #define CWidget Widget
  260. void edit_set_syntax_change_callback (void (*callback) (CWidget *));
  261. void edit_load_syntax (WEdit * edit, char **names, char *type);
  262. void edit_free_syntax_rules (WEdit * edit);
  263. void edit_get_syntax_color (WEdit * edit, long byte_index, int *color);
  264. int edit_check_spelling (WEdit * edit);
  265. void book_mark_insert (WEdit * edit, int line, int c);
  266. int book_mark_query_color (WEdit * edit, int line, int c);
  267. int book_mark_query_all (WEdit * edit, int line, int *c);
  268. struct _book_mark *book_mark_find (WEdit * edit, int line);
  269. int book_mark_clear (WEdit * edit, int line, int c);
  270. void book_mark_flush (WEdit * edit, int c);
  271. void book_mark_inc (WEdit * edit, int line);
  272. void book_mark_dec (WEdit * edit, int line);
  273. void user_menu (WEdit *edit);
  274. /* either command or char_for_insertion must be passed as -1 */
  275. int edit_execute_cmd (WEdit * edit, int command, int char_for_insertion);
  276. #define CPushFont(x,y)
  277. #define CPopFont()
  278. #define FIXED_FONT 1
  279. /* put OS2/NT/WIN95 defines here */
  280. #ifdef USE_O_TEXT
  281. # define MY_O_TEXT O_TEXT
  282. #else
  283. # define MY_O_TEXT 0
  284. #endif
  285. #define FONT_PIX_PER_LINE 1
  286. #define FONT_MEAN_WIDTH 1
  287. #define get_sys_error(s) (s)
  288. #define itoa MY_itoa
  289. #define edit_get_load_file(d,f,h) input_dialog (h, _(" Enter file name: "), f)
  290. #define edit_get_save_file(d,f,h) input_dialog (h, _(" Enter file name: "), f)
  291. #define CMalloc(x) malloc(x)
  292. #define edit_error_dialog(h,s) query_dialog (h, s, 0, 1, _("&Dismiss"))
  293. #define edit_message_dialog(h,s) query_dialog (h, s, 0, 1, _("&Ok"))
  294. #define edit_query_dialog2(h,t,a,b) query_dialog(h,t,0,2,a,b)
  295. #define edit_query_dialog3(h,t,a,b,c) query_dialog(h,t,0,3,a,b,c)
  296. #define edit_query_dialog4(h,t,a,b,c,d) query_dialog(h,t,0,4,a,b,c,d)
  297. #define color_palette(x) win->color[x].pixel
  298. extern char *home_dir;
  299. #define NUM_SELECTION_HISTORY 64
  300. #ifndef MAX_PATH_LEN
  301. #ifdef PATH_MAX
  302. #define MAX_PATH_LEN PATH_MAX
  303. #else
  304. #define MAX_PATH_LEN 1024
  305. #endif
  306. #endif
  307. /*
  308. what editor are we going to emulate? one of EDIT_KEY_EMULATION_NORMAL
  309. or EDIT_KEY_EMULATION_EMACS
  310. */
  311. extern int edit_key_emulation;
  312. extern WEdit *wedit;
  313. extern Menu EditMenuBar[];
  314. extern Dlg_head *edit_dlg;
  315. extern WMenu *edit_menubar;
  316. extern int option_word_wrap_line_length;
  317. extern int option_typewriter_wrap;
  318. extern int option_auto_para_formatting;
  319. extern int option_tab_spacing;
  320. extern int option_fill_tabs_with_spaces;
  321. extern int option_return_does_auto_indent;
  322. extern int option_backspace_through_tabs;
  323. extern int option_fake_half_tabs;
  324. extern int option_save_mode;
  325. extern int option_backup_ext_int;
  326. extern int option_max_undo;
  327. extern int option_syntax_highlighting;
  328. extern int option_edit_right_extreme;
  329. extern int option_edit_left_extreme;
  330. extern int option_edit_top_extreme;
  331. extern int option_edit_bottom_extreme;
  332. extern char *option_whole_chars_search;
  333. extern char *option_backup_ext;
  334. extern int edit_confirm_save;
  335. extern int column_highlighting;
  336. #endif /* __EDIT_H */