1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
double kolmo(char *f1, char *f2, int x, char * pathRepMail, char * pathRepSpam, char * pathRepNotSpam)
{
FILE *file1;
FILE *file2;
FILE *concat;
int res;
long tailleA;
long tailleB;
long tailleAB;
char final[200];
/* On compresse avec la méthode LZW */
printf("--- Fichiers analysés ---\n");
fflush(stdout);
printf("--- f1 : %s ---\n", f1);
fflush(stdout);
printf("--- f2 : %s ---\n", f2);
fflush(stdout);
sprintf(final, "%s%s", pathRepMail, f1);
res = LZW(final, "tmp1");
if (res < 0)
{
perror("kolmo : La compression a échouée ! \n");
return ECHEC_COMPRESSION;
}
if (x == SPAM)
{
sprintf(final, "%s%s", pathRepSpam, f2);
}
if (x == NOTSPAM)
{
sprintf(final, "%s%s", pathRepNotSpam, f2);
}
res = LZW(final, "tmp2");
if (res < 0)
{
perror("kolmo : La compression a échouée ! \n");
return ECHEC_COMPRESSION;
}
concatFiles(f1, f2, x, pathRepMail, pathRepSpam, pathRepNotSpam);
res = LZW("temp3", "tmp3");
if (res < 0)
{
perror("kolmo : La compression a échouée ! CONCATFILES !\n");
return ECHEC_COMPRESSION;
}
/* On va calculer la taille des 3 fichiers compressés */
file1 = fopen("tmp1","rb");
file2 = fopen("tmp2","rb");
concat = fopen("tmp3","rb");
if ((file1 == NULL) || (file2 == NULL) || (concat == NULL))
{
perror("kolmo : Erreur ouverture fichier");
return ECHEC_OUVERTURE_FICHIER;
}
tailleA = fsize(file1);
tailleB = fsize(file2);
tailleAB = fsize(concat);
fclose(file1);
fclose(file2);
fclose(concat);
/* Application de l'algo de Kolmo */
return distanceKolmo(tailleA, tailleB, tailleAB);
} |