Expand PMF_FN_* macros.
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / global / tok822_node.c
blob976f36c258efcb50ac8cef23778c44448c595cea
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* tok822_node 3
6 /* SUMMARY
7 /* token memory management
8 /* SYNOPSIS
9 /* #include <tok822.h>
11 /* TOK822 *tok822_alloc(type, strval)
12 /* int type;
13 /* const char *strval;
15 /* TOK822 *tok822_free(tp)
16 /* TOK822 *tp;
17 /* DESCRIPTION
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.
30 /* LICENSE
31 /* .ad
32 /* .fi
33 /* The Secure Mailer license must be distributed with this software.
34 /* AUTHOR(S)
35 /* Wietse Venema
36 /* IBM T.J. Watson Research
37 /* P.O. Box 704
38 /* Yorktown Heights, NY 10598, USA
39 /*--*/
41 /* System library. */
43 #include <sys_defs.h>
44 #include <string.h>
46 /* Utility library. */
48 #include <mymalloc.h>
49 #include <vstring.h>
51 /* Global library. */
53 #include "tok822.h"
55 /* tok822_alloc - allocate and initialize token */
57 TOK822 *tok822_alloc(int type, const char *strval)
59 TOK822 *tp;
61 #define CONTAINER_TOKEN(x) \
62 ((x) == TOK822_ADDR || (x) == TOK822_STARTGRP)
64 tp = (TOK822 *) mymalloc(sizeof(*tp));
65 tp->type = type;
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));
70 return (tp);
73 /* tok822_free - destroy token */
75 TOK822 *tok822_free(TOK822 *tp)
77 if (tp->vstr)
78 vstring_free(tp->vstr);
79 myfree((char *) tp);
80 return (0);