/*

    File:          dwgcheck.c
    Author:        Graham Toal
    Purpose:       check correct spelling using dict.dwg
    Creation date: 22/06/90
    Lastedit:      23/06/90 01:10:12

    Description:

       This can be expanded to be like the unix 'spell' command.
    This demo file simply checks words passed on the command line.
    note how it remembers words so that the second time it sees
    them, it will call them correct.  This is how you should
    implement the 'ignore' feature of an interactive checker.

    This code uses the dawg data structure, which I recommend
    you stick with; however for *extremely* fast checking in
    special circumstances you can use the 'pack' versions of
    check() et al.

*/


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

/*#define RCHECK*/     /* Enable for internal range checks... */

#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"   /* Hack 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;      /* precompiled dictionary (dict.dwg) */
INDEX edges;            /* size of above */

NODE PCCRAP *userdict;  /* run-time dictionary, added to dynamically */

char *word;
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 possibly mispeled wurdz\n", argv[0]);
    exit(EXIT_ERROR);
  }
  if (!dawg_init("", &dawg, &edges)) exit(EXIT_ERROR);

  if (!trie_new(&userdict)) exit(EXIT_ERROR);

  for (each = 1; each < argc; each++) {
    word = argv[each];
    fprintf(stderr, "* %s:\n", word);
    if (dawg_check(dawg, word) || dawg_check(userdict, word)) {
      fprintf(stderr, "Correct\n");
    } else {
      fprintf(stderr, "Wrong\n");
      (void)trie_add(&userdict, word);
    }
    if (each+1 != argc) fprintf(stderr, "\n");
  }

  exit(EXIT_OK);
}

