#include "xttversion.h"
#if 0
static char const * const releaseID =
_XTT_RELEASE_NAME;
#endif
#include "xttcommon.h"
#include "fntfilst.h"
#include "xttcap.h"
#include "xttcconv.h"
#include "xttcache.h"
#include "xttstruct.h"
#define CharInfoPoolUnitSize 256
CharInfoPoolPtr
CharInfoPool_Alloc(void)
{
CharInfoPoolPtr this = (CharInfoPoolPtr) xalloc(sizeof(*this));
if (this != NULL) {
this->unit = NULL;
this->n = this->index = 0;
this->bunit = NULL;
this->bn = 0;
}
return this;
}
CharInfoPtr
CharInfoPool_Get(CharInfoPoolPtr this)
{
CharInfoUnitPtr ptr;
CharInfoPtr cptr;
if ((this->n == 0) || (this->index == CharInfoPoolUnitSize)) {
ptr = (CharInfoUnitPtr) xrealloc(this->unit, (this->n + 1) *
sizeof(*ptr));
if (ptr == NULL)
return NULL;
this->unit = ptr;
cptr = (CharInfoPtr)xalloc(CharInfoPoolUnitSize * sizeof(CharInfoRec));
if (cptr == NULL)
return NULL;
ptr = this->unit + this->n;
ptr->charInfo = cptr;
this->n++;
this->index = 0;
} else
ptr = this->unit + (this->n - 1);
ptr->charInfo[this->index].bits = NULL;
return &ptr->charInfo[this->index++];
}
void
CharInfoPool_Set(CharInfoPoolPtr this, CharInfoPtr dat, int size)
{
BitmapInfoUnitPtr ptr;
char *bptr;
int newsize;
ptr = &this->bunit[this->bn - 1];
if (this->bn == 0 || ptr->cur + size > ptr->bitmapsize) {
ptr = (BitmapInfoUnitPtr) xrealloc(this->bunit, (this->bn + 1) *
sizeof(*ptr));
if (ptr == NULL)
return;
this->bunit = ptr;
newsize = 4096;
if (size > newsize / 2)
newsize = size;
bptr = (char *) xalloc(newsize);
if (bptr == NULL)
return;
memset(bptr, 0, newsize);
ptr = this->bunit + this->bn;
ptr->bitmap = bptr;
ptr->bitmapsize = newsize;
ptr->cur = 0;
this->bn++;
}
dat->bits = ptr->bitmap + ptr->cur;
ptr->cur += size;
}
void
CharInfoPool_Free(CharInfoPoolPtr this)
{
int i;
for (i = 0; i < this->n; i++)
xfree(this->unit[i].charInfo);
for (i = 0; i < this->bn; i++)
xfree(this->bunit[i].bitmap);
xfree(this->unit);
xfree(this->bunit);
this->unit = NULL;
this->bunit = NULL;
this->n = 0;
this->bn = 0;
}