Deleted Added
full compact
macro.c (66494) macro.c (71345)
1/*
2 * Copyright (c) 1998-2000 Sendmail, Inc. and its suppliers.
3 * All rights reserved.
4 * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved.
5 * Copyright (c) 1988, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * By using this file, you agree to the terms and conditions set
9 * forth in the LICENSE file which can be found at the top level of
10 * the sendmail distribution.
11 *
12 */
13
14#ifndef lint
1/*
2 * Copyright (c) 1998-2000 Sendmail, Inc. and its suppliers.
3 * All rights reserved.
4 * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved.
5 * Copyright (c) 1988, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * By using this file, you agree to the terms and conditions set
9 * forth in the LICENSE file which can be found at the top level of
10 * the sendmail distribution.
11 *
12 */
13
14#ifndef lint
15static char id[] = "@(#)$Id: macro.c,v 8.40.16.2 2000/09/17 17:04:26 gshapiro Exp $";
15static char id[] = "@(#)$Id: macro.c,v 8.40.16.7 2000/10/09 15:49:06 gshapiro Exp $";
16#endif /* ! lint */
17
18#include <sendmail.h>
19
16#endif /* ! lint */
17
18#include <sendmail.h>
19
20char *MacroName[256]; /* macro id to name table */
21int NextMacroId = 0240; /* codes for long named macros */
20#if MAXMACROID != (BITMAPBITS - 1)
21 ERROR Read the comment in conf.h
22#endif /* MAXMACROID != (BITMAPBITS - 1) */
22
23
24char *MacroName[MAXMACROID + 1]; /* macro id to name table */
25int NextMacroId = 0240; /* codes for long named macros */
23
24/*
25** EXPAND -- macro expand a string using $x escapes.
26**
27** Parameters:
28** s -- the string to expand.
29** buf -- the place to put the expansion.
30** bufsize -- the size of the buffer.

--- 75 unchanged lines hidden (view full) ---

106 iflev--;
107 if (skiplev == 0)
108 skipping = FALSE;
109 if (skipping)
110 skiplev--;
111 continue;
112
113 case MACROEXPAND: /* macro interpolation */
26
27/*
28** EXPAND -- macro expand a string using $x escapes.
29**
30** Parameters:
31** s -- the string to expand.
32** buf -- the place to put the expansion.
33** bufsize -- the size of the buffer.

--- 75 unchanged lines hidden (view full) ---

109 iflev--;
110 if (skiplev == 0)
111 skipping = FALSE;
112 if (skipping)
113 skiplev--;
114 continue;
115
116 case MACROEXPAND: /* macro interpolation */
114 c = *++s & 0377;
117 c = bitidx(*++s);
115 if (c != '\0')
116 q = macvalue(c, e);
117 else
118 {
119 s--;
120 q = NULL;
121 }
122 if (q == NULL)

--- 119 unchanged lines hidden (view full) ---

