Release 4.1
[unix-history] / usr / src / usr.bin / tn3270 / ctlr / screen.h
index 6b02198..27f7462 100644 (file)
@@ -1,5 +1,20 @@
 /*
 /*
- *     @(#)screen.h    3.1  10/29/86
+ * Copyright (c) 1988 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ *     @(#)screen.h    4.1 (Berkeley) %G%
  */
 
 #define        INCLUDED_SCREEN
  */
 
 #define        INCLUDED_SCREEN
 #define WhereAttrByte(p)       (IsStartField(p)? p: FieldDec(p))
 #define        WhereHighByte(p)        ScreenDec(FieldInc(p))
 #define WhereLowByte(p)                ScreenInc(WhereAttrByte(p))
 #define WhereAttrByte(p)       (IsStartField(p)? p: FieldDec(p))
 #define        WhereHighByte(p)        ScreenDec(FieldInc(p))
 #define WhereLowByte(p)                ScreenInc(WhereAttrByte(p))
-#define FieldAttributes(x)     (IsStartField(x)? Host[x].data : \
-                                   Host[WhereAttrByte(x)].data)
-#define FieldAttributesPointer(p)      (IsStartFieldPointer(p)? (p)->data : \
-                                   Host[WhereAttrByte((p)-&Host[0])].data)
-#define TurnOffMdt(x)  (Host[WhereAttrByte(x)].data &= ~ATTR_MDT)
-#define TurnOnMdt(x)   (Host[WhereAttrByte(x)].data |= ATTR_MDT)
-#define HasMdt(x)      (Host[x].data&ATTR_MDT) /* modified tag */
+#define FieldAttributes(x)     (IsStartField(x)? GetHost(x) : \
+                                   GetHost(WhereAttrByte(x)))
+#define FieldAttributesPointer(p)      (IsStartFieldPointer(p)? \
+                                   GetHostPointer(p): \
+                                   GetHost(WhereAttrByte((p)-&Host[0])))
+
+/*
+ * The MDT functions need to protect against the case where the screen
+ * is unformatted (sigh).
+ */
+
+/* Turn off the Modified Data Tag */
+#define TurnOffMdt(x) \
+    if (HasMdt(WhereAttrByte(x))) { \
+       ModifyMdt(x, 0); \
+    }
+
+/* Turn on the Modified Data Tag */
+#define TurnOnMdt(x) \
+    if (!HasMdt(WhereAttrByte(x))) { \
+       ModifyMdt(x, 1); \
+    }
+
+/* If this location has the MDT bit turned on (implies start of field) ... */
+#define HasMdt(x) \
+    ((GetHost(x)&(ATTR_MDT|ATTR_MASK)) == (ATTR_MDT|ATTR_MASK))
 
        /*
         * Is the screen formatted?  Some algorithms change depending
         * on whether there are any attribute bytes lying around.
         */
 #define        FormattedScreen() \
 
        /*
         * Is the screen formatted?  Some algorithms change depending
         * on whether there are any attribute bytes lying around.
         */
 #define        FormattedScreen() \
-           ((WhereAttrByte(0) != 0) || ((Host[0].data&ATTR_MASK) == ATTR_MASK))
+           ((WhereAttrByte(0) != 0) || ((GetHost(0)&ATTR_MASK) == ATTR_MASK))
 
                                            /* field starts here */
 
                                            /* field starts here */
-#define IsStartField(x)        ((Host[x].data&ATTR_MASK) == ATTR_MASK)
-#define IsStartFieldPointer(p) (((p)->data&ATTR_MASK) == ATTR_MASK)
+#define IsStartField(x)        ((GetHost(x)&ATTR_MASK) == ATTR_MASK)
+#define IsStartFieldPointer(p) ((GetHostPointer(p)&ATTR_MASK) == ATTR_MASK)
 
 
-#define NewField(p,a)  (Host[p].data = (a)|ATTR_MASK)
-#define DeleteField(p) (Host[p].data = 0)
+#define NewField(p,a)  SetHost(p, (a)|ATTR_MASK)
+#define DeleteField(p) SetHost(p, 0)
 #define        DeleteAllFields()
 \f
 /* The following are independent of the implementation of fields */
 #define        DeleteAllFields()
 \f
 /* The following are independent of the implementation of fields */
 #define MAX(x,y)       ((x)<(y)? (y):(x))
 #define MIN(x,y)       ((x)<(y)? x:(y))
 
 #define MAX(x,y)       ((x)<(y)? (y):(x))
 #define MIN(x,y)       ((x)<(y)? x:(y))
 
-typedef struct {
-       unsigned char   data;   /* data at this position */
-} ScreenImage;
+typedef unsigned char ScreenImage;
 
 extern int
        FieldFind();
 
 extern int
        FieldFind();
@@ -90,5 +122,12 @@ extern int
 extern char
        CIABuffer[];
 
 extern char
        CIABuffer[];
 
-#define GetHost(i)     Host[i].data
-#define SetHost(p,c)   (Host[p].data = c)
+#define        GetGeneric(i,h)         (h)[i]
+#define        GetGenericPointer(p)    (*(p))
+#define        SetGeneric(i,c,h)       ((h)[i] = (c))
+#define        ModifyGeneric(i,what,h) {(h)[i] what;}
+
+#define GetHost(i)             GetGeneric(i,Host)
+#define GetHostPointer(p)      GetGenericPointer(p)
+#define        SetHost(i,c)            SetGeneric(i,c,Host)
+#define        ModifyHost(i,what)      ModifyGeneric(i,what,Host)