nasm/rdoff/collectn.c

45 lines
783 B
C
Raw Normal View History

/*
* collectn.c - implements variable length pointer arrays [collections].
2002-05-01 04:51:32 +08:00
*
* This file is public domain.
*/
#include "rdfutils.h"
#include "collectn.h"
2002-05-01 04:51:32 +08:00
void collection_init(Collection * c)
{
int i;
2002-05-01 04:51:32 +08:00
for (i = 0; i < 32; i++)
2005-01-16 06:15:51 +08:00
c->p[i] = NULL;
c->next = NULL;
2002-05-01 04:51:32 +08:00
}
void **colln(Collection * c, int index)
2002-05-01 04:51:32 +08:00
{
while (index >= 32) {
2005-01-16 06:15:51 +08:00
index -= 32;
if (c->next == NULL) {
c->next = nasm_malloc(sizeof(Collection));
2005-01-16 06:15:51 +08:00
collection_init(c->next);
}
c = c->next;
2002-05-01 04:51:32 +08:00
}
return &(c->p[index]);
2002-05-01 04:51:32 +08:00
}
void collection_reset(Collection * c)
2002-05-01 04:51:32 +08:00
{
int i;
2002-05-01 04:51:32 +08:00
if (c->next) {
2005-01-16 06:15:51 +08:00
collection_reset(c->next);
nasm_free(c->next);
}
c->next = NULL;
for (i = 0; i < 32; i++)
2005-01-16 06:15:51 +08:00
c->p[i] = NULL;
2002-05-01 04:51:32 +08:00
}