/*
 *  mach_gui.cpp
 *  Mach2
 *
 *  Created by Antoni Galmiche on 06/05/10.
 *  Copyright 2010 EFREI. All rights reserved.
 *
 */

#include "mach_gui.h"

void mui() {
	Automate * a = new Automate("sm/test1.sm");
	string command =" ";
	string rep = "sm/";
	string mot="";
	cout << "#UI prête, tapez \"liste\" pour lister les commandes.";
	do {
		cout << endl <<"$ ";
		cin >> command;
		
		if (command == "afficher" && a != NULL) a->afficher();
		if (command == "liste") liste();
		if (command == "ouvrir") {
			cin >> command;
			string fname = rep+command;
			ifstream fichier(fname.c_str(), ios::in);
			if (fichier.is_open()) {
				delete a;
				cout << "#Chargement de '" << fname << "'... ";
				a=new Automate(fname);
				cout << "Ok";
			}
			else cout << "#Le fichier '"<< fname << "' n'existe pas";
		}
		if (command == "completer") { a->completer(); cout << "#Automate complété."; }
	
	} while (command != "quit" && command != "quitter" && command != "exit" && command != "q");
}

void liste() {
	cout << "\n#Commandes:\n";
	cout << "#'afficher': affiche l'automate actuellement en mémoire." << endl;
	cout << "#'completer': complète l'automate si besoin en ajoutant un état poubelle." << endl;
	cout << "#'liste': affiche les commandes de l'interface." << endl;
	cout << "#'ouvrir [nom de fichier]': Ouvre un automate du dossier './sm'" << endl;
	cout << "#'quitter'/'quit'/'exit'/'q': stoppe le programme.";
	
}