1 /*-
2  * Copyright (c) 1988 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *	This product includes software developed by the University of
16  *	California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  *	@(#)terminal.h	4.3 (Berkeley) 4/26/91
34  */
35 
36 #define	INCLUDED_TERMINAL
37 
38 /*
39  * In the situation where we have a copy of the terminal screen in front
40  * of us, here are some macros to deal with them.
41  */
42 
43 #define TermAttributes(x)	(TermIsStartField(x)? GetTerminal(x)&0xff : \
44 				    GetTerminal(WhereTermAttrByte(x))&0xff)
45 #define TermIsStartField(x)	((GetTerminal(x)&ATTR_MASK) == ATTR_MASK)
46 #define TermNewField(p,a)	SetTerminal(p, (a)|ATTR_MASK)
47 #define TermDeleteField(p)	SetTerminal(p, 0)
48 #define TermIsNonDisplay(x)	\
49 		    ((TermAttributes(x)&ATTR_DSPD_MASK) == ATTR_DSPD_NONDISPLAY)
50 #define TermIsHighlighted(x) \
51 		(((TermAttributes(x)&ATTR_DSPD_MASK) == ATTR_DSPD_HIGH) \
52 				    && !TermIsStartField(x))
53 
54 #define TerminalCharacterAttr(c,p,a)	(IsNonDisplayAttr(a) ? ' ':c)
55 #define TerminalCharacter(c,p)	TerminalCharacterAttr(c,p,FieldAttributes(p))
56 
57 	/*
58 	 * Is the screen formatted?  Some algorithms change depending
59 	 * on whether there are any attribute bytes lying around.
60 	 */
61 #define	TerminalFormattedScreen() \
62 	    ((WhereTermAttrByte(0) != 0) || ((GetTerminal(0)&ATTR_MASK) == ATTR_MASK))
63 
64 #define NeedToRedisplayFields(p) ((TermIsNonDisplay(p) != IsNonDisplay(p)) || \
65 				(TermIsHighlighted(p) != IsHighlighted(p)))
66 #define NeedToRedisplayFieldsAttr(p,c) ( \
67 			(TermIsNonDisplay(p) != IsNonDisplayAttr(c)) || \
68 			(TermIsHighlighted(p) != IsHighlightedAttr(c)))
69 
70 #define NotVisuallyCompatibleAttributes(p,c,d) ( \
71 			(IsNonDisplayAttr(c) != IsNonDisplayAttr(d)) || \
72 			(IsHighlightedAttr(c) != IsHighlightedAttr(d)))
73 
74 #define NeedToRedisplayAttr(c,p,a) \
75 			((c != GetTerminal(p)) || NeedToRedisplayFieldsAttr(p,a))
76 #define NeedToRedisplay(c,p)	NeedToRedisplayAttr(c,p,FieldAttributes(p))
77 
78 
79 #define GetTerminal(i)		GetGeneric(i, Terminal)
80 #define GetTerminalPointer(p)	GetGenericPointer(p)
81 #define SetTerminal(i,c)	SetGeneric(i,c,Terminal)
82