[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.2

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