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