5
/* token memory management
9
/* TOK822 *tok822_alloc(type, strval)
11
/* const char *strval;
13
/* TOK822 *tok822_free(tp)
16
/* This module implements memory management for token
17
/* structures. A distinction is made between single-character
18
/* tokens that have no string value, and string-valued tokens.
20
/* tok822_alloc() allocates memory for a token structure of
21
/* the named type, and initializes it properly. In case of
22
/* a single-character token, no string memory is allocated.
23
/* Otherwise, \fIstrval\fR is a null pointer or provides
24
/* string data to initialize the token with.
26
/* tok822_free() releases the memory used for the specified token
27
/* and conveniently returns a null pointer value.
31
/* The Secure Mailer license must be distributed with this software.
34
/* IBM T.J. Watson Research
36
/* Yorktown Heights, NY 10598, USA
44
/* Utility library. */
53
/* tok822_alloc - allocate and initialize token */
55
TOK822 *tok822_alloc(int type, const char *strval)
59
#define CONTAINER_TOKEN(x) \
60
((x) == TOK822_ADDR || (x) == TOK822_STARTGRP)
62
tp = (TOK822 *) mymalloc(sizeof(*tp));
64
tp->next = tp->prev = tp->head = tp->tail = tp->owner = 0;
65
tp->vstr = (type < TOK822_MINTOK || CONTAINER_TOKEN(type) ? 0 :
66
strval == 0 ? vstring_alloc(10) :
67
vstring_strcpy(vstring_alloc(strlen(strval) + 1), strval));
71
/* tok822_free - destroy token */
73
TOK822 *tok822_free(TOK822 *tp)
76
vstring_free(tp->vstr);