Commit | Line | Data |
---|---|---|
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 | * | |
7bcb0072 | 6 | * @(#)ex.h 7.9.1.1 (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 |
89 | extern int errno; |
90 | ||
44232d5b | 91 | #ifndef VMUNIX |
e753e5e9 | 92 | typedef short line; |
44232d5b MH |
93 | #else |
94 | typedef int line; | |
95 | #endif | |
e753e5e9 MH |
96 | typedef 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 | */ | |
108 | struct 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 | 125 | extern 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 |
65bacefd KB |
178 | #define CTRL(c) (c & 037) |
179 | #define NL CTRL('j') | |
180 | #define CR CTRL('m') | |
e753e5e9 MH |
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 |
187 | var bool aiflag; /* Append/change/insert with autoindent */ |
188 | var bool anymarks; /* We have used '[a-z] */ | |
189 | var int chng; /* Warn "No write" */ | |
190 | var char *Command; | |
191 | var short defwind; /* -w# change default window size */ | |
192 | var int dirtcnt; /* When >= MAXDIRT, should sync temporary */ | |
d266c416 | 193 | #ifdef TIOCLGET |
cb3ac212 | 194 | var bool dosusp; /* Do SIGTSTP in visual when ^Z typed */ |
d266c416 | 195 | #endif |
cb3ac212 MH |
196 | var bool edited; /* Current file is [Edited] */ |
197 | var line *endcore; /* Last available core location */ | |
198 | extern bool endline; /* Last cmd mode command ended with \n */ | |
5a6c967e | 199 | #ifdef EXSTRINGS |
cb3ac212 | 200 | var short erfile; /* Error message file unit */ |
44232d5b | 201 | #endif |
cb3ac212 MH |
202 | var line *fendcore; /* First address in line pointer space */ |
203 | var char file[FNSIZE]; /* Working file name */ | |
4e3d2679 | 204 | var char genbuf[MAXBSIZE]; /* Working buffer when manipulating linebuf */ |
cb3ac212 MH |
205 | var bool hush; /* Command line option - was given, hush up! */ |
206 | var char *globp; /* (Untyped) input string to command mode */ | |
207 | var bool holdcm; /* Don't cursor address */ | |
208 | var bool inappend; /* in ex command append mode */ | |
209 | var bool inglobal; /* Inside g//... or v//... */ | |
210 | var char *initev; /* Initial : escape for visual */ | |
211 | var bool inopen; /* Inside open or visual */ | |
212 | var char *input; /* Current position in cmd line input buffer */ | |
213 | var bool intty; /* Input is a tty */ | |
214 | var short io; /* General i/o unit (auto-closed on error!) */ | |
215 | extern short lastc; /* Last character ret'd from cmd input */ | |
216 | var bool laste; /* Last command was an "e" (or "rec") */ | |
217 | var char lastmac; /* Last macro called for ** */ | |
218 | var char lasttag[TAGSIZE]; /* Last argument to a tag command */ | |
219 | var char *linebp; /* Used in substituting in \n */ | |
220 | var char linebuf[LBSIZE]; /* The primary line buffer */ | |
221 | var bool listf; /* Command should run in list mode */ | |
222 | var char *loc1; /* Where re began to match (in linebuf) */ | |
223 | var char *loc2; /* First char after re match (") */ | |
224 | var line names['z'-'a'+2]; /* Mark registers a-z,' */ | |
225 | var int notecnt; /* Count for notify (to visual from cmd) */ | |
226 | var bool numberf; /* Command should run in number mode */ | |
227 | var char obuf[BUFSIZ]; /* Buffer for tty output */ | |
228 | var short oprompt; /* Saved during source */ | |
229 | extern short ospeed; /* Output speed (from gtty) */ | |
230 | var int otchng; /* Backup tchng to find changes in macros */ | |
231 | var short peekc; /* Peek ahead character (cmd mode input) */ | |
232 | var char *pkill[2]; /* Trim for put with ragged (LISP) delete */ | |
233 | var bool pfast; /* Have stty -nl'ed to go faster */ | |
234 | var int pid; /* Process id of child */ | |
235 | var int ppid; /* Process id of parent (e.g. main ex proc) */ | |
236 | var jmp_buf resetlab; /* For error throws to top level (cmd mode) */ | |
237 | var int rpid; /* Pid returned from wait() */ | |
238 | var bool ruptible; /* Interruptible is normal state */ | |
239 | var bool seenprompt; /* 1 if have gotten user input */ | |
240 | var bool shudclob; /* Have a prompt to clobber (e.g. on ^D) */ | |
241 | var int status; /* Status returned from wait() */ | |
242 | var int tchng; /* If nonzero, then [Modified] */ | |
243 | extern short tfile; /* Temporary file unit */ | |
244 | var bool vcatch; /* Want to catch an error (open/visual) */ | |
245 | var jmp_buf vreslab; /* For error throws to a visual catch */ | |
246 | var bool writing; /* 1 if in middle of a file write */ | |
247 | var int xchng; /* Suppresses multiple "No writes" in !cmd */ | |
4e3d2679 | 248 | var 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 |
280 | var char altfile[FNSIZE]; /* Alternate file name */ |
281 | extern char direct[ONMSZ]; /* Temp file goes here */ | |
282 | extern char shell[ONMSZ]; /* Copied to be settable */ | |
283 | extern char ttytype[ONMSZ]; /* A long and pretty name */ | |
284 | var 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 |
299 | var line *addr1; /* First addressed line in a command */ |
300 | var line *addr2; /* Second addressed line */ | |
301 | var line *dol; /* Last line in buffer */ | |
302 | var line *dot; /* Current line */ | |
303 | var line *one; /* First line */ | |
304 | var line *truedol; /* End of all lines, including saves */ | |
305 | var line *unddol; /* End of undo saved lines */ | |
306 | var 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 | 322 | var short undkind; |
e753e5e9 | 323 | |
cb3ac212 MH |
324 | var line *unddel; /* Saved deleted lines go after here */ |
325 | var line *undap1; /* Beginning of new lines */ | |
326 | var line *undap2; /* New lines end before undap2 */ | |
327 | var 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 |
342 | extern int (*Outchar)(); |
343 | extern int (*Pline)(); | |
5a6c967e | 344 | extern int (*Put_char)(); |
cb3ac212 | 345 | var int (*oldhup)(); |
e753e5e9 MH |
346 | int (*setlist())(); |
347 | int (*setnorm())(); | |
348 | int (*setnorm())(); | |
349 | int (*setnumb())(); | |
350 | line *address(); | |
351 | char *cgoto(); | |
352 | char *genindent(); | |
353 | char *getblock(); | |
354 | char *getenv(); | |
5a6c967e CH |
355 | #ifdef vms |
356 | char *getlog(); | |
357 | #endif | |
e753e5e9 MH |
358 | line *getmark(); |
359 | char *longname(); | |
360 | char *mesg(); | |
361 | char *place(); | |
362 | char *plural(); | |
363 | line *scanfor(); | |
364 | line *setin(); | |
365 | char *strcat(); | |
366 | char *strcpy(); | |
367 | char *strend(); | |
368 | char *tailpath(); | |
369 | char *tgetstr(); | |
370 | char *tgoto(); | |
371 | char *ttyname(); | |
372 | line *vback(); | |
373 | char *vfindcol(); | |
374 | char *vgetline(); | |
375 | char *vinit(); | |
376 | char *vpastwh(); | |
377 | char *vskipwh(); | |
378 | int put(); | |
379 | int putreg(); | |
380 | int YANKreg(); | |
5a6c967e | 381 | int ex_delete(); |
e753e5e9 MH |
382 | int execl(); |
383 | int filter(); | |
384 | int getfile(); | |
385 | int getsub(); | |
386 | int gettty(); | |
387 | int join(); | |
388 | int listchar(); | |
389 | off_t lseek(); | |
390 | int normchar(); | |
391 | int normline(); | |
392 | int numbline(); | |
cb3ac212 | 393 | var int (*oldquit)(); |
e753e5e9 MH |
394 | int onhup(); |
395 | int onintr(); | |
d266c416 | 396 | int onsusp(); |
e753e5e9 MH |
397 | int putch(); |
398 | int shift(); | |
399 | int termchar(); | |
400 | int vfilter(); | |
401 | #ifdef CBREAK | |
402 | int vintr(); | |
403 | #endif | |
404 | int vputch(); | |
405 | int vshftop(); | |
406 | int 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 |