restore creation of y.tab.c
[unix-history] / usr / src / usr.bin / mail / optim.c
index f61dca5..cd06387 100644 (file)
@@ -7,9 +7,10 @@
  */
 
 #include "rcv.h"
  */
 
 #include "rcv.h"
+#include "configdefs.h"
 #include <ctype.h>
 
 #include <ctype.h>
 
-static char *SccsId = "@(#)optim.c     1.1 %G%";
+static char *SccsId = "@(#)optim.c     2.5 %G%";
 
 /*
  * Map a name into the correct network "view" of the
 
 /*
  * Map a name into the correct network "view" of the
@@ -18,8 +19,6 @@ static char *SccsId = "@(#)optim.c    1.1 %G%";
  * nonsense.
  */
 
  * nonsense.
  */
 
-char   *metanet = "!^:%@.";
-
 char *
 netmap(name, from)
        char name[], from[];
 char *
 netmap(name, from)
        char name[], from[];
@@ -84,54 +83,10 @@ rename(str)
                return(savestr(path));
        return(str);
 }
                return(savestr(path));
        return(str);
 }
+
 /*
  * Turn a network machine name into a unique character
 /*
  * Turn a network machine name into a unique character
- * + give connection-to status.  BN -- connected to Bell Net.
- * AN -- connected to ARPA net, SN -- connected to Schmidt net.
- * CN -- connected to COCANET.
  */
  */
