- i_more = (*data->read_item)(data->clientData, &i_item_ptr, &i_mode);
-
- mb[ptr].block = pp->pos; /* is zero if no block on disk */
- mb[ptr].dirty = 0;
- mb[ptr].offset = 0;
-
- border = is->method->filecat[cat].bsize;
- /* border = get_border (is, mb, ptr, cat, firstpos); */
- while (i_more || f_more)
- {
- char *r_item = r_item_buf;
- int cmp;
-
- if (f_more > 1)
- {
- /* block to block boundary in the original file. */
- f_more = 1;
- if (cat == pp->cat)
- {
- /* the resulting output is of the same category as the
- the original
- */
- if (r_offset <= mb[ptr].offset +is->method->filecat[cat].mfill)
- {
- /* the resulting output block is too small/empty. Delete
- the original (if any)
- */
- if (debug > 3)
- logf (LOG_LOG, "isc: release A");
- if (mb[ptr].block)
- isamh_release_block (is, pp->cat, mb[ptr].block);
- mb[ptr].block = pp->pos;
- if (!mb[ptr].dirty)
- mb[ptr].dirty = 1;
- if (ptr > 0)
- mb[ptr-1].dirty = 1;
- }
- else
- {
- /* indicate new boundary based on the original file */
- mb[++ptr].block = pp->pos;
- mb[ptr].dirty = last_dirty;
- mb[ptr].offset = r_offset;
- if (debug > 3)
- logf (LOG_LOG, "isc: bound ptr=%d,offset=%d",
- ptr, r_offset);
- if (cat==is->max_cat && ptr >= is->method->max_blocks_mem)
- {
- /* We are dealing with block(s) of max size. Block(s)
- except 1 will be flushed.
- */
- if (debug > 2)
- logf (LOG_LOG, "isc: flush A %d sections", ptr);
- flush_blocks ((ISAMC)is, mb, ptr-1, r_buf, &firstpos, cat,
- 0, &pp->numKeys);
- mb[0].block = mb[ptr-1].block;
- mb[0].dirty = mb[ptr-1].dirty;
- memcpy (r_buf, r_buf + mb[ptr-1].offset,
- mb[ptr].offset - mb[ptr-1].offset);
- mb[0].offset = 0;
-
- mb[1].block = mb[ptr].block;
- mb[1].dirty = mb[ptr].dirty;
- mb[1].offset = mb[ptr].offset - mb[ptr-1].offset;
- ptr = 1;
- r_offset = mb[ptr].offset;
- }
- }
- }
- /*border = get_border (is, mb, ptr, cat, firstpos);*/
- border = is->method->filecat[cat].bsize;
- }
- last_dirty = 0;
- if (!f_more)
- cmp = -1;
- else if (!i_more)
- cmp = 1;
- else
- cmp = (*is->method->compare_item)(i_item, f_item);
- if (cmp == 0) /* insert i=f */
- {
- if (!i_mode) /* delete item? */
- {
- /* move i */
- i_item_ptr = i_item;
- i_more = (*data->read_item)(data->clientData, &i_item_ptr,
- &i_mode);
- /* is next input item the same as current except
- for the delete flag? */
- cmp = (*is->method->compare_item)(i_item, f_item);
- if (!cmp && i_mode) /* delete/insert nop? */
- {
- /* yes! insert as if it was an insert only */
- memcpy (r_item, i_item, i_item_ptr - i_item);
- i_item_ptr = i_item;
- i_more = (*data->read_item)(data->clientData, &i_item_ptr,
- &i_mode);
- }
- else
- {
- /* no! delete the item */
- r_item = NULL;
- last_dirty = 1;
- mb[ptr].dirty = 2;
- }
- }
- else
- {
- memcpy (r_item, f_item, f_item_ptr - f_item);