expand macros in rewriting rules early to allow multi-word macros to
authorEric Allman <eric@ucbvax.Berkeley.EDU>
Sun, 21 Feb 1982 05:00:31 +0000 (21:00 -0800)
committerEric Allman <eric@ucbvax.Berkeley.EDU>
Sun, 21 Feb 1982 05:00:31 +0000 (21:00 -0800)
be processed correctly.

SCCS-vsn: usr.sbin/sendmail/src/version.c 3.78
SCCS-vsn: usr.sbin/sendmail/src/main.c 3.63
SCCS-vsn: usr.sbin/sendmail/src/readcf.c 3.21
SCCS-vsn: usr.sbin/sendmail/src/macro.c 3.9

usr/src/usr.sbin/sendmail/src/macro.c
usr/src/usr.sbin/sendmail/src/main.c
usr/src/usr.sbin/sendmail/src/readcf.c
usr/src/usr.sbin/sendmail/src/version.c

index 77ec3d9..3199818 100644 (file)
@@ -1,7 +1,7 @@
 # include "useful.h"
 # include "conf.h"
 
 # include "useful.h"
 # include "conf.h"
 
-SCCSID(@(#)macro.c     3.8             %G%);
+SCCSID(@(#)macro.c     3.9             %G%);
 
 char   *Macro[128];
 extern int     Debug;
 
 char   *Macro[128];
 extern int     Debug;
@@ -60,7 +60,7 @@ expand(s, buf, buflim)
                                skipping = Macro[c] == NULL;
                                break;
 
                                skipping = Macro[c] == NULL;
                                break;
 
-                         case ':':     /* else */
+                         case '|':     /* else */
                                skipping = !skipping;
                                break;
 
                                skipping = !skipping;
                                break;
 
index a6ef7d9..d0eb13d 100644 (file)
@@ -7,7 +7,7 @@
 # include <syslog.h>
 # endif LOG
 
 # include <syslog.h>
 # endif LOG
 
-SCCSID(@(#)main.c      3.62            %G%);
+SCCSID(@(#)main.c      3.63            %G%);
 
 /*
 **  SENDMAIL -- Post mail to a set of destinations.
 
 /*
 **  SENDMAIL -- Post mail to a set of destinations.
@@ -160,6 +160,7 @@ main(argc, argv)
 # endif
        errno = 0;
        from = NULL;
 # endif
        errno = 0;
        from = NULL;
+       initmacros();
 
        /*
        ** Crack argv.
 
        /*
        ** Crack argv.
@@ -916,3 +917,41 @@ initsys()
                }
        }
 }
                }
        }
 }
+\f/*
+**  INITMACROS -- initialize the macro system
+**
+**     This just involves defining some macros that are actually
+**     used internally as metasymbols to be themselves.
+**
+**     Parameters:
+**             none.
+**
+**     Returns:
+**             none.
+**
+**     Side Effects:
+**             initializes several macros to be themselves.
+*/
+
+char   *MetaMacros[] =
+{
+       /* $0 .... are rewrite replacement */
+       "$$0",  "$$1",  "$$2",  "$$3",  "$$4",
+       "$$5",  "$$6",  "$$7",  "$$8",  "$$9",
+
+       /* these are important on the LHS */
+       "$$+",  "$$-",  "$$=",
+
+       /* these are RHS metasymbols */
+       "$$#",  "$$@",  "$$:",
+
+       NULL
+};
+
+initmacros()
+{
+       register char **pp;
+
+       for (pp = MetaMacros; *pp != NULL; pp++)
+               define((*pp)[2], *pp);
+}
index a5cfa09..450485d 100644 (file)
@@ -1,6 +1,6 @@
 # include "sendmail.h"
 
 # include "sendmail.h"
 
-SCCSID(@(#)readcf.c    3.20            %G%);
+SCCSID(@(#)readcf.c    3.21            %G%);
 
 /*
 **  READCF -- read control file.
 
 /*
 **  READCF -- read control file.
@@ -57,6 +57,7 @@ readcf(cfname, safe)
        extern char **copyplist();
        int class;
        int ruleset = 0;
        extern char **copyplist();
        int class;
        int ruleset = 0;
+       char exbuf[MAXLINE];
 
        cf = fopen(cfname, "r");
        if (cf == NULL)
 
        cf = fopen(cfname, "r");
        if (cf == NULL)
@@ -85,30 +86,38 @@ readcf(cfname, safe)
                                continue;
 
                        if (*p == '\0')
                                continue;
 
                        if (*p == '\0')
+                       {
                                syserr("invalid rewrite line \"%s\"", buf);
                                syserr("invalid rewrite line \"%s\"", buf);
+                               break;
+                       }
+
+                       /* allocate space for the rule header */
+                       if (rwp == NULL)
+                       {
+                               RewriteRules[ruleset] = rwp =
+                                       (struct rewrite *) xalloc(sizeof *rwp);
+                       }
                        else
                        {
                        else
                        {
-                               if (rwp == NULL)
-                               {
-                                       RewriteRules[ruleset] = rwp =
-                                               (struct rewrite *) xalloc(sizeof *rwp);
-                               }
-                               else
-                               {
-                                       rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp);
-                                       rwp = rwp->r_next;
-                               }
-                               rwp->r_next = NULL;
-
-                               rwp->r_lhs = prescan(&buf[1], '\t');
-                               if (rwp->r_lhs != NULL)
-                                       rwp->r_lhs = copyplist(rwp->r_lhs, TRUE);
-                               while (*p == '\t')
-                                       p++;
-                               rwp->r_rhs = prescan(p, '\t');
-                               if (rwp->r_rhs != NULL)
-                                       rwp->r_rhs = copyplist(rwp->r_rhs, TRUE);
+                               rwp->r_next = (struct rewrite *) xalloc(sizeof *rwp);
+                               rwp = rwp->r_next;
                        }
                        }
+                       rwp->r_next = NULL;
+
+                       /* expand and save the LHS */
+                       *p = '\0';
+                       (void) expand(&buf[1], exbuf, &exbuf[sizeof exbuf]);
+                       rwp->r_lhs = prescan(exbuf, '\t');
+                       if (rwp->r_lhs != NULL)
+                               rwp->r_lhs = copyplist(rwp->r_lhs, TRUE);
+
+                       /* expand and save the RHS */
+                       while (*++p == '\t')
+                               continue;
+                       (void) expand(p, exbuf, &exbuf[sizeof exbuf]);
+                       rwp->r_rhs = prescan(exbuf, '\t');
+                       if (rwp->r_rhs != NULL)
+                               rwp->r_rhs = copyplist(rwp->r_rhs, TRUE);
                        break;
 
                  case 'S':             /* select rewriting set */
                        break;
 
                  case 'S':             /* select rewriting set */
index dfa57db..53783f0 100644 (file)
@@ -1,5 +1,5 @@
 # ifndef lint
 # ifndef lint
-static char    SccsId[] = "@(#)SendMail version 3.77 of %G%";
+static char    SccsId[] = "@(#)SendMail version 3.78 of %G%";
 # endif lint
 
 # endif lint
 
-char   Version[] = "3.77 [%G%]";
+char   Version[] = "3.78 [%G%]";