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