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

Defined variables

aiflag defined in line 169; used 5 times
altfile defined in line 262; used 7 times
bsize defined in line 230; used 19 times
defwind defined in line 173; used 6 times
dot defined in line 284; used 233 times
erfile defined in line 182; used 6 times
fendcore defined in line 184; used 6 times
inappend defined in line 190; used 7 times
initev defined in line 192; used 14 times
input defined in line 194; used 10 times
io defined in line 196; used 48 times
laste defined in line 198; used 5 times
lasttag defined in line 200; used 12 times
linebp defined in line 201; used 3 times
listf defined in line 203; used 5 times
loc1 defined in line 204; used 25 times
loc2 defined in line 205; used 11 times
numberf defined in line 208; used 1 times
obuf defined in line 209; used 8 times
oprompt defined in line 210; used 3 times
otchng defined in line 212; used 2 times
pfast defined in line 215; used 14 times
pid defined in line 216; used 19 times
pkill defined in line 214; used 13 times
ppid defined in line 217; used 3 times
resetlab defined in line 218; used 4 times
rpid defined in line 219; used 5 times
seenprompt defined in line 221; used 3 times
status defined in line 223; used 6 times
techoin defined in line 131; used 5 times
tracbuf defined in line 132; never used
trubble defined in line 130; used 3 times
uxb defined in line 266; used 14 times
vcatch defined in line 226; used 9 times
vreslab defined in line 227; used 3 times
writing defined in line 228; used 4 times
xchng defined in line 229; used 4 times

Defined struct's

option defined in line 95; used 12 times

Defined typedef's

Defined macros

BUFSIZ defined in line 142; used 20 times
CBREAK defined in line 71; used 1 times
CR defined in line 162; used 1 times
CTRL defined in line 160; used 3 times
DELETE defined in line 163; used 4 times
EOF defined in line 146; used 1 times
ESCAPE defined in line 164; used 3 times
NL defined in line 161; used 2 times
NULL defined in line 145; never used
NUMERIC defined in line 105; used 8 times
ONOFF defined in line 104; used 28 times
OTERM defined in line 107; used 3 times
STRING defined in line 106; used 5 times
UNDMOVE defined in line 312; used 3 times
UNDPUT defined in line 315; used 4 times
copy defined in line 242; used 12 times
getexit defined in line 244; used 1 times
ignorf defined in line 395; used 2 times
lastchar defined in line 245; used 5 times
outchar defined in line 246; used 4 times
reset defined in line 249; used 2 times
resexit defined in line 250; used 2 times
var defined in line 58; used 76 times

Usage of this include

Last modified: 1987-02-24
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 5619
Valid CSS Valid XHTML 1.0 Strict