home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c160 / 1.ddi / EXAMPLES / U4SHRINK.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-22  |  1.4 KB  |  67 lines

  1.  
  2. /* Shrink.c
  3.  
  4.     Shrinks a database so that its size is consistent with its
  5.     record count bytes.
  6. */
  7.  
  8. #include "w4.h"
  9. #include "d4base.h"
  10. #include "u4error.h"
  11.  
  12. #include <io.h>
  13.  
  14. main(int argc, char *argv[])
  15. {
  16.    long  num_recs ;
  17.  
  18.    d4init() ;
  19.    w4clear(-1) ;
  20.  
  21.    if ( argc < 2 )
  22.    {
  23.       w4display( "SHRINK.EXE",
  24.                  "This program reduces the size of a dBASE data file to",
  25.                  "be consistent with the record count bytes.",
  26.                  "",
  27.                  "Run this program as follows:",
  28.                  "",
  29.                  "shrink  database_name",
  30.                   (char *) 0 ) ;
  31.       w4exit(0) ;
  32.    }
  33.  
  34.    if ( d4use(argv[1]) < 0 )
  35.       w4exit(1) ;
  36.  
  37.    if ( lseek( d4ptr()->file_hand, 4L, 0 ) != 4 )
  38.    {
  39.       u4error( E_LSEEK, d4name(), (char *) 0 ) ;
  40.       w4exit(1) ;
  41.    }
  42.  
  43.    if ( read( d4ptr()->file_hand, (void *) &num_recs, 4 ) != 4 )
  44.    {
  45.       u4error( E_READ, d4name(), (char *) 0) ;
  46.       w4exit(1) ;
  47.    }
  48.  
  49.    if ( num_recs < 0 )
  50.    {
  51.       w4display( "Data Error", "Negative Record Count Bytes",
  52.          "They will be increased to correspond to the file size.",
  53.          (char *) 0 ) ;
  54.       d4close_all() ;
  55.       w4exit(1) ;
  56.    }
  57.  
  58.    if ( num_recs < d4reccount() )
  59.       d4zap( num_recs+1L, d4reccount() ) ;
  60.  
  61.    w4( 22,0, "Final Record Count: " ) ;
  62.    w4long( 22,w4col(), d4reccount(), 8 ) ;
  63.  
  64.    d4close_all() ;
  65.    w4exit(0) ;
  66. }
  67.