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