-
-#define        AN      1                       /* Connected to ARPA net */
-#define        BN      2                       /* Connected to BTL net */
-#define        CN      4                       /* Connected to COCANET */
-#define        SN      8                       /* Connected to Schmidt net */
-
-struct netmach {
-       char    *nt_machine;
-       char    nt_mid;
-       short   nt_type;
-} netmach[] = {
-       "a",            'a',            SN,
-       "b",            'b',            SN,
-       "c",            'c',            SN,
-       "d",            'd',            SN,
-       "e",            'e',            SN,
-       "f",            'f',            SN,
-       "g",            'g',            SN,
-       "ingres",       'i',            AN|SN,
-       "ing70",        'i',            AN|SN,
-       "berkeley",     'i',            AN|SN,
-       "ingvax",       'j',            SN,
-       "virus",        'k',            SN,
-       "vlsi",         'l',            SN,
-       "image",        'm',            SN,
-       "esvax",        'o',            SN,
-       "sesm",         'o',            SN,
-       "q",            'q',            SN,
-       "research",     'R',            BN,
-       "arpavax",      'r',            SN,
-       "src",          's',            SN,
-       "mathstat",     't',            SN,
-       "csvax",        'v',            BN|SN,
-       "vax",          'v',            BN|SN,
-       "ucb",          'v',            BN|SN,
-       "ucbvax",       'v',            BN|SN,
-       "vax135",       'x',            BN,
-       "cory",         'y',            SN,
-       "eecs40",       'z',            SN,
-       0,              0,              0
-};
-
 netlook(machine, attnet)
        char machine[];
 {
 netlook(machine, attnet)
        char machine[];
 {
@@ -332,6 +287,7 @@ mstash(name, attnet)
 {
        register struct xtrahash *xp;
        struct xtrahash *xlocate();
 {
        register struct xtrahash *xp;
        struct xtrahash *xlocate();
+       int x;
 
        xp = xlocate(name);
        if (xp == (struct xtrahash *) 0) {
 
        xp = xlocate(name);
        if (xp == (struct xtrahash *) 0) {
@@ -347,22 +303,11 @@ mstash(name, attnet)
                xp->xh_name = savestr(name);
                xp->xh_mid = 0200 + midfree++;
        }
                xp->xh_name = savestr(name);
                xp->xh_mid = 0200 + midfree++;
        }
-       switch (attnet) {
-       case '!':
-       case '^':
-               xp->xh_attnet |= BN;
-               break;
-
-       default:
-       case ':':
+       x = ntype(attnet);
+       if (x == 0)
                xp->xh_attnet |= SN;
                xp->xh_attnet |= SN;
-               break;
-
-       case '@':
-       case '%':
-               xp->xh_attnet |= AN;
-               break;
-       }
+       else
+               xp->xh_attnet |= x;
        return(xp->xh_mid);
 }
 
        return(xp->xh_mid);
 }
 
@@ -446,7 +391,7 @@ mtype(mid)
 
 /*
  * Take a network name and optimize it.  This gloriously messy
 
 /*
  * Take a network name and optimize it.  This gloriously messy
- * opertions takes place as follows:  the name with machine names
+ * operation takes place as follows:  the name with machine names
  * in it is tokenized by mapping each machine name into a single
  * character machine id (netlook).  The separator characters (network
  * metacharacters) are left intact.  The last component of the network
  * in it is tokenized by mapping each machine name into a single
  * character machine id (netlook).  The separator characters (network
  * metacharacters) are left intact.  The last component of the network
@@ -514,6 +459,9 @@ err:
        while (*cp) {
                if ((cp2 = netname(*cp++)) == NOSTR) {
                        printf("Made up bad net name\n");
        while (*cp) {
                if ((cp2 = netname(*cp++)) == NOSTR) {
                        printf("Made up bad net name\n");
+                       printf("Machine code %c (0%o)\n", cp[-1], cp[-1]);
+                       printf("Sorry -- dumping now.  Alert K. Shoens\n");
+                       core(0);
                        goto err;
                }
                strcat(name, cp2);
                        goto err;
                }
                strcat(name, cp2);
@@ -529,9 +477,6 @@ err:
  * optimizer and concatenating the results.
  */
 
  * optimizer and concatenating the results.
  */
 
-#define        IMPLICIT        1
-#define        EXPLICIT        2
-
 optim1(netstr, name)
        char netstr[], name[];
 {
 optim1(netstr, name)
        char netstr[], name[];
 {
@@ -542,6 +487,12 @@ optim1(netstr, name)
        cp = netstr;
        prefer(cp);
        strcpy(name, "");
        cp = netstr;
        prefer(cp);
        strcpy(name, "");
+       /*
+        * If the address ultimately points back to us,
+        * just return a null network path.
+        */
+       if (strlen(cp) > 1 && cp[strlen(cp) - 2] == LOCAL)
+               return;
        while (*cp != 0) {
                strcpy(path, "");
                tp = ntype(cp[1]);
        while (*cp != 0) {
                strcpy(path, "");
                tp = ntype(cp[1]);
@@ -583,24 +534,12 @@ optim1(netstr, name)
 ntype(nc)
        register int nc;
 {
 ntype(nc)
        register int nc;
 {
+       register struct ntypetab *np;
 
 
-       switch (nc) {
-       case '^':
-       case '!':
-               return(BN);
-
-       case ':':
-       case '.':
-               return(SN);
-
-       case '@':
-       case '%':
-               return(AN);
-
-       default:
-               return(0);
-       }
-       /* NOTREACHED */
+       for (np = ntypetab; np->nt_char != 0; np++)
+               if (np->nt_char == nc)
+                       return(np->nt_bcode);
+       return(0);
 }
 
 /*
 }
 
 /*
@@ -613,19 +552,12 @@ ntype(nc)
 netkind(nt)
        register int nt;
 {
 netkind(nt)
        register int nt;
 {
+       register struct nkindtab *np;
 
 
-       switch (nt) {
-       case BN:
-               return(EXPLICIT);
-
-       case AN:
-       case SN:
-               return(IMPLICIT);
-
-       default:
-               return(0);
-       }
-       /* NOTREACHED */
+       for (np = nkindtab; np->nk_type != 0; np++)
+               if (np->nk_type == nt)
+                       return(np->nk_kind);
+       return(0);
 }
 
 /*
 }
 
 /*
@@ -681,7 +613,6 @@ optimimp(net, name)
 }
 
 /*
 }
 
 /*
-
  * Perform global optimization on the given network path.
  * The trick here is to look ahead to see if there are any loops
  * in the path and remove them.  The interpretation of loops is
  * Perform global optimization on the given network path.
  * The trick here is to look ahead to see if there are any loops
  * in the path and remove them.  The interpretation of loops is
@@ -753,18 +684,6 @@ prefer(name)
  * Return the best network separator for the given machine pair.
  */
 
  * Return the best network separator for the given machine pair.
  */
 
-struct netorder {
-       short   no_stat;
-       char    no_char;
-} netorder[] = {
-       CN,     ':',
-       AN,     '@',
-       AN,     '%',
-       SN,     ':',
-       BN,     '!',
-       -1,     0
-};
-
 best(src, dest)
 {
        register int dtype, stype;
 best(src, dest)
 {
        register int dtype, stype;
@@ -772,18 +691,13 @@ best(src, dest)
 
        stype = nettype(src);
        dtype = nettype(dest);
 
        stype = nettype(src);
        dtype = nettype(dest);
+       fflush(stdout);
        if (stype == 0 || dtype == 0) {
                printf("ERROR:  unknown internal machine id\n");
                return(0);
        }
        if (stype == 0 || dtype == 0) {
                printf("ERROR:  unknown internal machine id\n");
                return(0);
        }
-       if ((stype & dtype) == 0) {
-#ifdef DELIVERMAIL
-               if (src != LOCAL)
-#endif
-                       printf("No way to get from \"%s\" to \"%s\"\n", 
-                           netname(src), netname(dest));
+       if ((stype & dtype) == 0)
                return(0);
                return(0);
-       }
        np = &netorder[0];
        while ((np->no_stat & stype & dtype) == 0)
                np++;
        np = &netorder[0];
        while ((np->no_stat & stype & dtype) == 0)
                np++;
@@ -911,14 +825,14 @@ yylex()
                cp++;
        if (*cp == 0)
                return(0);
                cp++;
        if (*cp == 0)
                return(0);
-       if (any(*cp, "!^@:%")) {
+       if (any(*cp, metanet)) {
                charp = cp+1;
                return(*cp);
        }
        dot = cp;
                charp = cp+1;
                return(*cp);
        }
        dot = cp;
-       while (*cp && !any(*cp, " \t!^@:%"))
+       while (*cp && !any(*cp, metanet) && !any(*cp, " \t"))
                cp++;
                cp++;
-       if (any(*cp, "!^@:%"))
+       if (any(*cp, metanet))
                nexttok = *cp;
        if (*cp == 0)
                charp = cp;
                nexttok = *cp;
        if (*cp == 0)
                charp = cp;