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