|
|
1.1 root 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.10 (Berkeley) 9/11/89
7: */
8:
9: #ifdef V6
10: #include <retrofit.h>
11: #endif
12:
13: /*
14: * Ex version 3 (see exact version in ex_cmds.c, search for /Version/)
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: *
39: * Mark Horton
40: * Computer Science Division, EECS
41: * EVANS HALL
42: * U.C. Berkeley 94704
43: * (415) 642-4948
44: * (415) 642-1024 (dept. office)
45: *
46: * or to csvax.mark@berkeley on the ARPA-net. I would particularly like to hear
47: * of additional terminal descriptions you add to the termcap data base.
48: */
49:
50: #ifndef vms
51: #include <sys/param.h>
52: #else
53: #define MAXBSIZE 1024 /* Maximum block size */
54: #include <types.h>
55: #endif
56: #include <ctype.h>
57: #include <errno.h>
58: #include <signal.h>
59: #include <setjmp.h>
60: #ifndef vms
61: #include <sys/stat.h>
62: #else
63: #include <stat.h>
64: #endif
65:
66: #ifndef var
67: #define var extern
68: #endif
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
82: #ifndef vms
83: #include <sgtty.h>
84: #else
85: #include "vmstty.h"
86: #endif
87: #endif
88:
89: extern int errno;
90:
91: #ifndef VMUNIX
92: typedef short line;
93: #else
94: typedef int line;
95: #endif
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:
125: extern struct option options[NOPTS + 1];
126:
127: #ifdef vms
128: #define st_blksize st_fab_mrs
129: #define _exit(n) vms_exit(n)
130: #define fork() vfork()
131: #endif
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
146: # include <stdio.h>
147: var FILE *trace;
148: var bool trubble;
149: var bool techoin;
150: var char tracbuf[BUFSIZ];
151: #else
152: # ifdef VMUNIX
153: # define BUFSIZ 1024
154: # else
155: # ifdef u370
156: # define BUFSIZ 4096
157: # else
158: # define BUFSIZ 512
159: # endif
160: # endif
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
175: #ifndef vms
176: #undef CTRL
177: #endif
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: */
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 */
193: #ifdef TIOCLGET
194: var bool dosusp; /* Do SIGTSTP in visual when ^Z typed */
195: #endif
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 */
199: #ifdef EXSTRINGS
200: var short erfile; /* Error message file unit */
201: #endif
202: var line *fendcore; /* First address in line pointer space */
203: var char file[FNSIZE]; /* Working file name */
204: var char genbuf[MAXBSIZE]; /* Working buffer when manipulating linebuf */
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 */
248: var long bsize; /* Block size for disk i/o */
249:
250: /*
251: * Macros
252: */
253: #define CP(a, b) (ignore(strcpy(a, b)))
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))
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: */
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 !! */
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: */
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 */
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: */
322: var short undkind;
323:
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 */
328:
329: #define UNDCHANGE 0
330: #define UNDMOVE 1
331: #define UNDALL 2
332: #define UNDNONE 3
333: #define UNDPUT 4
334:
335: #ifdef CRYPT
336: /*
337: * Various miscellaneous flags and buffers needed by the encryption routines.
338: */
339: #define KSIZE 9 /* key size for encryption */
340: #define KEYPROMPT "Key: "
341: var int xflag; /* True if we are in encryption mode */
342: var int xtflag; /* True if the temp file is being encrypted */
343: var int kflag; /* True if the key has been accepted */
344: var char perm[768];
345: var char tperm[768];
346: var char *key;
347: var char crbuf[CRSIZE];
348: char *getpass();
349: #endif
350:
351: /*
352: * Function type definitions
353: */
354: #define NOSTR (char *) 0
355: #define NOLINE (line *) 0
356:
357: extern int (*Outchar)();
358: extern int (*Pline)();
359: extern int (*Put_char)();
360: var void (*oldhup)();
361: int (*setlist())();
362: int (*setnorm())();
363: int (*setnorm())();
364: int (*setnumb())();
365: line *address();
366: char *cgoto();
367: char *genindent();
368: char *getblock();
369: char *getenv();
370: #ifdef vms
371: char *getlog();
372: #endif
373: line *getmark();
374: char *longname();
375: char *mesg();
376: char *place();
377: char *plural();
378: line *scanfor();
379: line *setin();
380: char *strcat();
381: char *strcpy();
382: char *strend();
383: char *tailpath();
384: char *tgetstr();
385: char *tgoto();
386: char *ttyname();
387: line *vback();
388: char *vfindcol();
389: char *vgetline();
390: char *vinit();
391: char *vpastwh();
392: char *vskipwh();
393: int put();
394: int putreg();
395: int YANKreg();
396: int ex_delete();
397: int execl();
398: int filter();
399: int getfile();
400: int getsub();
401: int gettty();
402: int join();
403: int listchar();
404: off_t lseek();
405: int normchar();
406: int normline();
407: int numbline();
408: var void (*oldquit)();
409: int onhup();
410: int onintr();
411: int onsusp();
412: int putch();
413: int shift();
414: int termchar();
415: int vfilter();
416: #ifdef CBREAK
417: int vintr();
418: #endif
419: int vputch();
420: int vshftop();
421: int yank();
422:
423: /*
424: * C doesn't have a (void) cast, so we have to fake it for lint's sake.
425: */
426: #ifdef lint
427: # define ignore(a) Ignore((char *) (a))
428: # define ignorf(a) Ignorf((int (*) ()) (a))
429: #else
430: # define ignore(a) a
431: # define ignorf(a) a
432: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.