date and time created 83/02/11 15:44:54 by rrh
[unix-history] / usr / src / usr.bin / ex / ex.h
index 9493541..ad564bd 100644 (file)
@@ -1,10 +1,11 @@
-/* Copyright (c) 1979 Regents of the University of California */
+/* Copyright (c) 1981 Regents of the University of California */
+/* sccs id:    @(#)ex.h        7.4     %G%  */
 #ifdef V6
 #include <retrofit.h>
 #endif
 
 /*
 #ifdef V6
 #include <retrofit.h>
 #endif
 
 /*
- * Ex version 3.1
+ * Ex version 3 (see exact version in ex_cmds.c, search for /Version/)
  *
  * Mark Horton, UC Berkeley
  * Bill Joy, UC Berkeley
  *
  * Mark Horton, UC Berkeley
  * Bill Joy, UC Berkeley
  *
  * Please forward bug reports to
  *
  *
  * Please forward bug reports to
  *
- *     Bill Joy
+ *     Mark Horton
  *     Computer Science Division, EECS
  *     EVANS HALL
  *     U.C. Berkeley 94704
  *     (415) 642-4948
  *     (415) 642-1024 (dept. office)
  *
  *     Computer Science Division, EECS
  *     EVANS HALL
  *     U.C. Berkeley 94704
  *     (415) 642-4948
  *     (415) 642-1024 (dept. office)
  *
- * or to wnj@mit-mc on the ARPA-net.  I would particularly like to hear
+ * or to csvax.mark@berkeley on the ARPA-net.  I would particularly like to hear
  * of additional terminal descriptions you add to the termcap data base.
  */
 
 #include <sys/types.h>
 #include <ctype.h>
 #include <errno.h>
  * of additional terminal descriptions you add to the termcap data base.
  */
 
 #include <sys/types.h>
 #include <ctype.h>
 #include <errno.h>
-#include <sgtty.h>
 #include <signal.h>
 #include <setjmp.h>
 #include <sys/stat.h>
 
 #include <signal.h>
 #include <setjmp.h>
 #include <sys/stat.h>
 
+#ifndef var
+#define var    extern
+#endif
+/*
+ *     The following little dance copes with the new USG tty handling.
+ *     This stuff has the advantage of considerable flexibility, and
+ *     the disadvantage of being incompatible with anything else.
+ *     The presence of the symbol USG3TTY will indicate the new code:
+ *     in this case, we define CBREAK (because we can simulate it exactly),
+ *     but we won't actually use it, so we set it to a value that will
+ *     probably blow the compilation if we goof up.
+ */
+#ifdef USG3TTY
+#include <termio.h>
+#define CBREAK xxxxx
+#else
+#include <sgtty.h>
+#endif
+
 extern int errno;
 
 #ifndef VMUNIX
 extern int errno;
 
 #ifndef VMUNIX
