home *** CD-ROM | disk | FTP | other *** search
-
- /* Shrink.c
-
- Shrinks a database so that its size is consistent with its
- record count bytes.
- */
-
- #include "w4.h"
- #include "d4base.h"
- #include "u4error.h"
-
- #include <io.h>
-
- main(int argc, char *argv[])
- {
- long num_recs ;
-
- d4init() ;
- w4clear(-1) ;
-
- if ( argc < 2 )
- {
- w4display( "SHRINK.EXE",
- "This program reduces the size of a dBASE data file to",
- "be consistent with the record count bytes.",
- "",
- "Run this program as follows:",
- "",
- "shrink database_name",
- (char *) 0 ) ;
- w4exit(0) ;
- }
-
- if ( d4use(argv[1]) < 0 )
- w4exit(1) ;
-
- if ( lseek( d4ptr()->file_hand, 4L, 0 ) != 4 )
- {
- u4error( E_LSEEK, d4name(), (char *) 0 ) ;
- w4exit(1) ;
- }
-
- if ( read( d4ptr()->file_hand, (void *) &num_recs, 4 ) != 4 )
- {
- u4error( E_READ, d4name(), (char *) 0) ;
- w4exit(1) ;
- }
-
- if ( num_recs < 0 )
- {
- w4display( "Data Error", "Negative Record Count Bytes",
- "They will be increased to correspond to the file size.",
- (char *) 0 ) ;
- d4close_all() ;
- w4exit(1) ;
- }
-
- if ( num_recs < d4reccount() )
- d4zap( num_recs+1L, d4reccount() ) ;
-
- w4( 22,0, "Final Record Count: " ) ;
- w4long( 22,w4col(), d4reccount(), 8 ) ;
-
- d4close_all() ;
- w4exit(0) ;
- }
-