Annotation of 43BSDReno/usr.bin/window/ww.h, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.