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