#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <X11/fonts/fontmisc.h>
#include <X11/fonts/fontstruct.h>
void
FreeFontNames(FontNamesPtr pFN)
{
int i;
if (!pFN)
return;
for (i = 0; i < pFN->nnames; i++) {
xfree(pFN->names[i]);
}
xfree(pFN->names);
xfree(pFN->length);
xfree(pFN);
}
FontNamesPtr
MakeFontNamesRecord(unsigned int size)
{
FontNamesPtr pFN;
pFN = (FontNamesPtr) xalloc(sizeof(FontNamesRec));
if (pFN) {
pFN->nnames = 0;
pFN->size = size;
if (size)
{
pFN->length = (int *) xalloc(size * sizeof(int));
pFN->names = (char **) xalloc(size * sizeof(char *));
if (!pFN->length || !pFN->names) {
xfree(pFN->length);
xfree(pFN->names);
xfree(pFN);
pFN = (FontNamesPtr) 0;
}
}
else
{
pFN->length = 0;
pFN->names = 0;
}
}
return pFN;
}
int
AddFontNamesName(FontNamesPtr names, char *name, int length)
{
int index = names->nnames;
char *nelt;
nelt = (char *) xalloc(length + 1);
if (!nelt)
return AllocError;
if (index >= names->size) {
int size = names->size << 1;
int *nlength;
char **nnames;
if (size == 0)
size = 8;
nlength = (int *) xrealloc(names->length, size * sizeof(int));
nnames = (char **) xrealloc(names->names, size * sizeof(char *));
if (nlength && nnames) {
names->size = size;
names->length = nlength;
names->names = nnames;
} else {
xfree(nelt);
xfree(nlength);
xfree(nnames);
return AllocError;
}
}
names->length[index] = length;
names->names[index] = nelt;
strncpy(nelt, name, length);
nelt[length] = '\0';
names->nnames++;
return Successful;
}