1 /* Copyright (c) 1992, 1998 John E. Davis
2  * This file is part of JED editor library source.
3  *
4  * You may distribute this file under the terms the GNU General Public
5  * License.  See the file COPYING for more information.
6  */
7 #ifndef __JED_BUFFER_H_
8 #define  __JED_BUFFER_H_
9 
10 #ifdef HAVE_STDLIB_H
11 # include <stdlib.h>
12 #endif
13 
14 #include <limits.h>
15 
16 #ifdef PATH_MAX
17 # define JED_MAX_PATH_LEN PATH_MAX
18 #else
19 # ifdef IBMPC_SYSTEM
20 #  define JED_MAX_PATH_LEN 256
21 # else
22 #  define JED_MAX_PATH_LEN 1024
23 # endif
24 #endif
25 
26 #include <slang.h>
27 
28 typedef struct _Buffer Buffer;
29 
30 #include "jdmacros.h"
31 
32 #include "keymap.h"
33 #include "undo.h"
34 #include "indent.h"
35 #include "blocal.h"
36 #if JED_HAS_MENUS
37 # include "menu.h"
38 #endif
39 
40 /*
41 #define sprintf simple_sprintf
42 extern char *simple_sprintf(char *, char *, ...);
43 */
44 
45 typedef struct Line
46 {
47    struct Line *next;               /* pointer to next line */
48    struct Line *prev;               /* pointer to prev line */
49    unsigned char *data;             /* data for the line */
50    int len;                         /* actual length of line */
51 #ifdef KEEP_SPACE_INFO
52    int space;		       /* space allocated for line */
53 #endif
54 #if JED_HAS_LINE_ATTRIBUTES
55    /* The first 4 bits of the flags field represent a 4 bit integer that
56     * is used by the syntax parsing routines.  The next 4 bits
57     * control the various flags.  Finally the last 8 bits specify the
58     * color of the line.
59     */
60    unsigned int flags;
61 #endif
62 #define JED_LINE_IN_COMMENT		0x0001
63 #define JED_LINE_IN_STRING		0x0002
64 #define JED_LINE_HAS_EOL_COMMENT	0x0008
65 #define JED_LINE_SYNTAX_BITS		0x000F
66 
67 #define JED_LINE_HIDDEN			0x0010
68 #define JED_LINE_IS_READONLY		0x0020
69 
70 } Line;
71 
72 /* This is the price we pay for a linked list approach.  With straight
73    buffer gap, this would be an integer.  Sigh. */
74 typedef struct Mark
75   {
76      Line *line;                      /* line that marker points at */
77      int point;                       /* offset from beginning */
78      unsigned int n;		       /* line number in buffer */
79      struct Mark *next;
80      unsigned int flags;	       /* visible mark if non-zero */
81 #define MARK_COLOR_MASK		0x0FF
82 #define MARK_INVALID		0x100
83 #define VISIBLE_MARK		0x200
84 #define NARROW_REGION_MARK	0x400
85 #define JED_LINE_MARK		0x800
86   }
87 Mark;
88 
89 #define JED_MAX_MARK_ARRAY_SIZE 5
90 typedef struct Jed_Mark_Array_Type
91 {
92    struct Jed_Mark_Array_Type *next;
93    unsigned int num_marks;
94    Mark marks[JED_MAX_MARK_ARRAY_SIZE];
95 }
96 Jed_Mark_Array_Type;
97 
98 extern unsigned int LineNum;	       /* current line number */
99 extern unsigned int Max_LineNum;       /* max line number */
100 
101 typedef struct Narrow_Type
102 {
103    struct Narrow_Type *next;
104    unsigned int nup, ndown;	       /* (relative) lines above this narrow */
105    Line *beg, *end;		       /* pointers to lines to linkup with */
106    Line *beg1, *end1;		       /* beg and end before narrow */
107    int is_region;
108 } Narrow_Type;
109 
110 
111 #if JED_HAS_SAVE_NARROW
112 typedef struct _Jed_Save_Narrow_Type
113 {
114    Mark *beg, *end;
115    struct _Jed_Save_Narrow_Type *next;
116 }
117 Jed_Save_Narrow_Type;
118 #endif
119 
120 /* These are buffer local variables that slang can access */
121 typedef struct
122 {
123    int tab;			       /* tab width */
124 } Buffer_Local_Type;
125 
126 extern Buffer_Local_Type Buffer_Local;
127 
128 struct _Buffer
129 {
130    Line *beg;			       /* Top line of buffer */
131    Line *end;			       /* Bottom line */
132    Line *line;		       /* current line */
133    int point;			       /* current offset */
134    unsigned int linenum;	       /* current line number */
135    unsigned int max_linenum;	       /* lines in buffer */
136    char *name;			       /* name of this buffer */
137    char *file;			       /* filename sans dir (slstring) */
138    char *dir;			       /* directory of file (slstring) */
139 #ifdef REAL_UNIX_SYSTEM
140    int device;			       /* inode and device of DIRECTORY that file
141 					* resides in */
142    int inode;
143 #endif
144    int umask;
145    unsigned int flags;	       /* flags  (autosave, etc...) */
146    Narrow_Type *narrow;	       /* info for use by widen */
147    unsigned int nup;		       /* lines above narrow (absolute) */
148    unsigned int ndown;	       /* lines below narrow */
149    Mark *marks;
150    Mark *spots;
151    Mark *user_marks;
152    unsigned int modes;	       /* c-mode, wrap, etc... */
153    SLKeyMap_List_Type *keymap;       /* keymap attached to this buffer */
154    struct _Buffer *next;	       /*  */
155    struct _Buffer *prev;
156    char *mode_string;
157    int hits;			       /* number of hits on buffer since
158 					* last autosave.  A hit is the number
159 					* of times the buffer was hit on at top level  */
160    unsigned long m_time;	       /* time when buffer first modified */
161    unsigned long c_time;	       /* time when buffer first created or  */
162    /* when file visited */
163    Undo_Type *undo;		       /* pointer to undo ring */
164    Buffer_Local_Type local_vars;
165 
166 #define SPOT_ARRAY_SIZE 4
167 
168    Jed_Mark_Array_Type *spot_array;
169    Jed_Mark_Array_Type *mark_array;
170    int vis_marks;		       /* number of visible marks */
171    char status_line[80];
172    SLang_Name_Type *par_sep;		       /* paragraph sep function */
173    SLang_Name_Type *indent_hook;
174    SLang_Name_Type *newline_indent_hook;
175    SLang_Name_Type *wrap_hook;
176    SLang_Name_Type *bob_eob_error_hook;
177 #ifdef HAS_MOUSE
178    SLang_Name_Type *mouse_down_hook;
179    SLang_Name_Type *mouse_up_hook;
180    SLang_Name_Type *mouse_drag_hook;
181 # if JED_HAS_MULTICLICK
182    SLang_Name_Type *mouse_2click_hook;
183    SLang_Name_Type *mouse_3click_hook;
184 # endif
185 #endif
186 #if JED_HAS_COLOR_COLUMNS
187    unsigned int coloring_style;
188    unsigned char *column_colors;
189    unsigned int num_column_colors;
190 #endif
191 #if JED_HAS_ABBREVS
192    int abbrev_table_handle;
193 #endif
194    Syntax_Table_Type *syntax_table;
195 #if JED_HAS_SUBPROCESSES
196    int subprocess;		       /* 1 + subprocess id */
197    int locked;
198 #endif
199 #if JED_HAS_SAVE_NARROW
200    Jed_Save_Narrow_Type *save_narrow;
201 #endif
202 #if JED_HAS_BUFFER_LOCAL_VARS
203    Jed_BLocal_Table_Type *blocal_table;
204 #endif
205 #if JED_HAS_LINE_ATTRIBUTES
206    unsigned int max_unparsed_line_num;
207    unsigned int min_unparsed_line_num;
208 #endif
209 #if JED_HAS_MENUS
210    Menu_Bar_Type *menubar;
211 #endif
212    SLang_Name_Type *update_hook;
213    int user_abort;
214    int kfcode;                       /* Kanji file code */
215 };
216 
217 extern char Default_Status_Line[80];
218 
219 /* flags */
220 #define BUFFER_MODIFIED 0x01
221 
222 /* This flag cannot be used with the AUTO_SAVE_JUST_SAVE flag */
223 #define AUTO_SAVE_BUFFER 0x02
224 /* these two flags are to tell user that the buffer and the file on disk
225    have been modified--- see update_marks and main editor loop */
226 #define FILE_MODIFIED 0x04
227 #define READ_ONLY 0x08
228 #define OVERWRITE_MODE 0x10
229 #define UNDO_ENABLED 0x20
230 
231 /* skip this buffer if looking for a pop up one. */
232 #define BURIED_BUFFER 0x40
233 
234 /* Instead of autosaving saving the buffer, just save it.  This flag
235  * is only used when SIGHUP or something like that hits.  It is also
236  * used when exiting the editor.  It will cause the buffer to be silently
237  * saved.  It is possible that I need another flag for this.
238  */
239 #define AUTO_SAVE_JUST_SAVE 0x80
240 #define NO_BACKUP_FLAG  0x100
241 #define BINARY_FILE  0x200
242 #define ADD_CR_ON_WRITE_FLAG 0x400
243 #if SUPPORT_CRONLY
244 #define CR_ONLY_ON_WRITE_FLAG 0x800
245 #endif
246 
247 #define ABBREV_MODE 0x1000
248 
249 #ifndef VMS
250 #define MAP_CR_TO_NL_FLAG 0x2000
251 #endif
252 
253 extern char *Read_Only_Error;
254 extern char *Line_Read_Only_Error;
255 
256 #if JED_HAS_LINE_ATTRIBUTES
257 #define CHECK_READ_ONLY\
258     if (CBuf->flags & READ_ONLY) { msg_error(Read_Only_Error); return(1);}\
259     if (CLine->flags & JED_LINE_IS_READONLY) {msg_error(Line_Read_Only_Error); return 1;}
260 #else
261 #define CHECK_READ_ONLY\
262     if (CBuf->flags & READ_ONLY) { msg_error(Read_Only_Error); return(1);}
263 #endif
264 
265 
266 #if JED_HAS_LINE_ATTRIBUTES
267 #define CHECK_READ_ONLY_VOID\
268     if (CBuf->flags & READ_ONLY) { msg_error(Read_Only_Error); return;}\
269     if (CLine->flags & JED_LINE_IS_READONLY) {msg_error(Line_Read_Only_Error); return;}
270 #else
271 #define CHECK_READ_ONLY_VOID\
272     if (CBuf->flags & READ_ONLY) { msg_error(Read_Only_Error); return;}
273 #endif
274 
275 #define NO_MODE 0x00
276 #define WRAP_MODE 0x01
277 #define C_MODE 0x02
278 #define LANG_MODE 0x04		       /* to be a replacement for C_MODE */
279 #define SL_MODE 0x08		       /* S-Lang mode (ored with C_MODE) */
280 #define F_MODE 0x10		       /* Fortran mode */
281 #define TEX_MODE 0x20		       /* ored with TEXT_MODE */
282 
283 extern Buffer *CBuf;
284 extern Line *CLine;
285 
286 
287 extern int bob(void);
288 extern int eob(void);                  /* point to end of buffer */
289 extern int bol(void);
290 extern int eol(void);
291 
292 extern int bobp(void);
293 extern int eobp(void);
294 extern int eolp(void);
295 extern int bolp(void);
296 
297 extern int prevline(int *);
298 extern int nextline(int *);
299 
300 extern int forwchars(int *);
301 extern int backwchars(int *);
302 extern void goto_line(int *);
303 
304 extern Line *make_line1(int);
305 extern unsigned char *make_line(int);
306 extern unsigned char *remake_line(int);
307 
308 extern Buffer *make_buffer(char *, char *, char *);
309 extern void uniquely_name_buffer(Buffer *, char *);
310 extern void buffer_filename(Buffer *, char *, char *);
311 extern Buffer *find_file_buffer(char *);
312 extern Buffer *find_buffer(char *);
313 extern int delete_line(void);
314 extern void delete_buffer(Buffer *);
315 extern int switch_to_buffer(Buffer *);
316 extern int get_percent(void);
317 extern int what_line(void);
318 extern int erase_buffer(void);
319 extern void mark_buffer_modified (int);
320 extern Line *dup_line(Line *);
321 extern void free_line(Line *);
322 extern void check_buffers(void);
323 extern int buffer_exists(Buffer *);
324 extern int Point;
325 extern int Number_Zero;
326 extern int Number_One;
327 extern int Number_Two;
328 extern int Number_Ten;
329 extern void mark_undo_boundary(Buffer *);
330 extern void delete_undo_ring(Buffer *);
331 
332 extern int Batch;		       /* JED used in batch mode. */
333 extern void touch_screen(void);
334 extern void check_line(void);
335 
336 extern int jed_set_buffer_hook (Buffer *, char *, SLang_Name_Type *);
337 extern int jed_unset_buffer_hook (Buffer *, char *);
338 
339 extern Buffer *MiniBuffer;
340 #endif
341 
342