date and time created 80/07/31 23:00:00 by mark
[unix-history] / usr / src / usr.bin / ex / ex.h
CommitLineData
e753e5e9
MH
1/* Copyright (c) 1979 Regents of the University of California */
2#ifdef V6
3#include <retrofit.h>
4#endif
5
6/*
7 * Ex version 3.1
8 *
9 * Mark Horton, UC Berkeley
10 * Bill Joy, UC Berkeley
11 * November 1979
12 *
13 * This file contains most of the declarations common to a large number
14 * of routines. The file ex_vis.h contains declarations
15 * which are used only inside the screen editor.
16 * The file ex_tune.h contains parameters which can be diddled per installation.
17 *
18 * The declarations relating to the argument list, regular expressions,
19 * the temporary file data structure used by the editor
20 * and the data describing terminals are each fairly substantial and
21 * are kept in the files ex_{argv,re,temp,tty}.h which
22 * we #include separately.
23 *
24 * If you are going to dig into ex, you should look at the outline of the
25 * distribution of the code into files at the beginning of ex.c and ex_v.c.
26 * Code which is similar to that of ed is lightly or undocumented in spots
27 * (e.g. the regular expression code). Newer code (e.g. open and visual)
28 * is much more carefully documented, and still rough in spots.
29 *
30 * Please forward bug reports to
31 *
32 * Bill Joy
33 * Computer Science Division, EECS
34 * EVANS HALL
35 * U.C. Berkeley 94704
36 * (415) 642-4948
37 * (415) 642-1024 (dept. office)
38 *
39 * or to wnj@mit-mc on the ARPA-net. I would particularly like to hear
40 * of additional terminal descriptions you add to the termcap data base.
41 */
42
43#include <sys/types.h>
44#include <ctype.h>
45#include <errno.h>
46#include <sgtty.h>
47#include <signal.h>
48#include <setjmp.h>
49#include <sys/stat.h>
50
51extern int errno;
52
53typedef short line;
54typedef short bool;
55
56#include "ex_tune.h"
57#include "ex_vars.h"
58/*
59 * Options in the editor are referred to usually by "value(name)" where
60 * name is all uppercase, i.e. "value(PROMPT)". This is actually a macro
61 * which expands to a fixed field in a static structure and so generates
62 * very little code. The offsets for the option names in the structure
63 * are generated automagically from the structure initializing them in
64 * ex_data.c... see the shell script "makeoptions".
65 */
66struct option {
67 char *oname;
68 char *oabbrev;
69 short otype; /* Types -- see below */
70 short odefault; /* Default value */
71 short ovalue; /* Current value */
72 char *osvalue;
73};
74
75#define ONOFF 0
76#define NUMERIC 1
77#define STRING 2 /* SHELL or DIRECTORY */
78#define OTERM 3
79
80#define value(a) options[a].ovalue
81#define svalue(a) options[a].osvalue
82
83struct option options[NOPTS + 1];
84
85
86/*
87 * The editor does not normally use the standard i/o library. Because
88 * we expect the editor to be a heavily used program and because it
89 * does a substantial amount of input/output processing it is appropriate
90 * for it to call low level read/write primitives directly. In fact,
91 * when debugging the editor we use the standard i/o library. In any
92 * case the editor needs a printf which prints through "putchar" ala the
93 * old version 6 printf. Thus we normally steal a copy of the "printf.c"
94 * and "strout" code from the standard i/o library and mung it for our
95 * purposes to avoid dragging in the stdio library headers, etc if we
96 * are not debugging. Such a modified printf exists in "printf.c" here.
97 */
98#ifdef TRACE
99# include <stdio.h>
100 FILE *trace;
101 bool trubble;
102 bool techoin;
103 char tracbuf[BUFSIZ];
104# undef putchar
105# undef getchar
106#else
107# define BUFSIZ 512
108# define NULL 0
109# define EOF -1
110#endif
111
112/*
113 * Character constants and bits
114 *
115 * The editor uses the QUOTE bit as a flag to pass on with characters
116 * e.g. to the putchar routine. The editor never uses a simple char variable.
117 * Only arrays of and pointers to characters are used and parameters and
118 * registers are never declared character.
119 */
120#define QUOTE 0200
121#define TRIM 0177
122#define CTRL(c) ('c' & 037)
123#define NL CTRL(j)
124#define CR CTRL(m)
125#define DELETE 0177 /* See also ATTN, QUIT in ex_tune.h */
126#define ESCAPE 033
127
128/*
129 * Miscellaneous random variables used in more than one place
130 */
131bool aiflag; /* Append/change/insert with autoindent */
132bool anymarks; /* We have used '[a-z] */
133short chng; /* Warn "No write" */
134char *Command;
135short defwind; /* -w# change default window size */
136short dirtcnt; /* When >= MAXDIRT, should sync temporary */
137bool edited; /* Current file is [Edited] */
138line *endcore; /* Last available core location */
139bool endline; /* Last cmd mode command ended with \n */
140short erfile; /* Error message file unit */
141line *fendcore; /* First address in line pointer space */
142char file[FNSIZE]; /* Working file name */
143char genbuf[LBSIZE]; /* Working buffer when manipulating linebuf */
144bool hush; /* Command line option - was given, hush up! */
145char *globp; /* (Untyped) input string to command mode */
146bool holdcm; /* Don't cursor address */
147bool inglobal; /* Inside g//... or v//... */
148char *initev; /* Initial : escape for visual */
149bool inopen; /* Inside open or visual */
150char *input; /* Current position in cmd line input buffer */
151bool intty; /* Input is a tty */
152short io; /* General i/o unit (auto-closed on error!) */
153short lastc; /* Last character ret'd from cmd input */
154bool laste; /* Last command was an "e" (or "rec") */
155char lastmac; /* Last macro called for ** */
156char lasttag[TAGSIZE]; /* Last argument to a tag command */
157char *linebp; /* Used in substituting in \n */
158char linebuf[LBSIZE]; /* The primary line buffer */
159bool listf; /* Command should run in list mode */
160char *loc1; /* Where re began to match (in linebuf) */
161char *loc2; /* First char after re match (") */
162line names['z'-'a'+2]; /* Mark registers a-z,' */
163short notecnt; /* Count for notify (to visual from cmd) */
164bool numberf; /* Command should run in number mode */
165char obuf[BUFSIZ]; /* Buffer for tty output */
166short ospeed; /* Output speed (from gtty) */
167short otchng; /* Backup tchng to find changes in macros */
168short peekc; /* Peek ahead character (cmd mode input) */
169char *pkill[2]; /* Trim for put with ragged (LISP) delete */
170bool pfast; /* Have stty -nl'ed to go faster */
171int pid; /* Process id of child */
172int ppid; /* Process id of parent (e.g. main ex proc) */
173jmp_buf resetlab; /* For error throws to top level (cmd mode) */
174int rpid; /* Pid returned from wait() */
175bool ruptible; /* Interruptible is normal state */
176bool shudclob; /* Have a prompt to clobber (e.g. on ^D) */
177int status; /* Status returned from wait() */
178short tchng; /* If nonzero, then [Modified] */
179short tfile; /* Temporary file unit */
180bool vcatch; /* Want to catch an error (open/visual) */
181jmp_buf vreslab; /* For error throws to a visual catch */
182short xchng; /* Suppresses multiple "No writes" in !cmd */
183
184/*
185 * Macros
186 */
187#define CP(a, b) (ignore(strcpy(a, b)))
188#define ckaw() {if (chng && value(AUTOWRITE)) wop(0);}
189#define copy(a,b,c) Copy((char *) a, (char *) b, c)
190#define eq(a, b) ((a) && (b) && strcmp(a, b) == 0)
191#define getexit(a) copy(a, resetlab, sizeof (jmp_buf))
192#define lastchar() lastc
193#define outchar(c) (*Outchar)(c)
194#define pastwh() (ignore(skipwh()))
195#define pline(no) (*Pline)(no)
196#define reset() longjmp(resetlab,1)
197#define resexit(a) copy(resetlab, a, sizeof (jmp_buf))
198#define setexit() setjmp(resetlab)
199#define setlastchar(c) lastc = c
200#define ungetchar(c) peekc = c
201
202#define CATCH vcatch = 1; if (setjmp(vreslab) == 0) {
203#define ONERR } else { vcatch = 0;
204#define ENDCATCH } vcatch = 0;
205
206/*
207 * Environment like memory
208 */
209char altfile[FNSIZE]; /* Alternate file name */
210char direct[32]; /* Temp file goes here */
211char shell[32]; /* Copied to be settable */
212char ttytype[16]; /* A long and pretty name */
213char uxb[UXBSIZE + 2]; /* Last !command for !! */
214
215/*
216 * The editor data structure for accessing the current file consists
217 * of an incore array of pointers into the temporary file tfile.
218 * Each pointer is 15 bits (the low bit is used by global) and is
219 * padded with zeroes to make an index into the temp file where the
220 * actual text of the line is stored.
221 *
222 * To effect undo, copies of affected lines are saved after the last
223 * line considered to be in the buffer, between dol and unddol.
224 * During an open or visual, which uses the command mode undo between
225 * dol and unddol, a copy of the entire, pre-command buffer state
226 * is saved between unddol and truedol.
227 */
228line *addr1; /* First addressed line in a command */
229line *addr2; /* Second addressed line */
230line *dol; /* Last line in buffer */
231line *dot; /* Current line */
232line *one; /* First line */
233line *truedol; /* End of all lines, including saves */
234line *unddol; /* End of undo saved lines */
235line *zero; /* Points to empty slot before one */
236
237/*
238 * Undo information
239 *
240 * For most commands we save lines changed by salting them away between
241 * dol and unddol before they are changed (i.e. we save the descriptors
242 * into the temp file tfile which is never garbage collected). The
243 * lines put here go back after unddel, and to complete the undo
244 * we delete the lines [undap1,undap2).
245 *
246 * Undoing a move is much easier and we treat this as a special case.
247 * Similarly undoing a "put" is a special case for although there
248 * are lines saved between dol and unddol we don't stick these back
249 * into the buffer.
250 */
251short undkind;
252
253line *unddel; /* Saved deleted lines go after here */
254line *undap1; /* Beginning of new lines */
255line *undap2; /* New lines end before undap2 */
256line *undadot; /* If we saved all lines, dot reverts here */
257
258#define UNDCHANGE 0
259#define UNDMOVE 1
260#define UNDALL 2
261#define UNDNONE 3
262#define UNDPUT 4
263
264/*
265 * Function type definitions
266 */
267#define NOSTR (char *) 0
268#define NOLINE (line *) 0
269
270int (*Outchar)();
271int (*Pline)();
272int (*Putchar)();
273int (*oldhup)();
274int (*setlist())();
275int (*setnorm())();
276int (*setnorm())();
277int (*setnumb())();
278line *address();
279char *cgoto();
280char *genindent();
281char *getblock();
282char *getenv();
283line *getmark();
284char *longname();
285char *mesg();
286char *place();
287char *plural();
288line *scanfor();
289line *setin();
290char *strcat();
291char *strcpy();
292char *strend();
293char *tailpath();
294char *tgetstr();
295char *tgoto();
296char *ttyname();
297line *vback();
298char *vfindcol();
299char *vgetline();
300char *vinit();
301char *vpastwh();
302char *vskipwh();
303int put();
304int putreg();
305int YANKreg();
306int delete();
307int execl();
308int filter();
309int getfile();
310int getsub();
311int gettty();
312int join();
313int listchar();
314off_t lseek();
315int normchar();
316int normline();
317int numbline();
318int (*oldquit)();
319int onhup();
320int onintr();
321int putch();
322int shift();
323int termchar();
324int vfilter();
325#ifdef CBREAK
326int vintr();
327#endif
328int vputch();
329int vshftop();
330int yank();
331
332/*
333 * C doesn't have a (void) cast, so we have to fake it for lint's sake.
334 */
335#ifdef lint
336# define ignore(a) Ignore((char *) (a))
337# define ignorf(a) Ignorf((int (*) ()) (a))
338#else
339# define ignore(a) a
340# define ignorf(a) a
341#endif