home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Distributions / ucb / spencer_2bsd.tar.gz / 2bsd.tar / src / ex / ex.h < prev    next >
C/C++ Source or Header  |  1980-02-17  |  11KB  |  346 lines

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