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