~mdw
/
anag
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix maintainer address.
[anag]
/
trackword.c
diff --git
a/trackword.c
b/trackword.c
index
68e90e5
..
8d85745
100644
(file)
--- a/
trackword.c
+++ b/
trackword.c
@@
-1,6
+1,6
@@
/* -*-c-*-
*
/* -*-c-*-
*
- * $Id: trackword.c,v 1.
2 2001/02/04 19:52:53
mdw Exp $
+ * $Id: trackword.c,v 1.
4 2004/04/08 01:36:19
mdw Exp $
*
* Matches trackwords
*
*
* Matches trackwords
*
@@
-26,24
+26,13
@@
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-/*----- Revision history --------------------------------------------------*
- *
- * $Log: trackword.c,v $
- * Revision 1.2 2001/02/04 19:52:53 mdw
- * Remove debugging.
- *
- * Revision 1.1 2001/02/04 17:14:42 mdw
- * Initial checkin
- *
- */
-
/*----- Header files ------------------------------------------------------*/
#include "anag.h"
/*----- Data structures ---------------------------------------------------*/
/*----- Header files ------------------------------------------------------*/
#include "anag.h"
/*----- Data structures ---------------------------------------------------*/
-enum { N, NE, E, SE, S, SW, W, NW, NDIR };
+#define NDIR 9
typedef struct tcell {
struct tcell *hop[NDIR];
typedef struct tcell {
struct tcell *hop[NDIR];
@@
-109,17
+98,18
@@
long isqrt(long a)
static int track(tcell *c, const char *p)
{
static int track(tcell *c, const char *p)
{
-
int i
;
+
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 (i = 0; i < NDIR; i++) {
- if (!c->hop[i] || c->hop[i]->f)
+
+ for (cc = c->hop; *cc; cc++) {
+ if ((*cc)->f)
continue;
continue;
- if (track(
c->hop[i]
, p)) {
+ if (track(
*cc
, p)) {
c->f = 0;
return (1);
}
c->f = 0;
return (1);
}
@@
-153,7
+143,7
@@
node *trackword(const char *const *av)
unsigned i, j;
const char *p = av[0], *q, *l;
size_t sz = strlen(p);
unsigned i, j;
const char *p = av[0], *q, *l;
size_t sz = strlen(p);
- tcell *c;
+ tcell *c
, **cc, **ccc
;
/* --- Work out the dimensions --- */
/* --- Work out the dimensions --- */
@@
-200,32
+190,46
@@
node *trackword(const char *const *av)
for (i = 0; i < x; i++) {
c->ch = *q++;
c->f = 0;
for (i = 0; i < x; i++) {
c->ch = *q++;
c->f = 0;
+ cc = c->hop;
#define NOK (j > 0)
#define SOK (j < y - 1)
#define WOK (i > 0)
#define EOK (i < x - 1)
#define NOK (j > 0)
#define SOK (j < y - 1)
#define WOK (i > 0)
#define EOK (i < x - 1)
-
c->hop[N] = NOK ? c - x : 0
;
-
c->hop[S] = SOK ? c + x : 0
;
-
c->hop[W] = WOK ? c - 1 : 0
;
-
c->hop[E] = EOK ? c + 1 : 0
;
+
if (NOK) *cc++ = c - x
;
+
if (SOK) *cc++ = c + x
;
+
if (WOK) *cc++ = c - 1
;
+
if (EOK) *cc++ = c + 1
;
-
c->hop[NW] = NOK && WOK ? c - x - 1 : 0
;
-
c->hop[NE] = NOK && EOK ? c - x + 1 : 0
;
-
c->hop[SW] = SOK && WOK ? c + x - 1 : 0
;
-
c->hop[SE] = SOK && EOK ? c + x + 1 : 0
;
+
if (NOK && WOK) *cc++ = c - x - 1
;
+
if (NOK && EOK) *cc++ = c - x + 1
;
+
if (SOK && WOK) *cc++ = c + x - 1
;
+
if (SOK && EOK) *cc++ = c + x + 1
;
#undef NOK
#undef SOK
#undef WOK
#undef EOK
#undef NOK
#undef SOK
#undef WOK
#undef EOK
+ *cc++ = 0;
c++;
}
}
c->ch = 0;
c++;
}
}
c->ch = 0;
+ /* --- 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;
+ }
+ }
+ *ccc++ = 0;
+ }
+
/* --- Done --- */
return (&n->n);
/* --- Done --- */
return (&n->n);