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 (Berkeley) 5/31/85
   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 long    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: #ifdef CRYPT
 318: /*
 319:  * Various miscellaneous flags and buffers needed by the encryption routines.
 320:  */
 321: #define KSIZE   9       /* key size for encryption */
 322: #define KEYPROMPT       "Key: "
 323: var int xflag;      /* True if we are in encryption mode */
 324: var int xtflag;     /* True if the temp file is being encrypted */
 325: var int kflag;      /* True if the key has been accepted */
 326: var char    perm[768];
 327: var char    tperm[768];
 328: var char    *key;
 329: var char    crbuf[CRSIZE];
 330: char    *getpass();
 331: #endif
 332: 
 333: /*
 334:  * Function type definitions
 335:  */
 336: #define NOSTR   (char *) 0
 337: #define NOLINE  (line *) 0
 338: 
 339: extern  int (*Outchar)();
 340: extern  int (*Pline)();
 341: extern  int (*Putchar)();
 342: var int (*oldhup)();
 343: int (*setlist())();
 344: int (*setnorm())();
 345: int (*setnorm())();
 346: int (*setnumb())();
 347: line    *address();
 348: char    *cgoto();
 349: char    *genindent();
 350: char    *getblock();
 351: char    *getenv();
 352: line    *getmark();
 353: char    *longname();
 354: char    *mesg();
 355: char    *place();
 356: char    *plural();
 357: line    *scanfor();
 358: line    *setin();
 359: char    *strcat();
 360: char    *strcpy();
 361: char    *strend();
 362: char    *tailpath();
 363: char    *tgetstr();
 364: char    *tgoto();
 365: char    *ttyname();
 366: line    *vback();
 367: char    *vfindcol();
 368: char    *vgetline();
 369: char    *vinit();
 370: char    *vpastwh();
 371: char    *vskipwh();
 372: int put();
 373: int putreg();
 374: int YANKreg();
 375: int delete();
 376: int execl();
 377: int filter();
 378: int getfile();
 379: int getsub();
 380: int gettty();
 381: int join();
 382: int listchar();
 383: off_t   lseek();
 384: int normchar();
 385: int normline();
 386: int numbline();
 387: var int (*oldquit)();
 388: int onhup();
 389: int onintr();
 390: int onsusp();
 391: int putch();
 392: int shift();
 393: int termchar();
 394: int vfilter();
 395: #ifdef CBREAK
 396: int vintr();
 397: #endif
 398: int vputch();
 399: int vshftop();
 400: int yank();
 401: 
 402: /*
 403:  * C doesn't have a (void) cast, so we have to fake it for lint's sake.
 404:  */
 405: #ifdef lint
 406: #	define    ignore(a)   Ignore((char *) (a))
 407: #	define    ignorf(a)   Ignorf((int (*) ()) (a))
 408: #else
 409: #	define    ignore(a)   a
 410: #	define    ignorf(a)   a
 411: #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
crbuf defined in line 329; used 3 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
key defined in line 328; used 3 times
kflag defined in line 325; used 4 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
perm defined in line 326; used 4 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
tperm defined in line 327; used 6 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
xflag defined in line 323; used 4 times
xtflag defined in line 324; used 6 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
CR defined in line 162; used 1 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
KEYPROMPT defined in line 322; used 1 times
KSIZE defined in line 321; used 2 times
NL defined in line 161; used 2 times
NULL defined in line 145; used 5 times
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 410; used 2 times
lastchar defined in line 245; used 5 times
outchar defined in line 246; used 6 times
reset defined in line 249; used 2 times
resexit defined in line 250; used 2 times
var defined in line 58; used 83 times

Usage of this include

Last modified: 1985-06-08
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3262
Valid CSS Valid XHTML 1.0 Strict