Force the initialization of fd in all cases (from Keith Muller)
[unix-history] / usr / src / usr.bin / window / ww.h
CommitLineData
bb05dfb5 1/*
4c049d16 2 * @(#)ww.h 3.37 %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 */
bb05dfb5 80 char *ww_label; /* the user supplied label */
b27a9cfb 81 struct ww_dim ww_alt; /* alternate position and size */
4711df8b
EW
82};
83
b47565d0 84 /* state of a tty */
4711df8b 85struct ww_tty {
0edb449f
EW
86 struct sgttyb ww_sgttyb;
87 struct tchars ww_tchars;
88 struct ltchars ww_ltchars;
89 int ww_lmode;
90 int ww_ldisc;
b1189050 91 int ww_fflags;
0edb449f
EW
92};
93
0896e17e
EW
94union ww_char {
95 short c_w; /* as a word */
96 struct {
d99cae10 97#ifndef mc68000
0896e17e
EW
98 char C_c; /* the character part */
99 char C_m; /* the mode part */
a6fccdf5
EW
100#else
101 char C_m; /* the mode part */
102 char C_c; /* the character part */
103#endif
0896e17e
EW
104 } c_un;
105};
106#define c_c c_un.C_c
107#define c_m c_un.C_m
108
109 /* parts of ww_char */
110#define WWC_CMASK 0x00ff
111#define WWC_MMASK 0xff00
112#define WWC_MSHIFT 8
113
114 /* c_m bits */
115#define WWM_REV 0x01 /* reverse video */
116#define WWM_BLK 0x02 /* blinking */
117#define WWM_UL 0x04 /* underlined */
a830e8bb 118#define WWM_GRP 0x08 /* graphics */
0896e17e 119#define WWM_GLS 0x10 /* window only, glass, i.e. transparent */
0896e17e
EW
120
121 /* ww_state values */
122#define WWS_INITIAL 0 /* just opened */
b47565d0 123#define WWS_HASPROC 1 /* has process on pty */
0896e17e
EW
124#define WWS_DEAD 3 /* child died */
125
2357b64e 126 /* flags for ww_fmap */
0896e17e
EW
127#define WWF_U 0x01
128#define WWF_R 0x02
129#define WWF_D 0x04
130#define WWF_L 0x08
131#define WWF_MASK (WWF_U|WWF_R|WWF_D|WWF_L)
132#define WWF_LABEL 0x40
133#define WWF_TOP 0x80
134
2357b64e
EW
135 /* flags to wwopen() */
136#define WWO_PTY 0x01 /* want pty */
7ecf4dca
EW
137#define WWO_SOCKET 0x02 /* want socket pair */
138#define WWO_REVERSE 0x04 /* make it all reverse video */
139#define WWO_GLASS 0x08 /* make it all glass */
140#define WWO_FRAME 0x10 /* this is a frame window */
2357b64e 141
0896e17e
EW
142 /* special ww_index value */
143#define WWX_NOBODY NWW
144
04d70db4 145 /* error codes */
03e75950
EW
146#define WWE_NOERR 0
147#define WWE_SYS 1 /* system error */
148#define WWE_NOMEM 2 /* out of memory */
149#define WWE_TOOMANY 3 /* too many windows */
150#define WWE_NOPTY 4 /* no more ptys */
151#define WWE_SIZE 5 /* bad window size */
152#define WWE_BADTERM 6 /* bad terminal type */
153#define WWE_CANTDO 7 /* dumb terminal */
154
04d70db4
EW
155 /* wwtouched[] bits */
156#define WWU_TOUCHED 0x01 /* touched */
157#define WWU_MAJOR 0x02 /* major change */
158
8fa6d94c 159 /* the window structures */
bb05dfb5 160struct ww wwhead;
0896e17e 161struct ww *wwindex[NWW + 1]; /* last location is for wwnobody */
bb05dfb5 162struct ww wwnobody;
2b44d852 163
8fa6d94c 164 /* tty things */
0896e17e
EW
165struct ww_tty wwoldtty; /* the old (saved) terminal settings */
166struct ww_tty wwnewtty; /* the new (current) terminal settings */
167struct ww_tty wwwintty; /* the terminal settings for windows */
168char *wwterm; /* the terminal name */
169char wwtermcap[1024]; /* place for the termcap */
170char wwkeys[512]; /* termcap fields for the function keys */
4222244b 171char wwwintermcap[1024]; /* termcap for windows */
bb05dfb5 172
8fa6d94c 173 /* generally useful variables */
bb05dfb5 174int wwnrow, wwncol; /* the screen size */
7d77e730 175char wwavailmodes; /* actually supported modes */
73218728 176char wwcursormodes; /* the modes for the fake cursor */
5e785082 177char wwwrap; /* terminal has auto wrap around */
0896e17e 178int wwdtablesize; /* result of getdtablesize() call */
bb05dfb5 179char **wwsmap; /* the screen map */
0896e17e
EW
180union ww_char **wwos; /* the old (current) screen */
181union ww_char **wwns; /* the new (desired) screen */
861cd1ed 182char *wwtouched; /* wwns changed flags */
0896e17e
EW
183int wwbaudmap[]; /* maps stty() baud rate code into number */
184int wwbaud; /* wwbaudmap[wwoldtty.ww_sgttyb.sg_ospeed] */
185int wwcursorrow, wwcursorcol; /* where we want the cursor to be */
03e75950 186int wwerrno; /* error number */
0edb449f 187
bb05dfb5 188 /* statistics */
b1189050
EW
189int wwnflush, wwnwr, wwnwre, wwnwrz, wwnwrc;
190int wwnwwr, wwnwwra, wwnwwrc;
04d70db4 191int wwnupdate, wwnupdline, wwnupdmiss, wwnmajline, wwnmajmiss;
8fa6d94c
EW
192int wwnread, wwnreade, wwnreadz, wwnreadc;
193int wwnwread, wwnwreade, wwnwreadz, wwnwreadd, wwnwreadc, wwnwreadp;
194int wwnselect, wwnselecte, wwnselectz;
0edb449f 195
0896e17e 196 /* quicky macros */
bb05dfb5 197#define wwsetcursor(r,c) (wwcursorrow = (r), wwcursorcol = (c))
f2a77fe1 198#define wwcurtowin(w) wwsetcursor((w)->ww_cur.r, (w)->ww_cur.c)
2357b64e 199#define wwunbox(w) wwunframe(w)
f2a77fe1 200#define wwclreol(w,r,c) wwclreol1((w), (r), (c), 0)
86697c44 201#define wwredrawwin(w) wwredrawwin1((w), (w)->ww_i.t, (w)->ww_i.b, 0)
b1189050 202#define wwupdate() wwupdate1(0, wwnrow);
2b44d852 203
8fa6d94c 204 /* things for handling input */
b1189050
EW
205int wwrint(); /* interrupt handler */
206struct ww *wwcurwin; /* window to copy input into */
207char wwsetjmp; /* want a longjmp() from wwrint() */
208jmp_buf wwjmpbuf; /* jmpbuf for above */
8fa6d94c
EW
209char *wwib; /* input (keyboard) buffer */
210char *wwibe; /* wwib + sizeof buffer */
b1189050
EW
211char *wwibp; /* current read position in buffer */
212char *wwibq; /* current write position in buffer */
213#define wwgetc() (wwibp < wwibq ? *wwibp++ & 0x7f : -1)
214#define wwpeekc() (wwibp < wwibq ? *wwibp & 0x7f : -1)
215#define wwungetc(c) (wwibp > wwib ? *--wwibp = (c) : -1)
216#define wwinterrupt() (wwibp < wwibq)
8fa6d94c 217
7d77e730
EW
218 /* the window virtual terminal */
219#define WWT_TERM "TERM=window"
a598c465 220#define WWT_TERMCAP "WW|window|window package:\
7d77e730 221 :cr=^M:nl=^J:bl=^G:\
a598c465
EW
222 :al=\\EL:am:le=^H:bs:cd=\\EJ:ce=\\EK:cl=\\EE:cm=\\EY%+ %+ :\
223 :da:db:dc=\\EN:dl=\\EM:do=\\EB:ei=\\EO:ho=\\EH:im=\\E@:mi:\
7d77e730
EW
224 :nd=\\EC:ta=^I:pt:up=\\EA:"
225#define WWT_REV "se=\\Eq:so=\\Ep:"
226#define WWT_UL "ue=\\Es:us=\\Er:"
78be6843 227#define WWT_GRP "ae=\\EG:as=\\EF:"
7d77e730 228
0896e17e 229 /* our functions */
2b44d852 230struct ww *wwopen();
2b44d852 231int wwchild();
bb05dfb5 232int wwsuspend();
bb05dfb5 233char **wwalloc();
03e75950 234char *wwerror();
bb05dfb5 235
0896e17e 236 /* c library functions */
bb05dfb5
EW
237char *malloc();
238char *calloc();
239char *getenv();
240char *tgetstr();
241char *rindex();
242char *strcpy();
243char *strcat();
b1189050 244char *sprintf();
bb05dfb5
EW
245
246#undef MIN
247#undef MAX
248#define MIN(x, y) ((x) > (y) ? (y) : (x))
249#define MAX(x, y) ((x) > (y) ? (x) : (y))