5 /* maintain pool of unused token structures
11 /* struct token *tok_alloc()
16 /* tok_alloc() and tok_free() maintain a pool of unused token
19 /* tok_alloc() takes the first free token structure from the pool
20 /* or allocates a new one if the pool is empty.
22 /* tok_free() adds a (possibly composite) token structure to the pool.
24 /* The pool never shrinks.
27 /* Eindhoven University of Technology
28 /* Department of Mathematics and Computer Science
29 /* Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
36 static char pool_sccsid[] = "@(#) tok_pool.c 1.2 92/01/15 21:53:04";
40 extern char *malloc();
42 /* Application-specific stuff */
48 #define TOKLEN 5 /* initial string buffer length */
50 struct token *tok_pool = 0; /* free token pool */
52 /* tok_alloc - allocate token structure from pool or heap */
54 struct token *tok_alloc()
56 register struct token *t;
58 if (tok_pool) { /* re-use an old one */
61 } else { /* create a new one */
62 if ((t = (struct token *) malloc(sizeof(struct token))) == 0
63 || (t->vstr = vs_alloc(TOKLEN)) == 0)
64 fatal("out of memory");
66 t->next = t->head = t->tail = 0;
68 strcpy(t->vstr->str, "BUSY");
73 /* tok_free - return (possibly composite) token to pool of free tokens */
76 register struct token *t;
79 /* Check if we are freeing free token */
81 register struct token *p;
83 for (p = tok_pool; p; p = p->next)
85 fatal("freeing free token");
88 /* Free neighbours and subordinates first */
98 t->head = t->tail = 0;
101 strcpy(t->vstr->str, "FREE");