1: /* 2: * @(#)ww.h 3.37.1 1996/3/22 3: */ 4: 5: /* 6: * Copyright (c) 1983 Regents of the University of California, 7: * All rights reserved. Redistribution permitted subject to 8: * the terms of the Berkeley Software License Agreement. 9: */ 10: 11: #include <sgtty.h> 12: #include <setjmp.h> 13: #include <stdlib.h> 14: #include <string.h> 15: #include <errno.h> 16: 17: #ifdef pdp11 18: #define NWW 9 /* maximum number of windows */ 19: #else 20: #define NWW 30 /* maximum number of windows */ 21: #endif 22: 23: /* a rectangle */ 24: struct ww_dim { 25: int nr; /* number of rows */ 26: int nc; /* number of columns */ 27: int t, b; /* top, bottom */ 28: int l, r; /* left, right */ 29: }; 30: 31: /* a coordinate */ 32: struct ww_pos { 33: int r; /* row */ 34: int c; /* column */ 35: }; 36: 37: /* the window structure */ 38: struct ww { 39: /* general flags and states */ 40: char ww_state; /* state of window */ 41: char ww_oflags; /* wwopen flags */ 42: 43: /* information for overlap */ 44: struct ww *ww_forw; /* doubly linked list, for overlapping info */ 45: struct ww *ww_back; 46: char ww_index; /* the window index, for wwindex[] */ 47: char ww_order; /* the overlapping order */ 48: 49: /* sizes and positions */ 50: struct ww_dim ww_w; /* window size and pos */ 51: struct ww_dim ww_b; /* buffer size and pos */ 52: struct ww_dim ww_i; /* the part inside the screen */ 53: struct ww_pos ww_cur; /* the cursor position, relative to ww_w */ 54: 55: /* arrays */ 56: char **ww_win; /* the window */ 57: union ww_char **ww_buf; /* the buffer */ 58: char **ww_fmap; /* map for frame and box windows */ 59: short *ww_nvis; /* how many ww_buf chars are visible per row */ 60: 61: /* information for wwwrite() and company */ 62: char ww_wstate; /* state for outputting characters */ 63: char ww_modes; /* current display modes */ 64: char ww_insert; /* insert mode */ 65: char ww_mapnl; /* map \n to \r\n */ 66: char ww_noupdate; /* don't do updates in wwwrite() */ 67: char ww_unctrl; /* expand control characters */ 68: char ww_nointr; /* wwwrite() not interruptable */ 69: char ww_hascursor; /* has fake cursor */ 70: 71: /* things for the window process and io */ 72: char ww_ispty; /* ww_pty is really a pty, not socket pair */ 73: char ww_stopped; /* output stopped */ 74: int ww_pty; /* file descriptor of pty or socket pair */ 75: int ww_socket; /* other end of socket pair */ 76: int ww_pid; /* pid of process, if WWS_HASPROC true */ 77: char ww_ttyname[11]; /* "/dev/ttyp?" */ 78: char *ww_ob; /* output buffer */ 79: char *ww_obe; /* end of ww_ob */ 80: char *ww_obp; /* current read position in ww_ob */ 81: char *ww_obq; /* current write position in ww_ob */ 82: 83: /* things for the user, they really don't belong here */ 84: char ww_id; /* the user window id */ 85: char ww_center; /* center the label */ 86: char ww_hasframe; /* frame it */ 87: char *ww_label; /* the user supplied label */ 88: struct ww_dim ww_alt; /* alternate position and size */ 89: }; 90: 91: /* state of a tty */ 92: struct ww_tty { 93: struct sgttyb ww_sgttyb; 94: struct tchars ww_tchars; 95: struct ltchars ww_ltchars; 96: int ww_lmode; 97: int ww_ldisc; 98: int ww_fflags; 99: }; 100: 101: union ww_char { 102: short c_w; /* as a word */ 103: struct { 104: #ifndef mc68000 105: char C_c; /* the character part */ 106: char C_m; /* the mode part */ 107: #else 108: char C_m; /* the mode part */ 109: char C_c; /* the character part */ 110: #endif 111: } c_un; 112: }; 113: #define c_c c_un.C_c 114: #define c_m c_un.C_m 115: 116: /* parts of ww_char */ 117: #define WWC_CMASK 0x00ff 118: #define WWC_MMASK 0xff00 119: #define WWC_MSHIFT 8 120: 121: /* c_m bits */ 122: #define WWM_REV 0x01 /* reverse video */ 123: #define WWM_BLK 0x02 /* blinking */ 124: #define WWM_UL 0x04 /* underlined */ 125: #define WWM_GRP 0x08 /* graphics */ 126: #define WWM_USR 0x10 /* user specified mode */ 127: #define WWM_GLS 0x40 /* window only, glass, i.e. transparent */ 128: 129: /* ww_state values */ 130: #define WWS_INITIAL 0 /* just opened */ 131: #define WWS_HASPROC 1 /* has process on pty */ 132: #define WWS_DEAD 3 /* child died */ 133: 134: /* flags for ww_fmap */ 135: #define WWF_U 0x01 136: #define WWF_R 0x02 137: #define WWF_D 0x04 138: #define WWF_L 0x08 139: #define WWF_MASK (WWF_U|WWF_R|WWF_D|WWF_L) 140: #define WWF_LABEL 0x40 141: #define WWF_TOP 0x80 142: 143: /* flags to wwopen() */ 144: #define WWO_PTY 0x01 /* want pty */ 145: #define WWO_SOCKET 0x02 /* want socket pair */ 146: #define WWO_REVERSE 0x04 /* make it all reverse video */ 147: #define WWO_GLASS 0x08 /* make it all glass */ 148: #define WWO_FRAME 0x10 /* this is a frame window */ 149: 150: /* special ww_index value */ 151: #define WWX_NOBODY NWW 152: 153: /* error codes */ 154: #define WWE_NOERR 0 155: #define WWE_SYS 1 /* system error */ 156: #define WWE_NOMEM 2 /* out of memory */ 157: #define WWE_TOOMANY 3 /* too many windows */ 158: #define WWE_NOPTY 4 /* no more ptys */ 159: #define WWE_SIZE 5 /* bad window size */ 160: #define WWE_BADTERM 6 /* bad terminal type */ 161: #define WWE_CANTDO 7 /* dumb terminal */ 162: 163: /* wwtouched[] bits */ 164: #define WWU_TOUCHED 0x01 /* touched */ 165: #define WWU_MAJOR 0x02 /* major change */ 166: 167: /* the window structures */ 168: struct ww wwhead; 169: struct ww *wwindex[NWW + 1]; /* last location is for wwnobody */ 170: struct ww wwnobody; 171: 172: /* tty things */ 173: struct ww_tty wwoldtty; /* the old (saved) terminal settings */ 174: struct ww_tty wwnewtty; /* the new (current) terminal settings */ 175: struct ww_tty wwwintty; /* the terminal settings for windows */ 176: char *wwterm; /* the terminal name */ 177: #ifdef pdp11 178: /* these are on the stack; see main.c */ 179: char *wwtermcap; /* place for the termcap */ 180: char *wwkeys; /* termcap fields for the function keys */ 181: char *wwwintermcap; /* termcap for windows */ 182: #else 183: char wwtermcap[1024]; /* place for the termcap */ 184: char wwkeys[512]; /* termcap fields for the function keys */ 185: char wwwintermcap[1024]; /* termcap for windows */ 186: #endif 187: 188: /* generally useful variables */ 189: int wwnrow, wwncol; /* the screen size */ 190: char wwavailmodes; /* actually supported modes */ 191: char wwcursormodes; /* the modes for the fake cursor */ 192: char wwwrap; /* terminal has auto wrap around */ 193: int wwdtablesize; /* result of getdtablesize() call */ 194: char **wwsmap; /* the screen map */ 195: union ww_char **wwos; /* the old (current) screen */ 196: union ww_char **wwns; /* the new (desired) screen */ 197: char *wwtouched; /* wwns changed flags */ 198: int wwbaudmap[]; /* maps stty() baud rate code into number */ 199: unsigned wwbaud; /* wwbaudmap[wwoldtty.ww_sgttyb.sg_ospeed] */ 200: int wwcursorrow, wwcursorcol; /* where we want the cursor to be */ 201: int wwerrno; /* error number */ 202: 203: /* statistics */ 204: int wwnflush, wwnwr, wwnwre, wwnwrz, wwnwrc; 205: int wwnwwr, wwnwwra, wwnwwrc; 206: int wwnupdate, wwnupdline, wwnupdmiss, wwnmajline, wwnmajmiss; 207: int wwnread, wwnreade, wwnreadz, wwnreadc; 208: int wwnwread, wwnwreade, wwnwreadz, wwnwreadd, wwnwreadc, wwnwreadp; 209: int wwnselect, wwnselecte, wwnselectz; 210: 211: /* quicky macros */ 212: #define wwsetcursor(r,c) (wwcursorrow = (r), wwcursorcol = (c)) 213: #define wwcurtowin(w) wwsetcursor((w)->ww_cur.r, (w)->ww_cur.c) 214: #define wwunbox(w) wwunframe(w) 215: #define wwclreol(w,r,c) wwclreol1((w), (r), (c), 0) 216: #define wwredrawwin(w) wwredrawwin1((w), (w)->ww_i.t, (w)->ww_i.b, 0) 217: #define wwupdate() wwupdate1(0, wwnrow); 218: 219: /* things for handling input */ 220: int wwrint(); /* interrupt handler */ 221: struct ww *wwcurwin; /* window to copy input into */ 222: char wwsetjmp; /* want a longjmp() from wwrint() */ 223: jmp_buf wwjmpbuf; /* jmpbuf for above */ 224: char *wwib; /* input (keyboard) buffer */ 225: char *wwibe; /* wwib + sizeof buffer */ 226: char *wwibp; /* current read position in buffer */ 227: char *wwibq; /* current write position in buffer */ 228: #define wwgetc() (wwibp < wwibq ? *wwibp++ & 0x7f : -1) 229: #define wwpeekc() (wwibp < wwibq ? *wwibp & 0x7f : -1) 230: #define wwungetc(c) (wwibp > wwib ? *--wwibp = (c) : -1) 231: #define wwinterrupt() (wwibp < wwibq) 232: 233: /* the window virtual terminal */ 234: #define WWT_TERM "TERM=window" 235: #define WWT_TERMCAP "WW|window|window package:\ 236: :cr=^M:nl=^J:bl=^G:\ 237: :al=\\EL:am:le=^H:bs:cd=\\EJ:ce=\\EK:cl=\\EE:cm=\\EY%+ %+ :\ 238: :da:db:dc=\\EN:dl=\\EM:do=\\EB:ei=\\EO:ho=\\EH:im=\\E@:mi:\ 239: :nd=\\EC:ta=^I:pt:up=\\EA:" 240: #define WWT_REV "se=\\Eq:so=\\Ep:" 241: #define WWT_UL "ue=\\Es:us=\\Er:" 242: #define WWT_GRP "ae=\\EG:as=\\EF:" 243: #define WWT_USR "XE=\\EQ:XS=\\EP:" 244: 245: /* our functions */ 246: struct ww *wwopen(); 247: int wwchild(); 248: int wwsuspend(); 249: char **wwalloc(); 250: char *wwerror(); 251: 252: /* c library functions */ 253: char *tgetstr(); 254: 255: #undef MIN 256: #undef MAX 257: #define MIN(x, y) ((x) > (y) ? (y) : (x)) 258: #define MAX(x, y) ((x) > (y) ? (x) : (y))