add log device ; unused reset routines are nulldev
[unix-history] / usr / src / usr.bin / window / ww.h
CommitLineData
bb05dfb5 1/*
7edc52ec 2 * @(#)ww.h 3.33 %G%
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 11struct 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
19struct ww_pos {
20 int r; /* row */
21 int c; /* column */
c417b691
EW
22};
23
b47565d0 24 /* the window structure */
0edb449f 25struct ww {
0e64e422 26 /* information for overlap */
bb05dfb5
EW
27 struct ww *ww_forw; /* doubly linked list, for overlapping info */
28 struct ww *ww_back;
0e64e422
EW
29 char ww_state; /* state of window */
30 char ww_index; /* the window index, for wwindex[] */
bb05dfb5 31 char ww_order; /* the overlapping order */
f2a77fe1
EW
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 */
19f9784c 36 struct ww_dim ww_i; /* the part inside the screen */
bb05dfb5 37 struct ww_pos ww_cur; /* the cursor position, relative to ww_w */
f2a77fe1
EW
38
39 /* arrays */
bb05dfb5
EW
40 char **ww_win; /* the window */
41 union ww_char **ww_buf; /* the buffer */
2357b64e 42 char **ww_fmap; /* map for frame and box windows */
bb05dfb5 43 short *ww_nvis; /* how many ww_buf chars are visible per row */
f2a77fe1 44
0e64e422
EW
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
b1189050 56 /* things for the window process and io */
7ecf4dca
EW
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 */
bb05dfb5 61 int ww_pid; /* pid of process, if WWS_HASPROC true */
0896e17e 62 char ww_ttyname[11]; /* "/dev/ttyp?" */
8fa6d94c
EW
63 char *ww_ob; /* output buffer */
64 char *ww_obe; /* end of ww_ob */
7ecf4dca
EW
65 char *ww_obp; /* current read position in ww_ob */
66 char *ww_obq; /* current write position in ww_ob */
f176f953
EW
67
68 /* things for the user, they really don't belong here */
b1189050 69 char ww_center; /* center the label */
0e64e422 70 char ww_id; /* the user window id */
bb05dfb5 71 char *ww_label; /* the user supplied label */
f176f953 72 struct ww_pos ww_altpos;/* alternate position */
4711df8b
EW
73};
74
b47565d0 75 /* state of a tty */
4711df8b 76struct ww_tty {
0edb449f
EW
77 struct sgttyb ww_sgttyb;
78 struct tchars ww_tchars;
79 struct ltchars ww_ltchars;
80 int ww_lmode;
81 int ww_ldisc;
b1189050 82 int ww_fflags;
0edb449f
EW
83};
84
0896e17e
EW
85union ww_char {
86 short c_w; /* as a word */
87 struct {
d99cae10 88#ifndef mc68000
0896e17e
EW
89 char C_c; /* the character part */
90 char C_m; /* the mode part */
a6fccdf5
EW
91#else
92 char C_m; /* the mode part */
93 char C_c; /* the character part */
94#endif
0896e17e
EW
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 */
a830e8bb 109#define WWM_GRP 0x08 /* graphics */
0896e17e 110#define WWM_GLS 0x10 /* window only, glass, i.e. transparent */
0896e17e
EW
111
112 /* ww_state values */
113#define WWS_INITIAL 0 /* just opened */
b47565d0 114#define WWS_HASPROC 1 /* has process on pty */
0896e17e
EW
115#define WWS_DEAD 3 /* child died */
116
2357b64e 117 /* flags for ww_fmap */
0896e17e
EW
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
2357b64e
EW
126 /* flags to wwopen() */
127#define WWO_PTY 0x01 /* want pty */
7ecf4dca
EW
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 */
2357b64e 132
0896e17e
EW
133 /* special ww_index value */
134#define WWX_NOBODY NWW
135
04d70db4 136 /* error codes */
03e75950
EW
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
04d70db4
EW
146 /* wwtouched[] bits */
147#define WWU_TOUCHED 0x01 /* touched */
148#define WWU_MAJOR 0x02 /* major change */
149
8fa6d94c 150 /* the window structures */
bb05dfb5 151struct ww wwhead;
0896e17e 152struct ww *wwindex[NWW + 1]; /* last location is for wwnobody */
bb05dfb5 153struct ww wwnobody;
2b44d852 154
8fa6d94c 155 /* tty things */
0896e17e
EW
156struct ww_tty wwoldtty; /* the old (saved) terminal settings */
157struct ww_tty wwnewtty; /* the new (current) terminal settings */
158struct ww_tty wwwintty; /* the terminal settings for windows */
159char *wwterm; /* the terminal name */
160char wwtermcap[1024]; /* place for the termcap */
161char wwkeys[512]; /* termcap fields for the function keys */
4222244b 162char wwwintermcap[1024]; /* termcap for windows */
bb05dfb5 163
8fa6d94c 164 /* generally useful variables */
bb05dfb5 165int wwnrow, wwncol; /* the screen size */
7d77e730 166char wwavailmodes; /* actually supported modes */
73218728 167char wwcursormodes; /* the modes for the fake cursor */
5e785082 168char wwwrap; /* terminal has auto wrap around */
0896e17e 169int wwdtablesize; /* result of getdtablesize() call */
bb05dfb5 170char **wwsmap; /* the screen map */
0896e17e
EW
171union ww_char **wwos; /* the old (current) screen */
172union ww_char **wwns; /* the new (desired) screen */
861cd1ed 173char *wwtouched; /* wwns changed flags */
0896e17e
EW
174int wwbaudmap[]; /* maps stty() baud rate code into number */
175int wwbaud; /* wwbaudmap[wwoldtty.ww_sgttyb.sg_ospeed] */
176int wwcursorrow, wwcursorcol; /* where we want the cursor to be */
03e75950 177int wwerrno; /* error number */
0edb449f 178
bb05dfb5 179 /* statistics */
b1189050
EW
180int wwnflush, wwnwr, wwnwre, wwnwrz, wwnwrc;
181int wwnwwr, wwnwwra, wwnwwrc;
04d70db4 182int wwnupdate, wwnupdline, wwnupdmiss, wwnmajline, wwnmajmiss;
8fa6d94c
EW
183int wwnread, wwnreade, wwnreadz, wwnreadc;
184int wwnwread, wwnwreade, wwnwreadz, wwnwreadd, wwnwreadc, wwnwreadp;
185int wwnselect, wwnselecte, wwnselectz;
0edb449f 186
0896e17e 187 /* quicky macros */
bb05dfb5 188#define wwsetcursor(r,c) (wwcursorrow = (r), wwcursorcol = (c))
f2a77fe1 189#define wwcurtowin(w) wwsetcursor((w)->ww_cur.r, (w)->ww_cur.c)
2357b64e 190#define wwunbox(w) wwunframe(w)
f2a77fe1 191#define wwclreol(w,r,c) wwclreol1((w), (r), (c), 0)
86697c44 192#define wwredrawwin(w) wwredrawwin1((w), (w)->ww_i.t, (w)->ww_i.b, 0)
b1189050 193#define wwupdate() wwupdate1(0, wwnrow);
2b44d852 194
8fa6d94c 195 /* things for handling input */
b1189050
EW
196int wwrint(); /* interrupt handler */
197struct ww *wwcurwin; /* window to copy input into */
198char wwsetjmp; /* want a longjmp() from wwrint() */
199jmp_buf wwjmpbuf; /* jmpbuf for above */
8fa6d94c
EW
200char *wwib; /* input (keyboard) buffer */
201char *wwibe; /* wwib + sizeof buffer */
b1189050
EW
202char *wwibp; /* current read position in buffer */
203char *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)
8fa6d94c 208
7d77e730
EW
209 /* the window virtual terminal */
210#define WWT_TERM "TERM=window"
a598c465 211#define WWT_TERMCAP "WW|window|window package:\
7d77e730 212 :cr=^M:nl=^J:bl=^G:\
a598c465
EW
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:\
7d77e730
EW
215 :nd=\\EC:ta=^I:pt:up=\\EA:"
216#define WWT_REV "se=\\Eq:so=\\Ep:"
217#define WWT_UL "ue=\\Es:us=\\Er:"
78be6843 218#define WWT_GRP "ae=\\EG:as=\\EF:"
7d77e730 219
0896e17e 220 /* our functions */
2b44d852 221struct ww *wwopen();
2b44d852 222int wwchild();
bb05dfb5 223int wwsuspend();
bb05dfb5 224char **wwalloc();
03e75950 225char *wwerror();
bb05dfb5 226
0896e17e 227 /* c library functions */
bb05dfb5
EW
228char *malloc();
229char *calloc();
230char *getenv();
231char *tgetstr();
232char *rindex();
233char *strcpy();
234char *strcat();
b1189050 235char *sprintf();
bb05dfb5
EW
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
eec72f58 242#define sigmask(s) (1 << (s) - 1)