[BACK]Return to ww.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / window

Annotation of src/usr.bin/window/ww.h, Revision 1.6

1.6     ! downsj      1: /*     $OpenBSD$       */
        !             2: /*     $NetBSD: ww.h,v 1.9 1996/10/12 23:46:23 christos Exp $  */
1.1       deraadt     3:
                      4: /*
                      5:  * Copyright (c) 1983, 1993
                      6:  *     The Regents of the University of California.  All rights reserved.
                      7:  *
                      8:  * This code is derived from software contributed to Berkeley by
                      9:  * Edward Wang at The University of California, Berkeley.
                     10:  *
                     11:  * Redistribution and use in source and binary forms, with or without
                     12:  * modification, are permitted provided that the following conditions
                     13:  * are met:
                     14:  * 1. Redistributions of source code must retain the above copyright
                     15:  *    notice, this list of conditions and the following disclaimer.
                     16:  * 2. Redistributions in binary form must reproduce the above copyright
                     17:  *    notice, this list of conditions and the following disclaimer in the
                     18:  *    documentation and/or other materials provided with the distribution.
                     19:  * 3. All advertising materials mentioning features or use of this software
                     20:  *    must display the following acknowledgement:
                     21:  *     This product includes software developed by the University of
                     22:  *     California, Berkeley and its contributors.
                     23:  * 4. Neither the name of the University nor the names of its contributors
                     24:  *    may be used to endorse or promote products derived from this software
                     25:  *    without specific prior written permission.
                     26:  *
                     27:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     28:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     29:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     30:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     31:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     32:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     33:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     34:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     35:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     36:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     37:  * SUCH DAMAGE.
                     38:  *
                     39:  *     @(#)ww.h        8.1 (Berkeley) 6/6/93
                     40:  */
                     41:
                     42: #ifdef OLD_TTY
                     43: #include <sgtty.h>
                     44: #else
                     45: #include <termios.h>
                     46: #endif
                     47: #include <setjmp.h>
1.5       niklas     48: #include <sys/types.h>
1.1       deraadt    49:
                     50: #define NWW    30              /* maximum number of windows */
                     51:
1.3       niklas     52: /* Macros to clear/set/test flags. */
                     53: #define        SET(t, f)       (t) |= (f)
                     54: #define        CLR(t, f)       (t) &= ~(f)
                     55: #define        ISSET(t, f)     ((t) & (f))
                     56:
