home *** CD-ROM | disk | FTP | other *** search
-
- /* (c)Copyright Sequiter Software Inc., 1987-1990. All rights reserved.
-
- d4buf_tot.c
-
- Must change the order of the databases so that they match the
- order in which buffer memory was added. The order of buffer
- memory allocation is important to 'd4buf_compress' which is
- used to compress buffer memory.
- */
-
- #include "d4all.h"
- #include "h4memory.h"
-
- extern BASE *v4base ;
- extern int v4last_base, v4cur_base ;
-
-
- int d4buf_total( long rec_tot, int max_bufs, int may_lend )
- {
- BASE *base_ptr ;
- int i_buf ;
-
- base_ptr = d4ptr() ;
- if ( rec_tot < 0L) rec_tot = base_ptr->rec_tot ;
- if ( max_bufs < 0) max_bufs = base_ptr->max_bufs ;
- if ( may_lend < 0) may_lend = base_ptr->buf_may_lend ;
-
- if ( d4buf_clear_base( v4cur_base ) < 0 ) return -1 ;
-
- base_ptr->n_bufs = 0 ;
- base_ptr->buf_status = 0 ;
-
- if ( max_bufs != base_ptr->max_bufs )
- {
- if ( base_ptr->bufs != (BASE_BUF *) 0 )
- h4free_memory( (char *) base_ptr->bufs - sizeof(MEMORY) ) ;
-
- if ( max_bufs > 0 )
- {
- if (h4create( (char **) &base_ptr->bufs, max_bufs, (int) sizeof(BASE_BUF),-1) <0)
- {
- base_ptr->bufs = (BASE_BUF *) 0 ;
- base_ptr->max_bufs = 0 ;
- return 1 ;
- }
- for ( i_buf = 0; i_buf < max_bufs; i_buf++ )
- base_ptr->bufs[i_buf].start_rec= base_ptr->bufs[i_buf].end_rec= -1L;
- }
- else
- base_ptr->bufs = (BASE_BUF *) 0 ;
- }
-
- base_ptr->max_bufs = max_bufs ;
-
- if ( base_ptr->rec_tot == rec_tot && base_ptr->buf_may_lend == may_lend )
- return 0 ;
-
- /* Algorithm.
-
- 1. Determine the new position of the database and clear the databases
- - If lend status has not changed, the position will not change.
- Clear from the current database.
- - If lend status has gone to NOLEND, the position is immediately
- after the last NOLEND database.
- Clear all which may be lent.
- - If lend status has gone to LEND, the database position becomes
- the very end.
- Clear from the current database.
-
- 2. Move the database
-
- 3. Reset the memory.
-
- 4. Recalculate all of the pointers.
- */
-
- if ( base_ptr->buf_may_lend != may_lend )
- {
- if ( may_lend )
- {
- if ( d4buf_clear_after( v4cur_base) < 0 ) return -1 ;
-
- /* Move to the end. */
- h4move( (char **) &v4base, v4last_base, v4cur_base, 0 ) ;
- if ( v4cur_base != v4last_base ) v4last_base = v4cur_base ;
- }
- else
- {
- int first_lend ;
-
- /* May no longer be lent. */
- if ( (first_lend = d4buf_clear_lend(0)) < 0 ) return -1 ;
-
- if ( v4cur_base == v4last_base && first_lend != v4cur_base )
- if ( base_ptr->prev >= 0 ) v4last_base = base_ptr->prev ;
- h4move( (char **) &v4base, first_lend, v4cur_base, 1 ) ;
- }
- }
- else
- {
- /* Lend has not changed. */
- if ( d4buf_clear_after( v4cur_base) < 0 ) return -1 ;
- }
-
- base_ptr->buf_may_lend = may_lend ;
- base_ptr->rec_tot = rec_tot ;
-
- return( d4buf_calc() ) ;
- }
-
-
-