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 >
Wrap
C/C++ Source or Header
|
1991-09-11
|
7KB
|
201 lines
/*-------------------------------------------------------------------------*
* *
* Prints some not-so interesting statistics about your index files *
* *
* Compile/link for Manx C 5.0d *
* cc -hi allprecomp -pp -wnuq -o checkrmf.o checkrmf.c *
* ln -o checkrmf checkrmf.o -lc *
* *
* Compile/link for Lattice 5.10 *
* LC -L -Hinclude:allprecomp.q checkrmf *
* (pre-compiled header file) *
* *
* *
*-------------------------------------------------------------------------*/
#include "avl.structs.h"
int check_rmf_index( char *f );
main( int argc, char *argv[] )
{
char *indexname;
long namelen;
if( argc < 2 ) {
printf("\n Syntax is %s 'name of rmf file'\n",argv[0]);
exit( 10 );
}
namelen = strlen(argv[1]) + 50;
indexname = AllocMem( namelen, MEMF_CLEAR );
strcpy(indexname,argv[1]);
strcat(indexname,".rmfindex");
check_rmf_index( indexname );
FreeMem( indexname, namelen );
}
int check_rmf_index( char *indexfile )
{
struct IndexFile *ix;
struct DiskIndex *dtnode;
int i;
long ok,err,skipkeybytes;
ULONG ifd;
ULONG keylengths[MAXINDICES];
ULONG keysindex[MAXINDICES];
ULONG activeblocks;
ULONG deleteblocks;
ULONG totalblocks;
ULONG activeblocklength,largestactiveblock,smallestactiveblock;
ULONG deleteblocklength,largestdeleteblock,smallestdeleteblock;
ifd = Open(indexfile,MODE_OLDFILE);
if( !ifd ) {
printf("\n\n COULD NOT OPEN FILE\n\n");
return( FALSE );
}
ix = AllocMem( sizeof(struct IndexFile), MEMF_CLEAR );
dtnode = AllocMem( sizeof(struct DiskIndex), MEMF_CLEAR );
activeblocks = 0;
deleteblocks = 0;
activeblocklength = 0;
deleteblocklength = 0;
largestactiveblock = 0;
smallestactiveblock = 99999999L;
largestdeleteblock = 0;
smallestdeleteblock = 99999999L;
for( i = 0; i < MAXINDICES; i++ ) {
keylengths[i] = 0;
keysindex[i] = 0;
}
ok = Read(ifd,ix,sizeof(struct IndexFile));
ok = TRUE;
while( ok ) {
/* fixed portion */
err = Read(ifd,dtnode,sizeof(struct DI_Info));
if( err <= 0 )
break;
skipkeybytes = 0;
for( i=0; i <= MAXINDEXNUM; i++ ) {
if( dtnode->di_info.recstatus == 'A' ) {
keylengths[i] = keylengths[i] + dtnode->di_info.keylen[i];
if( dtnode->di_info.keylen[i] )
++keysindex[i];
}
skipkeybytes = skipkeybytes + dtnode->di_info.keylen[i];
}
/* zero length key found */
if( skipkeybytes <= 0 )
break;
/* skip variable key portion */
err = Read(ifd,&dtnode->keydata[0],skipkeybytes);
if( err <= 0 ) {
printf("Zero Length Key at record ");
printf("location %-d",dtnode->di_info.recaddr);
printf(" (%xhex) in datafile\n",dtnode->di_info.recaddr);
Close( ifd );
FreeMem( ix, sizeof(struct IndexFile) );
FreeMem( dtnode, sizeof(struct DiskIndex) );
return( FALSE );
}
if( dtnode->di_info.recstatus == 'A' ) {
++activeblocks;
activeblocklength = activeblocklength + dtnode->di_info.blklength;
if( dtnode->di_info.blklength > largestactiveblock )
largestactiveblock = dtnode->di_info.blklength;
if( dtnode->di_info.blklength < smallestactiveblock )
smallestactiveblock = dtnode->di_info.blklength;
}
if( dtnode->di_info.recstatus == 'D' ) {
++deleteblocks;
deleteblocklength = deleteblocklength + dtnode->di_info.blklength;
if( dtnode->di_info.blklength > largestdeleteblock )
largestdeleteblock = dtnode->di_info.blklength;
if( dtnode->di_info.blklength < smallestdeleteblock )
smallestdeleteblock = dtnode->di_info.blklength;
}
}
Close( ifd );
FreeMem( ix, sizeof(struct IndexFile) );
FreeMem( dtnode, sizeof(struct DiskIndex) );
totalblocks = activeblocks+deleteblocks;
if( totalblocks == 0 ) {
printf("\n\nFile contains 0 blocks\n\n");
return( FALSE );
}
if( !activeblocks )
smallestactiveblock = 0;
if( !deleteblocks )
smallestdeleteblock = 0;
printf("\n\nTotal Blocks : %-d\n",totalblocks);
printf("\n Active Blocks : %-d (%c%03d)\n",activeblocks,'%', \
(activeblocks*100)/totalblocks);
printf(" %-d bytes used \n",activeblocklength);
printf(" Largest Active Block %d bytes\n", \
largestactiveblock);
printf(" Smallest Active Block %d bytes\n", \
smallestactiveblock);
if( activeblocks )
printf(" Avg. %-d bytes per block\n", \
activeblocklength/activeblocks);
printf("\n Deleted Blocks : %-d (%c%03d)\n",deleteblocks,'%', \
(deleteblocks*100)/totalblocks);
printf(" %-d bytes used \n",deleteblocklength);
printf(" Largest Delete Block %d bytes\n", \
largestdeleteblock);
printf(" Smallest Delete Block %d bytes\n", \
smallestdeleteblock);
if( deleteblocks )
printf(" Avg. %-d bytes per block\n", \
deleteblocklength/deleteblocks);
printf("\n");
for( i = 0; i <= MAXINDEXNUM; i++ ) {
if( keysindex[i] )
printf(" Index %-d: Contains %4d keys Avg Key Len: %-d\n", \
i,keysindex[i],keylengths[i]/keysindex[i]);
else
printf(" Index %-d: Contains %4d keys Avg Key Len: %-d\n", \
i,keysindex[i],keysindex[i]);
}
return(TRUE);
}