/*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * (the "License"); you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
 * 
 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
 * language governing rights and limitations under the License.
 * 
 * The Original Code is the Venice Web Community System.
 * 
 * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
 * for Silverwrist Design Studios.  Portions created by Eric J. Bowersox are
 * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios.  All Rights Reserved.
 * 
 * Contributor(s): 
 */
package com.silverwrist.venice.htmlcheck.dict;

import java.io.*;
import java.util.*;

public class LexiconTest
{
  private LexiconTest()
  { // this class cannot be instantiated
  } // end constructor

  private static final String USAGE = "Usage: LexiconTest [-c] lexfile word [...]";

  public static void main(String args[])
  {
    if (args.length==0)
    { // print the usage string and exit
      System.err.println(USAGE);
      System.exit(1);

    } // end if

    boolean compress = false;
    int ifx = 0;
    if (args[0].equals("-c"))
    { // we're compressing the output
      compress = true;
      if (++ifx>=args.length)
      { // no lexicon specified!
	System.err.println("No lexicon file specified!");
	System.err.println(USAGE);
	System.exit(1);

      } // end if

    } // end if

    int wfx = ifx + 1;
    Lexicon lex = null;

    try
    { // save the lexicon to its very own file
      System.out.println("Loading " + args[ifx] + "...");
      Date start = new Date();
      lex = Lexicon.loadFromFile(args[ifx],compress);
      Date stop = new Date();
      long interval = stop.getTime() - start.getTime();
      System.out.println("Loaded " + args[ifx] + ", elapsed time " + String.valueOf(interval/1000) + "."
			 + String.valueOf(interval%1000) + " seconds");

    } // end try
    catch (IOException e)
    { // just die on IOException
      System.err.println("Error loading from " + args[ifx] + ": " + e.getMessage());
      System.exit(1);

    } // end catch

    while (wfx<args.length)
    { // check each word specified on the command line
      if (lex.checkWord(args[wfx]))
	System.out.println(args[wfx] + ": in the dictionary");
      else
	System.out.println(args[wfx] + ": NOT in the dictionary");

    } // end while

    System.exit(0);

  } // end main

} // end class LexiconTest