@@ -84,7 +103,7 @@ struct       option {
 #define        value(a)        options[a].ovalue
 #define        svalue(a)       options[a].osvalue
 
 #define        value(a)        options[a].ovalue
 #define        svalue(a)       options[a].osvalue
 
-struct option options[NOPTS + 1];
+extern  struct option options[NOPTS + 1];
 
 
 /*
 
 
 /*
@@ -101,18 +120,22 @@ struct    option options[NOPTS + 1];
  */
 #ifdef TRACE
 #      include <stdio.h>
  */
 #ifdef TRACE
 #      include <stdio.h>
-       FILE    *trace;
-       bool    trubble;
-       bool    techoin;
-       char    tracbuf[BUFSIZ];
+       var     FILE    *trace;
+       var     bool    trubble;
+       var     bool    techoin;
+       var     char    tracbuf[BUFSIZ];
 #      undef   putchar
 #      undef   getchar
 #else
 #      undef   putchar
 #      undef   getchar
 #else
-#ifdef VMUNIX
+# ifdef        VMUNIX
 #      define  BUFSIZ  1024
 #      define  BUFSIZ  1024
-#else
+# else
+#  ifdef u370
+#      define  BUFSIZ  4096
+#  else
 #      define  BUFSIZ  512
 #      define  BUFSIZ  512
-#endif
+#  endif
+# endif
 #      define  NULL    0
 #      define  EOF     -1
 #endif
 #      define  NULL    0
 #      define  EOF     -1
 #endif
@@ -136,65 +159,77 @@ struct    option options[NOPTS + 1];
 /*
  * Miscellaneous random variables used in more than one place
  */
 /*
  * Miscellaneous random variables used in more than one place
  */
-bool   aiflag;                 /* Append/change/insert with autoindent */
-bool   anymarks;               /* We have used '[a-z] */
-int    chng;                   /* Warn "No write" */
-char   *Command;
-short  defwind;                /* -w# change default window size */
-int    dirtcnt;                /* When >= MAXDIRT, should sync temporary */
-bool   edited;                 /* Current file is [Edited] */
-line   *endcore;               /* Last available core location */
-bool   endline;                /* Last cmd mode command ended with \n */
+var    bool    aiflag;         /* Append/change/insert with autoindent */
+var    bool    anymarks;       /* We have used '[a-z] */
+var    int     chng;           /* Warn "No write" */
+var    char    *Command;
+var    short   defwind;        /* -w# change default window size */
+var    int     dirtcnt;        /* When >= MAXDIRT, should sync temporary */
+#ifdef TIOCLGET
+var    bool    dosusp;         /* Do SIGTSTP in visual when ^Z typed */
+#endif
+var    bool    edited;         /* Current file is [Edited] */
+var    line    *endcore;       /* Last available core location */
+extern  bool   endline;        /* Last cmd mode command ended with \n */
 #ifndef VMUNIX
 #ifndef VMUNIX
-short  erfile;                 /* Error message file unit */
+var    short   erfile;         /* Error message file unit */
 #endif
 #endif
-line   *fendcore;              /* First address in line pointer space */
-char   file[FNSIZE];           /* Working file name */
-char   genbuf[LBSIZE];         /* Working buffer when manipulating linebuf */
-bool   hush;                   /* Command line option - was given, hush up! */
-char   *globp;                 /* (Untyped) input string to command mode */
-bool   holdcm;                 /* Don't cursor address */
-bool   inglobal;               /* Inside g//... or v//... */
-char   *initev;                /* Initial : escape for visual */
-bool   inopen;                 /* Inside open or visual */
-char   *input;                 /* Current position in cmd line input buffer */
-bool   intty;                  /* Input is a tty */
-short  io;                     /* General i/o unit (auto-closed on error!) */
-short  lastc;                  /* Last character ret'd from cmd input */
-bool   laste;                  /* Last command was an "e" (or "rec") */
-char   lastmac;                /* Last macro called for ** */
-char   lasttag[TAGSIZE];       /* Last argument to a tag command */
-char   *linebp;                /* Used in substituting in \n */
-char   linebuf[LBSIZE];        /* The primary line buffer */
-bool   listf;                  /* Command should run in list mode */
-char   *loc1;                  /* Where re began to match (in linebuf) */
-char   *loc2;                  /* First char after re match (") */
-line   names['z'-'a'+2];       /* Mark registers a-z,' */
-int    notecnt;                /* Count for notify (to visual from cmd) */
-bool   numberf;                /* Command should run in number mode */
-char   obuf[BUFSIZ];           /* Buffer for tty output */
-short  ospeed;                 /* Output speed (from gtty) */
-int    otchng;                 /* Backup tchng to find changes in macros */
-short  peekc;                  /* Peek ahead character (cmd mode input) */
-char   *pkill[2];              /* Trim for put with ragged (LISP) delete */
-bool   pfast;                  /* Have stty -nl'ed to go faster */
-int    pid;                    /* Process id of child */
-int    ppid;                   /* Process id of parent (e.g. main ex proc) */
-jmp_buf        resetlab;               /* For error throws to top level (cmd mode) */
-int    rpid;                   /* Pid returned from wait() */
-bool   ruptible;               /* Interruptible is normal state */
-bool   shudclob;               /* Have a prompt to clobber (e.g. on ^D) */
-int    status;                 /* Status returned from wait() */
-int    tchng;                  /* If nonzero, then [Modified] */
-short  tfile;                  /* Temporary file unit */
-bool   vcatch;                 /* Want to catch an error (open/visual) */
-jmp_buf        vreslab;                /* For error throws to a visual catch */
-int    xchng;                  /* Suppresses multiple "No writes" in !cmd */
+var    line    *fendcore;      /* First address in line pointer space */
+var    char    file[FNSIZE];   /* Working file name */
+var    char    genbuf[LBSIZE]; /* Working buffer when manipulating linebuf */
+var    bool    hush;           /* Command line option - was given, hush up! */
+var    char    *globp;         /* (Untyped) input string to command mode */
+var    bool    holdcm;         /* Don't cursor address */
+var    bool    inappend;       /* in ex command append mode */
+var    bool    inglobal;       /* Inside g//... or v//... */
+var    char    *initev;        /* Initial : escape for visual */
+var    bool    inopen;         /* Inside open or visual */
+var    char    *input;         /* Current position in cmd line input buffer */
+var    bool    intty;          /* Input is a tty */
+var    short   io;             /* General i/o unit (auto-closed on error!) */
+extern  short  lastc;          /* Last character ret'd from cmd input */
+var    bool    laste;          /* Last command was an "e" (or "rec") */
+var    char    lastmac;        /* Last macro called for ** */
+var    char    lasttag[TAGSIZE];       /* Last argument to a tag command */
+var    char    *linebp;        /* Used in substituting in \n */
+var    char    linebuf[LBSIZE];        /* The primary line buffer */
+var    bool    listf;          /* Command should run in list mode */
+var    char    *loc1;          /* Where re began to match (in linebuf) */
+var    char    *loc2;          /* First char after re match (") */
+var    line    names['z'-'a'+2];       /* Mark registers a-z,' */
+var    int     notecnt;        /* Count for notify (to visual from cmd) */
+var    bool    numberf;        /* Command should run in number mode */
+var    char    obuf[BUFSIZ];   /* Buffer for tty output */
+var    short   oprompt;        /* Saved during source */
+extern short   ospeed;         /* Output speed (from gtty) */
+var    int     otchng;         /* Backup tchng to find changes in macros */
+var    short   peekc;          /* Peek ahead character (cmd mode input) */
+var    char    *pkill[2];      /* Trim for put with ragged (LISP) delete */
+var    bool    pfast;          /* Have stty -nl'ed to go faster */
+var    int     pid;            /* Process id of child */
+var    int     ppid;           /* Process id of parent (e.g. main ex proc) */
+var    jmp_buf resetlab;       /* For error throws to top level (cmd mode) */
+var    int     rpid;           /* Pid returned from wait() */
+var    bool    ruptible;       /* Interruptible is normal state */
+var    bool    seenprompt;     /* 1 if have gotten user input */
+var    bool    shudclob;       /* Have a prompt to clobber (e.g. on ^D) */
+var    int     status;         /* Status returned from wait() */
+var    int     tchng;          /* If nonzero, then [Modified] */
+extern short   tfile;          /* Temporary file unit */
+var    bool    vcatch;         /* Want to catch an error (open/visual) */
+var    jmp_buf vreslab;        /* For error throws to a visual catch */
+var    bool    writing;        /* 1 if in middle of a file write */
+var    int     xchng;          /* Suppresses multiple "No writes" in !cmd */
 
 /*
  * Macros
  */
 #define        CP(a, b)        (ignore(strcpy(a, b)))
 
 /*
  * Macros
  */
 #define        CP(a, b)        (ignore(strcpy(a, b)))
+                       /*
+                        * FIXUNDO: do we want to mung undo vars?
+                        * Usually yes unless in a macro or global.
+                        */
+#define FIXUNDO                (inopen >= 0 && (inopen || !inglobal))
 #define ckaw()         {if (chng && value(AUTOWRITE)) wop(0);}
 #define        copy(a,b,c)     Copy((char *) a, (char *) b, c)
 #define        eq(a, b)        ((a) && (b) && strcmp(a, b) == 0)
 #define ckaw()         {if (chng && value(AUTOWRITE)) wop(0);}
 #define        copy(a,b,c)     Copy((char *) a, (char *) b, c)
 #define        eq(a, b)        ((a) && (b) && strcmp(a, b) == 0)
@@ -216,11 +251,11 @@ int       xchng;                  /* Suppresses multiple "No writes" in !cmd */
 /*
  * Environment like memory
  */
 /*
  * Environment like memory
  */
-char   altfile[FNSIZE];        /* Alternate file name */
-char   direct[32];             /* Temp file goes here */
-char   shell[32];              /* Copied to be settable */
-char   ttytype[16];            /* A long and pretty name */
-char   uxb[UXBSIZE + 2];       /* Last !command for !! */
+var    char    altfile[FNSIZE];        /* Alternate file name */
+extern  char   direct[ONMSZ];          /* Temp file goes here */
+extern  char   shell[ONMSZ];           /* Copied to be settable */
+extern  char   ttytype[ONMSZ];         /* A long and pretty name */
+var    char    uxb[UXBSIZE + 2];       /* Last !command for !! */
 
 /*
  * The editor data structure for accessing the current file consists
 
 /*
  * The editor data structure for accessing the current file consists
@@ -235,14 +270,14 @@ char      uxb[UXBSIZE + 2];       /* Last !command for !! */
  * dol and unddol, a copy of the entire, pre-command buffer state
  * is saved between unddol and truedol.
  */
  * dol and unddol, a copy of the entire, pre-command buffer state
  * is saved between unddol and truedol.
  */
-line   *addr1;                 /* First addressed line in a command */
-line   *addr2;                 /* Second addressed line */
-line   *dol;                   /* Last line in buffer */
-line   *dot;                   /* Current line */
-line   *one;                   /* First line */
-line   *truedol;               /* End of all lines, including saves */
-line   *unddol;                /* End of undo saved lines */
-line   *zero;                  /* Points to empty slot before one */
+var    line    *addr1;                 /* First addressed line in a command */
+var    line    *addr2;                 /* Second addressed line */
+var    line    *dol;                   /* Last line in buffer */
+var    line    *dot;                   /* Current line */
+var    line    *one;                   /* First line */
+var    line    *truedol;               /* End of all lines, including saves */
+var    line    *unddol;                /* End of undo saved lines */
+var    line    *zero;                  /* Points to empty slot before one */
 
 /*
  * Undo information
 
 /*
  * Undo information
@@ -258,12 +293,12 @@ line      *zero;                  /* Points to empty slot before one */
  * are lines saved between dol and unddol we don't stick these back
  * into the buffer.
  */
  * are lines saved between dol and unddol we don't stick these back
  * into the buffer.
  */
-short  undkind;
+var    short   undkind;
 
 
-line   *unddel;                /* Saved deleted lines go after here */
-line   *undap1;                /* Beginning of new lines */
-line   *undap2;                /* New lines end before undap2 */
-line   *undadot;               /* If we saved all lines, dot reverts here */
+var    line    *unddel;        /* Saved deleted lines go after here */
+var    line    *undap1;        /* Beginning of new lines */
+var    line    *undap2;        /* New lines end before undap2 */
+var    line    *undadot;       /* If we saved all lines, dot reverts here */
 
 #define        UNDCHANGE       0
 #define        UNDMOVE         1
 
 #define        UNDCHANGE       0
 #define        UNDMOVE         1
@@ -271,16 +306,32 @@ line      *undadot;               /* If we saved all lines, dot reverts here */
 #define        UNDNONE         3
 #define        UNDPUT          4
 
 #define        UNDNONE         3
 #define        UNDPUT          4
 
+#ifdef CRYPT
+/*
+ * Various miscellaneous flags and buffers needed by the encryption routines.
+ */
+#define        KSIZE   9       /* key size for encryption */
+#define        KEYPROMPT       "Key: "
+var    int     xflag;          /* True if we are in encryption mode */
+var    int     xtflag;         /* True if the temp file is being encrypted */
+var    int     kflag;          /* True if the key has been accepted */
+var    char    perm[768];
+var    char    tperm[768];
+var    char    *key;
+var    char    crbuf[CRSIZE];
+char   *getpass();
+#endif
+
 /*
  * Function type definitions
  */
 #define        NOSTR   (char *) 0
 #define        NOLINE  (line *) 0
 
 /*
  * Function type definitions
  */
 #define        NOSTR   (char *) 0
 #define        NOLINE  (line *) 0
 
-int    (*Outchar)();
-int    (*Pline)();
-int    (*Putchar)();
-int    (*oldhup)();
+extern int     (*Outchar)();
+extern int     (*Pline)();
+extern int     (*Putchar)();
+var    int     (*oldhup)();
 int    (*setlist())();
 int    (*setnorm())();
 int    (*setnorm())();
 int    (*setlist())();
 int    (*setnorm())();
 int    (*setnorm())();
@@ -325,9 +376,10 @@ off_t      lseek();
 int    normchar();
 int    normline();
 int    numbline();
 int    normchar();
 int    normline();
 int    numbline();
-int    (*oldquit)();
+var    int     (*oldquit)();
 int    onhup();
 int    onintr();
 int    onhup();
 int    onintr();
+int    onsusp();
 int    putch();
 int    shift();
 int    termchar();
 int    putch();
 int    shift();
 int    termchar();