From e3b384065b9a8cbd39bb68c279dad799ed3b99bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Y=C3=BBki?= <37001799+NyxiumYuuki@users.noreply.github.com> Date: Thu, 19 Nov 2020 10:46:20 +0100 Subject: [PATCH] Version Finale (Sans erreur de traitement) --- main_compress.c | 67 ++++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/main_compress.c b/main_compress.c index e72ca98..cf06b71 100644 --- a/main_compress.c +++ b/main_compress.c @@ -1,53 +1,59 @@ #include #include -#include -#include -#include "gestion_des_fichiers/gestion_fichiers.h" +#include #include "main_compress.h" #include "arbre_de_codage/arbre_binaire.h" - +#include "gestion_des_fichiers/gestion_fichiers.h" #define ASCII_EXT 256 + + + // main_compress.c [nom_du_fichier_a_compresser] int main(int argc, char **argv){ Bin_file *p; char *filename = argv[1]; char mode= 'r'; + // Vérification de l'existance du second argument (Nom du fichier à compresser) printf("Argc : %d\n",argc); if(argc != 2){ printf("\nErreur : Veuillez mettre en argument un nom de fichier à compresser (Ex: %s text.txt)\n",argv[0]); return -1; } + // Vérification de l'ouverture du fichier en mode lecture binaire !! FONCTION A MODIFIER - else if(!(p=Ouv_Bit(filename,mode))){ + else if(!(p=Ouv_Bit("test.txt",mode))){ printf("\nErreur : Fichier %s inexistant\n",filename); return -2; } printf("Tableau : \n"); arbre N[ASCII_EXT]; // Initialisation de l'arbre + printf("Tableau initialisé -1: \n"); init_tab(N,ASCII_EXT); // On initialise l'arbre avec des poids de -1 + printf("Tableau get freq : \n"); + frequence(N,p->file); // On récupère la fréquence d'apparition des lettres du fichiers + printf("Tableau tri : \n"); tri_tab(N,ASCII_EXT); // On fait un tri à bulle sur ce tableau + printf("Tableau affichage : \n"); afficher_tab(N,ASCII_EXT); + arbre huff; printf("Huffman : \n"); huff = huffman(N); + printf("Arbre :\n"); int found[1]={0}; - int taille=huff->poids; - plex Codage[taille]; - init_codage(Codage,taille); - printf("Lexique:\n"); + plex Codage[ASCII_EXT]; + init_codage(Codage,ASCII_EXT); get_lexique(p->file, Codage,huff); - printf("Compression %s : \n",Codage[0]->code); - compression(Codage,taille,huff); - printf("Fermeture:\n"); Ferm_Bit(p); + return 0; } @@ -106,6 +112,8 @@ void afficher_tab(arbre T[], int n){ arbre huffman(arbre T[]){ // Création de l'arbre de codage de Huffman en considérant une liste avec les fréquences d'apparition des caractères ordonnée croissante + + // récupérer les deux plus petits poids (cf : deux premieres occurences) arbre H = malloc(sizeof(arbre)); H=creer_arbre_vide(); int i; @@ -117,7 +125,7 @@ arbre huffman(arbre T[]){ Index=i; while(Indexelt=0; + tmp->elt=NULL; tmp->fils_gauche=T[Index]; tmp->fils_droit=T[Index+1]; tmp->poids=T[Index]->poids +T[Index+1]->poids; @@ -135,9 +143,9 @@ void init_codage(plex Code[], int n){ for(i=0;icode[j]=0; + tmp->code[j]=NULL; } - tmp->lettre=0; + tmp->lettre=NULL; Code[i]=tmp; } } @@ -157,22 +165,23 @@ void get_lexique(FILE *file, plex Code[], arbre huff){ i++; } } - -void compression(plex Code[],int n, arbre H){ - Bin_file* cmp; - cmp=Ouv_Bit("cmp.txt",'w'); - serialisation(H,cmp->file); - fwrite("123",3,1,cmp->file); +/* +void Compress(plex Code[],FILE*file){ + char s[]=""; int i; int j; - char tmp; - for(i=0;icode[j]!='\0'){ - printf(" %s %c\n",Code[i]->code,Code[i]->code[j]); - Ec_Bit(cmp,Code[i]->code[j]); - j++; + if(Code[i]->lettre!=NULL){ + while((Code[i]->code!='\0')&&(32%j!=0)){ + if(Code[i]->code!='\0'){ + Ec_Bit("comp.txt",Code[i]->code); + Code[i]->code++; + } + else{ + Ec_Bit("comp.txt",'0'); + } + } } - printf("\n"); } -} \ No newline at end of file +}*/ \ No newline at end of file