10 date 90.04.05.15.30.56; author sources; state Exp;
15 date 90.04.05.14.44.56; author sources; state Exp;
20 date 90.03.12.10.49.11; author sources; state Exp;
25 date 90.03.12.10.45.56; author sources; state Exp;
30 date 90.01.30.10.44.41; author sources; state Exp;
44 @/* formataddr.c - format an address field (from formatsbr) */
46 static char ident[] = "@@(#)$Id:$";
50 #include "../h/addrsbr.h"
51 #include "../h/formatsbr.h"
55 static char *buf; /* our current working buffer */
56 static char *bufend; /* end of working buffer */
57 static char *last_dst; /* buf ptr at end of last call */
58 static unsigned int bufsiz; /* current size of buf */
60 #define BUFINCR 512 /* how much to expand buf when if fills */
62 #define CPY(s) { cp = (s); while (*dst++ = *cp++) ; --dst; }
64 /* check if there's enough room in buf for str. add more mem if needed */
65 #define CHECKMEM(str) \
66 if ((len = strlen (str)) >= bufend - dst) {\
68 int n = last_dst - buf;\
69 bufsiz += ((dst + len - bufend) / BUFINCR + 1) * BUFINCR;\
70 buf = realloc (buf, bufsiz);\
74 adios (NULLCP, "formataddr: couldn't get buffer space");\
75 bufend = buf + bufsiz;\
79 /* fmtscan will call this routine if the user includes the function
80 * "(formataddr {component})" in a format string. "orig" is the
81 * original contents of the string register. "str" is the address
82 * string to be formatted and concatenated onto orig. This routine
83 * returns a pointer to the concatenated address string.
85 * We try to not do a lot of malloc/copy/free's (which is why we
86 * don't call "getcpy") but still place no upper limit on the
87 * length of the result string.
89 * This routine is placed in a separate library so it can be
90 * overridden by particular programs (e.g., "replsbr").
92 char *formataddr (orig, str)
101 register struct mailname *mp = NULL;
103 /* if we don't have a buffer yet, get one */
105 buf = malloc (BUFINCR);
107 adios (NULLCP, "formataddr: couldn't allocate buffer space");
108 last_dst = buf; /* XXX */
109 bufsiz = BUFINCR - 6; /* leave some slop */
110 bufend = buf + bufsiz;
113 * If "orig" points to our buffer we can just pick up where we
114 * left off. Otherwise we have to copy orig into our buffer.
118 else if (!orig || !*orig) {
122 dst = last_dst; /* XXX */
127 /* concatenate all the new addresses onto 'buf' */
128 for (isgroup = 0; cp = getname (str); ) {
129 if ((mp = getm (cp, NULLCP, 0, fmt_norm, NULLCP)) == NULL)
132 if (isgroup && (mp->m_gname || !mp->m_ingrp)) {
136 /* if we get here we're going to add an address */
142 CHECKMEM (mp->m_gname);
169 static char ident[] = "$Id:";
189 buf = malloc (BUFINCR);
200 buf = malloc (BUFINCR);