date and time created 88/12/14 16:21:45 by marc
[unix-history] / usr / src / usr.bin / tip / aculib / ventel.c
index 859795e..8d36d3b 100644 (file)
@@ -1,11 +1,27 @@
+/*
+ * Copyright (c) 1983 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)ventel.c   1.4 (Berkeley) %G%";
-#endif
+static char sccsid[] = "@(#)ventel.c   5.2 (Berkeley) %G%";
+#endif /* not lint */
 
 
-#if VENTEL
 /*
  * Routines for calling up on a Ventel Modem
 /*
  * Routines for calling up on a Ventel Modem
- * The Ventel is expected to be strapped for "no echo".
+ * The Ventel is expected to be strapped for local echo (just like uucp)
  */
 #include "tip.h"
 
  */
 #include "tip.h"
 
@@ -15,15 +31,24 @@ static      int sigALRM();
 static int timeout = 0;
 static jmp_buf timeoutbuf;
 
 static int timeout = 0;
 static jmp_buf timeoutbuf;
 
+/*
+ * some sleep calls have been replaced by this macro
+ * because some ventel modems require two <cr>s in less than
+ * a second in order to 'wake up'... yes, it is dirty...
+ */
+#define delay(num,denom) busyloop(CPUSPEED*num/denom)
+#define CPUSPEED 1000000       /* VAX 780 is 1MIPS */
+#define        DELAY(n)        { register long N = (n); while (--N > 0); }
+busyloop(n) { DELAY(n); }
+
 ven_dialer(num, acu)
        register char *num;
        char *acu;
 {
        register char *cp;
        register int connected = 0;
 ven_dialer(num, acu)
        register char *num;
        char *acu;
 {
        register char *cp;
        register int connected = 0;
-#ifdef ACULOG
-       char line[80];
-#endif
+       char *msg, *index(), line[80];
+
        /*
         * Get in synch with a couple of carriage returns
         */
        /*
         * Get in synch with a couple of carriage returns
         */
@@ -40,12 +65,14 @@ ven_dialer(num, acu)
        ioctl(FD, TIOCHPCL, 0);
        echo("#k$\r$\n$D$I$A$L$:$ ");
        for (cp = num; *cp; cp++) {
        ioctl(FD, TIOCHPCL, 0);
        echo("#k$\r$\n$D$I$A$L$:$ ");
        for (cp = num; *cp; cp++) {
-               sleep(1);
+               delay(1, 10);
                write(FD, cp, 1);
        }
                write(FD, cp, 1);
        }
-       echo("\r$\n");
-       if (gobble('\n'))
-               connected = gobble('!');
+       delay(1, 10);
+       write(FD, "\r", 1);
+       gobble('\n', line);
+       if (gobble('\n', line))
+               connected = gobble('!', line);
        ioctl(FD, TIOCFLUSH);
 #ifdef ACULOG
        if (timeout) {
        ioctl(FD, TIOCFLUSH);
 #ifdef ACULOG
        if (timeout) {
@@ -56,6 +83,26 @@ ven_dialer(num, acu)
 #endif
        if (timeout)
                ven_disconnect();       /* insurance */
 #endif
        if (timeout)
                ven_disconnect();       /* insurance */
+       if (connected || timeout || !boolean(value(VERBOSE)))
+               return (connected);
+       /* call failed, parse response for user */
+       cp = index(line, '\r');
+       if (cp)
+               *cp = '\0';
+       for (cp = line; cp = index(cp, ' '); cp++)
+               if (cp[1] == ' ')
+                       break;
+       if (cp) {
+               while (*cp == ' ')
+                       cp++;
+               msg = cp;
+               while (*cp) {
+                       if (isupper(*cp))
+                               *cp = tolower(*cp);
+                       cp++;
+               }
+               printf("%s...", msg);
+       }
        return (connected);
 }
 
        return (connected);
 }
 
@@ -106,9 +153,11 @@ sigALRM()
 }
 
 static int
 }
 
 static int
-gobble(match)
+gobble(match, response)
        register char match;
        register char match;
+       char response[];
 {
 {
+       register char *cp = response;
        char c;
        int (*f)();
 
        char c;
        int (*f)();
 
@@ -117,18 +166,20 @@ gobble(match)
        do {
                if (setjmp(timeoutbuf)) {
                        signal(SIGALRM, f);
        do {
                if (setjmp(timeoutbuf)) {
                        signal(SIGALRM, f);
+                       *cp = '\0';
                        return (0);
                }
                alarm(number(value(DIALTIMEOUT)));
                        return (0);
                }
                alarm(number(value(DIALTIMEOUT)));
-               read(FD, &c, 1);
+               read(FD, cp, 1);
                alarm(0);
                alarm(0);
-               c &= 0177;
+               c = (*cp++ &= 0177);
 #ifdef notdef
                if (boolean(value(VERBOSE)))
                        putchar(c);
 #endif
        } while (c != '\n' && c != match);
        signal(SIGALRM, SIG_DFL);
 #ifdef notdef
                if (boolean(value(VERBOSE)))
                        putchar(c);
 #endif
        } while (c != '\n' && c != match);
        signal(SIGALRM, SIG_DFL);
+       *cp = '\0';
        return (c == match);
 }
 
        return (c == match);
 }
 
@@ -153,7 +204,7 @@ vensync(fd)
         * with DTR, you can always try setting the baud rate to 0.
         */
        ioctl(FD, TIOCCDTR, 0);
         * with DTR, you can always try setting the baud rate to 0.
         */
        ioctl(FD, TIOCCDTR, 0);
-       sleep(2);
+       sleep(1);
        ioctl(FD, TIOCSDTR, 0);
        while (already < MAXRETRY) {
                /*
        ioctl(FD, TIOCSDTR, 0);
        while (already < MAXRETRY) {
                /*
@@ -162,9 +213,9 @@ vensync(fd)
                 * so the modem can frame the incoming characters.
                 */
                write(fd, "\r", 1);
                 * so the modem can frame the incoming characters.
                 */
                write(fd, "\r", 1);
-               sleep(1);
+               delay(1,10);
                write(fd, "\r", 1);
                write(fd, "\r", 1);
-               sleep(3);
+               sleep(2);
                if (ioctl(fd, FIONREAD, (caddr_t)&nread) < 0) {
                        perror("tip: ioctl");
                        continue;
                if (ioctl(fd, FIONREAD, (caddr_t)&nread) < 0) {
                        perror("tip: ioctl");
                        continue;
@@ -180,4 +231,4 @@ vensync(fd)
        }
        return (0);
 }
        }
        return (0);
 }
-#endif
+