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