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

int choix, choix2;
//--------------------------------------------------------------------------
void LBN();
void LHN();
void LC();
//--------------------------------------------------------------------------
int main()
{
 system("clear");
 do{
        cout << "Bienvenue" << endl;
        cout << "Menu"<< endl;
	cout << "1. Exo 1"<<endl;
        cout << "2. Exo 2" << endl;
        cout << "3. EXO 3" << endl;
        cout << "4. EXO 4" << endl;
	cout << "5. EXO 5"<<endl;
        cout << "6. EXO 6" << endl;
        cout << "7. Quitter " << endl;
	cin >> choix;

switch (choix){
		case 1:{
			do{
			   cout << "1. Language de bas niveau"<<endl;
			   cout << "2. Language de haut niveau" << endl;
			   cout << "3. Language C++" << endl;
			   cout << "4. Quitter " << endl;
			   cin >> choix2;

		           switch (choix2){
				           case 1: LBN();cin.get();break;
				           case 2: LHN();cin.get();break;
				           case 3: LC();cin.get();break;
				           case 4: return 0;
			                  }
			   } while (1);
		        break;
		       }

		case 2:{
		        int choix3,cpt=-1,cpt2=-1;
			do{
			   cout << "Menu" << endl;
			   cout << "1. Executé " <<endl;
			   cout << "2. Sortir " << endl;
			   cin >> choix3;
			   switch (choix3){
			                   case 1:{
					           FILE* f;
					           char car;
			                           f = fopen ("horaire.txt","r");
			                           while (!feof(f))
			                           {
			                            car = getc(f);
			                            cout<<car;
						    cpt+=1;
						    if (car=='\n')
						    cpt2+=1;
			                           }
			                           cin.get();
						   cout << cpt << " caracteres " << endl;
						   cout << cpt2 << " lignes " << endl; cin.get();
						   break;
						  }
					   case 2:return 0; break;
			                  }
			 }while (1);
			break;
		      }

		case 3:{
		        int choix4;
		        do{
			   cout << "Menu" << endl;
			   cout << "1. Executé " <<endl;
			   cout << "2. Sortir " << endl;
			   cin >> choix4;
			   switch (choix4)
			   {
			    case 1: system("./info1");break;
			    case 2: return 0;
			   }
			  }while (1);
			break;
		       }

		case 4:{
		        int choix5,cpt=-1,cpt2=-1,cpt3=-1;
		        do{
			   cout << "Menu" << endl;
			   cout << "1. Executé " <<endl;
			   cout << "2. Sortir " << endl;
			   cin >> choix5;
			   switch (choix5){
			                   case 1:{
					           FILE* f;
					           char car;
			                           f = fopen ("horaire.txt","r");
			                           while (!feof(f))
			                           {
			                            car = getc(f);
			                            cout<<car;
						    cpt+=1;
						    if (car =='\n')
						    {
						     cpt3+=1;
						     if (cpt2 == 11)
						     {
						      cin.get();cpt2=0;
						     }
						     else
						     {
						      cpt2+=1;
						     }
			                            }
						   }
			                           cin.get();
						   cout << cpt << " caracteres " << endl;
						   cout << cpt3 << " lignes " << endl; cin.get();
						   break;
						  }
					   case 2:return 0; break;
					  }
			  }while (1);
			break;
		       }

		case 5:{
		        int choix6;
		        do{
			   cout << "Menu" << endl;
			   cout << "1. Executé " <<endl;
			   cout << "2. Sortir " << endl;
			   cin >> choix6;
			   switch (choix6)
			   {
			    case 1: system("./info2");break;
			    case 2: return 0;
			   }
			  }while (1);
			break;
		       }

		case 6:{
		        int choix7;
		        do{
			   cout << "Menu" << endl;
			   cout << "1. Executé " <<endl;
			   cout << "2. Sortir " << endl;
			   cin >> choix7;
			   switch (choix7)
			   {
			    case 1: {
			             ifstream f ("/etc/passwd");
				     char car,tmp;
				     while (f.get(car))
                                     {
				      if (car == ':')
				      {
				       do
				         {
					  f.get(tmp);
					 }while (tmp != ':');
				      }
					cout<<car;
				     }
				      cin.get();
				     break;
				    }
			    case 2: {return 0;}
			   }
			  }while (1);
			break;
		       }

		case 7:{
			return 0;
		       }
	       }
}while (choix == 7);
return 0;
}

//---------------------------------------------------------------------------
//              FONCTIONS
//---------------------------------------------------------------------------
void LBN()
{
   int f;
   char car;
   f=open("/etc/resolv.conf",O_RDONLY);
   while (read (f, &car, 1))
   putchar (car);
   close (f);
}

void LHN()
{
  FILE* f;
  char car;
  f= fopen ("/etc/fstab", "r");
  car=getc(f);
  while (!feof(f))
  {
   putchar (car);
   car=getc(f);
  }
  fclose (f);
}

void LC()
{
 ifstream f ("/etc/passwd");
 char car;
 while (f.get(car))
 cout << car;
}
