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