chiark / gitweb /
chain.c: Access chain length via a macro.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 30 Mar 2025 20:32:15 +0000 (21:32 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 30 Mar 2025 21:48:44 +0000 (22:48 +0100)
chain.c

diff --git a/chain.c b/chain.c
index f37f1bd294b37abe1636ac2152718e176acd1acb..1b53ea7a157cad67c6b1859644a7f2760152b285 100644 (file)
--- a/chain.c
+++ b/chain.c
@@ -196,7 +196,8 @@ struct node {
 # define WORDLEN(node) ((node)->w.n)
 #endif
   struct node *down, *right, *up;
-  short len;
+  short chlen;
+# define CHLEN(node) ((node)->chlen)
 };
 
 #define WORDMAX 64
@@ -607,7 +608,7 @@ int main(void)
     else if (ch = getchar(), ch != EOF) bail("short read, found `%c'", ch);
 
     PREPNODE; INSERT;
-    if (node) { node->up = node->down = node->right = 0; node->len = 1; }
+    if (node) { node->up = node->down = node->right = 0; CHLEN(node) = 1; }
   }
 
   CHECK;
@@ -624,7 +625,7 @@ int main(void)
       /* fprintf(stderr, ";; search `%.*s'\n", word.n, word.p); */
       parent = LOOKUP; if (!parent) continue;
     }
-    node->up = parent; nlen = node->len;
+    node->up = parent; nlen = CHLEN(node);
     for (;;) {
       if (!parent) {
        if (nlen >= max) {
@@ -634,7 +635,7 @@ int main(void)
        }
        break;
       }
-      plen = parent->len; nlen++;
+      plen = CHLEN(parent); nlen++;
       if (plen > nlen)
        break;
       else if (plen == nlen) {
@@ -642,7 +643,7 @@ int main(void)
        break;
       } else {
        parent->down = node; node->right = 0;
-       parent->len = nlen;
+       CHLEN(parent) = nlen;
        node = parent; parent = node->up;
       }
     }