/*
* Scrabaid
*
* Revisions:
*
* 18/05/2001 lc - v1.0 release
*
* ----------------------------------------------------------------------------
*
* Scrabaid version 1.0, Copyright 2001 Linus Chang
* Scrabaid comes with ABSOLUTELY NO WARRANTY; for details, view the LICENCE
* file included with this distribution. This is free software, and you are
* welcome to redistribute it under certain conditions; view the LICENCE
* file for details.
*/


import java.io.*;

class WordListGenerator {
	static File m_dir;
	static PrintWriter[] m_wordfiles;

	private static void createDirectory() {
			m_dir = new File(WordList.WORDLIST_DIRECTORY);
			if (!m_dir.isDirectory())
				m_dir.mkdir();
	}
	private static void createFiles() {
		try {
			m_wordfiles = new PrintWriter[16];
			for (int c = 2; c <= 15; c++) {
				File f = new File(m_dir, WordList.getWordListFilename(c));
				m_wordfiles[c] = new PrintWriter(new BufferedWriter(new FileWriter(f)));
			}
		}
		catch (IOException ioe) {
			System.err.println("Unable to create wordlist file: " + ioe);
			ioe.printStackTrace();
			System.exit(1);
		}
	}
	private static void closeFiles() {
		for (int c = 2; c <= 15; c++) {
			m_wordfiles[c].close();
		}
	}
	public static void main(String []args) {
		if (args.length != 1) {
			System.out.println("Usage: java WordListGenerator <wordlist file>");
			System.exit(1);
		}

		System.out.println("Generating wordlist files.");
		createDirectory();
		createFiles();
		try {
			BufferedReader wordlist = new BufferedReader(new FileReader(args[0]));
			String line;
			while ( (line = wordlist.readLine()) != null)
				if (line.length() >= 2 && line.length() <= 15)
					m_wordfiles[line.length()].println(line);
		}
		catch (IOException ioe) {
			System.err.println("Unexpected IOException whilst generating wordlists: " + ioe);
			ioe.printStackTrace();
		}
		closeFiles();
	}
}

