BSD 4_3_Net_2 release
[unix-history] / usr / src / usr.bin / window / ww.h
index dc02cad..9acbc8e 100644 (file)
@@ -1,9 +1,48 @@
 /*
 /*
- *     @(#)ww.h        3.26 84/03/03   
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Edward Wang at The University of California, Berkeley.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *     @(#)ww.h        3.63 (Berkeley) 3/2/91
  */
 
  */
 
+#ifdef OLD_TTY
 #include <sgtty.h>
 #include <sgtty.h>
+#else
+#include <termios.h>
+#endif
 #include <setjmp.h>
 #include <setjmp.h>
+#include <machine/endian.h>
 
 #define NWW    30              /* maximum number of windows */
 
 
 #define NWW    30              /* maximum number of windows */
 
@@ -23,17 +62,14 @@ struct ww_pos {
 
        /* the window structure */
 struct ww {
 
        /* the window structure */
 struct ww {
+               /* general flags and states */
+       char ww_state;          /* state of window */
+       char ww_oflags;         /* wwopen flags */
+
+               /* information for overlap */
        struct ww *ww_forw;     /* doubly linked list, for overlapping info */
        struct ww *ww_back;
        struct ww *ww_forw;     /* doubly linked list, for overlapping info */
        struct ww *ww_back;
-       char ww_state;          /* state of window creation */
-       char ww_wstate;         /* state for printing charcters */
-       char ww_modes;          /* current printing modes */
-       char ww_insert :1;      /* insert mode, for printing */
-       char ww_mapnl :1;       /* map \n to \r\n */
-       char ww_hascursor :1;   /* has fake cursor */
-       char ww_hasframe :1;    /* frame it */
-       char ww_nointr : 1;     /* wwwrite() not interruptable */
-       char ww_index;          /* the index, for wwindex[] */
+       char ww_index;          /* the window index, for wwindex[] */
        char ww_order;          /* the overlapping order */
 
                /* sizes and positions */
        char ww_order;          /* the overlapping order */
 
                /* sizes and positions */
@@ -48,40 +84,59 @@ struct ww {
        char **ww_fmap;         /* map for frame and box windows */
        short *ww_nvis;         /* how many ww_buf chars are visible per row */
 
        char **ww_fmap;         /* map for frame and box windows */
        short *ww_nvis;         /* how many ww_buf chars are visible per row */
 
+               /* information for wwwrite() and company */
+       char ww_wstate;         /* state for outputting characters */
+       char ww_modes;          /* current display modes */
+       char ww_insert;         /* insert mode */
+       char ww_mapnl;          /* map \n to \r\n */
+       char ww_noupdate;       /* don't do updates in wwwrite() */
+       char ww_unctrl;         /* expand control characters */
+       char ww_nointr;         /* wwwrite() not interruptable */
+       char ww_hascursor;      /* has fake cursor */
+
                /* things for the window process and io */
                /* things for the window process and io */
-       int ww_pty;             /* file descriptor of pty */
+       char ww_ispty;          /* ww_pty is really a pty, not socket pair */
+       char ww_stopped;        /* output stopped */
+       int ww_pty;             /* file descriptor of pty or socket pair */
+       int ww_socket;          /* other end of socket pair */
        int ww_pid;             /* pid of process, if WWS_HASPROC true */
        char ww_ttyname[11];    /* "/dev/ttyp?" */
        char *ww_ob;            /* output buffer */
        char *ww_obe;           /* end of ww_ob */
        int ww_pid;             /* pid of process, if WWS_HASPROC true */
        char ww_ttyname[11];    /* "/dev/ttyp?" */
        char *ww_ob;            /* output buffer */
        char *ww_obe;           /* end of ww_ob */
-       char *ww_obp;           /* current position in ww_ob */
-       int ww_obc;             /* character count */
-       char ww_stopped;        /* output stopped */
+       char *ww_obp;           /* current read position in ww_ob */
+       char *ww_obq;           /* current write position in ww_ob */
 
                /* things for the user, they really don't belong here */
 
                /* things for the user, they really don't belong here */
+       char ww_id;             /* the user window id */
        char ww_center;         /* center the label */
        char ww_center;         /* center the label */
-       int ww_id;              /* the user window id */
+       char ww_hasframe;       /* frame it */
+       char ww_keepopen;       /* keep it open after the process dies */
        char *ww_label;         /* the user supplied label */
        char *ww_label;         /* the user supplied label */
-       struct ww_pos ww_altpos;/* alternate position */
+       struct ww_dim ww_alt;   /* alternate position and size */
 };
 
        /* state of a tty */
 struct ww_tty {
 };
 
        /* state of a tty */
 struct ww_tty {
+#ifdef OLD_TTY
        struct sgttyb ww_sgttyb;
        struct tchars ww_tchars;
        struct ltchars ww_ltchars;
        int ww_lmode;
        int ww_ldisc;
        struct sgttyb ww_sgttyb;
        struct tchars ww_tchars;
        struct ltchars ww_ltchars;
        int ww_lmode;
        int ww_ldisc;
+#else
+       struct termios ww_termios;
+#endif
        int ww_fflags;
 };
 
 union ww_char {
        short c_w;              /* as a word */
        struct {
        int ww_fflags;
 };
 
 union ww_char {
        short c_w;              /* as a word */
        struct {
-#ifndef O_SUN
+#if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
                char C_c;       /* the character part */
                char C_m;       /* the mode part */
                char C_c;       /* the character part */
                char C_m;       /* the mode part */
-#else
+#endif
+#if BYTE_ORDER == BIG_ENDIAN
                char C_m;       /* the mode part */
                char C_c;       /* the character part */
 #endif
                char C_m;       /* the mode part */
                char C_c;       /* the character part */
 #endif
@@ -90,6 +145,13 @@ union ww_char {
 #define c_c c_un.C_c
 #define c_m c_un.C_m
 
 #define c_c c_un.C_c
 #define c_m c_un.C_m
 
+       /* for display update */
+struct ww_update {
+       int best_gain;
+       int best_col;
+       int gain;
+};
+
        /* parts of ww_char */
 #define WWC_CMASK      0x00ff
 #define WWC_MMASK      0xff00
        /* parts of ww_char */
 #define WWC_CMASK      0x00ff
 #define WWC_MMASK      0xff00
@@ -100,7 +162,9 @@ union ww_char {
 #define WWM_BLK                0x02    /* blinking */
 #define WWM_UL         0x04    /* underlined */
 #define WWM_GRP                0x08    /* graphics */
 #define WWM_BLK                0x02    /* blinking */
 #define WWM_UL         0x04    /* underlined */
 #define WWM_GRP                0x08    /* graphics */
-#define WWM_GLS                0x10    /* window only, glass, i.e. transparent */
+#define WWM_DIM                0x10    /* half intensity */
+#define WWM_USR                0x20    /* user specified mode */
+#define WWM_GLS                0x40    /* window only, glass, i.e., transparent */
 
        /* ww_state values */
 #define WWS_INITIAL    0       /* just opened */
 
        /* ww_state values */
 #define WWS_INITIAL    0       /* just opened */
@@ -118,9 +182,10 @@ union ww_char {
 
        /* flags to wwopen() */
 #define WWO_PTY                0x01            /* want pty */
 
        /* flags to wwopen() */
 #define WWO_PTY                0x01            /* want pty */
-#define WWO_REVERSE    0x02            /* make it all reverse video */
-#define WWO_GLASS      0x04            /* make it all glass */
-#define WWO_FRAME      0x08            /* this is a frame window */
+#define WWO_SOCKET     0x02            /* want socket pair */
+#define WWO_REVERSE    0x04            /* make it all reverse video */
+#define WWO_GLASS      0x08            /* make it all glass */
+#define WWO_FRAME      0x10            /* this is a frame window */
 
        /* special ww_index value */
 #define WWX_NOBODY     NWW
 
        /* special ww_index value */
 #define WWX_NOBODY     NWW
@@ -135,9 +200,8 @@ union ww_char {
 #define WWE_BADTERM    6               /* bad terminal type */
 #define WWE_CANTDO     7               /* dumb terminal */
 
 #define WWE_BADTERM    6               /* bad terminal type */
 #define WWE_CANTDO     7               /* dumb terminal */
 
-       /* wwtouched[] bits */
+       /* wwtouched[] bits, there used to be more than one */
 #define WWU_TOUCHED    0x01            /* touched */
 #define WWU_TOUCHED    0x01            /* touched */
-#define WWU_MAJOR      0x02            /* major change */
 
        /* the window structures */
 struct ww wwhead;
 
        /* the window structures */
 struct ww wwhead;
@@ -150,7 +214,6 @@ struct ww_tty wwnewtty;             /* the new (current) terminal settings */
 struct ww_tty wwwintty;                /* the terminal settings for windows */
 char *wwterm;                  /* the terminal name */
 char wwtermcap[1024];          /* place for the termcap */
 struct ww_tty wwwintty;                /* the terminal settings for windows */
 char *wwterm;                  /* the terminal name */
 char wwtermcap[1024];          /* place for the termcap */
-char wwkeys[512];              /* termcap fields for the function keys */
 
        /* generally useful variables */
 int wwnrow, wwncol;            /* the screen size */
 
        /* generally useful variables */
 int wwnrow, wwncol;            /* the screen size */
@@ -162,15 +225,18 @@ char **wwsmap;                    /* the screen map */
 union ww_char **wwos;          /* the old (current) screen */
 union ww_char **wwns;          /* the new (desired) screen */
 char *wwtouched;               /* wwns changed flags */
 union ww_char **wwos;          /* the old (current) screen */
 union ww_char **wwns;          /* the new (desired) screen */
 char *wwtouched;               /* wwns changed flags */
-int wwbaudmap[];               /* maps stty() baud rate code into number */
-int wwbaud;                    /* wwbaudmap[wwoldtty.ww_sgttyb.sg_ospeed] */
+struct ww_update *wwupd;       /* for display update */
+int wwospeed;                  /* output baud rate, copied from wwoldtty */
+int wwbaud;                    /* wwospeed converted into actual number */
 int wwcursorrow, wwcursorcol;  /* where we want the cursor to be */
 int wwerrno;                   /* error number */
 
        /* statistics */
 int wwnflush, wwnwr, wwnwre, wwnwrz, wwnwrc;
 int wwnwwr, wwnwwra, wwnwwrc;
 int wwcursorrow, wwcursorcol;  /* where we want the cursor to be */
 int wwerrno;                   /* error number */
 
        /* statistics */
 int wwnflush, wwnwr, wwnwre, wwnwrz, wwnwrc;
 int wwnwwr, wwnwwra, wwnwwrc;
-int wwnupdate, wwnupdline, wwnupdmiss, wwnmajline, wwnmajmiss;
+int wwntokdef, wwntokuse, wwntokbad, wwntoksave, wwntokc;
+int wwnupdate, wwnupdline, wwnupdmiss;
+int wwnupdscan, wwnupdclreol, wwnupdclreos, wwnupdclreosmiss, wwnupdclreosline;
 int wwnread, wwnreade, wwnreadz, wwnreadc;
 int wwnwread, wwnwreade, wwnwreadz, wwnwreadd, wwnwreadc, wwnwreadp;
 int wwnselect, wwnselecte, wwnselectz;
 int wwnread, wwnreade, wwnreadz, wwnreadc;
 int wwnwread, wwnwreade, wwnwreadz, wwnwreadd, wwnwreadc, wwnwreadp;
 int wwnselect, wwnselecte, wwnselectz;
@@ -184,10 +250,8 @@ int wwnselect, wwnselecte, wwnselectz;
 #define wwupdate()     wwupdate1(0, wwnrow);
 
        /* things for handling input */
 #define wwupdate()     wwupdate1(0, wwnrow);
 
        /* things for handling input */
-int wwrint();          /* interrupt handler */
+void wwrint();         /* interrupt handler */
 struct ww *wwcurwin;   /* window to copy input into */
 struct ww *wwcurwin;   /* window to copy input into */
-char wwsetjmp;         /* want a longjmp() from wwrint() */
-jmp_buf wwjmpbuf;      /* jmpbuf for above */
 char *wwib;            /* input (keyboard) buffer */
 char *wwibe;           /* wwib + sizeof buffer */
 char *wwibp;           /* current read position in buffer */
 char *wwib;            /* input (keyboard) buffer */
 char *wwibe;           /* wwib + sizeof buffer */
 char *wwibp;           /* current read position in buffer */
@@ -195,25 +259,39 @@ char *wwibq;              /* current write position in buffer */
 #define wwgetc()       (wwibp < wwibq ? *wwibp++ & 0x7f : -1)
 #define wwpeekc()      (wwibp < wwibq ? *wwibp & 0x7f : -1)
 #define wwungetc(c)    (wwibp > wwib ? *--wwibp = (c) : -1)
 #define wwgetc()       (wwibp < wwibq ? *wwibp++ & 0x7f : -1)
 #define wwpeekc()      (wwibp < wwibq ? *wwibp & 0x7f : -1)
 #define wwungetc(c)    (wwibp > wwib ? *--wwibp = (c) : -1)
-#define wwinterrupt()  (wwibp < wwibq)
+
+       /* things for short circuiting wwiomux() */
+char wwintr;           /* interrupting */
+char wwsetjmp;         /* want a longjmp() from wwrint() and wwchild() */
+jmp_buf wwjmpbuf;      /* jmpbuf for above */
+#define wwinterrupt()  wwintr
+#define wwsetintr()    do { wwintr = 1; if (wwsetjmp) longjmp(wwjmpbuf, 1); } \
+                       while (0)
+#define wwclrintr()    (wwintr = 0)
 
        /* the window virtual terminal */
 
        /* the window virtual terminal */
-#define WWT_TERM       "TERM=window"
-#define WWT_TERMCAP    "WW|window|window package:\
-       :cr=^M:nl=^J:bl=^G:\
-       :al=\\EL:am:le=^H:bs:cd=\\EJ:ce=\\EK:cl=\\EE:cm=\\EY%+ %+ :\
-       :da:db:dc=\\EN:dl=\\EM:do=\\EB:ei=\\EO:ho=\\EH:im=\\E@:mi:\
-       :nd=\\EC:ta=^I:pt:up=\\EA:"
-#define WWT_REV                "se=\\Eq:so=\\Ep:"
-#define WWT_UL         "ue=\\Es:us=\\Er:"
-#define WWT_GRP                "ae=\\EG:as=\\EF:"
+#define WWT_TERM       "window-v2"
+#define WWT_TERMCAP    "WW|window-v2|window program version 2:\
+       :am:bs:da:db:ms:pt:cr=^M:nl=^J:bl=^G:ta=^I:\
+       :cm=\\EY%+ %+ :le=^H:nd=\\EC:up=\\EA:do=\\EB:ho=\\EH:\
+       :cd=\\EJ:ce=\\EK:cl=\\EE:me=\\Er^?:"
+#define WWT_REV                "se=\\ErA:so=\\EsA:mr=\\EsA:"
+#define WWT_BLK                "BE=\\ErB:BS=\\EsB:mb=\\EsB:"
+#define WWT_UL         "ue=\\ErD:us=\\EsD:"
+#define WWT_GRP                "ae=\\ErH:as=\\EsH:"
+#define WWT_DIM                "HE=\\ErP:HS=\\EsP:mh=\\EsP:"
+#define WWT_USR                "XE=\\Er`:XS=\\Es`:"
+#define WWT_ALDL       "al=\\EL:dl=\\EM:"
+#define WWT_IMEI       "im=\\E@:ei=\\EO:ic=:mi:" /* XXX, ic for emacs bug */
+#define WWT_IC         "ic=\\EP:"
+#define WWT_DC         "dc=\\EN:"
+char wwwintermcap[1024];       /* terminal-specific but window-independent
+                                  part of the window termcap */
 
        /* our functions */
 struct ww *wwopen();
 
        /* our functions */
 struct ww *wwopen();
-struct ww *wwfind();
-int wwchild();
-int wwsuspend();
-char *unctrl();
+void wwchild();
+void wwsuspend();
 char **wwalloc();
 char *wwerror();
 
 char **wwalloc();
 char *wwerror();
 
@@ -225,23 +303,8 @@ char *tgetstr();
 char *rindex();
 char *strcpy();
 char *strcat();
 char *rindex();
 char *strcpy();
 char *strcat();
-char *sprintf();
 
 #undef MIN
 #undef MAX
 #define MIN(x, y)      ((x) > (y) ? (y) : (x))
 #define MAX(x, y)      ((x) > (y) ? (x) : (y))
 
 #undef MIN
 #undef MAX
 #define MIN(x, y)      ((x) > (y) ? (y) : (x))
 #define MAX(x, y)      ((x) > (y) ? (x) : (y))
-
-#undef CTRL
-#define CTRL(c)                ('c'&0x1f)
-#define DEL            0x7f
-#define ISCTRL(c)      ((c) < ' ' & (c) != '\t' || (c) >= DEL)
-
-#if defined(O_4_1A)||defined(O_4_1C)
-int (*sigset)();
-#define signal(s, v)   sigset((s), (v))
-#else
-#define sigmask(s)     (1 << (s) - 1)
-#define sighold(s)     sigblock(sigmask(s))
-#define sigrelse(s)    sigsetmask(sigblock(0) & ~sigmask(s))
-#endif