home *** CD-ROM | disk | FTP | other *** search
-
- /* m4check.c (c)Copyright Sequiter Software Inc., 1987-1990. All rights reserved. */
-
- #include "p4misc.h"
- #include "d4all.h"
- #include "u4error.h"
- #include "m4.h"
-
- #include <string.h>
- #ifndef UNIX
- #include <io.h>
- #endif
-
- extern int m4to_disk( FREE_AREA *, M *) ;
- extern int m4skip_area( M *) ;
- extern BASE *v4base ;
-
- long data[5] ;
-
- #define NO_ENTRIES data[0] /* The number of free chain entries */
- #define FREE_BLOCKS data[1] /* The number of free blocks */
- #define ADJACENT data[2] /* The number of adjacent free entries */
- #define LOST_BLOCKS data[3] /* The number of lost blocks */
- #define USED_BLOCKS data[4] /* The number of used blocks */
-
-
- long *m4check( long field_ref )
- {
- M m ;
- MEMO_BLOCK memo_block ;
- char *ptr ;
- long on_rec, memo_num, tot_len, tot_blocks, len_read ;
- int rc ;
-
- memset( (char *) &m, (int) 0, sizeof(m) ) ;
- m.base_ref = (int) (field_ref >> 16) ;
-
- if ( m4open(m.base_ref) < 0 ) return (long *) 0 ;
-
- m.block_size = v4base[m.base_ref].memo_size ;
- if ( m.block_size <= 0 ) m.block_size = 0x200 ;
- m.hand = v4base[m.base_ref].memo_file ;
-
- memset( (char *) data, 0, sizeof(data) ) ;
-
- if ( (ptr = h4alloc( 0x7FFF )) == (char *) 0 ) return( (long *) 0 ) ;
-
- for( rc = m4skip_area(&m); rc == 0 && m.cur.num < 0xFFFFFFL; rc = m4skip_area(&m) )
- {
- NO_ENTRIES++ ;
- FREE_BLOCKS += m.cur.num ;
-
- if ( m.cur.block_no == m.prev.block_no + m.prev.num && m.cur.block_no != 0L )
- ADJACENT++ ;
- }
- if ( rc < 0 )
- {
- h4free_memory(ptr) ;
- return (long *) 0 ;
- }
-
- for ( on_rec = 1L ; on_rec <= d4reccount(); on_rec++ )
- {
- if ( d4go( on_rec ) != 0 )
- {
- h4free_memory(ptr) ;
- return (long *) 0 ;
- }
-
- memo_num = (long) c4atol(f4ptr(field_ref), f4width(field_ref)) ;
- if ( memo_num == 0L ) continue ;
-
- lseek( m.hand, memo_num * m.block_size, 0 ) ;
- rc = read( m.hand, (char *) &memo_block, sizeof(MEMO_BLOCK) ) ;
- if ( rc < 0 )
- {
- u4error( E_READ, "Memo File:", m4name(m.base_ref), (char *) 0 ) ;
- h4free_memory( ptr ) ;
- return (long *) 0 ;
- }
-
- if ( memo_block.minus_one == -1 )
- len_read = memo_block.num_chars ;
- else
- {
- len_read = (int) m4read( field_ref, on_rec, (char *) ptr, 0x7FFF) ;
- if ( len_read < 0 )
- {
- h4free_memory(ptr) ;
- return (long *) 0 ;
- }
- }
-
- USED_BLOCKS += (len_read+ m.block_size-1) / m.block_size ;
- }
-
- NO_ENTRIES-- ;
- h4free_memory(ptr) ;
-
- if ( rc < 0 )
- return (long *) 0 ;
-
- /* Compute the number of lost blocks */
- if ( (tot_len = filelength(m.hand)) < 0L)
- return (long *) 0 ;
-
- tot_blocks = (tot_len + m.block_size -1) / m.block_size ;
- LOST_BLOCKS = tot_blocks - USED_BLOCKS - FREE_BLOCKS - 1 ;
-
- return data ;
- }
-