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