+ void *r_clientData; /* encode client data */
+ int newblock;
+ int newcat;
+ int maxkeys;
+ int maxsize;
+ int retval;
+ int maxcat;
+
+ pp = firstpp = isamh_pp_open (is, ipos);
+ prevpp =0; /* only used when new blocks allocated */
+
+ assert (*is->method->code_reset);
+
+ maxcat=0; /* find the largest block size for default allocation */
+ for ( newcat=0; is->method->filecat[newcat].mblocks > 0; newcat++)
+ if ( is->method->filecat[newcat].bsize >
+ is->method->filecat[maxcat].bsize)
+ maxcat = newcat;
+
+ if ( 0==ipos)
+ { /* new block */
+ pp->cat=maxcat; /* start large... */
+ pp->pos = 0; /* not allocated yet */
+ pp->size= pp->offset = ISAMH_BLOCK_OFFSET_1 ;
+ pp->buf=xrealloc(pp->buf,is->method->filecat[maxcat].bsize);
+ r_clientData = (*is->method->code_start)(ISAMH_ENCODE);
+ if (pp->is->method->debug > 2)
+ logf(LOG_LOG,"isamh_append: starting with new block");
+ }
+ else
+ { /* existing block */
+ if (isamh_block(firstpp->lastblock) == firstpp->pos)
+ /*!!! TODO: BUG: Compare whole addresses !!! (later) */
+ { /* only one block, we have it already */
+ pp->offset=ISAMH_BLOCK_OFFSET_1;
+ if (pp->is->method->debug > 2)
+ logf(LOG_LOG,"isamh_append: starting with one block %d",pp->pos);
+ }
+ else
+ {
+ if (pp->is->method->debug > 2)
+ logf(LOG_LOG,"isamh_append: starting with multiple blocks %d>%d>%d",
+ firstpp->pos,isamh_block(firstpp->next),isamh_block(firstpp->lastblock));
+ pp=isamh_pp_open(is,firstpp->lastblock);
+ /* dirty, but this can also read a N-block. Just clear extra values*/
+ pp->lastblock=0;
+ pp->offset=ISAMH_BLOCK_OFFSET_N;
+ } /* get last */
+ r_clientData = (*is->method->code_start)(ISAMH_ENCODE);
+ if (pp->is->method->debug > 3)
+ logf(LOG_LOG,"isamh_append: scanning to end of block %d %d->%d",
+ pp->pos, pp->offset, pp->size);
+ codeptr=codebuffer;
+ while (pp->offset<pp->size) {
+ codeptr=codebuffer;
+ bufptr=pp->buf + pp->offset;
+ (*is->method->code_item)(ISAMH_DECODE, r_clientData, &codeptr, &bufptr);
+ codelen = bufptr - (pp->buf+pp->offset) ;
+ if (pp->is->method->debug > 3)
+ logf(LOG_LOG,"isamh_append: dec at %d %d/%d:%s",
+ pp->offset, codelen, codeptr-codebuffer,
+ hexdump(codebuffer,codeptr-codebuffer,0) );
+ pp->offset += codelen;
+ }
+ } /* existing block */