1 /*
2  * Copyright (c) 1988 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * advertising materials, and other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  *	@(#)terminal.h	4.2 (Berkeley) 05/30/89
18  */
19 
20 #define	INCLUDED_TERMINAL
21 
22 /*
23  * In the situation where we have a copy of the terminal screen in front
24  * of us, here are some macros to deal with them.
25  */
26 
27 #define TermAttributes(x)	(TermIsStartField(x)? GetTerminal(x)&0xff : \
28 				    GetTerminal(WhereTermAttrByte(x))&0xff)
29 #define TermIsStartField(x)	((GetTerminal(x)&ATTR_MASK) == ATTR_MASK)
30 #define TermNewField(p,a)	SetTerminal(p, (a)|ATTR_MASK)
31 #define TermDeleteField(p)	SetTerminal(p, 0)
32 #define TermIsNonDisplay(x)	\
33 		    ((TermAttributes(x)&ATTR_DSPD_MASK) == ATTR_DSPD_NONDISPLAY)
34 #define TermIsHighlighted(x) \
35 		(((TermAttributes(x)&ATTR_DSPD_MASK) == ATTR_DSPD_HIGH) \
36 				    && !TermIsStartField(x))
37 
38 #define TerminalCharacterAttr(c,p,a)	(IsNonDisplayAttr(a) ? ' ':c)
39 #define TerminalCharacter(c,p)	TerminalCharacterAttr(c,p,FieldAttributes(p))
40 
41 	/*
42 	 * Is the screen formatted?  Some algorithms change depending
43 	 * on whether there are any attribute bytes lying around.
44 	 */
45 #define	TerminalFormattedScreen() \
46 	    ((WhereTermAttrByte(0) != 0) || ((GetTerminal(0)&ATTR_MASK) == ATTR_MASK))
47 
48 #define NeedToRedisplayFields(p) ((TermIsNonDisplay(p) != IsNonDisplay(p)) || \
49 				(TermIsHighlighted(p) != IsHighlighted(p)))
50 #define NeedToRedisplayFieldsAttr(p,c) ( \
51 			(TermIsNonDisplay(p) != IsNonDisplayAttr(c)) || \
52 			(TermIsHighlighted(p) != IsHighlightedAttr(c)))
53 
54 #define NotVisuallyCompatibleAttributes(p,c,d) ( \
55 			(IsNonDisplayAttr(c) != IsNonDisplayAttr(d)) || \
56 			(IsHighlightedAttr(c) != IsHighlightedAttr(d)))
57 
58 #define NeedToRedisplayAttr(c,p,a) \
59 			((c != GetTerminal(p)) || NeedToRedisplayFieldsAttr(p,a))
60 #define NeedToRedisplay(c,p)	NeedToRedisplayAttr(c,p,FieldAttributes(p))
61 
62 
63 #define GetTerminal(i)		GetGeneric(i, Terminal)
64 #define GetTerminalPointer(p)	GetGenericPointer(p)
65 #define SetTerminal(i,c)	SetGeneric(i,c,Terminal)
66