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