file reorg, pathnames.h, paths.h
[unix-history] / usr / src / usr.bin / uucp / uucico / conn.c
index b77096d..9fdc307 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)conn.c     5.8 (Berkeley) %G%";
+static char sccsid[] = "@(#)conn.c     5.15    (Berkeley) %G%";
 #endif
 
 #include <signal.h>
 #endif
 
 #include <signal.h>
@@ -40,7 +40,8 @@ char  *AbortOn = NULL;
 char   par_tab[128];   /* must be power of two */
 int    linebaudrate;   /* used for the sleep test in pk1.c */
 int next_fd = -1;      /* predicted fd to close interrupted opens */
 char   par_tab[128];   /* must be power of two */
 int    linebaudrate;   /* used for the sleep test in pk1.c */
 int next_fd = -1;      /* predicted fd to close interrupted opens */
-                               /* rti!trt, courtesy unc!smb */
+
+char *PCP = "PCP";     /* PC Pursuit device type */
 /*
  *     catch alarm routine for "expect".
  */
 /*
  *     catch alarm routine for "expect".
  */
@@ -55,6 +56,49 @@ alarmtr()
        longjmp(Sjbuf, 1);
 }
 
        longjmp(Sjbuf, 1);
 }
 
+/* This template is for seismo to call ihnp4 
+ * the 3 lines marked ---> will be overwritten for the appropriate city
+ */
+#define PCP_BAUD       3
+#define PCP_PHONE      4
+#define PCP_CITY       14
+#define PCP_PASSWORD   16
+#define PCP_RPHONE     20
+#define NPCFIELDS      23
+
+static char *PCFlds[] = {
+       "PC-PURSUIT",
+       "Any",
+       "ACU",
+       "1200",
+       CNULL,
+       CNULL,
+       "P_ZERO",       /* Telenet insists on zero parity */
+       "ABORT",
+       "BUSY",         /* Abort on Busy Signal */
+       CNULL,
+       "\\d\\d\\r\\d\\r",      /* Get telenet's attention */
+       "TERMINAL=~3-\r-TERM~3-\r-TERM~5",      /* Terminal type ? */
+       "\\r",
+       "@",            /* telenet's prompt */
+       "D/DCWAS/21,telenetloginstring", /* overwritten later */
+       "PASSWORD",
+       CNULL,          /* telenet password */
+       "CONNECTED",    /* We're now talking to a Hayes in the remote city */
+       "ATZ",          /* Reset it */
+       "OK",
+       "ATDT6907171", /* overwritten */
+       "CONNECT",      
+       "\\d\\r",               /* We're in !*/
+       CNULL,
+};
+
+static char PCP_brand[25];
+int Dcf = -1;
+char *Flds[MAXC/10];
+char LineType[10];
+extern int LocalOnly;
+
 /*
  *     place a telephone call to system and login, etc.
  *
 /*
  *     place a telephone call to system and login, etc.
  *
@@ -67,16 +111,10 @@ alarmtr()
  *
  *             >0  - file no.  -  connect ok
  */
  *
  *             >0  - file no.  -  connect ok
  */
