nasm/rdoff/collectn.c

46 lines
793 B
C
Raw Normal View History

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