setup home directory for globbing
[unix-history] / usr / src / usr.bin / mail / optim.c
index 5af2dd4..eadb38f 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.3 %G%";
+static char *SccsId = "@(#)optim.c     2.7 %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.3 %G%";
  * nonsense.
  */
 
  * nonsense.
  */
 
-char   *metanet = "!^:%@.";
-
 char *
 netmap(name, from)
        char name[], from[];
 char *
 netmap(name, from)
        char name[], from[];
@@ -84,55 +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|BN,
-       "virus",        'k',            SN,
-       "vlsi",         'l',            SN,
-       "image",        'm',            SN,
-       "esvax",        'o',            SN,
-       "sesm",         'o',            SN,
-       "q",            'q',            SN,
-       "research",     'R',            BN,
-       "arpavax",      'r',            SN|BN,
-       "src",          's',            SN,
-       "mathstat",     't',            SN,
-       "csvax",        'v',            BN|SN,
-       "vax",          'v',            BN|SN,
-       "ucb",          'v',            BN|SN,
-       "ucbvax",       'v',            BN|SN,
-       "onyx",         'x',            SN,
-       "vax135",       'X',            BN,
-       "cory",         'y',            SN,
-       "eecs40",       'z',            SN,
-       0,              0,              0
-};
-
+ */
 netlook(machine, attnet)
        char machine[];
 {
 netlook(machine, attnet)
        char machine[];
 {
@@ -333,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) {
@@ -348,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);
 }
 
@@ -515,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);
@@ -530,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,13 +486,13 @@ optim1(netstr, name)
 
        cp = netstr;
        prefer(cp);
 
        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;
        /*
         * If the address ultimately points back to us,
         * just return a null network path.
         */
        if (strlen(cp) > 1 && cp[strlen(cp) - 2] == LOCAL)
                return;
-       strcpy(name, "");
        while (*cp != 0) {
                strcpy(path, "");
                tp = ntype(cp[1]);
        while (*cp != 0) {
                strcpy(path, "");
                tp = ntype(cp[1]);
@@ -590,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);
 }
 
 /*
 }
 
 /*
@@ -620,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);
 }
 
 /*
 }
 
 /*
@@ -759,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;
@@ -791,6 +704,27 @@ best(src, dest)
        return(np->no_char);
 }
 
        return(np->no_char);
 }
 
+#ifdef GETHOST
+/*
+ * Initialize the network name of the current host.
+ */
+inithost()
+{
+       register struct netmach *np;
+       static char host[64];
+
+       gethostname(host, sizeof host);
+       for (np = netmach; np->nt_machine != 0; np++)
+               if (strcmp(np->nt_machine, EMPTY) == 0)
+                       break;
+       if (np->nt_machine == 0) {
+               printf("Cannot find empty slot for dynamic host entry\n");
+               exit(1);
+       }
+       np->nt_machine = host;
+}
+#endif GETHOST
+
 /*
  * Code to twist around arpa net names.
  */
 /*
  * Code to twist around arpa net names.
  */
@@ -912,14 +846,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;