65 lines
1.9 KiB
Ada
65 lines
1.9 KiB
Ada
with Ada.Text_Io; use Ada.Text_Io;
|
|
with Contact_Cle; use Contact_Cle;
|
|
with Arbre_Bin_Recherche_Cle_G;
|
|
|
|
|
|
procedure Tester_Abr_Contacts is
|
|
|
|
-- Instanciation du paquetage
|
|
package Arbre_Contacts is new Arbre_Bin_Recherche_Cle_G(Un_Contact, Cle_contact, Cle, "<", "=", Liberer_Contact, Contact_To_string);
|
|
use Arbre_Contacts;
|
|
|
|
|
|
-- Variables pour la lecture du fichier annuaire
|
|
Fichier : File_Type;
|
|
Chaine, Ligne : String(1..80);
|
|
Len, last : Integer := 0;
|
|
AB : Arbre;
|
|
C : Un_Contact;
|
|
|
|
Prenom, Nom, Ville, Specia, Telephone, Fin, I : Integer := 0;
|
|
begin
|
|
|
|
-----------------------------------------------------------
|
|
-- Utilisation d'annuaires
|
|
-----------------------------------------------------------
|
|
|
|
-- Entourloupe pour avoir un nom de fichier contraint, saisi par l'utilisateur et de bonne taille
|
|
Put_Line("Lecture d'un fichier de contact, veillez saisir le nom du fichier : ");
|
|
Get_Line(Chaine, Len);
|
|
declare
|
|
Nom_Fichier : String(Chaine'First..Len) := Chaine(Chaine'First..Len);
|
|
begin
|
|
open(Fichier, in_File, "./jeux_de_donnees/" & Nom_Fichier);
|
|
while not End_Of_File(Fichier) loop
|
|
Get_Line (Fichier, Ligne , Len ) ;
|
|
Put_Line ( "Ajouté à l'arbre: " & Ligne(1..Len));
|
|
|
|
Prenom := 1;
|
|
Nom := 0;
|
|
Ville := 0;
|
|
Specia := 0;
|
|
Telephone := 0;
|
|
Fin := 0;
|
|
I := 1;
|
|
|
|
while Telephone = 0 loop
|
|
if Ligne(I) = ' ' then
|
|
if Nom = 0 then Nom := I;
|
|
elsif Ville = 0 then Ville := I;
|
|
elsif Specia = 0 then Specia := I;
|
|
elsif Telephone = 0 then Telephone := I; Fin := Telephone + 10;
|
|
end if;
|
|
end if;
|
|
I := I + 1;
|
|
end loop;
|
|
C := Creer_Contact(Ligne(Prenom..Nom-1), Ligne(Nom+1..Ville-1), Ligne(Ville+1..Specia-1), Ligne(Specia+1..Telephone-1), Ligne(Telephone+1..Fin-1) & " ");
|
|
Inserer(C, AB);
|
|
end loop;
|
|
Close(Fichier);
|
|
|
|
|
|
Put_Line(Arbre_To_String(AB));
|
|
end;
|
|
|
|
end Tester_Abr_Contacts;
|