1.1       deraadt    57:        /* a rectangle */
                     58: struct ww_dim {
                     59:        int nr;                 /* number of rows */
                     60:        int nc;                 /* number of columns */
                     61:        int t, b;               /* top, bottom */
                     62:        int l, r;               /* left, right */
                     63: };
                     64:
                     65:        /* a coordinate */
                     66: struct ww_pos {
                     67:        int r;                  /* row */
                     68:        int c;                  /* column */
                     69: };
                     70:
                     71:        /* the window structure */
                     72: struct ww {
1.3       niklas     73:        int ww_flags;
                     74:
1.1       deraadt    75:                /* general flags and states */
1.3       niklas     76:        int ww_state;           /* state of window */
                     77: #define WWS_INITIAL    0       /* just opened */
                     78: #define WWS_HASPROC    1       /* has process on pty */
                     79: #define WWS_DEAD       3       /* child died */
                     80: #define        ww_oflags       ww_flags
                     81: #define WWO_REVERSE    0x0001  /* make it all reverse video */
                     82: #define WWO_GLASS      0x0002  /* make it all glass */
                     83: #define WWO_FRAME      0x0004  /* this is a frame window */
                     84: #define        WWO_ALLFLAGS    0x0007
1.1       deraadt    85:
                     86:                /* information for overlap */
                     87:        struct ww *ww_forw;     /* doubly linked list, for overlapping info */
                     88:        struct ww *ww_back;
1.3       niklas     89:        unsigned char ww_index; /* the window index, for wwindex[] */
                     90: #define WWX_NOBODY     NWW
                     91:        int ww_order;           /* the overlapping order */
1.1       deraadt    92:
                     93:                /* sizes and positions */
                     94:        struct ww_dim ww_w;     /* window size and pos */
                     95:        struct ww_dim ww_b;     /* buffer size and pos */
                     96:        struct ww_dim ww_i;     /* the part inside the screen */
                     97:        struct ww_pos ww_cur;   /* the cursor position, relative to ww_w */
                     98:
                     99:                /* arrays */
                    100:        char **ww_win;          /* the window */
                    101:        union ww_char **ww_buf; /* the buffer */
                    102:        char **ww_fmap;         /* map for frame and box windows */
                    103:        short *ww_nvis;         /* how many ww_buf chars are visible per row */
                    104:
                    105:                /* information for wwwrite() and company */
1.3       niklas    106:        int ww_wstate;          /* state for outputting characters */
1.1       deraadt   107:        char ww_modes;          /* current display modes */
1.3       niklas    108: #define        ww_wflags       ww_flags
                    109: #define        WWW_INSERT      0x0008  /* insert mode */
                    110: #define        WWW_MAPNL       0x0010  /* map \n to \r\n */
                    111: #define        WWW_NOUPDATE    0x0020  /* don't do updates in wwwrite() */
                    112: #define        WWW_UNCTRL      0x0040  /* expand control characters */
                    113: #define        WWW_NOINTR      0x0080  /* wwwrite() not interruptable */
                    114: #define        WWW_HASCURSOR   0x0100  /* has fake cursor */
1.1       deraadt   115:
                    116:                /* things for the window process and io */
1.3       niklas    117:        int ww_type;
                    118: #define        WWT_PTY         0       /* pty */
                    119: #define        WWT_SOCKET      1       /* socket pair */
                    120: #define        WWT_INTERNAL    2
                    121: #define        ww_pflags       ww_flags
                    122: #define        WWP_STOPPED     0x0200  /* output stopped */
1.1       deraadt   123:        int ww_pty;             /* file descriptor of pty or socket pair */
                    124:        int ww_socket;          /* other end of socket pair */
                    125:        int ww_pid;             /* pid of process, if WWS_HASPROC true */
                    126:        char ww_ttyname[11];    /* "/dev/ttyp?" */
                    127:        char *ww_ob;            /* output buffer */
                    128:        char *ww_obe;           /* end of ww_ob */
                    129:        char *ww_obp;           /* current read position in ww_ob */
                    130:        char *ww_obq;           /* current write position in ww_ob */
                    131:
                    132:                /* things for the user, they really don't belong here */
1.3       niklas    133:        int ww_id;              /* the user window id */
                    134: #define        ww_uflags       ww_flags
                    135: #define        WWU_CENTER      0x0400  /* center the label */
                    136: #define        WWU_HASFRAME    0x0800  /* frame it */
                    137: #define        WWU_KEEPOPEN    0x1000  /* keep it open after the process dies */
                    138: #define        WWU_ALLFLAGS    0x1c00
1.1       deraadt   139:        char *ww_label;         /* the user supplied label */
                    140:        struct ww_dim ww_alt;   /* alternate position and size */
                    141: };
                    142:
                    143:        /* state of a tty */
                    144: struct ww_tty {
                    145: #ifdef OLD_TTY
                    146:        struct sgttyb ww_sgttyb;
                    147:        struct tchars ww_tchars;
                    148:        struct ltchars ww_ltchars;
                    149:        int ww_lmode;
                    150:        int ww_ldisc;
                    151: #else
                    152:        struct termios ww_termios;
                    153: #endif
                    154: };
                    155:
                    156: union ww_char {
                    157:        short c_w;              /* as a word */
                    158:        struct {
                    159: #if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
                    160:                char C_c;       /* the character part */
                    161:                char C_m;       /* the mode part */
                    162: #endif
                    163: #if BYTE_ORDER == BIG_ENDIAN
                    164:                char C_m;       /* the mode part */
                    165:                char C_c;       /* the character part */
                    166: #endif
                    167:        } c_un;
                    168: };
                    169: #define c_c c_un.C_c
                    170: #define c_m c_un.C_m
                    171:
                    172:        /* for display update */
                    173: struct ww_update {
                    174:        int best_gain;
                    175:        int best_col;
                    176:        int gain;
                    177: };
                    178:
                    179:        /* parts of ww_char */
                    180: #define WWC_CMASK      0x00ff
                    181: #define WWC_MMASK      0xff00
                    182: #define WWC_MSHIFT     8
                    183:
                    184:        /* c_m bits */
                    185: #define WWM_REV                0x01    /* reverse video */
                    186: #define WWM_BLK                0x02    /* blinking */
                    187: #define WWM_UL         0x04    /* underlined */
                    188: #define WWM_GRP                0x08    /* graphics */
                    189: #define WWM_DIM                0x10    /* half intensity */
                    190: #define WWM_USR                0x20    /* user specified mode */
                    191: #define WWM_GLS                0x40    /* window only, glass, i.e., transparent */
                    192:
                    193:        /* flags for ww_fmap */
                    194: #define WWF_U          0x01
                    195: #define WWF_R          0x02
                    196: #define WWF_D          0x04
                    197: #define WWF_L          0x08
                    198: #define WWF_MASK       (WWF_U|WWF_R|WWF_D|WWF_L)
                    199: #define WWF_LABEL      0x40
                    200: #define WWF_TOP                0x80
