{
long i, q;
- /* --- Initial guess is half the input length --- */
-
- for (i = q = a; q; q >>= 2)
- i >>= 1;
-
- /* --- Do the main series iteration --- */
+ /* Initial guess is half the input length. */
+ for (i = q = a; q; q >>= 2) i >>= 1;
+ /* Do the main series iteration. */
for (;;) {
- q = i * i - a;
- if (!q || (q < 0 && -q <= 2 * i))
- return (i);
- q /= 2 * i;
- if (!q)
- i--;
- else
- i -= q;
+ q = i*i - a;
+ if (q > -2*i && q <= 0) return (i);
+ q /= 2*i;
+ if (!q) i--;
+ else i -= q;
}
}
{
tcell **cc;
- if (*p++ != c->ch)
- return (0);
- if (!*p)
- return (1);
- c->f = 1;
+ if (*p++ != c->ch) return (0);
+ if (!*p) return (1);
+ c->f = 1;
for (cc = c->hop; *cc; cc++) {
- if ((*cc)->f)
- continue;
- if (track(*cc, p)) {
- c->f = 0;
- return (1);
- }
+ if ((*cc)->f) continue;
+ if (track(*cc, p)) { c->f = 0; return (1); }
}
c->f = 0;
+
return (0);
}
node_track *n = (node_track *)nn;
tcell *c;
- if (!*p)
- return (1);
- for (c = n->c; c->ch; c++) {
- if (track(c, p))
- return (1);
- }
+ if (!*p) return (1);
+ for (c = n->c; c->ch; c++)
+ if (track(c, p)) return (1);
return (0);
}
size_t sz = strlen(p);
tcell *c, **cc, **ccc;
- /* --- Work out the dimensions --- */
-
+ /* Work out the dimensions. */
x = strcspn(p, "/");
if (!p[x]) {
x = isqrt(sz);
- if (x * x != sz)
+ if (x*x != sz)
die("bad trackword `%s': not square, and no line markers", p);
y = x;
}
- if (!x)
- die("bad trackword `%s': no columns", p);
+ if (!x) die("bad trackword `%s': no columns", p);
y = 0;
l = p + sz;
q = p;
for (;;) {
- if (*q == '/')
- q++;
- if (!*q)
- break;
+ if (*q == '/') q++;
+ if (!*q) break;
if (l - q < x)
die("bad trackword `%s': inconsistent line lengths", p);
q += x;
y++;
}
- if (!y)
- die("bad trackword `%s': no rows", p);
-
- /* --- Build the match node --- */
+ if (!y) die("bad trackword `%s': no rows", p);
+ /* Build the match node. */
n = xmalloc(sizeof(*n));
n->n.func = n_track;
n->x = x; n->y = y;
- n->c = xmalloc((x * y + 1) * sizeof(tcell));
+ n->c = xmalloc((x*y + 1)*sizeof(tcell));
q = p;
c = n->c;
for (j = 0; j < y; j++) {
- if (*q == '/')
- q++;
+ if (*q == '/') q++;
for (i = 0; i < x; i++) {
c->ch = *q++;
c->f = 0;
}
c->ch = 0;
- /* --- Now prune out bogus links --- */
-
+ /* Now prune out bogus links. */
for (c = n->c; c->ch; c++) {
ccc = c->hop;
- for (cc = c->hop; *cc; cc++) {
- if (isalpha((unsigned char)(*cc)->ch)) {
- *ccc++ = *cc;
- }
- }
+ for (cc = c->hop; *cc; cc++)
+ if (isalpha((unsigned char)(*cc)->ch)) *ccc++ = *cc;
*ccc++ = 0;
}
- /* --- Done --- */
-
+ /* Done. */
return (&n->n);
}