Amélioration de l'affichage verbeux sur +eurs fichiers

This commit is contained in:
Mattéo Delabre 2016-10-22 19:01:48 +02:00
parent 6cea8e8db5
commit 3aef7806cd
3 changed files with 25 additions and 17 deletions

View File

@ -54,14 +54,16 @@ double* _createFrequencies(const char* filepath) {
}
void compress(const char* filepath) {
printVerbose("Calcul des fréquences d'apparition de chaque caractère\n");
printVerbose("Compression du fichier '%s'...\n", filepath);
printVerbose("Calcul des fréquences d'apparition des caractères.\n");
double* frequencies = _createFrequencies(filepath);
if (isVerbose()) {
printFrequenciesTable(frequencies, NUM_CHARS);
}
printVerbose("\nConstruction de l'arbre de Huffman\n");
printVerbose("\nConstruction de l'arbre de Huffman.\n");
HufTree tree = createTree(frequencies);
free(frequencies);
@ -71,7 +73,7 @@ void compress(const char* filepath) {
printTree(tree);
}
printVerbose("\nÉtiquetage des feuilles de l'arbre\n");
printVerbose("\nÉtiquetage des feuilles de l'arbre.\n");
char** labels = createTreeLabels(tree);
freeTree(tree);
@ -81,4 +83,5 @@ void compress(const char* filepath) {
}
freeTreeLabels(labels);
labels = NULL;
}

View File

@ -74,44 +74,44 @@ int _maxDepth(HufVertex vert) {
}
void printFrequenciesTable(double* table, size_t size) {
printf("╭─┬───┬─────────╮\n");
printf("│C│num│fréquence│\n");
printf("├─┼───┼─────────┤\n");
printf("┌─┬────┬─────────┐\n");
printf("│C│code│fréquence│\n");
printf("├─┼───┼─────────┤\n");
double sum = 0;
for (size_t i = 0; i < size; i++) {
if (table[i] != 0) {
printf("│%c│%3d│%9lf│\n", _safeChar(i), (int) i, table[i]);
printf("│%c│%4d│%9.4lf│\n", _safeChar(i), (int) i, table[i]);
sum += table[i];
}
}
printf("├─┴───┼─────────┤\n");
printf("Total│%9lf│\n", sum);
printf("╰─────┴─────────╯\n");
printf("├─┴───┼─────────┤\n");
printf(" Total│%9.4lf│\n", sum);
printf("└──────┴─────────┘\n");
}
void printLabelsTable(char** table, size_t size) {
printf("╭─┬───┬────────────────╮\n");
printf("│C│num│ étiquette│\n");
printf("├─┼───┼────────────────┤\n");
printf("┌─┬────┬────────────────┐\n");
printf("│C│code│ étiquette│\n");
printf("├─┼───┼────────────────┤\n");
double total_length = 0;
size_t label_count = 0;
for (size_t i = 0; i < size; i++) {
if (table[i] != 0) {
printf("│%c│%3d│%16s│\n", _safeChar(i), (int) i, table[i]);
printf("│%c│%4d│%16s│\n", _safeChar(i), (int) i, table[i]);
total_length += strlen(table[i]);
label_count++;
}
}
printf("├─┴───┴───┬───────────┤\n");
printf("│Long. moy.│%11lf│\n", total_length / label_count);
printf("╰──────────┴───────────╯\n");
printf("├─┴───┴───┬───────────┤\n");
printf("│Long. moy.│%12.4lf│\n", total_length / label_count);
printf("└──────────┴────────────┘\n");
}
char _safeChar(char input) {

View File

@ -81,5 +81,10 @@ int main(int argc, char** argv) {
while (*filepath != NULL) {
compress(*filepath);
filepath++;
// Ligne de séparation entre les différents fichier
if (*filepath != NULL) {
printVerbose("\n");
}
}
}