-
-int Dcf = -1;
-char *Flds[MAXC/10];
-extern int LocalOnly;
-
 conn(system)
 char *system;
 {
 conn(system)
 char *system;
 {
-       int ret, nf;
-       register int fn = 0;
+       int nf;
        char info[MAXC], wkpre[NAMESIZE], file[NAMESIZE];
        register FILE *fsys;
        int fcode = 0;
        char info[MAXC], wkpre[NAMESIZE], file[NAMESIZE];
        register FILE *fsys;
        int fcode = 0;
@@ -84,26 +122,76 @@ char *system;
        nf = 0;
 
        fsys = fopen(SYSFILE, "r");
        nf = 0;
 
        fsys = fopen(SYSFILE, "r");
-       ASSERT(fsys != NULL, "CAN'T OPEN", SYSFILE, 0);
+       if (fsys == NULL) {
+               syslog(LOG_ERR, "fopen(%s) failed: %m", SYSFILE);
+               cleanup(FAIL);
+       }
 
        DEBUG(4, "finds (%s) called\n", system);
 keeplooking:
        while((nf = finds(fsys, system, info, Flds)) > 0) {
 
        DEBUG(4, "finds (%s) called\n", system);
 keeplooking:
        while((nf = finds(fsys, system, info, Flds)) > 0) {
+               strncpy(LineType, Flds[F_LINE], 10);
                if (LocalOnly) {
                if (LocalOnly) {
-                       if (strcmp("TCP", Flds[F_LINE])
-                               && strcmp("DIR", Flds[F_LINE])
-                               && strcmp("LOCAL", Flds[F_LINE]) )
-                                       fn = CF_TIME;
+                       if (strcmp("TCP", LineType)
+                               && strcmp("DIR", LineType)
+                               && strcmp("LOCAL", LineType) ) {
+                                       fcode = CF_TIME;
+                                       continue;
+                       }
                }
                sprintf(wkpre, "%c.%.*s", CMDPRE, SYSNSIZE, Rmtname);
                if (!onesys && MaxGrade != DefMaxGrade &&
                }
                sprintf(wkpre, "%c.%.*s", CMDPRE, SYSNSIZE, Rmtname);
                if (!onesys && MaxGrade != DefMaxGrade &&
-                       !iswrk(file, "chk", Spool, wkpre)) 
-                               fn = CF_TIME;
-               if (fn != CF_TIME && (fn = getto(Flds)) > 0) {
-                       Dcf = fn;
+                       !iswrk(file, "chk", Spool, wkpre))  {
+                               fcode = CF_TIME;
+                               continue;
+               }
+               /* For GTE's PC Pursuit */
+               if (snccmp(LineType, PCP) == SAME) {
+                       FILE *dfp;
+                       int status;
+                       static struct Devices dev;
+
+                       dfp = fopen(DEVFILE, "r");
+                       if (dfp == NULL) {
+                               syslog(LOG_ERR, "fopen(%s) failed: %m",
+                                       DEVFILE);
+                               cleanup(FAIL);
+                       }
+                       while ((status=rddev(dfp, &dev)) != FAIL
+                               && strcmp(PCP, dev.D_type) != SAME)
+                                       ;
+                       fclose(dfp);
+                       if (status == FAIL)
+                               continue;
+                       if (mlock(PCP) == FAIL) {
+                               fcode = CF_NODEV;
+                               logent("DEVICE", "NO");
+                               continue;
+                       }
+                       PCFlds[PCP_BAUD] = dev.D_class;
+                       PCFlds[PCP_PHONE] = dev.D_calldev;
+                       sprintf(PCFlds[PCP_CITY], "c d/%s%s,%s",
+                               Flds[F_CLASS],
+                               index(Flds[F_CLASS], '/') == NULL ? "/12" : "",
+                               dev.D_arg[D_CHAT]);
+                       PCFlds[PCP_PASSWORD] = dev.D_line;
+                       strncpy(&PCFlds[PCP_RPHONE][4], Flds[F_PHONE], 7);
+                       strncpy(PCP_brand, dev.D_brand, sizeof(PCP_brand));
+                       if ((fcode = getto(PCFlds)) < 0) {
+                               rmlock(PCP);
+                               continue;
+                       }
+                       Dcf = fcode;
+                       fcode = login(NPCFIELDS, PCFlds, Dcf);
+                       if (fcode == SUCCESS)
+                               break;
+                       fcode = CF_DIAL;
+                       rmlock(PCP);
+                       /* end PC Pursuit */
+               } else if ((fcode = getto(Flds)) > 0)  {
+                       Dcf = fcode;
                        break;
                }
                        break;
                }
-               fcode = (fn == FAIL ? CF_DIAL : fn);
        }
 
        if (nf <= 0) {
        }
 
        if (nf <= 0) {
@@ -111,11 +199,14 @@ keeplooking:
                return fcode ? fcode : nf;
        }
 
                return fcode ? fcode : nf;
        }
 
-       DEBUG(4, "login %s\n", "called");
-       ret = login(nf, Flds, fn);
-       if (ret != SUCCESS) {
+
+       if (fcode >= 0) {
+               DEBUG(4, "login %s\n", "called");
+               setproctitle("login");
+               fcode = login(nf, Flds, Dcf); }
+       if (fcode < 0) {
                clsacu();
                clsacu();
-               if (ret == ABORT) {
+               if (fcode == ABORT) {
                        fcode = CF_DIAL;
                        goto  keeplooking;
                } else {
                        fcode = CF_DIAL;
                        goto  keeplooking;
                } else {
@@ -124,10 +215,13 @@ keeplooking:
                }
        }
        fclose(fsys);
                }
        }
        fclose(fsys);
-       fioclex(fn);
-       return fn;
+       fioclex(Dcf);
+       return Dcf;
 }
 
 }
 
