1 /************************************************************************
2  * This program is Copyright (C) 1986-1996 by Jonathan Payne.  JOVE is  *
3  * provided to you without charge, and with no warranty.  You may give  *
4  * away copies of JOVE, including sources, provided that this notice is *
5  * included in all the files.                                           *
6  ************************************************************************/
7 
8 /* maximum length of a line (including '\0').  Currently cannot
9    be larger than a logical disk block. */
10 #define	LBSIZE		JBUFSIZ
11 
12 /* buffer types */
13 #define B_SCRATCH	1	/* for internal things, e.g. minibuffer ... */
14 #define B_FILE		2	/* normal file (we auto-save these.) */
15 #define B_PROCESS	3	/* unix process output in this buffer */
16 
17 /* major modes */
18 #define FUNDAMENTAL	0	/* Fundamental mode */
19 #define TEXTMODE	1	/* Text mode */
20 #define CMODE		2	/* C mode */
21 #ifdef LISP
22 # define LISPMODE	3	/* Lisp mode */
23 # define NMAJORS	4
24 #else
25 # define NMAJORS	3
26 #endif
27 
28 #define MajorMode(x)	(curbuf->b_major == (x))
29 #define SetMajor(x)	{ curbuf->b_major = (x); UpdModLine = YES; }
30 
31 /* minor modes */
32 #define Indent		(1 << 0)	/* indent same as previous line after return */
33 #define ShowMatch	(1 << 1)	/* paren flash mode */
34 #define Fill		(1 << 2)	/* text fill mode */
35 #define OverWrite	(1 << 3)	/* over write mode */
36 #define Abbrev		(1 << 4)	/* abbrev mode */
37 #define ReadOnly	(1 << 5)	/* buffer is read only */
38 
39 #define BufMinorMode(b, x)	(((b)->b_minor & (x)) != 0)
40 #define MinorMode(x)		BufMinorMode(curbuf, (x))
41 
42 /* global line scratch buffers */
43 #ifdef AUTO_BUFS
44 extern char	*genbuf,	/* scratch pad points at s_genbuf (see main()) */
45 		*linebuf,	/* points at s_linebuf */
46 		*iobuff;	/* for file reading ... points at s_iobuff */
47 #else
48 extern char	genbuf[LBSIZE],
49 		linebuf[LBSIZE],
50 		iobuff[LBSIZE];
51 #endif
52 
53 /* typedef struct line *LinePtr in jove.h */
54 
55 struct line {
56 	LinePtr	l_prev,		/* pointer to prev */
57 		l_next;		/* pointer to next */
58 	daddr	l_dline;		/* pointer to disk location */
59 };
60 
61 /* typedef struct mark Mark in jove.h */
62 
63 struct mark {
64 	LinePtr	m_line;
65 	int	m_char;
66 	bool	m_big_delete;	/* mark was within the range of a multi-line delete */
67 	Mark	*m_next;	/* list of marks */
68 };
69 
70 /* typedef struct buffer Buffer in jove.h */
71 
72 struct buffer {
73 #ifdef MAC
74 	int Type;		/* kludge... to look like a data_obj */
75 	char *Name;		/* Name will not be used */
76 #endif
77 	Buffer	*b_next;		/* next buffer in chain */
78 	char	*b_name,		/* buffer name */
79 		*b_fname;		/* file name associated with buffer */
80 #ifdef USE_INO
81 	/* unique identification of file */
82 	dev_t	b_dev;			/* device of file name. */
83 	ino_t	b_ino;			/* inode of file name */
84 #endif
85 	time_t	b_mtime;		/* last modify time ...
86 					   to detect two people writing
87 					   to the same file */
88 	LinePtr	b_first,		/* pointer to first line in list */
89 		b_dot,			/* current line */
90 		b_last;		/* last line in list */
91 	int	b_char;			/* current character in line */
92 
93 #define NMARKS	8			/* number of marks in the ring */
94 
95 	Mark	*b_markring[NMARKS],	/* new marks are pushed here */
96 #define b_curmark(b)	((b)->b_markring[(b)->b_themark])
97 #define curmark		b_curmark(curbuf)
98 		*b_marks;		/* all the marks for this buffer */
99 	char	b_themark,		/* current mark (in b_markring) */
100 		b_type,			/* file, scratch, process, iprocess */
101 		b_ntbf,			/* (bool) needs to be found when we
102 					   first select? */
103 		b_modified,		/* (bool) is the buffer modified? */
104 		b_diverged;		/* (bool) has the underlying file been changed behind our back? */
105 	int	b_major,		/* major mode */
106 		b_minor;		/* and minor mode */
107 	struct keymap	*b_map;		/* local bindings (if any) */
108 #ifdef IPROCS
109 	struct process	*b_process;		/* process we're attached to */
110 #endif
111 };
112 
113 extern Buffer
114 	*world,		/* first buffer */
115 	*curbuf,	/* pointer into world for current buffer */
116 	*lastbuf,	/* Last buffer we were in so we have a default
117 			   buffer during a select buffer. */
118 	*perr_buf;	/* Buffer with error messages */
119 
120 #define curline	(curbuf->b_dot)
121 #define curchar (curbuf->b_char)
122 
123 /* typedef struct position Bufpos in jove.h */
124 
125 struct position {
126 	LinePtr	p_line;
127 	int	p_char;
128 };
129 
130 extern bool
131 	valid_bp proto((Buffer	*bp));
132 
133 extern Buffer
134 	*buf_exists proto((char *name)),
135 	*do_find proto((Window *w, char *fname, bool force, bool do_macros)),
136 	*do_select proto((Window *w,char *name)),
137 	*do_stat proto((char *name, Buffer *target, int flags));
138 
139 /* flags to do_stat */
140 #define DS_NONE	0
141 #define DS_SET	1	/* set target buffers stat fields */
142 #define DS_REUSE	2	/* reuse result of last stat */
143 #define DS_DIR	4	/* directory OK as result */
144 
145 extern bool
146 	was_dir,	/* do_stat found a directory */
147 	was_file;	/* do_stat found a (plain) file */
148 
149 extern char
150 	*ask_buf proto((Buffer *def, int flags));
151 
152 #ifdef USE_PROTOTYPES
153 struct macro;	/* forward declaration preventing prototype scoping */
154 #endif /* USE_PROTOTYPES */
155 
156 extern void
157 	TogMinor proto((int bit)),
158 	buf_clear proto((Buffer *b)),
159 	setfname proto((Buffer *b,char *name)),
160 	SetABuf proto((Buffer *b)),
161 	SetBuf proto((Buffer *newbuf)),
162 	buf_init proto((void));
163 
164 extern LinePtr
165 	lastline proto((LinePtr lp)),
166 	listput proto((Buffer *buf,LinePtr after)),
167 	next_line proto((LinePtr line,int num)),
168 	prev_line proto((LinePtr line,int num));
169 
170 /* Commands: */
171 
172 extern void
173 	BufErase proto((void)),
174 	BufKill proto((void)),
175 	BufList proto((void)),
176 	BufSelect proto((void)),
177 	FindFile proto((void)),
178 	KillSome proto((void)),
179 	ReNamBuf proto((void));
180 
181 extern void
182 	Buf1Select proto((void)),
183 	Buf2Select proto((void)),
184 	Buf3Select proto((void)),
185 	Buf4Select proto((void)),
186 	Buf5Select proto((void)),
187 	Buf6Select proto((void)),
188 	Buf7Select proto((void)),
189 	Buf8Select proto((void)),
190 	Buf9Select proto((void)),
191 	Buf10Select proto((void));
192