home *** CD-ROM | disk | FTP | other *** search
/ Superpower (Alt) / SUPERPOWER.iso / q / util / mbq319 / fatso.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-01  |  1.7 KB  |  79 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. // this program scans the symbol file to find large static objects
  5.  
  6. #define NUM_TO_REPORT    30
  7.  
  8. int smallest_fatso;
  9. int top_ten_fatso_sizes[NUM_TO_REPORT];
  10. char top_ten_fatso_names[NUM_TO_REPORT][256];
  11.  
  12. int main(int argc, char **argv)
  13. {
  14.  
  15.     char last_name[256];
  16.     char name[256];
  17.     char buffer[256];
  18.     char type[2];
  19.     int last_loc;
  20.     int loc;
  21.     int size;
  22.     int rc;
  23.     int i, j;
  24.     FILE *f;
  25.  
  26.     f = fopen("dos/sym_dos", "r");
  27.     if (!f)
  28.     {
  29.         fprintf(stderr, "Could not find dos/sym_dos\n");
  30.         return -1;
  31.     }
  32.  
  33.     memset(top_ten_fatso_sizes, 0, sizeof top_ten_fatso_sizes);
  34.     smallest_fatso = 0;
  35.     last_loc = 0;
  36.     strcpy(last_name, "[dos stub]");
  37.  
  38.     while (fgets(buffer, sizeof buffer, f))
  39.     {
  40.         rc = strlen(buffer);
  41.         buffer[rc-1] = 0;
  42.         rc = sscanf(buffer, "%x %s %s", &loc, type, name);
  43.         if (rc < 3)
  44.         {
  45.             fprintf(stderr, "bad line : [%s]\n", buffer);
  46.             continue;
  47.         }
  48.         size = loc - last_loc;
  49.         if (size > top_ten_fatso_sizes[smallest_fatso])
  50.         {
  51.             top_ten_fatso_sizes[smallest_fatso] = size;
  52.             strcpy(top_ten_fatso_names[smallest_fatso], last_name);
  53.             for (i=0 ; i<NUM_TO_REPORT ; i++)
  54.             {
  55.                 if (top_ten_fatso_sizes[i]
  56.                     < top_ten_fatso_sizes[smallest_fatso])
  57.                     smallest_fatso = i;
  58.             }
  59.         }
  60.         strcpy(last_name, name);
  61.         last_loc = loc;
  62.     }
  63.  
  64.     for (j=0 ; j<NUM_TO_REPORT ; j++)
  65.     {
  66.         printf("%8d bytes : [%s]\n", top_ten_fatso_sizes[smallest_fatso],
  67.             top_ten_fatso_names[smallest_fatso]);
  68.         top_ten_fatso_sizes[smallest_fatso] = 0x7fffffff;
  69.         for (i=0 ; i<NUM_TO_REPORT ; i++)
  70.         {
  71.             if (top_ten_fatso_sizes[i] < top_ten_fatso_sizes[smallest_fatso])
  72.                 smallest_fatso = i;
  73.         }
  74.     }
  75.  
  76.     return 0;
  77.  
  78. }
  79.