/*

    File:          proot.c
    Author:        Graham Toal
    Purpose:       find all words starting with 'root'
    Creation date: 22/06/90
    Lastedit:      22:24:32

    Description:
      some spelling programs remove characters from the end of
    wrongly spelt words one by one until the resulting root is
    found to be a prefix of other words in the dictionary.  This
    works because the assumption is made that the word was in
    fact correct, but was an inflected form of a word in the
    dictionary which had not been stored.
*/


/* Manadatory header files */
#include <stdio.h>
#include "dawg.h"
#include "grope.h"
#include "utils.c"

/* Headers here as needed on per-program basis */
#include <ctype.h>  /* eg, for isalpha() */

/* Spelling library utilities */
#include "init.c"        /* Loading dicts */
/*#include "dyntrie.c"*/ /* Creating dicts at run-time */
#include "print.c"       /* Printing dicts */
/*#include "check.c"*/   /* Checking words */
#include "locate.c"      /* Finding words by their stems */

/*#include "soundex.c"*/ /* Soundex algorithm for word-likeness comparison */
/*#include "similcmp.c"*//* Closeness-metric for correction */
/*#include "correct.c"*/ /* Code to attempt error correction (uses above) */

/* Let's be friendly to these guys... */
#ifdef SYS_MAC
/* To compile with THINK C 4.0, place all the relevant .h and .c
   files in a folder.  Then create a project which contains this main.c
   and the libraries unix and ANSI.
*/
#include <unix.h>
#include <stdlib.h>
#include <console.h>
#endif

/* Your own header files go here, for instance:
               #include "readword.h"
 */



int
#ifdef PROTOTYPES
main(int argc, char **argv)
#else
main(argc, argv)
int argc;
char **argv;
#endif
{
NODE PCCRAP *dawg;
INDEX root;
INDEX edges;
int each;

#ifdef SYS_MAC
  argc = ccommand(&argv);  /* Mac users have my sympathy */
#endif

  /* Your program goes here... */
  if (argc == 1) {
    fprintf(stderr, "usage: %s part\n", argv[0]);
    exit(EXIT_ERROR);
  }
  if (!dawg_init("", &dawg, &edges)) exit(EXIT_ERROR);
  for (each = 1; each < argc; each++) {
    fprintf(stderr, "* %s:\n", argv[each]);
    root = dawg_locate_prefix(dawg, argv[each], ROOT_NODE);
    if (root != ROOT_NODE) {
      dawg_print_prefix(dawg, argv[each], root);
    } else {
      fprintf(stderr, "(none found)\n");
    }
    if (each+1 != argc) fprintf(stderr, "\n");
  }

  exit(EXIT_OK);
}

