/*

    File:    locate.c
    Author:  Graham Toal
    Purpose: Find all words beginning with particular prefix.
    Functions exported:  locate_prefix

Description:
   Searches as in spell-check for prefix in dict, but doesn't
   fail if word doesn't terminate at that point.  It returns
   an index into the dict which can be used with print_dawg_prefix
   to display all the words found.  However it is more useful
   than that; text-analysis programs can check that a word matches
   "root*", for instance, when doing stylistic analysis etc.

*/

INDEX
#ifdef PROTOTYPES
dawg_locate_prefix(NODE PCCRAP *dawg, char *word, INDEX edge)
#else
dawg_locate_prefix(dawg, word, edge)
NODE PCCRAP *dawg;
char *word;
INDEX edge;
#endif
{
  for (;;) {
    if (*word == (((dawg[edge] >> V_LETTER) & M_LETTER))) {
      if (*++word == '\0') {
        return(dawg[edge]&M_NODE_POINTER);
      } else {
        if ((edge = (dawg[edge] & M_NODE_POINTER)) == ROOT_NODE) break;
        continue;
      }
    }
    if (((dawg[edge++]) & M_END_OF_NODE) != 0) break;
  }
  /* What to do when none found? -- fail-safe, or some error code...? */
  return(ROOT_NODE);
}

