2024-10-04 23:41:10 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <merror.h>
|
|
|
|
|
2024-10-21 16:27:18 +00:00
|
|
|
#include "../tab.h"
|
2024-10-04 23:41:10 +00:00
|
|
|
|
|
|
|
#define REFTAB_INIT_LEN 8
|
|
|
|
|
|
|
|
int reftab_init(struct reference_table *reftab)
|
|
|
|
{
|
|
|
|
reftab->size = REFTAB_INIT_LEN;
|
|
|
|
reftab->len = 0;
|
|
|
|
reftab->references = malloc(sizeof(struct reference)
|
|
|
|
* REFTAB_INIT_LEN);
|
|
|
|
|
|
|
|
if (reftab->references == NULL) {
|
|
|
|
PERROR("cannot alloc");
|
|
|
|
return M_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return M_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
void reftab_free(struct reference_table *reftab)
|
|
|
|
{
|
|
|
|
free(reftab->references);
|
|
|
|
}
|
|
|
|
|
|
|
|
int reftab_push(struct reference_table *reftab, struct reference *ref)
|
|
|
|
{
|
|
|
|
if (reftab->len >= reftab->size) {
|
|
|
|
reftab->size *= 2;
|
|
|
|
reftab->references = realloc(reftab->references,
|
|
|
|
sizeof(struct reference) * reftab->size);
|
|
|
|
|
|
|
|
if (reftab->references == NULL) {
|
|
|
|
PERROR("cannot realloc");
|
|
|
|
return M_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
reftab->references[reftab->len++] = *ref;
|
|
|
|
return M_SUCCESS;
|
|
|
|
}
|