+int nulldev();
+int (*CU_end)() = nulldev;
+
 /*
  *     connect to remote machine
  *
 /*
  *     connect to remote machine
  *
@@ -135,12 +229,11 @@ keeplooking:
  *             >0  -  file number - ok
  *             FAIL  -  failed
  */
  *             >0  -  file number - ok
  *             FAIL  -  failed
  */
-
 getto(flds)
 register char *flds[];
 {
        register struct condev *cd;
 getto(flds)
 register char *flds[];
 {
        register struct condev *cd;
-       int nulldev(), diropn();
+       int diropn();
        char *line;
 
        DEBUG(4, "getto: call no. %s ", flds[F_PHONE]);
        char *line;
 
        DEBUG(4, "getto: call no. %s ", flds[F_PHONE]);
@@ -155,13 +248,23 @@ register char *flds[];
                reenable();
 #endif DIALINOUT
        CU_end = nulldev;
                reenable();
 #endif DIALINOUT
        CU_end = nulldev;
-       for (cd = condevs; cd->CU_meth != NULL; cd++) {
-               if (snccmp(cd->CU_meth, line) == SAME) {
-                       DEBUG(4, "Using %s to call\n", cd->CU_meth);
-                       return (*(cd->CU_gen))(flds);
+       if (snccmp(line, PCP) == SAME) {
+               for(cd = condevs; cd->CU_meth != NULL; cd++) {
+                       if (snccmp(PCP_brand, cd->CU_brand) == SAME) {
+                               CU_end = cd->CU_clos;
+                               return diropn(flds);
+                       }
                }
                }
+               logent(PCP_brand, "UNSUPPORTED ACU TYPE");
+       } else {
+               for (cd = condevs; cd->CU_meth != NULL; cd++) {
+                       if (snccmp(cd->CU_meth, line) == SAME) {
+                               DEBUG(4, "Using %s to call\n", cd->CU_meth);
+                               return (*(cd->CU_gen))(flds);
+                       }
+               }
+               DEBUG(1, "Can't find %s, assuming DIR\n", flds[F_LINE]);
        }
        }
-       DEBUG(1, "Can't find %s, assuming DIR\n", flds[F_LINE]);
        return diropn(flds);    /* search failed, so use direct */
 }
 
        return diropn(flds);    /* search failed, so use direct */
 }
 
@@ -170,8 +273,6 @@ register char *flds[];
  *
  *     return codes:  none
  */
  *
  *     return codes:  none
  */
