Get rid of FieldForward, FieldReverse.
authorGregory Minshall <minshall@ucbvax.Berkeley.EDU>
Mon, 11 May 1987 04:01:29 +0000 (20:01 -0800)
committerGregory Minshall <minshall@ucbvax.Berkeley.EDU>
Mon, 11 May 1987 04:01:29 +0000 (20:01 -0800)
SCCS-vsn: usr.bin/tn3270/ctlr/screen.h 1.3
SCCS-vsn: usr.bin/tn3270/ctlr/outbound.c 1.8
SCCS-vsn: usr.bin/tn3270/general/bsubs.ext 1.2
SCCS-vsn: usr.bin/tn3270/general/genbsubs.c 1.2

usr/src/usr.bin/tn3270/ctlr/outbound.c
usr/src/usr.bin/tn3270/ctlr/screen.h
usr/src/usr.bin/tn3270/general/bsubs.ext
usr/src/usr.bin/tn3270/general/genbsubs.c

index 9335b99..5da7e90 100644 (file)
@@ -82,27 +82,39 @@ init_ctlr()
     init_inbound();
 }
 
     init_inbound();
 }
 
-/* What we know is that table is of size ScreenSize */
 
 
-FieldFind(table, position, failure)
-register char *table;          /* which table of bytes to use */
-register int position;         /* what position to start from */
-int failure;                   /* if unformatted, what value to return */
+FieldInc(position)
+register int   position;               /* Position in previous field */
 {
 {
-    register int ourp;
-
-    ourp = position + 1 + bskip(table+position+1, ScreenSize-position-1, 0);
-    if (ourp < ScreenSize) {
-       return(ourp);
+    register ScreenImage *ptr;
+
+    ptr = (ScreenImage *)memNSchr((char *)Host+position+1, ATTR_MASK,
+                       HighestScreen()-position, ATTR_MASK, sizeof Host[0]);
+    if (ptr == 0) {
+       ptr = (ScreenImage *)memNSchr((char *)Host+LowestScreen(), ATTR_MASK,
+                       position-LowestScreen(), ATTR_MASK, sizeof Host[0]);
+       if (ptr == 0) {
+           return LowestScreen();
+       }
     }
     }
-    /* No fields in table after position.  Look for fields from beginning
-     * of table.
-     */
-    ourp = bskip(table, position+1, 0);
-    if (ourp <= position) {
-       return(ourp);
+    return ptr-Host;
+}
+
+FieldDec(position)
+int    position;
+{
+    register ScreenImage *ptr;
+
+    ptr = (ScreenImage *)memNSchr((char *)(Host+position)-1, ATTR_MASK,
+                       position-LowestScreen(), ATTR_MASK, -sizeof Host[0]);
+    if (ptr == 0) {
+       ptr = (ScreenImage *)memNSchr((char *)Host+HighestScreen(), ATTR_MASK,
+                       HighestScreen()-position, ATTR_MASK, -sizeof Host[0]);
+       if (ptr == 0) {
+           return HighestScreen();
+       }
     }
     }
-    return(failure);
+    return ptr-Host;
 }
 
 /* Clear3270 - called to clear the screen */
 }
 
 /* Clear3270 - called to clear the screen */
index 48e2bcb..a01d286 100644 (file)
 \f
 /* These know how fields are implemented... */
 
 \f
 /* These know how fields are implemented... */
 
-#define        FieldInc(p)     FieldFind(FieldForward, p, LowestScreen())
-#define        FieldDec(p)     (HighestScreen() - \
-                               FieldFind(FieldReverse, \
-                                       HighestScreen()-(p), HighestScreen()))
 #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 IsStartField(x)        ((Host[x].data&ATTR_MASK) == ATTR_MASK)
 #define IsStartFieldPointer(p) (((p)->data&ATTR_MASK) == ATTR_MASK)
 
 #define IsStartField(x)        ((Host[x].data&ATTR_MASK) == ATTR_MASK)
 #define IsStartFieldPointer(p) (((p)->data&ATTR_MASK) == ATTR_MASK)
 
-#define NewField(p,a)  (Host[p].data = (a)|ATTR_MASK, \
-                           FieldForward[p] = FieldReverse[ScreenSize-p-1] = 1)
-#define DeleteField(p) (Host[p].data = 0, \
-                           FieldForward[p] = FieldReverse[ScreenSize-p-1] = 0)
-#define        DeleteAllFields()       (bzero(FieldForward, sizeof FieldForward), \
-                                   bzero(FieldReverse, sizeof FieldReverse))
-
+#define NewField(p,a)  (Host[p].data = (a)|ATTR_MASK)
+#define DeleteField(p) (Host[p].data = 0)
+#define        DeleteAllFields()
 \f
 /* The following are independent of the implementation of fields */
 #define IsProtectedAttr(p,a)   (IsStartField(p) || ((a)&ATTR_PROT))
 \f
 /* The following are independent of the implementation of fields */
 #define IsProtectedAttr(p,a)   (IsStartField(p) || ((a)&ATTR_PROT))
index 35224af..04efda0 100644 (file)
@@ -8,3 +8,6 @@
 extern int
     bunequal(),
     bskip();
 extern int
     bunequal(),
     bskip();
+
+extern unsigned char
+    *memNSchr();       /* Search for a character ANDED, increment by stride */
index bf8e8e9..ad4b4de 100644 (file)
@@ -61,3 +61,81 @@ register int b;
     }
     return(i-1);
 }
     }
     return(i-1);
 }
+
+/*
+ * memNIchr(const void *s, int c, size_t n, int and)
+ *
+ * Like memchr, but the comparison is '((*s)&and) == c'.
+ *
+ */
+
+unsigned char *
+memNIchr(s, c, n, and)
+char *s;
+int c;
+unsigned int n;
+int and;
+{
+    register unsigned char _c, *_s, _and;
+
+    _and = and;
+    _c = (c&_and);
+    _s = (unsigned char *)s;
+    while (n--) {
+       if (((*_s)&_and) == _c) {
+           return _s;
+       }
+       _s++;
+    }
+    return 0;
+}
+
+/*
+ * memNDchr(const void *s, int c, size_t n, int and)
+ *
+ * Like memchr, but the comparison is '((*s)&and) == c',
+ * and we increment our way through s by "stride" ('s += stride').
+ *
+ * We optimize for the most used strides of +1 and -1.
+ */
+
+unsigned char *
+memNSchr(s, c, n, and, stride)
+char *s;
+int c;
+unsigned int n;
+int and;
+int stride;
+{
+    register unsigned char _c, *_s, _and;
+
+    _and = and;
+    _c = (c&_and);
+    _s = (unsigned char *)s;
+    switch (stride) {
+    case 1:
+       while (n--) {
+           if (((*_s)&_and) == _c) {
+               return _s;
+           }
+           _s++;
+       }
+       break;
+    case -1:
+       while (n--) {
+           if (((*_s)&_and) == _c) {
+               return _s;
+           }
+           _s--;
+       }
+       break;
+    default:
+       while (n--) {
+           if (((*_s)&_and) == _c) {
+               return _s;
+           }
+           _s += stride;
+       }
+    }
+    return 0;
+}