make l_window() accept "*" again
[unix-history] / usr / src / usr.bin / window / ww.h
CommitLineData
bb05dfb5 1/*
04d70db4 2 * @(#)ww.h 3.21 83/12/02
bb05dfb5 3 */
0edb449f 4
4711df8b 5#include <stdio.h>
0edb449f 6#include <sgtty.h>
bb05dfb5
EW
7
8#define NWW 30
0edb449f 9
c417b691 10struct ww_dim {
bb05dfb5
EW
11 int nr; /* number of rows */
12 int nc; /* number of columns */
13 int t, b; /* top, bottom */
14 int l, r; /* left, right */
15};
16
17struct ww_pos {
18 int r; /* row */
19 int c; /* column */
c417b691
EW
20};
21
0edb449f 22struct ww {
bb05dfb5
EW
23 struct ww *ww_forw; /* doubly linked list, for overlapping info */
24 struct ww *ww_back;
2b44d852 25 char ww_state; /* state of window creation */
2b44d852 26 char ww_wstate; /* state for printing charcters */
7d77e730
EW
27 char ww_modes; /* current printing modes */
28 char ww_insert :1; /* insert mode, for printing */
29 char ww_mapnl :1; /* map \n to \r\n */
73218728 30 char ww_hascursor :1; /* has fake cursor */
c04e1ce2 31 char ww_hasframe :1; /* frame it */
bb05dfb5
EW
32 char ww_index; /* the index, for wwindex[] */
33 char ww_order; /* the overlapping order */
f2a77fe1
EW
34
35 /* sizes and positions */
36 struct ww_dim ww_w; /* window size and pos */
37 struct ww_dim ww_b; /* buffer size and pos */
19f9784c 38 struct ww_dim ww_i; /* the part inside the screen */
bb05dfb5 39 struct ww_pos ww_cur; /* the cursor position, relative to ww_w */
f2a77fe1
EW
40
41 /* arrays */
bb05dfb5
EW
42 char **ww_win; /* the window */
43 union ww_char **ww_buf; /* the buffer */
2357b64e 44 char **ww_fmap; /* map for frame and box windows */
bb05dfb5 45 short *ww_nvis; /* how many ww_buf chars are visible per row */
f2a77fe1 46
f176f953 47 /* things for the window process */
bb05dfb5 48 int ww_pty; /* file descriptor of pty */
bb05dfb5 49 int ww_pid; /* pid of process, if WWS_HASPROC true */
0896e17e 50 char ww_ttyname[11]; /* "/dev/ttyp?" */
f176f953
EW
51
52 /* things for the user, they really don't belong here */
bb05dfb5 53 char ww_center :1; /* center the label */
f176f953 54 int ww_id; /* the user window id */
bb05dfb5 55 char *ww_label; /* the user supplied label */
f176f953 56 struct ww_pos ww_altpos;/* alternate position */
4711df8b
EW
57};
58
59struct ww_tty {
0edb449f
EW
60 struct sgttyb ww_sgttyb;
61 struct tchars ww_tchars;
62 struct ltchars ww_ltchars;
63 int ww_lmode;
64 int ww_ldisc;
65 int ww_pgrp;
0edb449f
EW
66};
67
0896e17e
EW
68union ww_char {
69 short c_w; /* as a word */
70 struct {
a6fccdf5 71#ifndef O_SUN
0896e17e
EW
72 char C_c; /* the character part */
73 char C_m; /* the mode part */
a6fccdf5
EW
74#else
75 char C_m; /* the mode part */
76 char C_c; /* the character part */
77#endif
0896e17e
EW
78 } c_un;
79};
80#define c_c c_un.C_c
81#define c_m c_un.C_m
82
83 /* parts of ww_char */
84#define WWC_CMASK 0x00ff
85#define WWC_MMASK 0xff00
86#define WWC_MSHIFT 8
87
88 /* c_m bits */
89#define WWM_REV 0x01 /* reverse video */
90#define WWM_BLK 0x02 /* blinking */
91#define WWM_UL 0x04 /* underlined */
92#define WWM_GLS 0x10 /* window only, glass, i.e. transparent */
0896e17e
EW
93
94 /* ww_state values */
95#define WWS_INITIAL 0 /* just opened */
96#define WWS_HASPROC 1 /* forked, in parent */
97#define WWS_INCHILD 2 /* forked, in child */
98#define WWS_DEAD 3 /* child died */
99
2357b64e 100 /* flags for ww_fmap */
0896e17e
EW
101#define WWF_U 0x01
102#define WWF_R 0x02
103#define WWF_D 0x04
104#define WWF_L 0x08
105#define WWF_MASK (WWF_U|WWF_R|WWF_D|WWF_L)
106#define WWF_LABEL 0x40
107#define WWF_TOP 0x80
108
2357b64e
EW
109 /* flags to wwopen() */
110#define WWO_PTY 0x01 /* want pty */
111#define WWO_REVERSE 0x02 /* make it all reverse video */
112#define WWO_GLASS 0x04 /* make it all glass */
113#define WWO_FRAME 0x08 /* this is a frame window */
114
0896e17e
EW
115 /* special ww_index value */
116#define WWX_NOBODY NWW
117
04d70db4 118 /* error codes */
03e75950
EW
119#define WWE_NOERR 0
120#define WWE_SYS 1 /* system error */
121#define WWE_NOMEM 2 /* out of memory */
122#define WWE_TOOMANY 3 /* too many windows */
123#define WWE_NOPTY 4 /* no more ptys */
124#define WWE_SIZE 5 /* bad window size */
125#define WWE_BADTERM 6 /* bad terminal type */
126#define WWE_CANTDO 7 /* dumb terminal */
127
04d70db4
EW
128 /* wwtouched[] bits */
129#define WWU_TOUCHED 0x01 /* touched */
130#define WWU_MAJOR 0x02 /* major change */
131
bb05dfb5 132struct ww wwhead;
0896e17e 133struct ww *wwindex[NWW + 1]; /* last location is for wwnobody */
bb05dfb5 134struct ww wwnobody;
2b44d852 135
0896e17e
EW
136struct ww_tty wwoldtty; /* the old (saved) terminal settings */
137struct ww_tty wwnewtty; /* the new (current) terminal settings */
138struct ww_tty wwwintty; /* the terminal settings for windows */
139char *wwterm; /* the terminal name */
140char wwtermcap[1024]; /* place for the termcap */
141char wwkeys[512]; /* termcap fields for the function keys */
bb05dfb5 142
bb05dfb5 143int wwnrow, wwncol; /* the screen size */
7d77e730 144char wwavailmodes; /* actually supported modes */
73218728 145char wwcursormodes; /* the modes for the fake cursor */
5e785082 146char wwwrap; /* terminal has auto wrap around */
0896e17e 147int wwdtablesize; /* result of getdtablesize() call */
bb05dfb5 148char **wwsmap; /* the screen map */
0896e17e
EW
149union ww_char **wwos; /* the old (current) screen */
150union ww_char **wwns; /* the new (desired) screen */
861cd1ed 151char *wwtouched; /* wwns changed flags */
0896e17e
EW
152int wwbaudmap[]; /* maps stty() baud rate code into number */
153int wwbaud; /* wwbaudmap[wwoldtty.ww_sgttyb.sg_ospeed] */
154int wwcursorrow, wwcursorcol; /* where we want the cursor to be */
03e75950 155int wwerrno; /* error number */
0edb449f 156
bb05dfb5 157 /* statistics */
861cd1ed 158int wwnwrite, wwnwritec;
04d70db4 159int wwnupdate, wwnupdline, wwnupdmiss, wwnmajline, wwnmajmiss;
0edb449f 160
0896e17e 161 /* quicky macros */
bb05dfb5 162#define wwsetcursor(r,c) (wwcursorrow = (r), wwcursorcol = (c))
f2a77fe1 163#define wwcurtowin(w) wwsetcursor((w)->ww_cur.r, (w)->ww_cur.c)
bb05dfb5 164#define wwbell() putchar(CTRL(g))
2357b64e 165#define wwunbox(w) wwunframe(w)
f2a77fe1 166#define wwclreol(w,r,c) wwclreol1((w), (r), (c), 0)
86697c44 167#define wwredrawwin(w) wwredrawwin1((w), (w)->ww_i.t, (w)->ww_i.b, 0)
2b44d852 168
7d77e730
EW
169 /* the window virtual terminal */
170#define WWT_TERM "TERM=window"
a598c465 171#define WWT_TERMCAP "WW|window|window package:\
7d77e730 172 :cr=^M:nl=^J:bl=^G:\
a598c465
EW
173 :al=\\EL:am:le=^H:bs:cd=\\EJ:ce=\\EK:cl=\\EE:cm=\\EY%+ %+ :\
174 :da:db:dc=\\EN:dl=\\EM:do=\\EB:ei=\\EO:ho=\\EH:im=\\E@:mi:\
7d77e730
EW
175 :nd=\\EC:ta=^I:pt:up=\\EA:"
176#define WWT_REV "se=\\Eq:so=\\Ep:"
177#define WWT_UL "ue=\\Es:us=\\Er:"
178
0896e17e 179 /* our functions */
2b44d852
EW
180struct ww *wwopen();
181struct ww *wwfind();
182int wwchild();
bb05dfb5 183int wwsuspend();
27fd1bda 184char *unctrl();
bb05dfb5 185char **wwalloc();
03e75950 186char *wwerror();
bb05dfb5 187
0896e17e 188 /* c library functions */
bb05dfb5
EW
189char *malloc();
190char *calloc();
191char *getenv();
192char *tgetstr();
193char *rindex();
194char *strcpy();
195char *strcat();
196
197#undef MIN
198#undef MAX
199#define MIN(x, y) ((x) > (y) ? (y) : (x))
200#define MAX(x, y) ((x) > (y) ? (x) : (y))
201
202#undef CTRL
203#define CTRL(c) ('c'&0x1f)
204#define DEL 0x7f
205#define ISCTRL(c) ((c) < ' ' || (c) >= DEL)
57fc9db6
EW
206
207#if defined(O_4_1A)||defined(O_4_1C)
208int (*sigset)();
209#define signal(s, v) sigset((s), (v))
eec72f58
EW
210#else
211#define sigmask(s) (1 << (s) - 1)
212#define sighold(s) sigblock(sigmask(s))
213#define sigrelse(s) sigsetmask(sigblock(0) & ~sigmask(s))
57fc9db6 214#endif