+ if (islower(*s1))
+ c1 = toupper(*s1);
+ else
+ c1 = *s1;
+ if (islower(*s2))
+ c2 = toupper(*s2);
+ else
+ c2 = *s2;
+ }
+ return c1 - c2;
+}
+
+/*
+ * Compare strings: s1>s2: >0 s1==s2: 0 s1<s2: <0
+ * Strings are compared as if they contain all capital letters.
+ */
+sncncmp(s1, s2, n)
+register char *s1, *s2;
+register int n;
+{
+ char c1, c2;
+
+ if (islower(*s1))
+ c1 = toupper(*s1);
+ else
+ c1 = *s1;
+ if (islower(*s2))
+ c2 = toupper(*s2);
+ else
+ c2 = *s2;
+
+ while ( --n >= 0 && c1 == c2) {
+ if (*s1++ == '\0')
+ return 0;
+ s2++;
+ if (islower(*s1))
+ c1 = toupper(*s1);
+ else
+ c1 = *s1;
+ if (islower(*s2))
+ c2 = toupper(*s2);
+ else
+ c2 = *s2;
+ }
+ return n<0 ? 0 : (c1 - c2);
+}
+/*
+ * do chat script
+ * occurs after local port is opened,
+ * before 'dialing' the other machine.
+ */
+dochat(dev, flds, fd)
+register struct Devices *dev;
+char *flds[];
+int fd;
+{
+ register int i;
+ register char *p;
+ char bfr[sizeof(dev->D_argbfr)];
+
+ if (dev->D_numargs <= 5)
+ return(0);
+ DEBUG(4, "dochat called %d\n", dev->D_numargs);
+ for (i = 0; i < dev->D_numargs-5; i++) {
+ sprintf(bfr, dev->D_arg[D_CHAT+i], flds[F_PHONE]);
+ if (strcmp(bfr, dev->D_arg[D_CHAT+i])) {
+ p = malloc((unsigned)strlen(bfr)+1);
+ if (p != NULL) {
+ strcpy(p, bfr);
+ dev->D_arg[D_CHAT+i] = p;
+ }
+ }
+ }
+ /* following is a kludge because login() arglist is a kludge */
+ i = login(dev->D_numargs, &dev->D_arg[D_CHAT-5], fd);
+ /*
+ * If login() last did a sendthem(), must pause so things can settle.
+ * But don't bother if chat failed.
+ */
+ if (i == 0 && (dev->D_numargs&01))
+ 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);