/* File: prefix.c Author: Graham Toal Purpose: Check the stem of a word using DAWG or TRIE. Functions exported: dawg_prefix Description: Call as: dawg_prefix(dawg, "stem"); returns TRUE or FALSE depending on whether any words in the dictionary start with stem. */ #include "../splib.h" #include <ctype.h> /* for isalpha, tolower */ /* Check that the parameter exists as a prefix of a word in the dawg - must be exact case match */ int dawg_prefix(NODE *dict, char *word) { NODE *edge = dict+ROOT_NODE; if (edge == dict) return(0!=0); for (;;) { if (*word == (((*edge >> V_LETTER) & M_LETTER))) { if (*++word == '\0') { return(0==0); } else { if ((edge = dict+(*edge & M_NODE_POINTER)) == dict) break; continue; } } if (((*edge++) & M_END_OF_NODE) != 0) break; } return(0!=0); }