242void
243define(n, v, e)
244 int n;
245 char *v;
246 register ENVELOPE *e;
247{
248 int m;
249
118 if (c != '\0')
119 q = macvalue(c, e);
120 else
121 {
122 s--;
123 q = NULL;
124 }
125 if (q == NULL)

--- 119 unchanged lines hidden (view full) ---

245void
246define(n, v, e)
247 int n;
248 char *v;
249 register ENVELOPE *e;
250{
251 int m;
252
250 m = n & 0377;
253 m = bitidx(n);
251 if (tTd(35, 9))
252 {
253 dprintf("%sdefine(%s as ",
254 (e->e_macro[m] == NULL) ? ""
255 : "re", macname(n));
256 xputs(v);
257 dprintf(")\n");
258 }

--- 21 unchanged lines hidden (view full) ---

280** none.
281*/
282
283char *
284macvalue(n, e)
285 int n;
286 register ENVELOPE *e;
287{
254 if (tTd(35, 9))
255 {
256 dprintf("%sdefine(%s as ",
257 (e->e_macro[m] == NULL) ? ""
258 : "re", macname(n));
259 xputs(v);
260 dprintf(")\n");
261 }

--- 21 unchanged lines hidden (view full) ---

283** none.
284*/
285
286char *
287macvalue(n, e)
288 int n;
289 register ENVELOPE *e;
290{
288 n &= 0377;
291 n = bitidx(n);
289 while (e != NULL)
290 {
291 register char *p = e->e_macro[n];
292
293 if (p != NULL)
294 return p;
295 e = e->e_parent;
296 }

--- 13 unchanged lines hidden (view full) ---

310*/
311
312char *
313macname(n)
314 int n;
315{
316 static char mbuf[2];
317
292 while (e != NULL)
293 {
294 register char *p = e->e_macro[n];
295
296 if (p != NULL)
297 return p;
298 e = e->e_parent;
299 }

--- 13 unchanged lines hidden (view full) ---

313*/
314
315char *
316macname(n)
317 int n;
318{
319 static char mbuf[2];
320
318 n &= 0377;
321 n = bitidx(n);
319 if (bitset(0200, n))
320 {
321 char *p = MacroName[n];
322
323 if (p != NULL)
324 return p;
325 return "***UNDEFINED MACRO***";
326 }

--- 36 unchanged lines hidden (view full) ---

363
364 if (*p == '\0' || (p[0] == '{' && p[1] == '}'))
365 {
366 syserr("Name required for macro/class");
367 if (ep != NULL)
368 *ep = p;
369 if (tTd(35, 14))
370 dprintf("NULL\n");
322 if (bitset(0200, n))
323 {
324 char *p = MacroName[n];
325
326 if (p != NULL)
327 return p;
328 return "***UNDEFINED MACRO***";
329 }

--- 36 unchanged lines hidden (view full) ---

366
367 if (*p == '\0' || (p[0] == '{' && p[1] == '}'))
368 {
369 syserr("Name required for macro/class");
370 if (ep != NULL)
371 *ep = p;
372 if (tTd(35, 14))
373 dprintf("NULL\n");
371 return '\0';
374 return 0;
372 }
373 if (*p != '{')
374 {
375 /* the macro is its own code */
376 if (ep != NULL)
377 *ep = p + 1;
378 if (tTd(35, 14))
375 }
376 if (*p != '{')
377 {
378 /* the macro is its own code */
379 if (ep != NULL)
380 *ep = p + 1;
381 if (tTd(35, 14))
379 dprintf("%c\n", *p);
380 return *p;
382 dprintf("%c\n", bitidx(*p));
383 return bitidx(*p);
381 }
382 bp = mbuf;
383 while (*++p != '\0' && *p != '}' && bp < &mbuf[sizeof mbuf - 1])
384 {
385 if (isascii(*p) && (isalnum(*p) || *p == '_'))
386 *bp++ = *p;
387 else
388 syserr("Invalid macro/class character %c", *p);

--- 7 unchanged lines hidden (view full) ---

396 else if (*p != '}')
397 {
398 syserr("Macro/class name ({%s}) too long (%d chars max)",
399 mbuf, sizeof mbuf - 1);
400 }
401 else if (mbuf[1] == '\0')
402 {
403 /* ${x} == $x */
384 }
385 bp = mbuf;
386 while (*++p != '\0' && *p != '}' && bp < &mbuf[sizeof mbuf - 1])
387 {
388 if (isascii(*p) && (isalnum(*p) || *p == '_'))
389 *bp++ = *p;
390 else
391 syserr("Invalid macro/class character %c", *p);

--- 7 unchanged lines hidden (view full) ---

399 else if (*p != '}')
400 {
401 syserr("Macro/class name ({%s}) too long (%d chars max)",
402 mbuf, sizeof mbuf - 1);
403 }
404 else if (mbuf[1] == '\0')
405 {
406 /* ${x} == $x */
404 mid = mbuf[0];
407 mid = bitidx(mbuf[0]);
405 p++;
406 }
407 else
408 {
409 register STAB *s;
410
411 s = stab(mbuf, ST_MACRO, ST_ENTER);
412 if (s->s_macro != 0)

--- 10 unchanged lines hidden (view full) ---

423 MacroName[NextMacroId] = s->s_name;
424 s->s_macro = mid = NextMacroId++;
425 }
426 }
427 p++;
428 }
429 if (ep != NULL)
430 *ep = p;
408 p++;
409 }
410 else
411 {
412 register STAB *s;
413
414 s = stab(mbuf, ST_MACRO, ST_ENTER);
415 if (s->s_macro != 0)

--- 10 unchanged lines hidden (view full) ---

426 MacroName[NextMacroId] = s->s_name;
427 s->s_macro = mid = NextMacroId++;
428 }
429 }
430 p++;
431 }
432 if (ep != NULL)
433 *ep = p;
434 if (mid < 0 || mid > MAXMACROID)
435 {
436 syserr("Unable to assign macro/class ID (mid = 0x%x)", mid);
437 if (tTd(35, 14))
438 dprintf("NULL\n");
439 return 0;
440 }
431 if (tTd(35, 14))
432 dprintf("0x%x\n", mid);
433 return mid;
434}
435 /*
436** WORDINCLASS -- tell if a word is in a specific class
437**
438** Parameters:

--- 8 unchanged lines hidden (view full) ---

447bool
448wordinclass(str, cl)
449 char *str;
450 int cl;
451{
452 register STAB *s;
453
454 s = stab(str, ST_CLASS, ST_FIND);
441 if (tTd(35, 14))
442 dprintf("0x%x\n", mid);
443 return mid;
444}
445 /*
446** WORDINCLASS -- tell if a word is in a specific class
447**
448** Parameters:

--- 8 unchanged lines hidden (view full) ---

457bool
458wordinclass(str, cl)
459 char *str;
460 int cl;
461{
462 register STAB *s;
463
464 s = stab(str, ST_CLASS, ST_FIND);
455 return s != NULL && bitnset(cl & 0xff, s->s_class);
465 return s != NULL && bitnset(bitidx(cl), s->s_class);
456}
466}