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