-
Notifications
You must be signed in to change notification settings - Fork 1
/
estruct.h
288 lines (246 loc) · 10 KB
/
estruct.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/*
* ESTRUCT: Structure and preprocesser defined for MicroEMACS 3.10
*
* written by Daniel Lawrence based on code by Dave G. Conroy, Steve Wilhite and
* George Jones
*/
#define PROGNAME "Dynamic"
#define VERSION "1.0"
/* Configuration options */
#define TYPEAH 1 /* type ahead causes update to be skipped */
#define CALLED 0 /* is emacs a called subroutine? or stand
* alone */
/* handle constant and voids properly */
#define CONST const
/* System dependant library redefinitions, structures and includes */
/*
* the following define allows me to initialize unions... otherwise we make
* them structures (like the keybinding table)
*/
#define ETYPE struct
/* internal constants */
#define NBINDS 300 /* max # of bound keys */
#define NFILEN 256
#define NBUFN 32 /* # of bytes, buffer name */
#define NLINE 256 /* # of bytes, input line */
#define NSTRING 128 /* # of bytes, string buffers */
#define NPAT 128 /* # of bytes, pattern */
#define HUGE 1000 /* Huge number */
#define KBLOCK 250 /* sizeof kill buffer chunks */
#define NBLOCK 16 /* line block chunk size */
#define NMARKS 10 /* number of marks */
#define CTRL 0x0100 /* Control flag, or'ed in */
#define META 0x0200 /* Meta flag, or'ed in */
#define CTLX 0x0400 /* ^X flag, or'ed in */
#define SPEC 0x0800 /* special key (function keys) */
#define MOUS 0x1000 /* alternative input device (mouse) */
#define SHFT 0x2000 /* shifted (for function keys) */
#define ALTD 0x4000 /* ALT key... */
#define BINDNUL 0 /* not bount to anything */
#define BINDFNC 1 /* key bound to a function */
#ifdef FALSE
#undef FALSE
#endif
#ifdef TRUE
#undef TRUE
#endif
#define FALSE 0 /* False, no, bad, etc. */
#define TRUE 1 /* True, yes, good, etc. */
#define ABORT 2 /* Death, ^G, abort, etc. */
#define FIOSUC 0 /* File I/O, success. */
#define FIOFNF 1 /* File I/O, file not found. */
#define FIOEOF 2 /* File I/O, end of file. */
#define FIOERR 3 /* File I/O, error. */
#define FIOMEM 4 /* File I/O, out of memory */
#define FIODEL 6 /* Can't delete/rename file */
#define CFCPCN 0x0001 /* Last command was C-P, C-N */
#define INTWIDTH sizeof(int) * 3
#ifdef islower
#undef islower
#endif
/*
* There is a window structure allocated for every active display window. The
* windows are kept in a big list, in top to bottom screen order, with the
* listhead at "wheadp". Each window contains its own values of dot and mark.
* The flag field contains some bits that are set by commands to guide
* redisplay. Although this is a bit of a compromise in terms of decoupling,
* the full blown redisplay is just too expensive to run for every input
* character.
*/
typedef struct WINDOW
{
struct WINDOW *w_wndp; /* Next window */
struct BUFFER *w_bufp; /* Buffer displayed in window */
struct LINE *w_linep; /* Top line in the window */
struct LINE *w_dotp; /* Line containing "." */
short w_doto; /* Byte offset for "." */
struct LINE *w_markp[NMARKS]; /* Line containing "mark" */
short w_marko[NMARKS]; /* Byte offset for "mark" */
char w_toprow; /* Origin 0 top row of window */
char w_ntrows; /* # of rows of text in window */
char w_force; /* If NZ, forcing row. */
char w_flag; /* Flags. */
int w_fcol; /* first column displayed */
} WINDOW;
#define WFFORCE 0x01 /* Window needs forced reframe */
#define WFMOVE 0x02 /* Movement from line to line */
#define WFEDIT 0x04 /* Editing within a line */
#define WFHARD 0x08 /* Better to a full display */
#define WFMODE 0x10 /* Update mode line. */
/*
* Text is kept in buffers. A buffer header, described below, exists for
* every buffer in the system. The buffers are kept in a big list, so that
* commands that search for a buffer by name can find the buffer header.
* There is a safe store for the dot and mark in the header, but this is only
* valid if the buffer is not being displayed (that is, if "b_nwnd" is 0).
* The text for the buffer is kept in a circularly linked list of lines, with
* a pointer to the header line in "b_linep" Buffers may be "Inactive"
* which means the files associated with them have not been read in yet.
* These get read in at "use buffer" time.
*/
typedef struct BUFFER
{
struct BUFFER *b_bufp; /* Link to next BUFFER */
struct LINE *b_dotp; /* Link to "." LINE structure */
short b_doto; /* Offset of "." in above LINE */
struct LINE *b_markp[NMARKS]; /* The same as the above two, */
short b_marko[NMARKS]; /* but for the "mark" */
int b_fcol; /* first col to display */
struct LINE *b_linep; /* Link to the header LINE */
struct LINE *b_topline; /* Link to narrowed top text */
struct LINE *b_botline; /* Link to narrowed bottom text */
char b_active; /* window activated flag */
char b_nwnd; /* Count of windows on buffer */
char b_flag; /* Flags */
int b_mode; /* editor mode of this buffer */
char b_fname[NFILEN]; /* File name */
char b_bname[NBUFN]; /* Buffer name */
} BUFFER;
#define BFINVS 0x01 /* Internal invisable buffer */
#define BFCHG 0x02 /* Changed since last write */
#define BFTRUNC 0x04 /* buffer was truncated when read */
#define BFNAROW 0x08 /* buffer has been narrowed */
/* mode flags */
#define NUMMODES 9 /* # of defined modes */
#define MDVIEW 0x0010 /* read-only buffer */
#define MDOVER 0x0020 /* overwrite mode */
#define MDASAVE 0x0100 /* auto-save mode */
/*
* The starting position of a region, and the size of the region in
* characters, is kept in a region structure. Used by the region commands.
*/
typedef struct
{
struct LINE *r_linep; /* Origin LINE address. */
short r_offset; /* Origin LINE offset. */
long r_size; /* Length in characters. */
} REGION;
/*
* All text is kept in circularly linked lists of "LINE" structures. These
* begin at the header line (which is the blank line beyond the end of the
* buffer). This line is pointed to by the "BUFFER". Each line contains a the
* number of bytes in the line (the "used" size), the size of the text array,
* and the text. The end of line is not stored as a byte; it's implied.
*/
typedef struct LINE
{
struct LINE *l_fp; /* Link to the next line */
struct LINE *l_bp; /* Link to the previous line */
short l_size; /* Allocated size */
short l_used; /* Used size */
char l_text[1]; /* A bunch of characters. */
} LINE;
#define lforw(lp) ((lp)->l_fp)
#define lback(lp) ((lp)->l_bp)
#define lgetc(lp, n) ((lp)->l_text[(n)]&0xFF)
#define lputc(lp, n, c) ((lp)->l_text[(n)]=(c))
#define llength(lp) ((lp)->l_used)
/*
* The editor communicates with the display using a high level interface. A
* "TERM" structure holds useful variables, and indirect pointers to routines
* that do useful operations. The low level get and put routines are here
* too. This lets a terminal, in addition to having non standard commands,
* have funny get and put character code too. The calls might get changed to
* "termp->t_field" style in the future, to make it possible to run more than
* one terminal type.
*/
typedef struct
{
short t_mrow; /* max number of rows allowable */
short t_nrow; /* current number of rows used */
short t_mcol; /* max Number of columns. */
short t_ncol; /* current Number of columns. */
short t_margin; /* min margin for extended lines */
short t_scrsiz; /* size of scroll region " */
int t_pause; /* # times thru update to pause */
int (*t_open) (); /* Open terminal at the start. */
int (*t_close) (); /* Close terminal at end. */
int (*t_kopen) (); /* Open keyboard */
int (*t_kclose) (); /* close keyboard */
int (*t_getchar) (); /* Get character from keyboard. */
int (*t_putchar) (); /* Put character to display. */
int (*t_flush) (); /* Flush output buffers. */
int (*t_move) (); /* Move the cursor, origin 0. */
int (*t_eeol) (); /* Erase to end of line. */
int (*t_eeop) (); /* Erase to end of page. */
int (*t_beep) (); /* Beep. */
int (*t_rev) (); /* set reverse video state */
int (*t_rez) (); /* change screen resolution */
int (*t_puts) (); /* put string */
} TERM;
/*
* TEMPORARY macros for terminal I/O (to be placed in a machine dependant
* place later)
*/
#define TTopen (*term.t_open)
#define TTclose (*term.t_close)
#define TTkopen (*term.t_kopen)
#define TTkclose (*term.t_kclose)
#define TTgetc (*term.t_getchar)
#define TTputc (*term.t_putchar)
#define TTflush (*term.t_flush)
#define TTmove (*term.t_move)
#define TTeeol (*term.t_eeol)
#define TTbeep (*term.t_beep)
#define TTrev (*term.t_rev)
/* Structure for the table of current key bindings */
ETYPE EPOINTER
{
int (*fp) (); /* C routine to invoke */
BUFFER *buf; /* buffer to execute */
};
typedef struct
{
short k_code; /* Key code */
short k_type; /* binding type (C function or EMACS
* buffer) */
ETYPE EPOINTER k_ptr; /* ptr to thing to execute */
} KEYTAB;
/* structure for the name binding table */
typedef struct
{
char *n_name; /* name of function key */
int (*n_func) (); /* function name is bound to */
} NBIND;
/*
* The editor holds deleted text chunks in the KILL buffer. The kill buffer
* is logically a stream of ascii characters, however due to its
* unpredicatable size, it gets implemented as a linked list of chunks. (The
* d_ prefix is for "deleted" text, as k_ was taken up by the keycode
* structure)
*/
typedef struct KILL
{
struct KILL *d_next; /* link to next chunk, NULL if last */
char d_chunk[KBLOCK]; /* deleted text */
} KILL;
/*
* When emacs' command interpetor needs to get a variable's name, rather than
* it's value, it is passed back as a VDESC variable description structure.
* The v_num field is a index into the appropriate variable table.
*/
typedef struct VDESC
{
int v_type; /* type of variable */
int v_num; /* ordinal pointer to variable in list */
} VDESC;