-
-int (*CU_end)() = nulldev;
 clsacu()
 {
        /* make *sure* Dcf is no longer exclusive.
 clsacu()
 {
        /* make *sure* Dcf is no longer exclusive.
@@ -180,7 +281,7 @@ clsacu()
         * easiest place to put the call.
         * Hopefully everyone honors the LCK protocol, of course
         */
         * easiest place to put the call.
         * Hopefully everyone honors the LCK protocol, of course
         */
-#ifndef        USG
+#ifdef TIOCNXCL
        if (!IsTcpIp && Dcf >= 0 && ioctl(Dcf, TIOCNXCL, STBNULL) < 0)
                DEBUG(5, "clsacu ioctl %s\n", sys_errlist[errno]);
 #endif
        if (!IsTcpIp && Dcf >= 0 && ioctl(Dcf, TIOCNXCL, STBNULL) < 0)
                DEBUG(5, "clsacu ioctl %s\n", sys_errlist[errno]);
 #endif
@@ -203,7 +304,6 @@ clsacu()
 /*
  *     expand phone number for given prefix and number
  */
 /*
  *     expand phone number for given prefix and number
  */
-
 exphone(in, out)
 register char *in, *out;
 {
 exphone(in, out)
 register char *in, *out;
 {
@@ -251,7 +351,6 @@ register char *in, *out;
  *
  *     return code - FAIL at end-of file; 0 otherwise
  */
  *
  *     return code - FAIL at end-of file; 0 otherwise
  */
-
 rddev(fp, dev)
 register struct Devices *dev;
 FILE *fp;
 rddev(fp, dev)
 register struct Devices *dev;
 FILE *fp;
@@ -261,7 +360,10 @@ FILE *fp;
        if (!cfgets(dev->D_argbfr, sizeof(dev->D_argbfr), fp))
                return FAIL;
        na = getargs(dev->D_argbfr, dev->D_arg, 20);
        if (!cfgets(dev->D_argbfr, sizeof(dev->D_argbfr), fp))
                return FAIL;
        na = getargs(dev->D_argbfr, dev->D_arg, 20);
-       ASSERT(na >= 4, "BAD DEVICE ENTRY", dev->D_argbfr, 0);
+       if (na < 4) {
+               syslog(LOG_ERR, "%s: invalid device entry", dev->D_argbfr);
+               cleanup(FAIL);
+       }
        if (na == 4) {
                dev->D_brand = "";
                na++;
        if (na == 4) {
                dev->D_brand = "";
                na++;
@@ -279,7 +381,6 @@ FILE *fp;
  *             CF_SYSTEM  -  system name not found
  *             CF_TIME  -  wrong time to call
  */
  *             CF_SYSTEM  -  system name not found
  *             CF_TIME  -  wrong time to call
  */
-
 finds(fsys, sysnam, info, flds)
 char *sysnam, info[], *flds[];
 FILE *fsys;
 finds(fsys, sysnam, info, flds)
 char *sysnam, info[], *flds[];
 FILE *fsys;
@@ -312,7 +413,6 @@ FILE *fsys;
  *
  *     return codes:  SUCCESS  |  FAIL
  */
  *
  *     return codes:  SUCCESS  |  FAIL
  */
-
 login(nf, flds, fn)
 register char *flds[];
 int nf, fn;
 login(nf, flds, fn)
 register char *flds[];
 int nf, fn;
@@ -320,12 +420,17 @@ int nf, fn;
        register char *want, *altern;
        int k, ok;
 
        register char *want, *altern;
        int k, ok;
 
-       ASSERT(nf > 4, "TOO FEW LOG FIELDS", CNULL, nf);
+       if (nf < 4) {
+               syslog(LOG_ERR, "Too few log fields: %d", nf);
+               cleanup(FAIL);
+       }
        if (setjmp(Cjbuf))
                return FAIL;
        AbortOn = NULL;
        for (k = F_LOGIN; k < nf; k += 2) {
                want = flds[k];
        if (setjmp(Cjbuf))
                return FAIL;
        AbortOn = NULL;
        for (k = F_LOGIN; k < nf; k += 2) {
                want = flds[k];
+               if (want == NULL)
+                       want = "";
                ok = FAIL;
                while (ok != SUCCESS) {
                        altern = index(want, '-');
                ok = FAIL;
                while (ok != SUCCESS) {
                        altern = index(want, '-');
@@ -336,7 +441,7 @@ int nf, fn;
                                DEBUG(4, "ABORT ON: %s\n", AbortOn);
                                goto nextfield;
                        }
                                DEBUG(4, "ABORT ON: %s\n", AbortOn);
                                goto nextfield;
                        }
-                       DEBUG(4, "wanted: %s\n", want);
+                       DEBUG(4, "wanted \"%s\"\n", want);
                        ok = expect(want, fn);
                        DEBUG(4, "got: %s\n", ok ? "?" : "that");
                        if (ok == FAIL) {
                        ok = expect(want, fn);
                        DEBUG(4, "got: %s\n", ok ? "?" : "that");
                        if (ok == FAIL) {
@@ -350,7 +455,9 @@ int nf, fn;
                                sendthem(altern, fn);
                        } else
                                if (ok == ABORT) {
                                sendthem(altern, fn);
                        } else
                                if (ok == ABORT) {
-                                       logent("LOGIN ABORTED", _FAILED);
+                                       char sbuf[MAXFULLNAME];
+                                       sprintf(sbuf, "LOGIN ABORTED on \"%s\"",                                                AbortOn);
+                                       logent(sbuf, _FAILED);
                                        return ABORT;
                                }
                }
                                        return ABORT;
                                }
                }
@@ -424,7 +531,6 @@ struct sg_spds {int sp_val, sp_name;} spds[] = {
  *
  *     return codes:  none
  */
  *
  *     return codes:  none
  */
-
 fixline(tty, spwant)
 int tty, spwant;
 {
 fixline(tty, spwant)
 int tty, spwant;
 {
@@ -439,7 +545,10 @@ int tty, spwant;
        for (ps = spds; ps->sp_val; ps++)
                if (ps->sp_val == spwant)
                        speed = ps->sp_name;
        for (ps = spds; ps->sp_val; ps++)
                if (ps->sp_val == spwant)
                        speed = ps->sp_name;
-       ASSERT(speed >= 0, "BAD SPEED", CNULL, speed);
+       if (speed < 0) {
+               syslog(LOG_ERR, "unrecognized speed: %d", speed);
+               cleanup(FAIL);
+       }
 #ifdef USG
        if (ioctl(tty, TCGETA, &ttbuf) < 0)
                return FAIL;
 #ifdef USG
        if (ioctl(tty, TCGETA, &ttbuf) < 0)
                return FAIL;
@@ -471,39 +580,6 @@ int tty, spwant;
        return SUCCESS;
 }
 
        return SUCCESS;
 }
 
-/***
- *     getbaud(tty)    set linebaudrate variable
- *
- *     return codes:  none
- */
-
-getbaud(tty)
-int tty;
-{
-#ifdef USG
-       struct termio ttbuf;
-#else
-       struct sgttyb ttbuf;
-#endif
-       register struct sg_spds *ps;
-       register int name;
-
-       if (IsTcpIp)
-               return;
-#ifdef USG
-       ioctl(tty, TCGETA, &ttbuf);
-       name = ttbuf.c_cflag & CBAUD;
-#else
-       ioctl(tty, TIOCGETP, &ttbuf);
-       name = ttbuf.sg_ispeed;
-#endif
-       for (ps = spds; ps->sp_val; ps++)
-               if (ps->sp_name == name) {
-                       linebaudrate = ps->sp_val;
-                       break;
-               }
-}
-
 #define MR 100
 
 /*
 #define MR 100
 
 /*
@@ -514,7 +590,6 @@ int tty;
  *             FAIL  -  lost line or too many characters read
  *             some character  -  timed out
  */
  *             FAIL  -  lost line or too many characters read
  *             some character  -  timed out
  */
-
 expect(str, fn)
 register char *str;
 int fn;
 expect(str, fn)
 register char *str;
 int fn;
@@ -533,7 +608,9 @@ int fn;
                        switch(*++strptr) {
                        case 's':
                                DEBUG(5, "BLANK\n", CNULL);
                        switch(*++strptr) {
                        case 's':
                                DEBUG(5, "BLANK\n", CNULL);
+                               strptr--;
                                *strptr = ' ';
                                *strptr = ' ';
+                               strcpy(&strptr[1], &strptr[4]);
                                break;
                        default:
                                strptr--;  /* back up to backslash */
                                break;
                        default:
                                strptr--;  /* back up to backslash */
@@ -558,6 +635,7 @@ int fn;
        alarm(timo);
        *rp = 0;
        while (notin(str, rdvec)) {
        alarm(timo);
        *rp = 0;
        while (notin(str, rdvec)) {
+               int c;
                if(AbortOn != NULL && !notin(AbortOn, rdvec)) {
                        DEBUG(1, "Call aborted on '%s'\n", AbortOn);
                        alarm(0);
                if(AbortOn != NULL && !notin(AbortOn, rdvec)) {
                        DEBUG(1, "Call aborted on '%s'\n", AbortOn);
                        alarm(0);
@@ -570,15 +648,11 @@ int fn;
                        logent("LOGIN", "LOST LINE");
                        return FAIL;
                }
                        logent("LOGIN", "LOST LINE");
                        return FAIL;
                }
-               {
-               int c;
                c = nextch & 0177;
                c = nextch & 0177;
-               DEBUG(4, c >= 040 ? "%c" : "\\%03o", c);
-               if (c == '\n')
-                       DEBUG(4,"\n", CNULL);
-               }
-               if ((*rp = nextch & 0177) != '\0')
-                       rp++;
+               if (c == '\0')
+                       continue;
+               DEBUG(4, (isprint(c) || isspace(c)) ? "%c" : "\\%03o", c);
+               *rp++ = c;
                if (rp >= rdvec + MR) {
                        register char *p;
                        for (p = rdvec+MR/2; p < rp; p++)
                if (rp >= rdvec + MR) {
                        register char *p;
                        for (p = rdvec+MR/2; p < rp; p++)
@@ -617,11 +691,11 @@ int fn;
        register char c;
        static int p_init = 0;
 
        register char c;
        static int p_init = 0;
 
-       DEBUG(5, "send %s\n", str);
+       DEBUG(5, "send \"%s\"\n", str);
 
        if (!p_init) {
                p_init++;
 
        if (!p_init) {
                p_init++;
-               bld_partab(P_EVEN);
+               bld_partab(P_ZERO);
        }
 
        if (prefix("BREAK", str)) {
        }
 
        if (prefix("BREAK", str)) {
@@ -648,12 +722,16 @@ int fn;
        }
 
        /* Send a '\n' */
        }
 
        /* Send a '\n' */
-       if (strcmp(str, "LF") == SAME)
-               str = "\\n\\c";
+       if (strcmp(str, "LF") == SAME) {
+               p_chwrite(fn, '\n');
+               return;
+       }
 
        /* Send a '\r' */
 
        /* Send a '\r' */
-       if (strcmp(str, "CR") == SAME)
-               str = "\\r\\c";
+       if (strcmp(str, "CR") == SAME) {
+               p_chwrite(fn, '\r');
+               return;
+       }
 
        /* Set parity as needed */
        if (strcmp(str, "P_ZERO") == SAME) {
 
        /* Set parity as needed */
        if (strcmp(str, "P_ZERO") == SAME) {
@@ -679,20 +757,29 @@ int fn;
                return;
        }
 
                return;
        }
 
-       for (strptr = str; c = *strptr++;) {
+       strptr = str;
+       while ((c = *strptr++) != '\0') {
                if (c == '\\') {
                        switch(*strptr++) {
                if (c == '\\') {
                        switch(*strptr++) {
+                       case '\0':
+                               DEBUG(5, "TRAILING BACKSLASH IGNORED\n", CNULL);
+                               --strptr;
+                               continue;
                        case 's':
                                DEBUG(5, "BLANK\n", CNULL);
                        case 's':
                                DEBUG(5, "BLANK\n", CNULL);
-                               p_chwrite(fn, ' ');
+                               c = ' ';
                                break;
                        case 'd':
                                DEBUG(5, "DELAY\n", CNULL);
                                sleep(1);
                                continue;
                                break;
                        case 'd':
                                DEBUG(5, "DELAY\n", CNULL);
                                sleep(1);
                                continue;
+                       case 'n':
+                               DEBUG(5, "NEW LINE\n", CNULL);
+                               c = '\n';
+                               break;
                        case 'r':
                                DEBUG(5, "RETURN\n", CNULL);
                        case 'r':
                                DEBUG(5, "RETURN\n", CNULL);
-                               p_chwrite(fn, '\r');
+                               c = '\r';
                                break;
                        case 'b':
                                if (isdigit(*strptr)) {
                                break;
                        case 'b':
                                if (isdigit(*strptr)) {
@@ -710,24 +797,24 @@ int fn;
                                if (*strptr == '\0') {
                                        DEBUG(5, "NO CR\n", CNULL);
                                        cr = 0;
                                if (*strptr == '\0') {
                                        DEBUG(5, "NO CR\n", CNULL);
                                        cr = 0;
-                                       continue;
-                               }
-                               DEBUG(5, "NO CR - MIDDLE IGNORED\n", CNULL);
+                               } else
+                                       DEBUG(5, "NO CR - IGNORED NOT EOL\n", CNULL);
                                continue;
                                continue;
+#define isoctal(x)     ((x >= '0') && (x <= '7'))
                        default:
                        default:
-                               if (isdigit(*strptr)) {
+                               if (isoctal(strptr[-1])) {
                                        i = 0;
                                        n = 0;
                                        i = 0;
                                        n = 0;
-                                       while (isdigit(*strptr) && ++n <= 3)
-                                               i = i*8 + (*strptr++ - '0');
+                                       --strptr;
+                                       while (isoctal(*strptr) && ++n <= 3)
+                                               i = i * 8 + (*strptr++ - '0');
+                                       DEBUG(5, "\\%o\n", i);
                                        p_chwrite(fn, (char)i);
                                        continue;
                                }
                                        p_chwrite(fn, (char)i);
                                        continue;
                                }
-                               DEBUG(5, "BACKSLASH\n", CNULL);
-                               --strptr;
                        }
                        }
-               } else
-                       p_chwrite(fn, c);
+               }
+               p_chwrite(fn, c);
        }
 
        if (cr)
        }
 
        if (cr)
@@ -766,53 +853,6 @@ int type;
        }
 }
 
        }
 }
 
-#define BSPEED B150
-
-/*
- *     send a break
- */
-genbrk(fn, bnulls)
-register int fn, bnulls;
-{
-#ifdef USG
-       if (ioctl(fn, TCSBRK, STBNULL) < 0)
-               DEBUG(5, "break ioctl %s\n", sys_errlist[errno]);
-#else  !USG
-       struct sgttyb ttbuf;
-       register int sospeed;
-# ifdef        TIOCSBRK
-       if (ioctl(fn, TIOCSBRK, STBNULL) < 0)
-               DEBUG(5, "break ioctl %s\n", sys_errlist[errno]);
-# ifdef        TIOCCBRK
-       sleep(1);
-       if (ioctl(fn, TIOCCBRK, STBNULL) < 0)
-               DEBUG(5, "break ioctl %s\n", sys_errlist[errno]);
-# endif TIOCCBRK
-       DEBUG(4, "ioctl %d second break\n", bnulls );
-# else !TIOCSBRK
-
-       if (ioctl(fn, TIOCGETP, &ttbuf) < 0)
-               DEBUG(5, "break ioctl %s\n", sys_errlist[errno]);
-       sospeed = ttbuf.sg_ospeed;
-       ttbuf.sg_ospeed = BSPEED;
-       if (ioctl(fn, TIOCSETP, &ttbuf) < 0)
-               DEBUG(5, "break ioctl %s\n", sys_errlist[errno]);
-       if (write(fn, "\0\0\0\0\0\0\0\0\0\0\0\0", bnulls) != bnulls) {
-badbreak:
-               logent(sys_errlist[errno], "BAD WRITE genbrk");
-               alarm(0);
-               longjmp(Sjbuf, 3);
-       }
-       ttbuf.sg_ospeed = sospeed;
-       if (ioctl(fn, TIOCSETP, &ttbuf) < 0)
-               DEBUG(5, "break ioctl %s\n", sys_errlist[errno]);
-       if (write(fn, "@", 1) != 1)
-               goto badbreak;
-       DEBUG(4, "sent BREAK nulls - %d\n", bnulls);
-#endif !TIOCSBRK
-#endif !USG
-}
-
 /*
  *     check for occurrence of substring "sh"
  *
 /*
  *     check for occurrence of substring "sh"
  *
@@ -838,7 +878,7 @@ register char *sh, *lg;
 ifdate(p)
 register char *p;
 {
 ifdate(p)
 register char *p;
 {
-       register char *np, c;
+       register char *np;
        register int ret, g;
        int rtime, i;
 
        register int ret, g;
        int rtime, i;
 
@@ -931,6 +971,12 @@ char *string;
                                || (tp->tm_wday == 0 && tp->tm_hour < 17))
                                        dayok = 1;
                }
                                || (tp->tm_wday == 0 && tp->tm_hour < 17))
                                        dayok = 1;
                }
+               if (prefix("NonPeak", s)) { /* For Tymnet and PC Pursuit */
+                       /* Sat or Sun */
+                       if (tp->tm_wday == 6 || tp->tm_wday == 0
+                               || tp->tm_hour >= 18 || tp->tm_hour < 7)
+                                       dayok = 1;
+               }
                s++;
        }
 
                s++;
        }
 
@@ -943,16 +989,10 @@ char *string;
        if (th < tl) {          /* crosses midnight */
                if (tl <= tn || tn < th)
                        return MGrade;
        if (th < tl) {          /* crosses midnight */
                if (tl <= tn || tn < th)
                        return MGrade;
-       } else
-
-       if (i < 2)
-               return MGrade;
-       if (th < tl) {  /* crosses midnight */
-               if (tl <= tn || tn < th)
-                       return MGrade;
-       } else
+       } else {
                if (tl <= tn && tn < th)
                        return MGrade;
                if (tl <= tn && tn < th)
                        return MGrade;
+       }
        return FAIL;
 }
 
        return FAIL;
 }
 
@@ -1078,3 +1118,49 @@ int fd;
                sleep(2);
        return(i);
 }
                sleep(2);
        return(i);
 }
+
+/*
+ *     fix kill/echo/raw on line
+ *
+ *     return codes:  none
+ */
+fixmode(tty)
+register int tty;
+{
+#ifdef USG
+       struct termio ttbuf;
+#else  !USG
+       struct sgttyb ttbuf;
+#endif !USG
+       register struct sg_spds *ps;
+       int speed;
+
+       if (IsTcpIp)
+               return;
+#ifdef USG
+       ioctl(tty, TCGETA, &ttbuf);
+       ttbuf.c_iflag = ttbuf.c_oflag = ttbuf.c_lflag = (ushort)0;
+       speed = ttbuf.c_cflag &= (CBAUD);
+       ttbuf.c_cflag |= (CS8|CREAD);
+       ttbuf.c_cc[VMIN] = 6;
+       ttbuf.c_cc[VTIME] = 1;
+       ioctl(tty, TCSETA, &ttbuf);
+#else  !USG
+       ioctl(tty, TIOCGETP, &ttbuf);
+       ttbuf.sg_flags = (ANYP | RAW);
+       ioctl(tty, TIOCSETP, &ttbuf);
+       speed = ttbuf.sg_ispeed;
+       ioctl(tty, TIOCEXCL, STBNULL);
+#endif !USG
+
+       for (ps = spds; ps->sp_val; ps++)
+               if (ps->sp_name == speed) {
+                       linebaudrate = ps->sp_val;
+                       DEBUG(9,"Incoming baudrate is %d\n", linebaudrate);
+                       return;
+               }
+       if (linebaudrate < 0) {
+               syslog(LOG_ERR, "unrecognized speed: %d", linebaudrate);
+               cleanup(FAIL);
+       }
+}