home *** CD-ROM | disk | FTP | other *** search
-
- /* x4pack.c (c)Copyright Sequiter Software Inc., 1987-1990. All rights reserved.
-
- Packs a database according to the filter conditions.
- It does not use 'chsize' routine.
- */
-
- #include "d4all.h"
- #include "u4error.h"
-
- #include <stdio.h>
- #include <string.h>
-
- #ifndef UNIX
- #include <io.h>
- #endif
-
- extern int v4cur_base, v4lock_wait ;
-
-
- int x4pack( int safety )
- {
- char part_name[258], final_name[258] ;
- int new_ref, final_ref ;
- BASE save_buffer, *ptr ;
-
- if ( (ptr = d4ptr()) == (BASE *) 0 )
- {
- u4error( E_D_MISSING, (char *) 0 ) ;
- return( -1 ) ;
- }
-
- memcpy( &save_buffer, ptr, sizeof(BASE) ) ;
-
- u4name_part( part_name, d4name(), 1, 0 ) ;
- u4name_full( final_name, part_name, ".BAK" ) ;
-
- if ( (new_ref = x4copy(final_name, 1L, safety)) < 0 ) return new_ref ;
-
- ptr->filter_ref = ptr->relate_ref = ptr->current_index = ptr->index_ref = -1;
- if ( d4close() < 0 ) return -1 ;
-
- d4select( new_ref ) ;
- final_ref = x4copy(save_buffer.name, 1L, 0) ;
- d4close() ;
- if ( final_ref < 0 ) return -1 ;
-
- if ( u4remove( final_name) < 0 ) return -1 ;
-
- d4select(final_ref) ;
- ptr = d4ptr() ;
- ptr->filter_ref = save_buffer.filter_ref ;
- ptr->relate_ref = save_buffer.relate_ref ;
- ptr->current_index = save_buffer.current_index ;
- ptr->index_ref = save_buffer.index_ref ;
-
- if ( i4reindex(-1) < 0 ) return -1 ;
-
- if ( save_buffer.rec_tot > 0L )
- {
- if ( d4buf_total( save_buffer.rec_tot, save_buffer.max_bufs,
- save_buffer.buf_may_lend ) < 0 ) return -1 ;
- if ( save_buffer.rec_per_buf > 0L )
- if ( d4buf_unit( save_buffer.rec_per_buf) < 0 ) return -1 ;
- }
-
- return final_ref ;
- }
-
-
-