xref: /titanic_52/usr/src/lib/libcurses/screen/curshdr.h (revision 174bc6499d233e329ecd3d98a880a7b07df16bfa)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 
23 /*
24  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  */
27 
28 /*	Copyright (c) 1988 AT&T	*/
29 /*	  All Rights Reserved	*/
30 
31 /*
32  * University Copyright- Copyright (c) 1982, 1986, 1988
33  * The Regents of the University of California
34  * All Rights Reserved
35  *
36  * University Acknowledgment- Portions of this document are derived from
37  * software developed by the University of California, Berkeley, and its
38  * contributors.
39  */
40 
41 #ifndef _CURSHDR_H
42 #define	_CURSHDR_H
43 
44 #pragma ident	"%Z%%M%	%I%	%E% SMI"
45 
46 #ifdef	__cplusplus
47 extern "C" {
48 #endif
49 
50 #define	_NOHASH		(-1)	/* if the hash value is unknown */
51 #define	_REDRAW		(-2)	/* if line need redrawn */
52 #define	_BLANK		(-3)	/* if line is blank */
53 #define	_THASH		(123)	/* base hash if clash with other hashes */
54 #define	_KEY		(01)
55 #define	_MACRO		(02)
56 
57 #define	_INPUTPENDING	cur_term->_iwait
58 #define	_PUTS(x, y)	(void) tputs(x, y, _outch)
59 #define	_VIDS(na, oa)	(vidupdate((na), (oa), _outch), curscr->_attrs = (na))
60 #define	_ONINSERT()	(_PUTS(enter_insert_mode, 1), SP->phys_irm = TRUE)
61 #define	_OFFINSERT()	(_PUTS(exit_insert_mode, 1), SP->phys_irm = FALSE)
62 #define	_STRNOTEQ(a, b)	(a == NULL ? (b != NULL) : \
63 			    (b == NULL ? 1 : strcmp(a, b)))
64 
65 /*
66  * IC and IL overheads and costs should be set to this
67  * value if the corresponding feature is missing
68  */
69 
70 #define	LARGECOST	500
71 
72 typedef	struct
73 {
74     short	icfixed;		/* Insert char fixed overhead */
75     short	dcfixed;		/* Delete char fixed overhead */
76     short	Insert_character;
77     short	Delete_character;
78     short	Cursor_home;
79     short	Cursor_to_ll;
80     short	Cursor_left;
81     short	Cursor_right;
82     short	Cursor_down;
83     short	Cursor_up;
84     short	Carriage_return;
85     short	Tab;
86     short	Back_tab;
87     short	Clr_eol;
88     short	Clr_bol;
89     short	Parm_ich;
90     short	Parm_dch;
91     short	Parm_left_cursor;
92     short	Parm_up_cursor;
93     short	Parm_down_cursor;
94     short	Parm_right_cursor;
95     short	Cursor_address;
96     short	Row_address;
97 } COSTS;
98 
99 #define	_COST(field)	(SP->term_costs.field)
100 
101 /* Soft label keys */
102 
103 #define	LABMAX	16	/* max number of labels allowed */
104 #define	LABLEN	8	/* max length of each label */
105 
106 typedef	struct
107 {
108     WINDOW	*_win;		/* the window to display labels */
109     char	_ldis[LABMAX][LABLEN+1]; /* labels suitable to display */
110     char	_lval[LABMAX][LABLEN+1]; /* labels' true values */
111     short	_labx[LABMAX];	/* where to display labels */
112     short	_num;		/* actual number of labels */
113     short	_len;		/* real length of labels */
114     bool	_changed;	/* TRUE if some labels changed */
115     bool	_lch[LABMAX];	/* change status */
116 } SLK_MAP;
117 
118 struct	screen
119 {
120     unsigned	fl_echoit : 1;	/* in software echo mode */
121     unsigned	fl_endwin : 2;	/* has called endwin */
122     unsigned	fl_meta : 1;	/* in meta mode */
123     unsigned	fl_nonl : 1;	/* do not xlate input \r-> \n */
124     unsigned	yesidln : 1;	/* has idln capabilities */
125     unsigned	dmode : 1;	/* Terminal has delete mode */
126     unsigned	imode : 1;	/* Terminal has insert mode */
127     unsigned	ichok : 1;	/* Terminal can insert characters */
128     unsigned	dchok : 1;	/* Terminal can delete characters */
129     unsigned	sid_equal : 1;	/* enter insert and delete mode equal */
130     unsigned	eid_equal : 1;	/* exit insert and delete mode equal */
131     unsigned	phys_irm : 1;	/* in insert mode or not */
132     long	baud;		/* baud rate of this tty */
133     short	kp_state;	/* 1 iff keypad is on, else 0 */
134     short	Yabove;		/* How many lines are above stdscr */
135     short	lsize;		/* How many lines decided by newscreen */
136     short	csize;		/* How many columns decided by newscreen */
137     short	tsize;		/* How big is a tab decided by newscreen */
138     WINDOW	*std_scr;	/* primary output screen */
139     WINDOW	*cur_scr;	/* what's physically on the screen */
140     WINDOW	*virt_scr;	/* what's virtually on the screen */
141     int		*cur_hash;	/* hash table of curscr */
142     int		*virt_hash;	/* hash table of virtscr */
143     TERMINAL	*tcap;		/* TERMINFO info */
144     FILE	*term_file;	/* File to write on for output. */
145     FILE	*input_file;	/* Where to get keyboard input */
146     SLK_MAP	*slk;		/* Soft label information */
147     char	**_mks;		/* marks, only used with xhp terminals */
148     COSTS	term_costs;	/* costs of various capabilities */
149     SGTTY	save_tty_buf;	/* saved termio state of this tty */
150 #ifdef	SYSV
151     SGTTYS	save_tty_bufs;	/* saved termios state of this tty */
152 #endif
153     char	**_color_mks;	/* marks, only used with color xhp terminals */
154     unsigned long  _trap_mbe;		/* trap these mouse button events    */
155     unsigned long  _map_mbe_to_key;	/* map selected buttons on top of    */
156 					/* slk's to function keys */
157 };
158 
159 extern	SCREEN	*SP;
160 extern	WINDOW	*_virtscr;
161 
162 #ifdef	DEBUG
163 #ifndef	outf
164 extern	FILE	*outf;
165 #endif	/* outf */
166 #endif	/* DEBUG */
167 
168 extern	short	cswidth[],	/* byte size of multi-byte chars */
169 		_curs_scrwidth[];	/* display size */
170 extern	short	_csmax,
171 		_scrmax;
172 extern	bool	_mbtrue;
173 
174 #define	MBIT		0200		/* indicator for a multi-byte char */
175 #define	CBIT		002000000000	/* indicator for a continuing col */
176 #define	RBYTE(x)	((x) & 0377)
177 #define	LBYTE(x)	(((x) >> 8) & 0177)
178 #define	ISMBIT(x)	((x) & MBIT)
179 #define	SETMBIT(x)	((x) |= MBIT)
180 #define	CLRMBIT(x)	((x) &= ~MBIT)
181 #define	ISCBIT(x)	((x) & CBIT)
182 #define	SETCBIT(x)	((x) |= CBIT)
183 #define	CLRCBIT(x)	((x) &= ~CBIT)
184 #define	TYPE(x)		((x) == SS2 ? 1 : (x) == SS3 ? 2 : ISMBIT(x) ? 0 : 3)
185 #define	TRIM		037777777777	/* 0xFFFFFFFF */
186 
187 /* terminfo magic number */
188 #define	MAGNUM	0432
189 
190 /* curses screen dump magic number */
191 #define	SVR2_DUMP_MAGIC_NUMBER	0433
192 #define	SVR3_DUMP_MAGIC_NUMBER	0434
193 
194 /* Getting the baud rate is different on the two systems. */
195 
196 #ifdef	SYSV
197 #define	_BR(x)	(x.c_cflag & CBAUD)
198 #define	_BRS(x)	(cfgetospeed(&x))
199 #include	<values.h>
200 #else	/* SYSV */
201 #define	BITSPERBYTE	8
202 #define	MAXINT		32767
203 #define	_BR(x)	(x.sg_ispeed)
204 #endif	/* SYSV */
205 
206 #define	_BLNKCHAR	' '
207 #define	_CTRL(c)	(c | 0100)
208 #define	_ATTR(c)	((c) & A_ATTRIBUTES)
209 #define	_CHAR(c)	((c) & A_CHARTEXT)
210 
211 /*
212  *	combine CHAR par of the character with the attributes of the window.
213  *	Two points: 1) If character is blank, usebackground instead
214  *		    2) If character contains color, delete color from
215  *			window attribute.
216  */
217 
218 #define	_WCHAR(w, c)    (_CHAR((c) == _BLNKCHAR ? (w)->_bkgd : (c))| \
219 			    (((c) & A_COLOR) ? ((w)->_attrs & ~A_COLOR) : \
220 			    ((w)->_attrs)))
221 
222 #define	_DARKCHAR(c)	((c) != _BLNKCHAR)
223 #define	_UNCTRL(c)	((c) ^ 0100)
224 
225 /* blank lines info of curscr */
226 #define	_BEGNS		curscr->_firstch
227 #define	_ENDNS		curscr->_lastch
228 
229 /* hash tables */
230 #define	_CURHASH	SP->cur_hash
231 #define	_VIRTHASH	SP->virt_hash
232 
233 /* top/bot line changed */
234 #define	_VIRTTOP	_virtscr->_parx
235 #define	_VIRTBOT	_virtscr->_pary
236 
237 /* video marks */
238 #define	_MARKS		SP->_mks
239 #define	_COLOR_MARKS	SP->_color_mks
240 
241 #define	_NUMELEMENTS(x)	(sizeof (x)/sizeof (x[0]))
242 
243 #ifdef	_VR3_COMPAT_CODE
244 /*
245  * #define	_TO_OCHTYPE(x)		((_ochtype)(((x&A_ATTRIBUTES)>>9)| \
246  * 						(x&0x0000007FUL)))
247  */
248 #define	_TO_OCHTYPE(x)		((_ochtype)(((x&A_ATTRIBUTES)>>9)|(x&0177)))
249 #define	_FROM_OCHTYPE(x)	((chtype) ((x&0177) | ((x&0177600)<<9)))
250 extern	void	(*_y16update)(WINDOW *, int, int, int, int);
251 #endif	/* _VR3_COMPAT_CODE */
252 
253 /* functions for screen updates */
254 
255 extern	int	(*_setidln)(void);
256 extern	int	(*_useidln)(void);
257 extern	int	(*_quick_ptr)(WINDOW *, chtype);
258 extern	int	(_quick_echo)(WINDOW *, chtype);
259 
260 /* min/max functions */
261 
262 #define	_MIN(a, b)	((a) < (b) ? (a) : (b))
263 #define	_MAX(a, b)	((a) > (b) ? (a) : (b))
264 
265 extern	int	(*_do_slk_ref)(void);
266 extern	int	(*_do_slk_tch)(void);
267 extern	int	(*_do_slk_noref)(void);
268 extern	int	_image(WINDOW *);
269 extern	int	_outch(char);
270 extern	int	_outwch(chtype);
271 extern	int	_chkinput(void);
272 extern	int	_curs_mbtowc(wchar_t *, const char *, size_t);
273 extern	int	_curs_wctomb(char *, wchar_t);
274 extern	int	_delay(int, int (*)(char));
275 extern	int	_mbaddch(WINDOW *, chtype, chtype);
276 extern	int	_mbclrch(WINDOW *, int, int);
277 extern	int	_mbinsshift(WINDOW *, int), _mbvalid(WINDOW *);
278 extern	int	_padjust(WINDOW *, int, int, int, int, int, int);
279 extern	int	_prefresh(int (*)(WINDOW *), WINDOW *, int, int, int,
280 		int, int, int);
281 extern	int	_overlap(WINDOW *, WINDOW *, int);
282 extern	int	_scr_all(char *, int);
283 extern	int	_slk_update(void);
284 extern	int	_tcsearch(char *, short [], char *[], int, int);
285 extern	int	_vsscanf(const char *, const char *, __va_list);
286 extern	int	force_doupdate(void);
287 extern	int	init_acs(void);
288 extern	int	mbscrw(int);
289 extern	int	mbeucw(int);
290 extern	int	scr_ll_dump(FILE *);
291 extern	int	scr_reset(FILE *, int);
292 extern	int	setkeymap(void);
293 extern	int	ttimeout(int);
294 extern	int	wadjcurspos(WINDOW *);
295 extern	int	wcscrw(wchar_t);
296 extern	int	wmbmove(WINDOW *, int, int);
297 
298 extern	chtype	tgetch(int);
299 
300 extern	WINDOW	*_makenew(int, int, int, int);
301 
302 extern	void	(*_slk_init)(void);
303 extern	void	(*_rip_init)(void);
304 extern	void	delkeymap(TERMINAL *);
305 extern	void	mbgetwidth(void);
306 extern	void	memSset(chtype *, chtype, int);
307 extern	void	_blast_keys(TERMINAL *);
308 extern	void	_init_costs(void);
309 extern	void	_init_HP_pair(short, short, short);
310 extern	void	_update_old_y_area(WINDOW *, int, int, int, int);
311 
312 extern	char    *tparm_p0(char *);
313 extern	char    *tparm_p1(char *, long);
314 extern	char    *tparm_p2(char *, long, long);
315 extern	char    *tparm_p3(char *, long, long, long);
316 extern	char    *tparm_p4(char *, long, long, long, long);
317 extern	char    *tparm_p7(char *, long, long, long, long, long, long, long);
318 
319 
320 extern	char	*infotocap(char *, int *);
321 extern	char	*_strcode2byte(wchar_t *, char *, int);
322 extern	char	*wmbinch(WINDOW *, int, int);
323 
324 #ifdef	__cplusplus
325 }
326 #endif
327 
328 #endif	/* _CURSHDR_H */
329