Lines Matching +full:mac +full:- +full:s
2 * Copyright (c) 1998-2001, 2003, 2006, 2007 Proofpoint, Inc. and its suppliers.
4 * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved.
16 SM_RCSID("@(#)$Id: macro.c,v 8.108 2013-11-22 20:51:55 ca Exp $")
19 #if MAXMACROID != (BITMAPBITS - 1)
37 /* table for next id in non-printable ASCII range: disallow some value */
49 /* 9 ht */ -1,
50 /* 10 nl */ -1,
51 /* 11 vt */ -1,
52 /* 12 np */ -1,
53 /* 13 cr */ -1,
72 /* 32 sp */ -1,
87 ** INITMACROS -- initialize the macro system
105 { '*', MATCHZANY }, { '+', MATCHANY }, { '-', MATCHONE },
126 stab(name, ST_MACRO, ST_ENTER)->s_macro = mid; \
137 for (m = MetaMacros; m->metaname != '\0'; m++)
139 buf[0] = m->metaval;
141 macdefine(&e->e_macro, A_TEMP, m->metaname, buf);
148 macdefine(&e->e_macro, A_TEMP, c, buf);
152 macdefine(&e->e_macro, A_PERM, 'n', "MAILER-DAEMON");
160 ** EXPAND/DOEXPAND -- macro expand a string using $x escapes.
164 ** s -- the string to expand. [i]
165 ** buf -- the place to put the expansion. [i]
166 ** bufsize -- the size of the buffer.
167 ** explevel -- the depth of expansion (doexpand only)
168 ** e -- envelope in which to work.
177 doexpand(s, buf, bufsize, explevel, e) in doexpand() argument
178 char *s; in doexpand()
197 xputs(sm_debug_file(), s);
206 if (s == NULL)
207 s = "";
208 for (xp = xbuf; *s != '\0'; s++)
213 ** Check for non-ordinary (special?) character.
218 c = *s & 0377;
230 c = *++s & 0377;
252 iflev--;
256 skiplev--;
260 c = bitidx(*++s);
265 s--;
283 if (skipping || xp >= &xbuf[sizeof(xbuf) - 1])
293 xp < &xbuf[sizeof(xbuf) - 1])
332 i = xp - xbuf;
334 i = bufsize - 1;
348 expand(s, buf, bufsize, e) in expand() argument
349 char *s; in expand()
354 doexpand(s, buf, bufsize, 0, e);
358 ** MACTABCLEAR -- clear entire macro table
361 ** mac -- Macro table.
367 ** clears entire mac structure including rpool pointer!
371 mactabclear(mac) in mactabclear() argument
372 MACROS_T *mac; in mactabclear()
376 if (mac->mac_rpool == NULL)
379 SM_FREE(mac->mac_table[i]);
381 memset((char *) mac, '\0', sizeof(*mac));
385 ** MACDEFINE -- bind a macro name to a value
393 ** mac -- Macro table.
394 ** vclass -- storage class of 'value', ignored if value==NULL.
401 ** at least the lifetime of mac. Use A_PERM if:
402 ** -- value == NULL,
403 ** -- value points to a string literal,
404 ** -- value was allocated from mac->mac_rpool
406 ** from e->e_rpool,
407 ** -- in the case of an envelope macro,
409 ** such as e->e_sender.
410 ** id -- Macro id. This is a single character macro name
412 ** value -- Macro value: either NULL, or a string.
420 macdefine_tagged(mac, vclass, id, value, file, line, grp) in macdefine_tagged() argument
422 macdefine(mac, vclass, id, value) in macdefine_tagged()
424 MACROS_T *mac; in macdefine_tagged()
441 sm_dprintf("%sdefine(%s as ",
442 mac->mac_table[id] == NULL ? "" : "re", macname(id));
451 if (mac->mac_rpool == NULL)
455 if (mac->mac_table[id] != NULL &&
456 bitnset(id, mac->mac_allocated))
457 freeit = mac->mac_table[id];
463 clrbitn(id, mac->mac_allocated);
472 setbitn(id, mac->mac_allocated);
474 mac->mac_table[id] = newvalue;
483 newvalue = sm_rpool_strdup_x(mac->mac_rpool, value);
484 mac->mac_table[id] = newvalue;
500 ** MACSET -- set a named macro to a value (low level)
506 ** mac -- Macro table.
507 ** i -- Macro name, specified as an integer offset.
508 ** value -- Macro value: either NULL, or a string.
515 macset(mac, i, value) in macset() argument
516 MACROS_T *mac; in macset()
525 sm_dprintf("macset(%s as ", macname(i));
529 mac->mac_table[i] = value;
533 ** MACVALUE -- return uninterpreted value of a macro.
539 ** n -- the name of the macro.
540 ** e -- envelope in which to start looking for the macro.
555 if (e != NULL && e->e_mci != NULL)
557 char *p = e->e_mci->mci_macro.mac_table[n];
564 char *p = e->e_macro.mac_table[n];
568 if (e == e->e_parent)
570 e = e->e_parent;
585 ** MACNAME -- return the name of a macro given its internal id
588 ** n -- the id of the macro
597 ** Not thread-safe.
627 ** MACID_PARSE -- return id of macro identified by its name
630 ** p -- pointer to name string -- either a single
632 ** ep -- filled in with the pointer to the byte
636 ** 0 -- An error was detected.
637 ** 1..MAXMACROID -- The internal id code for this macro.
686 while (*++p != '\0' && *p != '}' && bp < &mbuf[sizeof(mbuf) - 1])
694 mid = -1;
697 syserr("Unbalanced { on %s", mbuf); /* missing } */
701 syserr("Macro/class name ({%s}) too long (%d chars max)",
702 mbuf, (int) (sizeof(mbuf) - 1));
712 STAB *s; local
714 s = stab(mbuf, ST_MACRO, ST_ENTER);
715 if (s->s_macro != 0)
716 mid = s->s_macro;
721 syserr("Macro/class {%s}: too many long names",
723 s->s_macro = -1;
727 MacroName[NextMacroId] = s->s_name;
728 s->s_macro = mid = NextMacroId;
749 ** WORDINCLASS -- tell if a word is in a specific class
752 ** str -- the name of the word to look up.
753 ** cl -- the class name.
765 STAB *s; local
773 s = stab(p, ST_DYNMAP, ST_FIND);
774 if (NULL == s)
777 s = stab(str, ST_CLASS, ST_FIND);
778 return s != NULL && bitnset(bitidx(cl), s->s_class);
781 map = &s->s_dynclass;
784 if (bitset(MF_OPENBOGUS, map->map_mflags))
791 if (!SM_IS_EMPTY(map->map_tag))
793 sm_strlcpy(key, map->map_tag, sizeof(key));
798 p = (map->map_class->map_lookup)(map, key, NULL, &status);
804 sm_syslog(LOG_WARNING, CurEnv->e_id,
805 "dynamic class: A{%s}: map lookup failed: key=%s, status=%d",
806 map->map_mname, key, status);