home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / UTILITY / DIR / MFD_1_00.ZIP / fdstat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-17  |  2.9 KB  |  136 lines

  1. /*
  2.  * fdstat.c
  3.  *
  4.  * maintain, compute and print out statistics on duplicate files.
  5.  *
  6.  * Roy Bixler
  7.  * Monk Software
  8.  * March 29, 1991
  9.  *
  10.  * This program is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published by
  12.  * the Free Software Foundation; either version 1, or (at your option)
  13.  * any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to the Free Software
  22.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  */
  24.  
  25.  
  26.  
  27. #include <dir.h>
  28. #include <dos.h>
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31.  
  32. #include "fdcomm.h"
  33. #include "fdstat.h"
  34.  
  35.  
  36.  
  37. static unsigned long total_bytes = 0UL, total_dup_bytes = 0UL;
  38. static unsigned long total_del_bytes = 0UL;
  39. static unsigned int num_files = 0U, num_which_dupd = 0U, num_dups = 0U;
  40.  
  41.  
  42.  
  43. /*
  44.  * update_total_bytes
  45.  *
  46.  * called to update the total number of bytes in duplicate files
  47.  */
  48. void update_total_bytes(long f_size)
  49.  
  50. {
  51.     total_bytes += f_size;
  52. }
  53.  
  54.  
  55.  
  56. /*
  57.  * update_total_del_bytes
  58.  *
  59.  * called to update the total number of bytes in duplicate files
  60.  */
  61. void update_total_del_bytes(long f_size)
  62.  
  63. {
  64.     total_del_bytes += f_size;
  65. }
  66.  
  67.  
  68.  
  69. /*
  70.  * update_num_files
  71.  *
  72.  * called to update the total number of files
  73.  */
  74. void update_num_files()
  75.  
  76. {
  77.     num_files++;
  78. }
  79.  
  80.  
  81.  
  82. /*
  83.  * update_num_which_dupd
  84.  *
  85.  * called to update the total number of files which have duplicates
  86.  */
  87. void update_num_which_dupd()
  88.  
  89. {
  90.     num_which_dupd++;
  91. }
  92.  
  93.  
  94.  
  95. /*
  96.  * update_num_dups
  97.  *
  98.  * called to update the total number of duplicate files and total bytes in same
  99.  */
  100. void update_num_dups(unsigned n_dups, long bytes)
  101.  
  102. {
  103.     num_dups += n_dups;
  104.     total_dup_bytes += bytes;
  105. }
  106.  
  107.  
  108.  
  109. /*
  110.  * print_stats
  111.  *
  112.  * tabulate the statistics for this run of 'find duplicates'
  113.  */
  114. void print_stats()
  115.  
  116. {
  117.     printf("Total # of files = %u\n", num_files);
  118.     printf("Total bytes in files = %lu\n\n", total_bytes);
  119.  
  120.     printf("Total # of duplicate file names = %u\n", num_which_dupd);
  121.     printf("Total # of duplicate files = %u\n", num_dups);
  122.     printf("Total bytes in duplicate files = %lu\n", total_dup_bytes);
  123.     if (i_flag)
  124.         printf("Total bytes deleted = %lu\n", total_del_bytes);
  125.     if (num_dups > 0)
  126.         printf("\nAverage duplicate file size = %ld", total_dup_bytes/num_dups);
  127.     if ((num_files > 0) && (num_dups > 0))
  128.         printf("\nAverage # of duplicates per file = %f",
  129.                (float) num_dups/num_files);
  130.     if ((num_which_dupd > 0) && (num_dups > 0))
  131.         printf("\nAverage # of duplicates per duplicate name = %f",
  132.                (float) num_dups/num_which_dupd);
  133.     if (num_dups)
  134.         printf("\n");
  135. }
  136.