home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d559 / rexxrmf.lha / RexxRMF / rexxrmflib.lzh / checkrmf.c < prev    next >
C/C++ Source or Header  |  1991-09-11  |  7KB  |  201 lines

  1. /*-------------------------------------------------------------------------*
  2.  *                                                                         *
  3.  * Prints some not-so interesting statistics about your index files        *
  4.  *                                                                         *
  5.  * Compile/link for Manx C 5.0d                                            *
  6.  *   cc -hi allprecomp -pp -wnuq -o checkrmf.o checkrmf.c                  *
  7.  *   ln -o checkrmf checkrmf.o -lc                                         *
  8.  *                                                                         *
  9.  * Compile/link for Lattice 5.10                                           *
  10.  *   LC -L -Hinclude:allprecomp.q checkrmf                                 *
  11.  *         (pre-compiled header file)                                      *
  12.  *                                                                         *
  13.  *                                                                         *
  14.  *-------------------------------------------------------------------------*/
  15.  
  16. #include "avl.structs.h"
  17.  
  18. int check_rmf_index( char *f );
  19.  
  20. main( int argc, char *argv[] )
  21. {
  22.     char *indexname;
  23.     long namelen;
  24.  
  25.     if( argc < 2 ) {
  26.         printf("\n Syntax is %s 'name of rmf file'\n",argv[0]);
  27.         exit( 10 );
  28.     }
  29.         
  30.     namelen = strlen(argv[1]) + 50;
  31.     indexname = AllocMem( namelen, MEMF_CLEAR );
  32.     
  33.     strcpy(indexname,argv[1]);
  34.     strcat(indexname,".rmfindex");
  35.     
  36.     check_rmf_index( indexname );
  37.     
  38.     FreeMem( indexname, namelen );
  39.     
  40. }
  41.  
  42.  
  43. int check_rmf_index( char *indexfile )
  44. {
  45.  
  46.  
  47.    struct IndexFile *ix;
  48.    struct DiskIndex *dtnode; 
  49.    int i;
  50.    long  ok,err,skipkeybytes;
  51.    ULONG ifd;
  52.    ULONG keylengths[MAXINDICES];
  53.    ULONG keysindex[MAXINDICES];
  54.    ULONG activeblocks;
  55.    ULONG deleteblocks;
  56.    ULONG totalblocks;
  57.    ULONG activeblocklength,largestactiveblock,smallestactiveblock;
  58.    ULONG deleteblocklength,largestdeleteblock,smallestdeleteblock;
  59.    
  60.    ifd = Open(indexfile,MODE_OLDFILE);
  61.    if( !ifd ) {
  62.        printf("\n\n COULD NOT OPEN FILE\n\n");
  63.        return( FALSE );
  64.    }
  65.  
  66.    ix     = AllocMem( sizeof(struct IndexFile), MEMF_CLEAR );
  67.    dtnode = AllocMem( sizeof(struct DiskIndex), MEMF_CLEAR );
  68.    
  69.    activeblocks = 0;
  70.    deleteblocks = 0;
  71.    activeblocklength = 0;
  72.    deleteblocklength = 0;
  73.    largestactiveblock = 0;
  74.    smallestactiveblock = 99999999L;
  75.    largestdeleteblock = 0;
  76.    smallestdeleteblock = 99999999L;
  77.  
  78.    for( i = 0; i < MAXINDICES; i++ ) {
  79.         keylengths[i] = 0;
  80.         keysindex[i] = 0;
  81.    }
  82.    
  83.    ok = Read(ifd,ix,sizeof(struct IndexFile));
  84.    
  85.    ok = TRUE;
  86.    while( ok ) {
  87.    
  88.       /* fixed portion */
  89.       err = Read(ifd,dtnode,sizeof(struct DI_Info));
  90.       if( err <= 0 ) 
  91.            break;
  92.       
  93.       skipkeybytes = 0;
  94.       for( i=0; i <= MAXINDEXNUM; i++ ) {
  95.            if( dtnode->di_info.recstatus == 'A' ) {
  96.                keylengths[i] = keylengths[i] + dtnode->di_info.keylen[i];
  97.                if( dtnode->di_info.keylen[i] ) 
  98.                    ++keysindex[i];
  99.            }
  100.            skipkeybytes = skipkeybytes + dtnode->di_info.keylen[i]; 
  101.       }
  102.            
  103.       /* zero length key found */     
  104.       if( skipkeybytes <= 0 )
  105.           break;
  106.           
  107.       /* skip variable key portion */
  108.       err = Read(ifd,&dtnode->keydata[0],skipkeybytes);
  109.       
  110.       if( err <= 0 ) {
  111.           printf("Zero Length Key at record ");
  112.           printf("location %-d",dtnode->di_info.recaddr);
  113.           printf("  (%xhex) in datafile\n",dtnode->di_info.recaddr);
  114.           Close( ifd );
  115.           FreeMem( ix, sizeof(struct IndexFile) );
  116.           FreeMem( dtnode, sizeof(struct DiskIndex) );
  117.           return( FALSE );
  118.       }    
  119.  
  120.       if( dtnode->di_info.recstatus == 'A' ) {
  121.           ++activeblocks;
  122.           activeblocklength = activeblocklength + dtnode->di_info.blklength;
  123.           if( dtnode->di_info.blklength > largestactiveblock )
  124.               largestactiveblock = dtnode->di_info.blklength;
  125.           if( dtnode->di_info.blklength < smallestactiveblock )
  126.               smallestactiveblock = dtnode->di_info.blklength;
  127.       }
  128.  
  129.       if( dtnode->di_info.recstatus == 'D' ) {
  130.           ++deleteblocks;
  131.           deleteblocklength = deleteblocklength + dtnode->di_info.blklength;
  132.           if( dtnode->di_info.blklength > largestdeleteblock )
  133.               largestdeleteblock = dtnode->di_info.blklength;
  134.           if( dtnode->di_info.blklength < smallestdeleteblock )
  135.               smallestdeleteblock = dtnode->di_info.blklength;
  136.       }
  137.       
  138.    }   
  139.    
  140.    Close( ifd );
  141.    
  142.    FreeMem( ix, sizeof(struct IndexFile) );
  143.    FreeMem( dtnode, sizeof(struct DiskIndex) );
  144.    
  145.    totalblocks = activeblocks+deleteblocks;
  146.    
  147.    if( totalblocks == 0 ) {
  148.        printf("\n\nFile contains 0 blocks\n\n");
  149.        return( FALSE );
  150.    }    
  151.        
  152.    if( !activeblocks )
  153.        smallestactiveblock = 0;
  154.    if( !deleteblocks )
  155.        smallestdeleteblock = 0;
  156.     
  157.    printf("\n\nTotal Blocks         : %-d\n",totalblocks);
  158.  
  159.    printf("\n      Active Blocks  : %-d  (%c%03d)\n",activeblocks,'%', \
  160.                          (activeblocks*100)/totalblocks);
  161.  
  162.    printf("                       %-d bytes used \n",activeblocklength);
  163.  
  164.    printf("                       Largest Active Block %d bytes\n", \
  165.                          largestactiveblock);
  166.  
  167.    printf("                       Smallest Active Block %d bytes\n", \
  168.                          smallestactiveblock);
  169.  
  170.    if( activeblocks )
  171.        printf("                       Avg. %-d bytes per block\n", \
  172.                          activeblocklength/activeblocks);
  173.  
  174.    printf("\n      Deleted Blocks : %-d  (%c%03d)\n",deleteblocks,'%', \
  175.                          (deleteblocks*100)/totalblocks);
  176.  
  177.    printf("                       %-d bytes used \n",deleteblocklength);
  178.  
  179.    printf("                       Largest Delete Block %d bytes\n", \
  180.                          largestdeleteblock);
  181.  
  182.    printf("                       Smallest Delete Block %d bytes\n", \
  183.                          smallestdeleteblock);
  184.    if( deleteblocks )
  185.        printf("                       Avg. %-d bytes per block\n", \
  186.                          deleteblocklength/deleteblocks);
  187.        
  188.    printf("\n");
  189.    for( i = 0; i <= MAXINDEXNUM; i++ ) {
  190.    if( keysindex[i] )
  191.      printf("      Index %-d: Contains %4d keys  Avg Key Len: %-d\n", \
  192.                          i,keysindex[i],keylengths[i]/keysindex[i]);
  193.    else
  194.      printf("      Index %-d: Contains %4d keys  Avg Key Len: %-d\n", \
  195.                          i,keysindex[i],keysindex[i]);
  196.    }
  197.    
  198.    return(TRUE);
  199. }
  200.  
  201.