2 * This file is the general header file for all parts of the MicroEMACS
3 * display editor. It contains definitions used by everyone, and it contains
4 * the stuff you have to edit to create a version of the editor for a specific
5 * operating system and terminal.
9 * Uncomment exactly one of the following, as needed. Some systems already
10 * predefine one of these and will complain if you define it also.
13 #define AMIGA 1 /* AmigaDOS, Lattice */
14 /*#define ST520*/ /* ST520, TOS */
16 /*#define V7*/ /* V7 UN*X or Coherent */
17 /*#define VMS*/ /* VAX/VMS */
18 /*#define CPM*/ /* CP/M-86 */
20 #ifndef MSDOS /* Already defined for Lattice */
21 #define MSDOS 0 /* MS-DOS */
25 #define VT52 0 /* VT52 terminal (Zenith). */
26 #define VT100 0 /* Handle VT100 style keypad. */
27 #define LK201 0 /* Handle LK201 style keypad. */
28 #define RAINBOW 0 /* Use Rainbow fast video. */
29 #define TERMCAP 0 /* Use TERMCAP */
31 #define CVMVAS 1 /* C-V, M-V arg. in screens. */
33 #define NFILEN 80 /* # of bytes, file name */
34 #define NBUFN 16 /* # of bytes, buffer name */
35 #define NLINE 256 /* # of bytes, line */
36 #define NKBDM 256 /* # of strokes, keyboard macro */
37 #define NPAT 80 /* # of bytes, pattern */
38 #define HUGE 1000 /* Huge number */
40 #define AGRAVE 0x60 /* M- prefix, Grave (LK201) */
41 #define METACH 0x1B /* M- prefix, Control-[, ESC */
42 #define CTMECH 0x1C /* C-M- prefix, Control-\ */
43 #define EXITCH 0x1D /* Exit level, Control-] */
44 #define CTRLCH 0x1E /* C- prefix, Control-^ */
45 #define HELPCH 0x1F /* Help key, Control-_ */
47 #define CTRL 0x0100 /* Control flag, or'ed in */
48 #define META 0x0200 /* Meta flag, or'ed in */
49 #define CTLX 0x0400 /* ^X flag, or'ed in */
53 #define FALSE 0 /* False, no, bad, etc. */
54 #define TRUE 1 /* True, yes, good, etc. */
55 #define ABORT 2 /* Death, ^G, abort, etc. */
57 #define FIOSUC 0 /* File I/O, success. */
58 #define FIOFNF 1 /* File I/O, file not found. */
59 #define FIOEOF 2 /* File I/O, end of file. */
60 #define FIOERR 3 /* File I/O, error. */
62 #define CFCPCN 0x0001 /* Last command was C-P, C-N */
63 #define CFKILL 0x0002 /* Last command was a kill */
66 * There is a window structure allocated for every active display window. The
67 * windows are kept in a big list, in top to bottom screen order, with the
68 * listhead at "wheadp". Each window contains its own values of dot and mark.
69 * The flag field contains some bits that are set by commands to guide
70 * redisplay; although this is a bit of a compromise in terms of decoupling,
71 * the full blown redisplay is just too expensive to run for every input
74 typedef struct WINDOW
{
75 struct WINDOW
*w_wndp
; /* Next window */
76 struct BUFFER
*w_bufp
; /* Buffer displayed in window */
77 struct LINE
*w_linep
; /* Top line in the window */
78 struct LINE
*w_dotp
; /* Line containing "." */
79 short w_doto
; /* Byte offset for "." */
80 struct LINE
*w_markp
; /* Line containing "mark" */
81 short w_marko
; /* Byte offset for "mark" */
82 char w_toprow
; /* Origin 0 top row of window */
83 char w_ntrows
; /* # of rows of text in window */
84 char w_force
; /* If NZ, forcing row. */
85 char w_flag
; /* Flags. */
88 #define WFFORCE 0x01 /* Window needs forced reframe */
89 #define WFMOVE 0x02 /* Movement from line to line */
90 #define WFEDIT 0x04 /* Editing within a line */
91 #define WFHARD 0x08 /* Better to a full display */
92 #define WFMODE 0x10 /* Update mode line. */
95 * Text is kept in buffers. A buffer header, described below, exists for every
96 * buffer in the system. The buffers are kept in a big list, so that commands
97 * that search for a buffer by name can find the buffer header. There is a
98 * safe store for the dot and mark in the header, but this is only valid if
99 * the buffer is not being displayed (that is, if "b_nwnd" is 0). The text for
100 * the buffer is kept in a circularly linked list of lines, with a pointer to
101 * the header line in "b_linep".
103 typedef struct BUFFER
{
104 struct BUFFER
*b_bufp
; /* Link to next BUFFER */
105 struct LINE
*b_dotp
; /* Link to "." LINE structure */
106 short b_doto
; /* Offset of "." in above LINE */
107 struct LINE
*b_markp
; /* The same as the above two, */
108 short b_marko
; /* but for the "mark" */
109 struct LINE
*b_linep
; /* Link to the header LINE */
110 char b_nwnd
; /* Count of windows on buffer */
111 char b_flag
; /* Flags */
112 char b_fname
[NFILEN
]; /* File name */
113 char b_bname
[NBUFN
]; /* Buffer name */
116 #define BFTEMP 0x01 /* Internal temporary buffer */
117 #define BFCHG 0x02 /* Changed since last write */
120 * The starting position of a region, and the size of the region in
121 * characters, is kept in a region structure. Used by the region commands.
124 struct LINE
*r_linep
; /* Origin LINE address. */
125 short r_offset
; /* Origin LINE offset. */
126 short r_size
; /* Length in characters. */
130 * All text is kept in circularly linked lists of "LINE" structures. These
131 * begin at the header line (which is the blank line beyond the end of the
132 * buffer). This line is pointed to by the "BUFFER". Each line contains a the
133 * number of bytes in the line (the "used" size), the size of the text array,
134 * and the text. The end of line is not stored as a byte; it's implied. Future
135 * additions will include update hints, and a list of marks into the line.
137 typedef struct LINE
{
138 struct LINE
*l_fp
; /* Link to the next line */
139 struct LINE
*l_bp
; /* Link to the previous line */
140 short l_size
; /* Allocated size */
141 short l_used
; /* Used size */
142 char l_text
[1]; /* A bunch of characters. */
145 #define lforw(lp) ((lp)->l_fp)
146 #define lback(lp) ((lp)->l_bp)
147 #define lgetc(lp, n) ((lp)->l_text[(n)]&0xFF)
148 #define lputc(lp, n, c) ((lp)->l_text[(n)]=(c))
149 #define llength(lp) ((lp)->l_used)
152 * The editor communicates with the display using a high level interface. A
153 * "TERM" structure holds useful variables, and indirect pointers to routines
154 * that do useful operations. The low level get and put routines are here too.
155 * This lets a terminal, in addition to having non standard commands, have
156 * funny get and put character code too. The calls might get changed to
157 * "termp->t_field" style in the future, to make it possible to run more than
161 short t_nrow
; /* Number of rows. */
162 short t_ncol
; /* Number of columns. */
163 int (*t_open
)(); /* Open terminal at the start. */
164 int (*t_close
)(); /* Close terminal at end. */
165 int (*t_getchar
)(); /* Get character from keyboard. */
166 int (*t_putchar
)(); /* Put character to display. */
167 int (*t_flush
)(); /* Flush output buffers. */
168 int (*t_move
)(); /* Move the cursor, origin 0. */
169 int (*t_eeol
)(); /* Erase to end of line. */
170 int (*t_eeop
)(); /* Erase to end of page. */
171 int (*t_beep
)(); /* Beep. */
174 extern int fillcol
; /* Fill column */
175 extern int currow
; /* Cursor row */
176 extern int curcol
; /* Cursor column */
177 extern int thisflag
; /* Flags, this command */
178 extern int lastflag
; /* Flags, last command */
179 extern int curgoal
; /* Goal for C-P, C-N */
180 extern int mpresf
; /* Stuff in message line */
181 extern int sgarbf
; /* State of screen unknown */
182 extern WINDOW
*curwp
; /* Current window */
183 extern BUFFER
*curbp
; /* Current buffer */
184 extern WINDOW
*wheadp
; /* Head of list of windows */
185 extern BUFFER
*bheadp
; /* Head of list of buffers */
186 extern BUFFER
*blistp
; /* Buffer for C-X C-B */
187 extern short kbdm
[]; /* Holds kayboard macro data */
188 extern short *kbdmip
; /* Input pointer for above */
189 extern short *kbdmop
; /* Output pointer for above */
190 extern char pat
[]; /* Search pattern */
191 extern TERM term
; /*(Terminal information. */
193 extern BUFFER
*bfind(); /* Lookup a buffer by name */
194 extern WINDOW
*wpopup(); /* Pop up window creation */
195 extern LINE
*lalloc(); /* Allocate a line */
199 int addline(const char *text
);
200 void amg_flush(void);
202 int backchar(int f
, int n
);
203 int backdel(int f
, int n
);
204 int backline(int f
, int n
);
205 int backpage(int f
, int n
);
206 int backword(int f
, int n
);
207 int bclear(BUFFER
*bp
);
208 int ctrlg(int f
, int n
);
209 void edinit(char bname
[]);
210 int eq(int a
, int b
);
211 int execute(int c
, int f
, int n
);
213 int ffgetline(char buf
[], int nbuf
);
214 int ffputline(char buf
[], int nbuf
);
215 int ffropen(const char *fn
);
216 int ffwopen(const char *fn
);
217 int forwchar(int f
, int n
);
218 int forwword(int f
, int n
);
221 int getgoal(LINE
*dlp
);
223 int getregion(REGION
*r
);
225 void itoa(char buf
[], int width
, int num
);
230 int ldelete(int n
, int f
);
231 int ldelnewline(void);
232 void lfree(LINE
*lp
);
233 int linsert(int n
, int c
);
236 void makename(char bname
[], char fname
[]);
238 void mlputi(int i
, int r
);
239 void mlputli(long l
, int r
);
240 void mlputs(const char *s
);
241 int mlreply(const char *prompt
, char *buf
, int nbuf
);
242 void mlwrite(const char *fmt
, ...);
243 int mlyesno(const char *prompt
);
244 void modeline(WINDOW
*wp
);
245 void movecursor(int row
, int col
);
246 int mvupwind(int f
, int n
);
247 int newline(int f
, int n
);
248 int quickexit(int f
, int n
);
249 int readin(char fname
[]);
250 int readpattern(const char *p
);
251 int shrinkwind(int f
, int n
);
254 void updateline(int row
, char vline
[], char pline
[]);
258 int writeout(const char *s
);