1 /* Copyright (c) 2010
2  *      Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
3  *      Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
4  * Copyright (c) 2008, 2009
5  *      Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
6  *      Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
7  *      Micah Cowan (micah@cowan.name)
8  *      Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
9  * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
10  *      Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
11  *      Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
12  * Copyright (c) 1987 Oliver Laumann
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3, or (at your option)
17  * any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program (see the file COPYING); if not, see
26  * https://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
27  * 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
28  *
29  ****************************************************************
30  * $Id$ GNU
31  */
32 
33 #ifndef SCREEN_WINDOW_H
34 #define SCREEN_WINDOW_H
35 
36 /* keep this in sync with the initialisations in window.c */
37 struct NewWindow
38 {
39   int	StartAt;	/* where to start the search for the slot */
40   char	*aka;		/* aka string */
41   char	**args;		/* argv vector */
42   char	*dir;		/* directory for chdir */
43   char	*term;		/* TERM to be set instead of "screen" */
44   int	aflag;
45   int   dynamicaka;
46   int	flowflag;
47   int	lflag;
48   int	histheight;
49   int	monitor;
50   int   wlock;		/* default writelock setting */
51   int	silence;
52   int   wrap;
53   int	Lflag;		/* logging */
54   int	slow;		/* inter character milliseconds */
55   int   gr;
56   int   c1;
57   int   bce;
58   int   encoding;
59   char	*hstatus;
60   char	*charset;
61   int	poll_zombie_timeout;
62 };
63 
64 #ifdef PSEUDOS
65 
66 struct pseudowin
67 {
68   int	p_fdpat;
69   int	p_pid;
70   int	p_ptyfd;
71   struct event p_readev;
72   struct event p_writeev;
73   char	p_cmd[MAXSTR];
74   char	p_tty[MAXSTR];
75   char	p_inbuf[IOSIZE];	/* buffered writing to p_ptyfd */
76   int	p_inlen;
77 };
78 
79 /* bits for fdpat: */
80 #define F_PMASK 	0x0003
81 #define F_PSHIFT	2
82 #define F_PFRONT	0x0001			/* . */
83 #define F_PBACK 	0x0002			/* ! */
84 #define F_PBOTH 	(F_PFRONT | F_PBACK)	/* : */
85 
86 #define F_UWP		0x1000			/* | */
87 
88 /* The screen process ...)
89  * ... wants to write to pseudo */
90 #define W_WP(w) ((w)->w_pwin && ((w)->w_pwin->p_fdpat & F_PFRONT))
91 
92 /* ... wants to write to window: user writes to window
93  * or stdout/stderr of pseudo are duplicated to window */
94 #define W_WW(w) (!((w)->w_pwin) || \
95 (((w)->w_pwin->p_fdpat & F_PMASK) == F_PBACK) || \
96 ((((w)->w_pwin->p_fdpat >> F_PSHIFT) & F_PMASK) == F_PBOTH) || \
97 ((((w)->w_pwin->p_fdpat >> (F_PSHIFT * 2)) & F_PMASK) == F_PBOTH))
98 
99 /* ... wants to read from pseudowin */
100 #define W_RP(w) ((w)->w_pwin && ((w)->w_pwin->p_fdpat & \
101 ((F_PFRONT << (F_PSHIFT * 2)) | (F_PFRONT << F_PSHIFT)) ))
102 
103 /* ... wants to read from window */
104 #define W_RW(w) (!((w)->w_pwin) || ((w)->w_pwin->p_fdpat & F_PFRONT))
105 
106 /* user input is written to pseudo */
107 #define W_UWP(w) ((w)->w_pwin && ((w)->w_pwin->p_fdpat & F_UWP))
108 
109 /* pseudo output has to be stuffed in window */
110 #define W_PTOW(w) (\
111 ((w)->w_pwin->p_fdpat & F_PMASK << F_PSHIFT) == F_PBOTH << F_PSHIFT || \
112 ((w)->w_pwin->p_fdpat & F_PMASK << F_PSHIFT * 2) == F_PBOTH << F_PSHIFT * 2 )
113 
114 /* window output has to be stuffed in pseudo */
115 #define W_WTOP(w) (((w)->w_pwin->p_fdpat & F_PMASK) == F_PBOTH)
116 
117 #endif /* PSEUDOS */
118 
119 /* definitions for wlocktype */
120 #define WLOCK_OFF	0	/* all in w_userbits can write */
121 #define WLOCK_AUTO	1	/* who selects first, can write */
122 #define WLOCK_ON	2	/* user writes even if deselected */
123 
124 
125 #ifdef COPY_PASTE
126 struct paster
127 {
128   char	*pa_pastebuf;		/* this gets pasted in the window */
129   char	*pa_pasteptr;		/* pointer in pastebuf */
130   int	 pa_pastelen;		/* bytes left to paste */
131   struct layer *pa_pastelayer;	/* layer to paste into */
132   struct event pa_slowev;	/* slowpaste event */
133 };
134 #else
135 struct paster;
136 #endif
137 
138 struct win
139 {
140   struct win *w_next;		/* next window */
141   int    w_type;		/* type of window */
142   void  *w_data;
143   struct layer w_layer;		/* our layer */
144   struct layer *w_savelayer;	/* the layer to keep */
145   int    w_blocked;		/* block input */
146 #ifdef PSEUDOS
147   struct pseudowin *w_pwin;	/* ptr to pseudo */
148 #endif
149   struct display *w_pdisplay;	/* display for printer relay */
150   struct display *w_lastdisp;	/* where the last input was made */
151   int	 w_number;		/* window number */
152   struct event w_readev;
153   struct event w_writeev;
154   struct event w_silenceev;	/* silence event */
155   struct event w_zombieev;	/* event to try to resurrect window */
156   int	 w_poll_zombie_timeout;
157   int	 w_ptyfd;		/* fd of the master pty */
158   char	 w_inbuf[IOSIZE];
159   int	 w_inlen;
160   char	 w_outbuf[IOSIZE];
161   int	 w_outlen;
162   int	 w_aflag;		/* (-a option) */
163   int	 w_dynamicaka;		/* should we change name */
164   char  *w_title;		/* name of the window */
165   char  *w_akachange;		/* autoaka hack */
166   char	 w_akabuf[MAXSTR];	/* aka buffer */
167   int	 w_autoaka;		/* autoaka hack */
168   struct win *w_group;		/* window group we belong to */
169   int	 w_intermediate;	/* char used while parsing ESC-seq */
170   int	 w_args[MAXARGS];	/* emulator args */
171   int	 w_NumArgs;
172 
173 #ifdef MULTIUSER
174   int    w_wlock;		/* WLOCK_AUTO, WLOCK_OFF, WLOCK_ON */
175   struct acluser *w_wlockuser;	/* NULL when unlocked or user who writes */
176   AclBits w_userbits[ACL_BITS_PER_WIN];
177   AclBits w_lio_notify;		/* whom to tell when lastio+seconds < time() */
178   AclBits w_mon_notify;		/* whom to tell monitor statis */
179 #endif
180 
181   enum state_t w_state;		/* parser state */
182   enum string_t w_StringType;
183   struct mline *w_mlines;
184   struct mchar w_rend;		/* current rendition */
185 #ifdef FONT
186   char	 w_FontL;		/* character font GL */
187   char	 w_FontR;		/* character font GR */
188 # ifdef ENCODINGS
189   char	 w_FontE;		/* character font GR locked */
190 # endif
191   int	 w_Charset;		/* charset number GL */
192   int	 w_CharsetR;		/* charset number GR */
193   int	 w_charsets[4];		/* Font = charsets[Charset] */
194 #endif
195   int	 w_ss;
196   struct cursor {
197     int on;
198     int	 x, y;
199     struct mchar Rend;
200 #ifdef FONT
201     int	 Charset;
202     int	 CharsetR;
203     int	 Charsets[4];
204 #endif
205   } w_saved;
206   int	 w_top, w_bot;		/* scrollregion */
207   int	 w_wrap;		/* autowrap */
208   int	 w_origin;		/* origin mode */
209   int	 w_insert;		/* window is in insert mode */
210   int	 w_keypad;		/* keypad mode */
211   int	 w_cursorkeys;		/* appl. cursorkeys mode */
212   int	 w_revvid;		/* reverse video */
213   int	 w_curinv;		/* cursor invisible */
214   int	 w_curvvis;		/* cursor very visible */
215   int	 w_autolf;		/* automatic linefeed */
216   char  *w_hstatus;		/* hardstatus line */
217   int	 w_gr;			/* enable GR flag */
218   int	 w_c1;			/* enable C1 flag */
219   int	 w_bce;			/* enable backcol erase */
220 #if 0
221   int    w_encoding;		/* for input and paste */
222 #endif
223   int    w_decodestate;		/* state of our input decoder */
224 #ifdef DW_CHARS
225   int    w_mbcs;		/* saved char for multibytes charset */
226 #endif
227   char	 w_string[MAXSTR];
228   char	*w_stringp;
229   char	*w_tabs;		/* line with tabs */
230   int	 w_bell;		/* bell status of this window */
231   int	 w_flow;		/* flow flags */
232   struct logfile *w_log;	/* log to file */
233   int    w_logsilence;		/* silence in secs */
234   int	 w_monitor;		/* monitor status */
235   int	 w_silencewait;		/* wait for silencewait secs */
236   int	 w_silence;		/* silence status (Lloyd Zusman) */
237   char	 w_vbwait;
238   char	 w_norefresh;		/* dont redisplay when switching to that win */
239 #ifdef RXVT_OSC
240   char	 w_xtermosc[5][2560];	/* special xterm/rxvt escapes */
241 #endif
242   int    w_mouse;		/* mouse mode 0,9,1000 */
243   int    w_extmouse;		/* extended mouse mode 0,1006 */
244 #ifdef HAVE_BRAILLE
245   int	 w_bd_x, w_bd_y;	/* Braille cursor position */
246 #endif
247 
248 #ifdef COPY_PASTE
249   int    w_slowpaste;		/* do careful writes to the window */
250   int	 w_histheight;		/* all histbases are malloced with width * histheight */
251   int	 w_histidx;		/* 0 <= histidx < histheight; where we insert lines */
252   int	 w_scrollback_height;	/* number of lines of output stored, to be updated with w_histidx, w_histheight */
253   struct mline *w_hlines;	/* history buffer */
254   struct paster w_paster;	/* paste info */
255 #else
256   int	 w_histheight;		/* always 0 */
257 #endif
258   int	 w_pid;			/* process at the other end of ptyfd */
259   int	 w_deadpid;		/* saved w_pid of a process that closed the ptyfd to us */
260 
261   char  *w_cmdargs[MAXARGS];	/* command line argument vector */
262   char	*w_dir;			/* directory for chdir */
263   char	*w_term;		/* TERM to be set instead of "screen" */
264 
265   int    w_lflag;		/* login flag */
266   slot_t w_slot;		/* utmp slot */
267 #if defined (UTMPOK)
268   struct utmp w_savut;		/* utmp entry of this window */
269 #endif
270 
271   char	 w_tty[MAXSTR];
272 
273   int    w_zauto;
274 #ifdef ZMODEM
275   struct display *w_zdisplay;
276 #endif
277 #ifdef BUILTIN_TELNET
278   struct sockaddr_storage w_telsa;
279   char   w_telbuf[IOSIZE];
280   int    w_telbufl;
281   char   w_telmopts[256];
282   char   w_telropts[256];
283   int    w_telstate;
284   char   w_telsubbuf[128];
285   int    w_telsubidx;
286   struct event w_telconnev;
287 #endif
288   struct {
289     int    on;    /* Is the alternate buffer currently being used? */
290     struct mline *mlines;
291     int    width;
292     int    height;
293 #ifdef COPY_PASTE
294     int    histheight;
295     struct mline *hlines;
296     int    histidx;
297 #else
298     int histheight;	/* 0 */
299 #endif
300     struct cursor cursor;
301   } w_alt;
302 
303   struct event w_destroyev;	/* window destroy event */
304 #ifdef BSDWAIT
305   union wait w_exitstatus;	/* window exit status */
306 #else
307   int w_exitstatus;
308 #endif
309 };
310 
311 
312 #define w_encoding   w_layer.l_encoding
313 #define w_width  w_layer.l_width
314 #define w_height w_layer.l_height
315 #define w_x      w_layer.l_x
316 #define w_y      w_layer.l_y
317 
318 /* definitions for w_type */
319 #define W_TYPE_PTY		0
320 #define W_TYPE_PLAIN		1
321 #define W_TYPE_TELNET		2
322 #define W_TYPE_GROUP		3
323 
324 
325 /*
326  * Definitions for flow
327  *   000  -(-)	flow off, auto would be off
328  *   001  +(-)	flow on , auto would be off
329  *   010  -(+)	flow off, auto would be on
330  *   011  +(+)	flow on , auto would be on
331  *   100  -	flow auto, currently off
332  *   111  +	flow auto, currently on
333  * Application controls auto_flow via TIOCPKT, if available,
334  * else via application keypad mode.
335  */
336 #define FLOW_NOW	(1<<0)
337 #define FLOW_AUTO	(1<<1)
338 #define FLOW_AUTOFLAG	(1<<2)
339 
340 
341 /*
342  * WIN gives us a reference to line y of the *whole* image
343  * where line 0 is the oldest line in our history.
344  * y must be in whole image coordinate system, not in display.
345  */
346 
347 #define WIN(y) ((y < fore->w_histheight) ? \
348       &fore->w_hlines[(fore->w_histidx + y) % fore->w_histheight] \
349     : &fore->w_mlines[y - fore->w_histheight])
350 
351 #define Layer2Window(l) ((struct win *)(l)->l_bottom->l_data)
352 
353 int WindowChangeNumber __P((int, int));
354 int OpenDevice __P((char **, int, int *, char **));
355 
356 #endif /* SCREEN_WINDOW_H */
357 
358