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