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