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

  1.  
  2. /*  x4pack.c   (c)Copyright Sequiter Software Inc., 1987-1990.  All rights reserved.
  3.  
  4.     Packs a database according to the filter conditions.
  5.     It does not use 'chsize' routine.
  6. */
  7.  
  8. #include "d4all.h"
  9. #include "u4error.h"
  10.  
  11. #include <stdio.h>
  12. #include <string.h>
  13.  
  14. #ifndef UNIX
  15. #include <io.h>
  16. #endif
  17.  
  18. extern int  v4cur_base, v4lock_wait ;
  19.  
  20.  
  21. int  x4pack( int safety )
  22. {
  23.    char  part_name[258], final_name[258] ;
  24.    int   new_ref, final_ref ;
  25.    BASE  save_buffer, *ptr ;
  26.  
  27.    if ( (ptr = d4ptr()) == (BASE *) 0 )
  28.    {
  29.       u4error( E_D_MISSING, (char *) 0 ) ;
  30.       return( -1 ) ;
  31.    }
  32.  
  33.    memcpy( &save_buffer, ptr, sizeof(BASE) ) ;
  34.  
  35.    u4name_part( part_name, d4name(), 1, 0 ) ;
  36.    u4name_full( final_name, part_name, ".BAK" ) ;
  37.  
  38.    if ( (new_ref = x4copy(final_name, 1L, safety)) < 0 )  return new_ref ;
  39.  
  40.    ptr->filter_ref = ptr->relate_ref = ptr->current_index = ptr->index_ref = -1;
  41.    if ( d4close() < 0 )  return -1 ;
  42.  
  43.    d4select( new_ref ) ;
  44.    final_ref = x4copy(save_buffer.name, 1L, 0) ;
  45.    d4close() ;
  46.    if ( final_ref < 0 )  return -1 ;
  47.  
  48.    if ( u4remove( final_name) < 0 )  return -1 ;
  49.  
  50.    d4select(final_ref) ;
  51.    ptr =  d4ptr() ;
  52.    ptr->filter_ref =  save_buffer.filter_ref ;
  53.    ptr->relate_ref =  save_buffer.relate_ref ;
  54.    ptr->current_index =  save_buffer.current_index ;
  55.    ptr->index_ref  =  save_buffer.index_ref ;
  56.  
  57.    if ( i4reindex(-1) < 0 )  return -1 ;
  58.  
  59.    if ( save_buffer.rec_tot > 0L )
  60.    {
  61.       if ( d4buf_total( save_buffer.rec_tot, save_buffer.max_bufs,
  62.                         save_buffer.buf_may_lend ) < 0 )  return -1 ;
  63.       if ( save_buffer.rec_per_buf > 0L )
  64.          if ( d4buf_unit( save_buffer.rec_per_buf) < 0 )  return -1 ;
  65.    }
  66.  
  67.    return final_ref ;
  68. }
  69.  
  70.  
  71.