#include <fstream.h>
#include <iostream.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
    if (argc < 2)
    {
    	cout << "Vous devez specifier le fichier source et destination !\n";
	return -1;
    }
    
    char *infile=argv[1], *outfile=argv[2];
    int nb_tache;
    int succ;
    int i,j;
    int duree;
    int nb_succ;
    
    // ouverture du stream en lecture
    ifstream f(infile);
    ofstream f2(outfile);
    
    if ((!f) || (!f2))
    {
        cout << "Erreur d'ouverture du fichier\n";
        return -1;
    }
    else
    {
        f >> nb_tache;
        
        // on écrit nb_taches=X;
        f2 << "nb_taches=" << nb_tache << ";\n";
        
        // on écrit tache={Tx,Ty,...};
        f2 << "tache={";
        for (i=1; i <= nb_tache; i++)
        {
                f2 << "T" << i;
                if (i+1 > nb_tache) f2 << "};\n";
                else f2 << ",";
        }
        
        // on écrit duree=[x y ...];
        f2 << "duree=[";
        for (i=0; i < nb_tache; i++)
        {
                f >> duree;
                f2 << duree;
                if (i+1 == nb_tache) f2 << "];\n";
                else f2 << " ";
        }

        int numero_tache;

        // on écrit prec={<Tx,Ty>,<Ty,Tz>...};
        f2 << "prec={";
        while (!f.eof())
        {
                f >> numero_tache >> nb_succ;

                for (i=0; i < nb_succ; i++)
                {
                    f >> succ;
                    f2 << "<T" << numero_tache << ",T" << succ << ">";
                    if (i+1 != nb_succ) f2 << ",";
                }
                if (!f.eof()) f2 << ",";
         }
         f2 << "};\n";
    }
    
    // on ferme les streams
    f.close();
    f2.close();
    
    return 0;
}
