Append this chain with a sub-chain

Return TypeFunction nameArguments
uint32_thzChain::AppendSub(hzChain&,uint32_t,uint32_t,)

Declared in file: hzChain.h
Defined in file : hzChain.cpp

Function Logic:

0:START 1:unknown 2:Return 0 3:unknown 4:mx mx 5:unknown 6:mx 7:mx 8:curBlk 9:unknown 10:items 11:unknown 12:unknown 13:newBlk items items curBlk mx 14:curBlk items items items 15:Return nBytesWritten

Function body:

uint32_t hzChain::AppendSub (hzChain& Z)uint32_t nStart, uint32_t nBytes, 
{
   //  Append this chain with a sub-chain
   //  
   //  Arguments: 1) Z  Sub-chain input
   //     2) nStart Start position within sub-chain
   //     3) nBytes No of bytes to write from sub-chain 
   //  
   //  Returns: Number of bytes added
   _hzfunc("hzChain::Append(hzChain,Start,noBytes)") ;
   chIter      zi ;                    //  For iteration of operand chain
   _zblk*      curBlk ;                //  Working block pointer
   _zblk*      newBlk ;                //  Working block pointer
   uint32_t    nBytesWritten = 0;      //  Total bytes written
   if (!Z.Size())
       return 0;
   //  If nothing in this chain, create the first block
   if (!mx)
       { mx = new _chain() ; mx->m_Test = mx ; }
   if (!mx->m_Begin)
       mx->m_Begin = mx->m_End = _zblk_alloc() ;
   curBlk = (_zblk*) mx->m_End ;
   if (!curBlk)
       hzexit(E_MEMORY, "Chain %p has no end block\n", this) ;
   for (zi = Z, zi += nStart ; !zi.eof() && nBytesWritten < nBytes ; zi++)
   {
       if (curBlk->m_nUsage == ZBLKSIZE)
       {
           //  Out of space - make new block
           newBlk = _zblk_alloc() ;
           newBlk->Prev(curBlk) ;
           curBlk->Next(newBlk) ;
           mx->m_End = curBlk = newBlk ;
       }
       curBlk->m_Data[curBlk->m_nUsage] = *zi ;
       curBlk->m_nUsage++ ;
       mx->m_nSize++ ;
       nBytesWritten++ ;
   }
   return nBytesWritten ;
}