#include <astl_binary.h>

// Build a tree-like automaton from a list of words

template <class DFA>
void dfa_tree(DFA &A, const string &filename)
{
  if (filename.empty())
    tree_build(A, istream_iterator<string>(cin), istream_iterator<string>());
  else {
    ifstream input(filename.c_str());
    if (!input) {
      perror(filename.c_str());
      exit(2);
    }
    tree_build(A, istream_iterator<string>(input), istream_iterator<string>());
    input.close();
  } 
  DFA_stream output(cout);
  clone(output, dfirstc(A)); 
  exit(0);
}
  
int main(int argc, char **argv)
{
  usage use(argv[0]);
  use.push_back("[dictionary_file]");
  use.push_back("build a tree-like automaton from a list of words (one per line)");
  use.check(argc, argv, 0, 1);

  if (use[0] == "matrix") {
    DFA_matrix<plain> A;
    dfa_tree(A, use[1]);
  }
  if (use[0] == "map") {
    DFA_map<plain> A;
    dfa_tree(A, use[1]);
  }
  if (use[0] == "bin") {
    DFA_bin<plain> A;
    dfa_tree(A, use[1]);
  }
  if (use[0] == "mtf") {
    DFA_mtf<plain> A;
    dfa_tree(A, use[1]);
  }
  if (use[0] == "tr") {
    DFA_tr<plain> A;
    dfa_tree(A, use[1]);
  }
  if (use[0] == "hash") {
    DFA_hash<plain> A;
    dfa_tree(A, use[1]);
  }
  exit(1);
}
  