1.2       deraadt   201:
1.1       deraadt   202:        /* error codes */
                    203: #define WWE_NOERR      0
                    204: #define WWE_SYS                1               /* system error */
                    205: #define WWE_NOMEM      2               /* out of memory */
                    206: #define WWE_TOOMANY    3               /* too many windows */
                    207: #define WWE_NOPTY      4               /* no more ptys */
                    208: #define WWE_SIZE       5               /* bad window size */
                    209: #define WWE_BADTERM    6               /* bad terminal type */
                    210: #define WWE_CANTDO     7               /* dumb terminal */
                    211:
                    212:        /* wwtouched[] bits, there used to be more than one */
                    213: #define WWU_TOUCHED    0x01            /* touched */
                    214:
                    215:        /* the window structures */
                    216: struct ww wwhead;
                    217: struct ww *wwindex[NWW + 1];           /* last location is for wwnobody */
                    218: struct ww wwnobody;
                    219:
                    220:        /* tty things */
                    221: struct ww_tty wwoldtty;                /* the old (saved) terminal settings */
                    222: struct ww_tty wwnewtty;                /* the new (current) terminal settings */
                    223: struct ww_tty wwwintty;                /* the terminal settings for windows */
                    224: char *wwterm;                  /* the terminal name */
                    225: char wwtermcap[1024];          /* place for the termcap */
                    226:
                    227:        /* generally useful variables */
                    228: int wwnrow, wwncol;            /* the screen size */
                    229: char wwavailmodes;             /* actually supported modes */
                    230: char wwcursormodes;            /* the modes for the fake cursor */
                    231: char wwwrap;                   /* terminal has auto wrap around */
                    232: int wwdtablesize;              /* result of getdtablesize() call */
