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