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

Defined variables

aiflag defined in line 163; used 5 times
crbuf defined in line 322; used 3 times
defwind defined in line 167; used 6 times
dot defined in line 277; used 230 times
fendcore defined in line 178; used 6 times
inappend defined in line 184; used 7 times
input defined in line 188; used 9 times
key defined in line 321; used 3 times
kflag defined in line 318; used 4 times
linebp defined in line 195; used 3 times
linebuf defined in line 196; used 177 times
listf defined in line 197; used 5 times
loc2 defined in line 199; used 11 times
numberf defined in line 202; used 1 times
obuf defined in line 203; used 8 times
oprompt defined in line 204; used 3 times
otchng defined in line 206; used 2 times
perm defined in line 319; used 4 times
pfast defined in line 209; used 14 times
pid defined in line 210; used 20 times
ppid defined in line 211; used 3 times
resetlab defined in line 212; used 4 times
rpid defined in line 213; used 5 times
techoin defined in line 126; used 5 times
tperm defined in line 320; used 6 times
tracbuf defined in line 127; never used
trubble defined in line 125; used 3 times
uxb defined in line 259; used 14 times
vcatch defined in line 220; used 8 times
vreslab defined in line 221; used 3 times
writing defined in line 222; used 4 times
xflag defined in line 316; used 4 times
xtflag defined in line 317; used 6 times

Defined struct's

option defined in line 90; used 12 times

Defined typedef's

Defined macros

BUFSIZ defined in line 137; used 19 times
CBREAK defined in line 66; used 1 times
CR defined in line 156; used 1 times
DELETE defined in line 157; used 4 times
EOF defined in line 141; used 1 times
ESCAPE defined in line 158; used 3 times
KEYPROMPT defined in line 315; used 1 times
KSIZE defined in line 314; used 2 times
NL defined in line 155; used 2 times
NULL defined in line 140; used 3 times
NUMERIC defined in line 100; used 8 times
ONOFF defined in line 99; used 26 times
OTERM defined in line 102; used 3 times
STRING defined in line 101; used 5 times
UNDMOVE defined in line 305; used 3 times
UNDPUT defined in line 308; used 4 times
getexit defined in line 237; used 1 times
ignorf defined in line 403; used 2 times
lastchar defined in line 238; used 5 times
outchar defined in line 239; used 6 times
reset defined in line 242; used 2 times
resexit defined in line 243; used 2 times
value defined in line 104; used 150 times
var defined in line 53; used 82 times

Usage of this include

Last modified: 1982-01-24
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2427
Valid CSS Valid XHTML 1.0 Strict