1.3       niklas    233: unsigned char **wwsmap;                /* the screen map */
1.1       deraadt   234: union ww_char **wwos;          /* the old (current) screen */
                    235: union ww_char **wwns;          /* the new (desired) screen */
                    236: union ww_char **wwcs;          /* the checkpointed screen */
                    237: char *wwtouched;               /* wwns changed flags */
                    238: struct ww_update *wwupd;       /* for display update */
                    239: int wwospeed;                  /* output baud rate, copied from wwoldtty */
                    240: int wwbaud;                    /* wwospeed converted into actual number */
                    241: int wwcursorrow, wwcursorcol;  /* where we want the cursor to be */
                    242: int wwerrno;                   /* error number */
                    243:
                    244:        /* statistics */
                    245: int wwnflush, wwnwr, wwnwre, wwnwrz, wwnwrc;
                    246: int wwnwwr, wwnwwra, wwnwwrc;
                    247: int wwntokdef, wwntokuse, wwntokbad, wwntoksave, wwntokc;
                    248: int wwnupdate, wwnupdline, wwnupdmiss;
                    249: int wwnupdscan, wwnupdclreol, wwnupdclreos, wwnupdclreosmiss, wwnupdclreosline;
                    250: int wwnread, wwnreade, wwnreadz;
                    251: int wwnreadc, wwnreadack, wwnreadnack, wwnreadstat, wwnreadec;
                    252: int wwnwread, wwnwreade, wwnwreadz, wwnwreadd, wwnwreadc, wwnwreadp;
                    253: int wwnselect, wwnselecte, wwnselectz;
                    254:
                    255:        /* quicky macros */
                    256: #define wwsetcursor(r,c) (wwcursorrow = (r), wwcursorcol = (c))
                    257: #define wwcurtowin(w)  wwsetcursor((w)->ww_cur.r, (w)->ww_cur.c)
                    258: #define wwunbox(w)     wwunframe(w)
                    259: #define wwclreol(w,r,c)        wwclreol1((w), (r), (c), 0)
                    260: #define wwredrawwin(w) wwredrawwin1((w), (w)->ww_i.t, (w)->ww_i.b, 0)
                    261: #define wwupdate()     wwupdate1(0, wwnrow);
                    262:
                    263:        /* things for handling input */
                    264: void wwrint();         /* interrupt handler */
                    265: struct ww *wwcurwin;   /* window to copy input into */
                    266: char *wwib;            /* input (keyboard) buffer */
                    267: char *wwibe;           /* wwib + sizeof buffer */
                    268: char *wwibp;           /* current read position in buffer */
                    269: char *wwibq;           /* current write position in buffer */
                    270: #define wwmaskc(c)     ((c) & 0x7f)
                    271: #define wwgetc()       (wwibp < wwibq ? wwmaskc(*wwibp++) : -1)
                    272: #define wwpeekc()      (wwibp < wwibq ? wwmaskc(*wwibp) : -1)
                    273: #define wwungetc(c)    (wwibp > wwib ? *--wwibp = (c) : -1)
                    274:
                    275:        /* things for short circuiting wwiomux() */
                    276: char wwintr;           /* interrupting */
                    277: char wwsetjmp;         /* want a longjmp() from wwrint() and wwchild() */
                    278: jmp_buf wwjmpbuf;      /* jmpbuf for above */
                    279: #define wwinterrupt()  wwintr
                    280: #define wwsetintr()    do { wwintr = 1; if (wwsetjmp) longjmp(wwjmpbuf, 1); } \
                    281:                        while (0)
                    282: #define wwclrintr()    (wwintr = 0)
                    283:
                    284:        /* checkpointing */
                    285: int wwdocheckpoint;
                    286:
                    287:        /* the window virtual terminal */
                    288: #define WWT_TERM       "window-v2"
                    289: #define WWT_TERMCAP    "WW|window-v2|window program version 2:\
                    290:        :am:bs:da:db:ms:pt:cr=^M:nl=^J:bl=^G:ta=^I:\
                    291:        :cm=\\EY%+ %+ :le=^H:nd=\\EC:up=\\EA:do=\\EB:ho=\\EH:\
                    292:        :cd=\\EJ:ce=\\EK:cl=\\EE:me=\\Er^?:"
                    293: #define WWT_REV                "se=\\ErA:so=\\EsA:mr=\\EsA:"
                    294: #define WWT_BLK                "BE=\\ErB:BS=\\EsB:mb=\\EsB:"
                    295: #define WWT_UL         "ue=\\ErD:us=\\EsD:"
                    296: #define WWT_GRP                "ae=\\ErH:as=\\EsH:"
                    297: #define WWT_DIM                "HE=\\ErP:HS=\\EsP:mh=\\EsP:"
                    298: #define WWT_USR                "XE=\\Er`:XS=\\Es`:"
                    299: #define WWT_ALDL       "al=\\EL:dl=\\EM:"
                    300: #define WWT_IMEI       "im=\\E@:ei=\\EO:ic=:mi:" /* XXX, ic for emacs bug */
                    301: #define WWT_IC         "ic=\\EP:"
                    302: #define WWT_DC         "dc=\\EN:"
                    303: char wwwintermcap[1024];       /* terminal-specific but window-independent
                    304:                                   part of the window termcap */
                    305: #ifdef TERMINFO
                    306:        /* where to put the temporary terminfo directory */
                    307: char wwterminfopath[1024];
                    308: #endif
                    309:
                    310:        /* our functions */
                    311: struct ww *wwopen();
                    312: void wwchild();
                    313: void wwalarm();
                    314: void wwquit();
                    315: char **wwalloc();
                    316: char *wwerror();
                    317:
                    318: #undef MIN
                    319: #undef MAX
                    320: #define MIN(x, y)      ((x) > (y) ? (y) : (x))
                    321: #define MAX(x, y)      ((x) > (y) ? (x) : (y))