Commit | Line | Data |
---|---|---|
bb05dfb5 | 1 | /* |
90986835 KB |
2 | * Copyright (c) 1983, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
46e9ea25 | 4 | * |
3dd3a9e5 KB |
5 | * This code is derived from software contributed to Berkeley by |
6 | * Edward Wang at The University of California, Berkeley. | |
7 | * | |
87f529ec | 8 | * %sccs.include.redist.c% |
46e9ea25 | 9 | * |
90986835 | 10 | * @(#)ww.h 8.1 (Berkeley) %G% |
bb05dfb5 | 11 | */ |
0edb449f | 12 | |
9de86788 | 13 | #ifdef OLD_TTY |
0edb449f | 14 | #include <sgtty.h> |
bbbb7b14 EW |
15 | #else |
16 | #include <termios.h> | |
17 | #endif | |
b1189050 | 18 | #include <setjmp.h> |
2453701d | 19 | #include <machine/endian.h> |
bb05dfb5 | 20 | |
8fa6d94c | 21 | #define NWW 30 /* maximum number of windows */ |
0edb449f | 22 | |
b47565d0 | 23 | /* a rectangle */ |
c417b691 | 24 | struct ww_dim { |
bb05dfb5 EW |
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 | ||
b47565d0 | 31 | /* a coordinate */ |
bb05dfb5 EW |
32 | struct ww_pos { |
33 | int r; /* row */ | |
34 | int c; /* column */ | |
c417b691 EW |
35 | }; |
36 | ||
b47565d0 | 37 | /* the window structure */ |
0edb449f | 38 | struct ww { |
b27a9cfb EW |
39 | /* general flags and states */ |
40 | char ww_state; /* state of window */ | |
41 | char ww_oflags; /* wwopen flags */ | |
42 | ||
0e64e422 | 43 | /* information for overlap */ |
bb05dfb5 EW |
44 | struct ww *ww_forw; /* doubly linked list, for overlapping info */ |
45 | struct ww *ww_back; | |
0e64e422 | 46 | char ww_index; /* the window index, for wwindex[] */ |
bb05dfb5 | 47 | char ww_order; /* the overlapping order */ |
f2a77fe1 EW |
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 */ | |
19f9784c | 52 | struct ww_dim ww_i; /* the part inside the screen */ |
bb05dfb5 | 53 | struct ww_pos ww_cur; /* the cursor position, relative to ww_w */ |
f2a77fe1 EW |
54 | |
55 | /* arrays */ | |
bb05dfb5 EW |
56 | char **ww_win; /* the window */ |
57 | union ww_char **ww_buf; /* the buffer */ | |
2357b64e | 58 | char **ww_fmap; /* map for frame and box windows */ |
bb05dfb5 | 59 | short *ww_nvis; /* how many ww_buf chars are visible per row */ |
f2a77fe1 | 60 | |
0e64e422 EW |
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 */ | |
0e64e422 | 70 | |
b1189050 | 71 | /* things for the window process and io */ |
7ecf4dca EW |
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 */ | |
bb05dfb5 | 76 | int ww_pid; /* pid of process, if WWS_HASPROC true */ |
0896e17e | 77 | char ww_ttyname[11]; /* "/dev/ttyp?" */ |
8fa6d94c EW |
78 | char *ww_ob; /* output buffer */ |
79 | char *ww_obe; /* end of ww_ob */ | |
7ecf4dca EW |
80 | char *ww_obp; /* current read position in ww_ob */ |
81 | char *ww_obq; /* current write position in ww_ob */ | |
f176f953 EW |
82 | |
83 | /* things for the user, they really don't belong here */ | |
0e64e422 | 84 | char ww_id; /* the user window id */ |
b27a9cfb EW |
85 | char ww_center; /* center the label */ |
86 | char ww_hasframe; /* frame it */ | |
2422abab | 87 | char ww_keepopen; /* keep it open after the process dies */ |
bb05dfb5 | 88 | char *ww_label; /* the user supplied label */ |
b27a9cfb | 89 | struct ww_dim ww_alt; /* alternate position and size */ |
4711df8b EW |
90 | }; |
91 | ||
b47565d0 | 92 | /* state of a tty */ |
4711df8b | 93 | struct ww_tty { |
9de86788 | 94 | #ifdef OLD_TTY |
0edb449f EW |
95 | struct sgttyb ww_sgttyb; |
96 | struct tchars ww_tchars; | |
97 | struct ltchars ww_ltchars; | |
98 | int ww_lmode; | |
99 | int ww_ldisc; | |
bbbb7b14 EW |
100 | #else |
101 | struct termios ww_termios; | |
102 | #endif | |
b1189050 | 103 | int ww_fflags; |
0edb449f EW |
104 | }; |
105 | ||
0896e17e EW |
106 | union ww_char { |
107 | short c_w; /* as a word */ | |
108 | struct { | |
2453701d | 109 | #if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN |
0896e17e EW |
110 | char C_c; /* the character part */ |
111 | char C_m; /* the mode part */ | |
2453701d EW |
112 | #endif |
113 | #if BYTE_ORDER == BIG_ENDIAN | |
a6fccdf5 EW |
114 | char C_m; /* the mode part */ |
115 | char C_c; /* the character part */ | |
116 | #endif | |
0896e17e EW |
117 | } c_un; |
118 | }; | |
119 | #define c_c c_un.C_c | |
120 | #define c_m c_un.C_m | |
121 | ||
6a1ef78a EW |
122 | /* for display update */ |
123 | struct ww_update { | |
124 | int best_gain; | |
125 | int best_col; | |
126 | int gain; | |
127 | }; | |
128 | ||
0896e17e EW |
129 | /* parts of ww_char */ |
130 | #define WWC_CMASK 0x00ff | |
131 | #define WWC_MMASK 0xff00 | |
132 | #define WWC_MSHIFT 8 | |
133 | ||
134 | /* c_m bits */ | |
135 | #define WWM_REV 0x01 /* reverse video */ | |
136 | #define WWM_BLK 0x02 /* blinking */ | |
137 | #define WWM_UL 0x04 /* underlined */ | |
a830e8bb | 138 | #define WWM_GRP 0x08 /* graphics */ |
a6833679 EW |
139 | #define WWM_DIM 0x10 /* half intensity */ |
140 | #define WWM_USR 0x20 /* user specified mode */ | |
141 | #define WWM_GLS 0x40 /* window only, glass, i.e., transparent */ | |
0896e17e EW |
142 | |
143 | /* ww_state values */ | |
144 | #define WWS_INITIAL 0 /* just opened */ | |
b47565d0 | 145 | #define WWS_HASPROC 1 /* has process on pty */ |
0896e17e EW |
146 | #define WWS_DEAD 3 /* child died */ |
147 | ||
2357b64e | 148 | /* flags for ww_fmap */ |
0896e17e EW |
149 | #define WWF_U 0x01 |
150 | #define WWF_R 0x02 | |
151 | #define WWF_D 0x04 | |
152 | #define WWF_L 0x08 | |
153 | #define WWF_MASK (WWF_U|WWF_R|WWF_D|WWF_L) | |
154 | #define WWF_LABEL 0x40 | |
155 | #define WWF_TOP 0x80 | |
156 | ||
2357b64e EW |
157 | /* flags to wwopen() */ |
158 | #define WWO_PTY 0x01 /* want pty */ | |
7ecf4dca EW |
159 | #define WWO_SOCKET 0x02 /* want socket pair */ |
160 | #define WWO_REVERSE 0x04 /* make it all reverse video */ | |
161 | #define WWO_GLASS 0x08 /* make it all glass */ | |
162 | #define WWO_FRAME 0x10 /* this is a frame window */ | |
2357b64e | 163 | |
0896e17e EW |
164 | /* special ww_index value */ |
165 | #define WWX_NOBODY NWW | |
166 | ||
04d70db4 | 167 | /* error codes */ |
03e75950 EW |
168 | #define WWE_NOERR 0 |
169 | #define WWE_SYS 1 /* system error */ | |
170 | #define WWE_NOMEM 2 /* out of memory */ | |
171 | #define WWE_TOOMANY 3 /* too many windows */ | |
172 | #define WWE_NOPTY 4 /* no more ptys */ | |
173 | #define WWE_SIZE 5 /* bad window size */ | |
174 | #define WWE_BADTERM 6 /* bad terminal type */ | |
175 | #define WWE_CANTDO 7 /* dumb terminal */ | |
176 | ||
6a1ef78a | 177 | /* wwtouched[] bits, there used to be more than one */ |
04d70db4 | 178 | #define WWU_TOUCHED 0x01 /* touched */ |
04d70db4 | 179 | |
8fa6d94c | 180 | /* the window structures */ |
bb05dfb5 | 181 | struct ww wwhead; |
0896e17e | 182 | struct ww *wwindex[NWW + 1]; /* last location is for wwnobody */ |
bb05dfb5 | 183 | struct ww wwnobody; |
2b44d852 | 184 | |
8fa6d94c | 185 | /* tty things */ |
0896e17e EW |
186 | struct ww_tty wwoldtty; /* the old (saved) terminal settings */ |
187 | struct ww_tty wwnewtty; /* the new (current) terminal settings */ | |
188 | struct ww_tty wwwintty; /* the terminal settings for windows */ | |
189 | char *wwterm; /* the terminal name */ | |
190 | char wwtermcap[1024]; /* place for the termcap */ | |
bb05dfb5 | 191 | |
8fa6d94c | 192 | /* generally useful variables */ |
bb05dfb5 | 193 | int wwnrow, wwncol; /* the screen size */ |
7d77e730 | 194 | char wwavailmodes; /* actually supported modes */ |
73218728 | 195 | char wwcursormodes; /* the modes for the fake cursor */ |
5e785082 | 196 | char wwwrap; /* terminal has auto wrap around */ |
0896e17e | 197 | int wwdtablesize; /* result of getdtablesize() call */ |
bb05dfb5 | 198 | char **wwsmap; /* the screen map */ |
0896e17e EW |
199 | union ww_char **wwos; /* the old (current) screen */ |
200 | union ww_char **wwns; /* the new (desired) screen */ | |
20849355 | 201 | union ww_char **wwcs; /* the checkpointed screen */ |
861cd1ed | 202 | char *wwtouched; /* wwns changed flags */ |
6a1ef78a | 203 | struct ww_update *wwupd; /* for display update */ |
9de86788 EW |
204 | int wwospeed; /* output baud rate, copied from wwoldtty */ |
205 | int wwbaud; /* wwospeed converted into actual number */ | |
0896e17e | 206 | int wwcursorrow, wwcursorcol; /* where we want the cursor to be */ |
03e75950 | 207 | int wwerrno; /* error number */ |
0edb449f | 208 | |
bb05dfb5 | 209 | /* statistics */ |
b1189050 EW |
210 | int wwnflush, wwnwr, wwnwre, wwnwrz, wwnwrc; |
211 | int wwnwwr, wwnwwra, wwnwwrc; | |
0ab446d2 | 212 | int wwntokdef, wwntokuse, wwntokbad, wwntoksave, wwntokc; |
6a1ef78a EW |
213 | int wwnupdate, wwnupdline, wwnupdmiss; |
214 | int wwnupdscan, wwnupdclreol, wwnupdclreos, wwnupdclreosmiss, wwnupdclreosline; | |
20849355 EW |
215 | int wwnread, wwnreade, wwnreadz; |
216 | int wwnreadc, wwnreadack, wwnreadnack, wwnreadstat, wwnreadec; | |
8fa6d94c EW |
217 | int wwnwread, wwnwreade, wwnwreadz, wwnwreadd, wwnwreadc, wwnwreadp; |
218 | int wwnselect, wwnselecte, wwnselectz; | |
0edb449f | 219 | |
0896e17e | 220 | /* quicky macros */ |
bb05dfb5 | 221 | #define wwsetcursor(r,c) (wwcursorrow = (r), wwcursorcol = (c)) |
f2a77fe1 | 222 | #define wwcurtowin(w) wwsetcursor((w)->ww_cur.r, (w)->ww_cur.c) |
2357b64e | 223 | #define wwunbox(w) wwunframe(w) |
f2a77fe1 | 224 | #define wwclreol(w,r,c) wwclreol1((w), (r), (c), 0) |
86697c44 | 225 | #define wwredrawwin(w) wwredrawwin1((w), (w)->ww_i.t, (w)->ww_i.b, 0) |
b1189050 | 226 | #define wwupdate() wwupdate1(0, wwnrow); |
2b44d852 | 227 | |
8fa6d94c | 228 | /* things for handling input */ |
419d8eab | 229 | void wwrint(); /* interrupt handler */ |
b1189050 | 230 | struct ww *wwcurwin; /* window to copy input into */ |
8fa6d94c EW |
231 | char *wwib; /* input (keyboard) buffer */ |
232 | char *wwibe; /* wwib + sizeof buffer */ | |
b1189050 EW |
233 | char *wwibp; /* current read position in buffer */ |
234 | char *wwibq; /* current write position in buffer */ | |
21e9e78d EW |
235 | #define wwmaskc(c) ((c) & 0x7f) |
236 | #define wwgetc() (wwibp < wwibq ? wwmaskc(*wwibp++) : -1) | |
237 | #define wwpeekc() (wwibp < wwibq ? wwmaskc(*wwibp) : -1) | |
b1189050 | 238 | #define wwungetc(c) (wwibp > wwib ? *--wwibp = (c) : -1) |
16078900 EW |
239 | |
240 | /* things for short circuiting wwiomux() */ | |
241 | char wwintr; /* interrupting */ | |
242 | char wwsetjmp; /* want a longjmp() from wwrint() and wwchild() */ | |
243 | jmp_buf wwjmpbuf; /* jmpbuf for above */ | |
244 | #define wwinterrupt() wwintr | |
77f9a432 EW |
245 | #define wwsetintr() do { wwintr = 1; if (wwsetjmp) longjmp(wwjmpbuf, 1); } \ |
246 | while (0) | |
16078900 | 247 | #define wwclrintr() (wwintr = 0) |
8fa6d94c | 248 | |
20849355 EW |
249 | /* checkpointing */ |
250 | int wwdocheckpoint; | |
251 | ||
7d77e730 | 252 | /* the window virtual terminal */ |
91b689b9 EW |
253 | #define WWT_TERM "window-v2" |
254 | #define WWT_TERMCAP "WW|window-v2|window program version 2:\ | |
cf28fdac EW |
255 | :am:bs:da:db:ms:pt:cr=^M:nl=^J:bl=^G:ta=^I:\ |
256 | :cm=\\EY%+ %+ :le=^H:nd=\\EC:up=\\EA:do=\\EB:ho=\\EH:\ | |
257 | :cd=\\EJ:ce=\\EK:cl=\\EE:me=\\Er^?:" | |
a6833679 EW |
258 | #define WWT_REV "se=\\ErA:so=\\EsA:mr=\\EsA:" |
259 | #define WWT_BLK "BE=\\ErB:BS=\\EsB:mb=\\EsB:" | |
260 | #define WWT_UL "ue=\\ErD:us=\\EsD:" | |
261 | #define WWT_GRP "ae=\\ErH:as=\\EsH:" | |
262 | #define WWT_DIM "HE=\\ErP:HS=\\EsP:mh=\\EsP:" | |
263 | #define WWT_USR "XE=\\Er`:XS=\\Es`:" | |
cf28fdac | 264 | #define WWT_ALDL "al=\\EL:dl=\\EM:" |
06c005f0 | 265 | #define WWT_IMEI "im=\\E@:ei=\\EO:ic=:mi:" /* XXX, ic for emacs bug */ |
07578449 | 266 | #define WWT_IC "ic=\\EP:" |
cf28fdac EW |
267 | #define WWT_DC "dc=\\EN:" |
268 | char wwwintermcap[1024]; /* terminal-specific but window-independent | |
269 | part of the window termcap */ | |
d1d76d41 EW |
270 | #ifdef TERMINFO |
271 | /* where to put the temporary terminfo directory */ | |
272 | char wwterminfopath[1024]; | |
273 | #endif | |
7d77e730 | 274 | |
0896e17e | 275 | /* our functions */ |
2b44d852 | 276 | struct ww *wwopen(); |
a50b4763 | 277 | void wwchild(); |
20849355 | 278 | void wwalarm(); |
d1d76d41 | 279 | void wwquit(); |
bb05dfb5 | 280 | char **wwalloc(); |
03e75950 | 281 | char *wwerror(); |
bb05dfb5 | 282 | |
0896e17e | 283 | /* c library functions */ |
bb05dfb5 EW |
284 | char *malloc(); |
285 | char *calloc(); | |
286 | char *getenv(); | |
287 | char *tgetstr(); | |
288 | char *rindex(); | |
289 | char *strcpy(); | |
290 | char *strcat(); | |
291 | ||
292 | #undef MIN | |
293 | #undef MAX | |
294 | #define MIN(x, y) ((x) > (y) ? (y) : (x)) | |
295 | #define MAX(x, y) ((x) > (y) ? (x) : (y)) |