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