home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff345.lzh / MemFrag / memfrag.c < prev    next >
C/C++ Source or Header  |  1990-04-16  |  5KB  |  231 lines

  1. /************************************************************************ 
  2. *                                                                       * 
  3. *                                                                       * 
  4. *                      Filename:        MemFrag.c                       *      
  5. *                       Version:        0.0                             * 
  6. *                       Author :        Gary Duncan                     * 
  7. *                                                                       * 
  8. *                                frags , heavily modified               *
  9. *-----------------------------------------------------------------------* 
  10. *
  11. * Function:
  12. * ~~~~~~~~~
  13. *
  14. * Invocation:
  15. * ~~~~~~~~~~
  16. *
  17. * Modification record: 
  18. *~~~~~~~~~~~~~~~~~~~~
  19. * Date         By whom             Change 
  20. * ----         -------             ------ 
  21. * 17 Jan 89    GMD          Original ; frags.c heavily modified
  22. *                                            ( from FF69)
  23. *
  24. * 01 Jul 89    "          Date added
  25. *
  26. * Contents:    Function    Description
  27. * ~~~~~~~~     ~~~~~~~~    ~~~~~~~~~~~
  28. *+  
  29. *+  _main
  30. *+  print_count
  31. *+  ascify
  32. *+  MemCleanup
  33. *+ 
  34. *
  35. *
  36. *******************************************************************************/
  37.  
  38.  
  39. #include "gd_functions.h"
  40.  
  41.  
  42. #include <exec/types.h>
  43. #include <exec/exec.h>
  44. #include <exec/execbase.h>
  45.  
  46.  
  47. extern char *MakeDate[] ;
  48.  
  49. #if 0
  50. char redpen[]  =  "\033[33m";      /* red pen     */
  51. char witepen[] =  "\033[0m";      /* white  pen  */
  52. #endif
  53.  
  54. char ghdr[] = "\n\033[33m\
  55.                    Chip:Fast \n\
  56.                    ~~~~ ~~~~\033[0m\n" ;
  57.  
  58. char buffer[100] = "12345678 : 123     123 :123         \n"  ;
  59.  
  60. struct gazza { int   kk ;
  61.                 BYTE chip ;
  62.                 BYTE fast ; }  Chunk_Count[25] ;
  63.  
  64.  
  65.  
  66. _main() 
  67. {
  68.  
  69. long aggrF = 0 ;        /* GMD    */
  70. long aggrC = 0 ;        /* GMD    */
  71. char flag ;
  72. struct MemHeader *hdr ;
  73. struct MemChunk *chunk ;
  74. long    size ;
  75. extern struct ExecBase *SysBase ;
  76. short j ;
  77.  
  78.     {
  79.      char vvv[100] ;
  80.      sprintf ( vvv, "\nMemFrag: (%s) \n", 
  81.                 MakeDate[0] ) ;
  82.      Write(Output(), vvv, (long)strlen(vvv) ) ;    /* GMD */    
  83.     }
  84.     Forbid() ;
  85.  
  86.     hdr = (struct MemHeader *) SysBase -> MemList . lh_Head ;
  87.  
  88.     while (hdr ->mh_Node.ln_Succ) 
  89.          {
  90.         flag = *(char *)(hdr->mh_Node.ln_Name) ; /* 'F'ast or 'C'hip */
  91.  
  92.         for (chunk = hdr -> mh_First; chunk; chunk = chunk -> mc_Next)
  93.                   {
  94.             size = chunk -> mc_Bytes ;
  95.             for (j = 0; size; j += 1) 
  96.                 size >>= 1 ;
  97.  
  98.             Chunk_Count[j].kk += 1 ;
  99.             if ( flag == 'e' )    /* count Fast or Chip chunks */
  100.               ++Chunk_Count[j].fast ;
  101.             else
  102.               ++Chunk_Count[j].chip ;    /* GMD    */
  103.  
  104.         }
  105.  
  106.         hdr = (struct MemHeader *) hdr -> mh_Node . ln_Succ ;
  107.  
  108.       } /*end-while */
  109.  
  110.     Permit() ;
  111.  
  112.     Write(Output(), ghdr, (long)strlen(ghdr) ) ;    /* GMD */    
  113.  
  114.     for (j = 1; j <= 23; ++j )
  115.           {
  116.         if (Chunk_Count[j].kk)
  117.             print_count( j ) ;    /* print # of blocks    */
  118.           }
  119.  
  120.         exit ( 0 ) ;            /* GMD         */
  121. }
  122.  
  123. /*************************************************************************** 
  124.  
  125.  
  126.   Name :          print_count 
  127.  
  128.   Purpose:           Given index into array , prints line
  129.  
  130.  
  131.   Entry    :           
  132.  
  133.  
  134.   Returns  :           
  135.                                
  136.  
  137.  
  138. ****************************************************************************/ 
  139.  
  140.  
  141.  
  142. print_count ( j )
  143.  
  144. int j ;
  145. {
  146.  
  147.  
  148.     ascify ( (1L << (j-1)) ,             8 ,   &buffer[0]  ) ;
  149.     ascify ( (long)Chunk_Count[j].kk ,   3 ,   &buffer[11] ) ;
  150.     ascify ( (long)Chunk_Count[j].chip , 3 ,   &buffer[19] ) ;
  151.     ascify ( (long)Chunk_Count[j].fast , 3 ,   &buffer[24] ) ;
  152.  
  153.     Write(Output(), buffer,(long)strlen(buffer) ) ;
  154. }
  155.  
  156. /*************************************************************************** 
  157.  
  158.  
  159.   Name :          ascify
  160.  
  161.   Purpose:      Converts a long number  to an ASCII string
  162.  
  163.  
  164.   Entry    :    (long)numb = number
  165.              (int) digs = # of digits to print ( field-width )
  166.                 (char *) where = ptr to where sting is to be copied
  167.  
  168.  
  169.   Returns  :           
  170.                                
  171.  
  172.  
  173. ****************************************************************************/ 
  174.  
  175.  
  176. ascify ( numb , digs , where )
  177.  
  178. long numb ;
  179. int digs ;
  180. char *where ;
  181.  
  182. {
  183. int j , k ;
  184. char *ptr = where ;
  185.  
  186.     for ( j=0 , where += digs-1 ; j < digs ; ++j  )
  187.        {
  188.          k = numb%10 ;
  189.          numb /= 10  ; 
  190.          *where-- = k + '0'  ;
  191.  
  192.        }
  193.     while ( *ptr == '0' )
  194.           *ptr++ = ' ' ;
  195.     
  196.     
  197. }
  198. /*************************************************************************** 
  199.  
  200.  
  201.   Name :          MemCleanup
  202.  
  203.   Purpose:
  204.  
  205.  *
  206.  * To cut down on memory useage, we provide a stub for a routine pulled
  207.  * in by the default startup code in _main. This code cleans up
  208.  * dynamically allocated memory, which we don't need. So we flush the code
  209.  * here. By making this a smallcode, smalldata program, turning off stack 
  210.  * checking (nothing recursive, and only three routines, so who needs it?),
  211.  * and adding this, I've reduced the size of MemFrag to 1644 bytes. Since the
  212.  * original MemFrag is 1964 bytes long, I'm happy. Just out of curiosity, I'd
  213.  * like to know how large a binary Manx 3.4 produces.
  214.  
  215.  
  216.   Entry    :           
  217.  
  218.  
  219.   Returns  :           
  220.                                
  221.  
  222.  
  223. ****************************************************************************/ 
  224.  
  225.  
  226. MemCleanup() {}
  227.  
  228.