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