diff tools/fanalyze.c @ 2011:8e38fa3c4f98

Fix use of qsort().
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 08 Jul 2018 00:47:22 +0300
parents 4a4c3e15b8c2
children 8a9ef75fd3cd
line wrap: on
line diff
--- a/tools/fanalyze.c	Sat Jul 07 22:20:47 2018 +0300
+++ b/tools/fanalyze.c	Sun Jul 08 00:47:22 2018 +0300
@@ -130,18 +130,15 @@
 }
 
 
-void dmSortStats(DMStats *stats)
-{
-    qsort(&stats->cv, sizeof(DMStatValue), SET_MAX_ELEMS, dmCompareStatFunc);
-}
-
-
 void dmPrintStats(DMStats *stats, const int nmax, const size_t size)
 {
+    qsort(&stats->cv, SET_MAX_ELEMS, sizeof(DMStatValue), dmCompareStatFunc);
+
     for (int n = 0; n < nmax; n++)
     {
-        printf("$%02x (%1.2f%%), ",
+        printf("$%02x (%d = %1.2f%%), ",
             stats->cv[n].value,
+            stats->cv[n].count,
             ((float) stats->cv[n].count * 100.0f) / (float) size);
     }
     printf("\n\n");
@@ -188,6 +185,7 @@
             compBufSize = file->size;
 
         totalSize += file->size;
+        dmInitStats(&file->stats);
     }
 
     // Allocate comparision buffer
@@ -206,7 +204,6 @@
     for (int nfile = 0; nfile < nsrcFiles; nfile++)
     {
         DMSourceFile *file = &srcFiles[nfile];
-        dmInitStats(&file->stats);
 
         for (size_t offs = 0; offs < file->size; offs++)
         {
@@ -220,11 +217,7 @@
             Uint8 data = offs < file->size ? file->data[offs] : 0;
             compBuf[offs].stats[data]++;
         }
-
-        dmSortStats(&file->stats);
     }
-    dmSortStats(&totalStats);
-
 
     for (size_t offs = 0; offs < compBufSize; offs++)
     {