macro.c revision 7800901e60d340b6af88e94a2149805dcfcaaf56
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright (c) 1998-2001, 2003, 2006, 2007 Sendmail, Inc. and its suppliers.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright (c) 1988, 1993
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The Regents of the University of California. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * By using this file, you agree to the terms and conditions set
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * forth in the LICENSE file which can be found at the top level of
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the sendmail distribution.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#pragma ident "%Z%%M% %I% %E% SMI"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sendmail.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteSM_RCSID("@(#)$Id: macro.c,v 8.107 2007/08/06 22:29:02 ca Exp $")
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sm/sendmail.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if MAXMACROID != (BITMAPBITS - 1)
3fb517f786391b507780c78aabb8d98bfea9efe9James Moore ERROR Read the comment in conf.h
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* MAXMACROID != (BITMAPBITS - 1) */
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko
042f029e72a2d7a92c989ad0d0570f7b21efa2aaAlexander Stetsenkostatic char *MacroName[MAXMACROID + 1]; /* macro id to name table */
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov/*
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko** Codes for long named macros.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** See also macname():
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if not ASCII printable, look up the name *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (n <= 0x20 || n > 0x7f)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** First use 1 to NEXTMACROID_L, then use NEXTMACROID_H to MAXMACROID.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define NEXTMACROID_L 037
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan#define NEXTMACROID_H 0240
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if _FFR_MORE_MACROS
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* table for next id in non-printable ASCII range: disallow some value */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int NextMIdTable[] =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* 0 nul */ 1,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* 1 soh */ 2,
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv /* 2 stx */ 3,
427fcaf873956aad428be801380a44e59d38b8b5tim szeto /* 3 etx */ 4,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* 4 eot */ 5,
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan /* 5 enq */ 6,
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan /* 6 ack */ 7,
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan /* 7 bel */ 8,
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan /* 8 bs */ 14,
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan /* 9 ht */ -1,
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan /* 10 nl */ -1,
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan /* 11 vt */ -1,
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan /* 12 np */ -1,
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan /* 13 cr */ -1,
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan /* 14 so */ 15,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* 15 si */ 16,
780c822c86101e82568fa9e357d13965b9f0cf81tim szeto /* 16 dle */ 17,
780c822c86101e82568fa9e357d13965b9f0cf81tim szeto /* 17 dc1 */ 18,
780c822c86101e82568fa9e357d13965b9f0cf81tim szeto /* 18 dc2 */ 19,
780c822c86101e82568fa9e357d13965b9f0cf81tim szeto /* 19 dc3 */ 20,
780c822c86101e82568fa9e357d13965b9f0cf81tim szeto /* 20 dc4 */ 21,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* 21 nak */ 22,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* 22 syn */ 23,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* 23 etb */ 24,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* 24 can */ 25,
cbdc6dc775d8961a464fa0e1ca1bc234719c6e0dJohn Forte /* 25 em */ 26,
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan /* 26 sub */ 27,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* 27 esc */ 28,
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov /* 28 fs */ 29,
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov /* 29 gs */ 30,
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov /* 30 rs */ 31,
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov /* 31 us */ 32,
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov /* 32 sp */ -1,
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov};
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov#define NEXTMACROID(mid) ( \
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkov (mid < NEXTMACROID_L) ? (NextMIdTable[mid]) : \
042f029e72a2d7a92c989ad0d0570f7b21efa2aaAlexander Stetsenko ((mid < NEXTMACROID_H) ? NEXTMACROID_H : (mid + 1)))
042f029e72a2d7a92c989ad0d0570f7b21efa2aaAlexander Stetsenko
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint NextMacroId = 1; /* codes for long named macros */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* see sendmail.h: Special characters in rewriting rules. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else /* _FFR_MORE_MACROS */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint NextMacroId = 0240; /* codes for long named macros */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define NEXTMACROID(mid) ((mid) + 1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _FFR_MORE_MACROS */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** INITMACROS -- initialize the macro system
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte**
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** This just involves defining some macros that are actually
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte** used internally as metasymbols to be themselves.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte**
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte** Parameters:
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte** none.
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte**
40c3e8ff0f3a541e3a203404d3a5dc7eb0f5aee8John Forte** Returns:
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan** none.
716c180559045549271833327182dc6a266134f1Nattuvetty Bhavyan**
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte** Side Effects:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** initializes several macros to be themselves.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
a49dc89305dba244dc67270b5afddcf7da3e36cfSaso Kiselkovstruct metamac MetaMacros[] =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
6ac72a9ce9da39bd0abf3111fb48494c6d892613Alexander Stetsenko /* LHS pattern matching characters */
042f029e72a2d7a92c989ad0d0570f7b21efa2aaAlexander Stetsenko { '*', MATCHZANY }, { '+', MATCHANY }, { '-', MATCHONE },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { '=', MATCHCLASS }, { '~', MATCHNCLASS },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* these are RHS metasymbols */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { '#', CANONNET }, { '@', CANONHOST }, { ':', CANONUSER },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { '>', CALLSUBR },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* the conditional operations */
91159e90831fc9243576f2ec1a483b3bb462bcf4John Forte { '?', CONDIF }, { '|', CONDELSE }, { '.', CONDFI },
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* the hostname lookup characters */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { '[', HOSTBEGIN }, { ']', HOSTEND },
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto { '(', LOOKUPBEGIN }, { ')', LOOKUPEND },
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* miscellaneous control characters */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { '&', MACRODEXPAND },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { '\0', '\0' }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define MACBINDING(name, mid) \
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stab(name, ST_MACRO, ST_ENTER)->s_macro = mid; \
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte MacroName[mid] = name;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortevoid
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forteinitmacros(e)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ENVELOPE *e;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte struct metamac *m;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int c;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte char buf[5];
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte for (m = MetaMacros; m->metaname != '\0'; m++)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte buf[0] = m->metaval;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte buf[1] = '\0';
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte macdefine(&e->e_macro, A_TEMP, m->metaname, buf);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte buf[0] = MATCHREPL;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte buf[2] = '\0';
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte for (c = '0'; c <= '9'; c++)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte buf[1] = c;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte macdefine(&e->e_macro, A_TEMP, c, buf);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
427fcaf873956aad428be801380a44e59d38b8b5tim szeto /* set defaults for some macros sendmail will use later */
427fcaf873956aad428be801380a44e59d38b8b5tim szeto macdefine(&e->e_macro, A_PERM, 'n', "MAILER-DAEMON");
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto /* set up external names for some internal macros */
427fcaf873956aad428be801380a44e59d38b8b5tim szeto MACBINDING("opMode", MID_OPMODE);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto /*XXX should probably add equivalents for all short macros here XXX*/
427fcaf873956aad428be801380a44e59d38b8b5tim szeto}
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto/*
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto** EXPAND/DOEXPAND -- macro expand a string using $x escapes.
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto**
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto** After expansion, the expansion will be in external form (that is,
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto** there will be no sendmail metacharacters and METAQUOTEs will have
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto** been stripped out).
427fcaf873956aad428be801380a44e59d38b8b5tim szeto**
427fcaf873956aad428be801380a44e59d38b8b5tim szeto** Parameters:
427fcaf873956aad428be801380a44e59d38b8b5tim szeto** s -- the string to expand.
427fcaf873956aad428be801380a44e59d38b8b5tim szeto** buf -- the place to put the expansion.
427fcaf873956aad428be801380a44e59d38b8b5tim szeto** bufsize -- the size of the buffer.
427fcaf873956aad428be801380a44e59d38b8b5tim szeto** explevel -- the depth of expansion (doexpand only)
427fcaf873956aad428be801380a44e59d38b8b5tim szeto** e -- envelope in which to work.
427fcaf873956aad428be801380a44e59d38b8b5tim szeto**
427fcaf873956aad428be801380a44e59d38b8b5tim szeto** Returns:
427fcaf873956aad428be801380a44e59d38b8b5tim szeto** none.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte**
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** Side Effects:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** none.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void doexpand __P(( char *, char *, size_t, int, ENVELOPE *));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedoexpand(s, buf, bufsize, explevel, e)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *s;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *buf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t bufsize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int explevel;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ENVELOPE *e;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *xp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bool skipping; /* set if conditionally skipping output */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bool recurse; /* set if recursion required */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int skiplev; /* skipping nesting level */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int iflev; /* if nesting level */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bool quotenext; /* quote the following character */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char xbuf[MACBUFSIZE];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (tTd(35, 24))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sm_dprintf("expand(");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xputs(sm_debug_file(), s);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sm_dprintf(")\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte recurse = false;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte skipping = false;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte skiplev = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iflev = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte quotenext = false;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (s == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s = "";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (xp = xbuf; *s != '\0'; s++)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int c;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ** Check for non-ordinary (special?) character.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ** 'q' will be the interpolated quantity.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c = *s & 0377;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (quotenext)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte quotenext = false;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto simpleinterpolate;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (c)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case CONDIF: /* see if var set */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iflev++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c = *++s & 0377;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (skipping)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte skiplev++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *mv;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mv = macvalue(c, e);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte skipping = (mv == NULL || *mv == '\0');
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case CONDELSE: /* change state of skipping */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iflev == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break; /* XXX: error */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (skiplev == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte skipping = !skipping;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case CONDFI: /* stop skipping */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iflev == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break; /* XXX: error */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iflev--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (skiplev == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte skipping = false;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (skipping)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte skiplev--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case MACROEXPAND: /* macro interpolation */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c = bitidx(*++s);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (c != '\0')
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = macvalue(c, e);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = NULL;
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto }
034d83c4b3be1c9bbe03552a652ebb90d4d66885tim szeto if (q == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case METAQUOTE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* next octet completely quoted */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte quotenext = true;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ** Interpolate q or output one character
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte simpleinterpolate:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (skipping || xp >= &xbuf[sizeof(xbuf) - 1])
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (q == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *xp++ = c;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* copy to end of q or max space remaining in buf */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bool hiderecurse = false;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((c = *q++) != '\0' &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xp < &xbuf[sizeof(xbuf) - 1])
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* check for any sendmail metacharacters */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!hiderecurse && (c & 0340) == 0200)
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli recurse = true;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli *xp++ = c;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* give quoted characters a free ride */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hiderecurse = (c & 0377) == METAQUOTE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
427fcaf873956aad428be801380a44e59d38b8b5tim szeto }
427fcaf873956aad428be801380a44e59d38b8b5tim szeto }
427fcaf873956aad428be801380a44e59d38b8b5tim szeto *xp = '\0';
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto if (tTd(35, 28))
427fcaf873956aad428be801380a44e59d38b8b5tim szeto {
427fcaf873956aad428be801380a44e59d38b8b5tim szeto sm_dprintf("expand(%d) ==> ", explevel);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xputs(sm_debug_file(), xbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sm_dprintf("\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* recurse as appropriate */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (recurse)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (explevel < MaxMacroRecursion)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte doexpand(xbuf, buf, bufsize, explevel + 1, e);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto return;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syserr("expand: recursion too deep (%d max)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MaxMacroRecursion);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* copy results out */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (explevel == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sm_strlcpy(buf, xbuf, bufsize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* leave in internal form */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte i = xp - xbuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (i >= bufsize)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte i = bufsize - 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memmove(buf, xbuf, i);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buf[i] = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (tTd(35, 24))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sm_dprintf("expand ==> ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xputs(sm_debug_file(), buf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sm_dprintf("\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteexpand(s, buf, bufsize, e)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *s;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *buf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t bufsize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ENVELOPE *e;
427fcaf873956aad428be801380a44e59d38b8b5tim szeto{
427fcaf873956aad428be801380a44e59d38b8b5tim szeto doexpand(s, buf, bufsize, 0, e);
427fcaf873956aad428be801380a44e59d38b8b5tim szeto}
427fcaf873956aad428be801380a44e59d38b8b5tim szeto
427fcaf873956aad428be801380a44e59d38b8b5tim szeto/*
427fcaf873956aad428be801380a44e59d38b8b5tim szeto** MACDEFINE -- bind a macro name to a value
427fcaf873956aad428be801380a44e59d38b8b5tim szeto**
427fcaf873956aad428be801380a44e59d38b8b5tim szeto** Set a macro to a value, with fancy storage management.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** macdefine will make a copy of the value, if required,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** and will ensure that the storage for the previous value
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** is not leaked.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte**
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** Parameters:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** mac -- Macro table.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** vclass -- storage class of 'value', ignored if value==NULL.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** A_HEAP means that the value was allocated by
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** malloc, and that macdefine owns the storage.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** A_TEMP means that value points to temporary storage,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** and thus macdefine needs to make a copy.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** A_PERM means that value points to storage that
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** will remain allocated and unchanged for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** at least the lifetime of mac. Use A_PERM if:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** -- value == NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** -- value points to a string literal,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** -- value was allocated from mac->mac_rpool
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** or (in the case of an envelope macro)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** from e->e_rpool,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** -- in the case of an envelope macro,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** value is a string member of the envelope
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** such as e->e_sender.
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto** id -- Macro id. This is a single character macro name
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto** such as 'g', or a value returned by macid().
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** value -- Macro value: either NULL, or a string.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if SM_HEAP_CHECK
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortemacdefine_tagged(mac, vclass, id, value, file, line, grp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else /* SM_HEAP_CHECK */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortemacdefine(mac, vclass, id, value)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* SM_HEAP_CHECK */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MACROS_T *mac;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ARGCLASS_T vclass;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *value;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if SM_HEAP_CHECK
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *file;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int line;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int grp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* SM_HEAP_CHECK */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *newvalue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (id < 0 || id > MAXMACROID)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (tTd(35, 9))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sm_dprintf("%sdefine(%s as ",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mac->mac_table[id] == NULL ? "" : "re", macname(id));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xputs(sm_debug_file(), value);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sm_dprintf(")\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mac->mac_rpool == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *freeit = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mac->mac_table[id] != NULL &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bitnset(id, mac->mac_allocated))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte freeit = mac->mac_table[id];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (value == NULL || vclass == A_HEAP)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sm_heap_checkptr_tagged(value, file, line);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newvalue = value;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte clrbitn(id, mac->mac_allocated);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if SM_HEAP_CHECK
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newvalue = sm_strdup_tagged_x(value, file, line, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else /* SM_HEAP_CHECK */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newvalue = sm_strdup_x(value);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* SM_HEAP_CHECK */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte setbitn(id, mac->mac_allocated);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mac->mac_table[id] = newvalue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (freeit != NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sm_free(freeit);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (value == NULL || vclass == A_PERM)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newvalue = value;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newvalue = sm_rpool_strdup_x(mac->mac_rpool, value);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mac->mac_table[id] = newvalue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vclass == A_HEAP)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sm_free(value);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if _FFR_RESET_MACRO_GLOBALS
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (id)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'j':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte PSTRSET(MyHostName, value);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _FFR_RESET_MACRO_GLOBALS */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** MACSET -- set a named macro to a value (low level)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte**
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** No fancy storage management; the caller takes full responsibility.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** Often used with macget; see also macdefine.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte**
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** Parameters:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** mac -- Macro table.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** i -- Macro name, specified as an integer offset.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** value -- Macro value: either NULL, or a string.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortemacset(mac, i, value)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MACROS_T *mac;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *value;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (i < 0 || i > MAXMACROID)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (tTd(35, 9))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sm_dprintf("macset(%s as ", macname(i));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xputs(sm_debug_file(), value);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sm_dprintf(")\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mac->mac_table[i] = value;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** MACVALUE -- return uninterpreted value of a macro.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte**
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** Does fancy path searching.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** The low level counterpart is macget.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte**
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** Parameters:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** n -- the name of the macro.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** e -- envelope in which to start looking for the macro.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte**
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** Returns:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** The value of n.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte**
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** Side Effects:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** none.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortechar *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortemacvalue(n, e)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int n;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ENVELOPE *e;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte n = bitidx(n);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (e != NULL && e->e_mci != NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *p = e->e_mci->mci_macro.mac_table[n];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (p != NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (e != NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *p = e->e_macro.mac_table[n];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (p != NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (e == e->e_parent)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte e = e->e_parent;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return GlobalMacros.mac_table[n];
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** MACNAME -- return the name of a macro given its internal id
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte**
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** Parameter:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** n -- the id of the macro
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte**
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** Returns:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** The name of n.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte**
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** Side Effects:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** none.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte**
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** WARNING:
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli** Not thread-safe.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortechar *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortemacname(n)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int n;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte static char mbuf[2];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte n = (int)(unsigned char)n;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (n > MAXMACROID)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return "***OUT OF RANGE MACRO***";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* if not ASCII printable, look up the name */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (n <= 0x20 || n > 0x7f)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *p = MacroName[n];
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (p != NULL)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return p;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return "***UNDEFINED MACRO***";
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* if in the ASCII graphic range, just return the id directly */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mbuf[0] = n;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mbuf[1] = '\0';
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return mbuf;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto** MACID_PARSE -- return id of macro identified by its name
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto**
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto** Parameters:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto** p -- pointer to name string -- either a single
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto** character or {name}.
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto** ep -- filled in with the pointer to the byte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto** after the name.
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto**
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto** Returns:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto** 0 -- An error was detected.
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto** 1..MAXMACROID -- The internal id code for this macro.
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto**
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto** Side Effects:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto** If this is a new macro name, a new id is allocated.
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto** On error, syserr is called.
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto*/
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortemacid_parse(p, ep)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *p;
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv char **ep;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int mid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *bp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char mbuf[MAXMACNAMELEN + 1];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (tTd(35, 14))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sm_dprintf("macid(");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte xputs(sm_debug_file(), p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sm_dprintf(") => ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (*p == '\0' || (p[0] == '{' && p[1] == '}'))
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto syserr("Name required for macro/class");
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ep != NULL)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *ep = p;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (tTd(35, 14))
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sm_dprintf("NULL\n");
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (*p != '{')
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* the macro is its own code */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ep != NULL)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *ep = p + 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (tTd(35, 14))
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char buf[2];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buf[0] = *p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buf[1] = '\0';
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv xputs(sm_debug_file(), buf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sm_dprintf("\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return bitidx(*p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bp = mbuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (*++p != '\0' && *p != '}' && bp < &mbuf[sizeof(mbuf) - 1])
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isascii(*p) && (isalnum(*p) || *p == '_'))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *bp++ = *p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syserr("Invalid macro/class character %c", *p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *bp = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mid = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*p == '\0')
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syserr("Unbalanced { on %s", mbuf); /* missing } */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if (*p != '}')
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syserr("Macro/class name ({%s}) too long (%d chars max)",
5679c89fcd2facbb4334df8870d3d7a4d2b11673jv mbuf, (int) (sizeof(mbuf) - 1));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if (mbuf[1] == '\0' && mbuf[0] >= 0x20)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* ${x} == $x */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mid = bitidx(mbuf[0]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STAB *s;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s = stab(mbuf, ST_MACRO, ST_ENTER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (s->s_macro != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mid = s->s_macro;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (NextMacroId > MAXMACROID)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syserr("Macro/class {%s}: too many long names",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s->s_macro = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MacroName[NextMacroId] = s->s_name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s->s_macro = mid = NextMacroId;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NextMacroId = NEXTMACROID(NextMacroId);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ep != NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *ep = p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mid < 0 || mid > MAXMACROID)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syserr("Unable to assign macro/class ID (mid = 0x%x)", mid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (tTd(35, 14))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sm_dprintf("NULL\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (tTd(35, 14))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sm_dprintf("0x%x\n", mid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return mid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** WORDINCLASS -- tell if a word is in a specific class
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte**
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** Parameters:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** str -- the name of the word to look up.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** cl -- the class name.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte**
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** Returns:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** true if str can be found in cl.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte** false otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortebool
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortewordinclass(str, cl)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *str;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STAB *s;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s = stab(str, ST_CLASS, ST_FIND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return s != NULL && bitnset(bitidx(cl), s->s_class);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte