aboutsummaryrefslogtreecommitdiffstats
path: root/awka.c
blob: 2de6670021a6a55513a3b33cf6e55c4181128bf8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
 * some speciallized memory allocation routines
 *
 * $Log:	awka.c,v $
 * Revision 1.1  89/03/22  21:04:00  david
 * Initial revision
 * 
 */

#include "awk.h"

#define NODECHUNK	50

NODE *nextfree = NULL;
NODE *lastfree = NULL;

NODE *
newnode(ty)
NODETYPE ty;
{
	NODE *it;
	NODE *np;

	if (nextfree == lastfree) {
		emalloc(nextfree, NODE *, NODECHUNK * sizeof(NODE), "newnode");
		for (np = nextfree; np < &nextfree[NODECHUNK - 1]; np++)
			np->nextp = np + 1;
		np->nextp = lastfree;
		lastfree = np;
	}
	it = nextfree;
	nextfree = nextfree->nextp;
	it->type = ty;
	it->flags = MALLOC;
	return it;
}

freenode(it)
NODE *it;
{
	lastfree->nextp = it;
	it->nextp = NULL;
	lastfree = it;
}