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