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