BSD 4_3_Net_2 release
[unix-history] / usr / src / usr.bin / tip / aculib / courier.c
index 585faab..c7bb4c1 100644 (file)
@@ -2,26 +2,39 @@
  * Copyright (c) 1986 The Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1986 The Regents of the University of California.
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that: (1) source distributions retain this entire copyright
- * notice and comment, and (2) distributions including binaries display
- * the following acknowledgement:  ``This product includes software
- * developed by the University of California, Berkeley and its contributors''
- * in the documentation or other materials provided with the distribution
- * and in all advertising materials mentioning features or use of this
- * software. Neither the name of the University nor the names of its
- * contributors may 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 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)courier.c  5.5 (Berkeley) 6/1/90";
+static char sccsid[] = "@(#)courier.c  5.7 (Berkeley) 3/2/91";
 #endif /* not lint */
 
 #endif /* not lint */
 
-#define write cour_write
 /*
  * Routines for calling up on a Courier modem.
  * Derived from Hayes driver.
 /*
  * Routines for calling up on a Courier modem.
  * Derived from Hayes driver.
@@ -35,7 +48,7 @@ static        void sigALRM();
 static int timeout = 0;
 static int connected = 0;
 static jmp_buf timeoutbuf, intbuf;
 static int timeout = 0;
 static int connected = 0;
 static jmp_buf timeoutbuf, intbuf;
-static int (*osigint)();
+static int coursync();
 
 cour_dialer(num, acu)
        register char *num;
 
 cour_dialer(num, acu)
        register char *num;
@@ -45,6 +58,8 @@ cour_dialer(num, acu)
 #ifdef ACULOG
        char line[80];
 #endif
 #ifdef ACULOG
        char line[80];
 #endif
+       static int cour_connect(), cour_swallow();
+
        if (boolean(value(VERBOSE)))
                printf("Using \"%s\"\n", acu);
 
        if (boolean(value(VERBOSE)))
                printf("Using \"%s\"\n", acu);
 
@@ -60,23 +75,23 @@ badsynch:
 #endif
                return (0);
        }
 #endif
                return (0);
        }
-       write(FD, "AT E0\r", 6);        /* turn off echoing */
+       cour_write(FD, "AT E0\r", 6);   /* turn off echoing */
        sleep(1);
 #ifdef DEBUG
        if (boolean(value(VERBOSE)))
                verbose_read();
 #endif
        ioctl(FD, TIOCFLUSH, 0);        /* flush any clutter */
        sleep(1);
 #ifdef DEBUG
        if (boolean(value(VERBOSE)))
                verbose_read();
 #endif
        ioctl(FD, TIOCFLUSH, 0);        /* flush any clutter */
-       write(FD, "AT C1 E0 H0 Q0 X6 V1\r", 21);
+       cour_write(FD, "AT C1 E0 H0 Q0 X6 V1\r", 21);
        if (!cour_swallow("\r\nOK\r\n"))
                goto badsynch;
        fflush(stdout);
        if (!cour_swallow("\r\nOK\r\n"))
                goto badsynch;
        fflush(stdout);
-       write(FD, "AT D", 4);
+       cour_write(FD, "AT D", 4);
        for (cp = num; *cp; cp++)
                if (*cp == '=')
                        *cp = ',';
        for (cp = num; *cp; cp++)
                if (*cp == '=')
                        *cp = ',';
-       write(FD, num, strlen(num));
-       write(FD, "\r", 1);
+       cour_write(FD, num, strlen(num));
+       cour_write(FD, "\r", 1);
        connected = cour_connect();
 #ifdef ACULOG
        if (timeout) {
        connected = cour_connect();
 #ifdef ACULOG
        if (timeout) {
@@ -102,7 +117,7 @@ cour_disconnect()
 
 cour_abort()
 {
 
 cour_abort()
 {
-       write(FD, "\r", 1);     /* send anything to abort the call */
+       cour_write(FD, "\r", 1);        /* send anything to abort the call */
        cour_disconnect();
 }
 
        cour_disconnect();
 }
 
@@ -247,7 +262,7 @@ coursync()
 
        while (already++ < MAXRETRY) {
                ioctl(FD, TIOCFLUSH, 0);        /* flush any clutter */
 
        while (already++ < MAXRETRY) {
                ioctl(FD, TIOCFLUSH, 0);        /* flush any clutter */
-               write(FD, "\rAT Z\r", 6);       /* reset modem */
+               cour_write(FD, "\rAT Z\r", 6);  /* reset modem */
                bzero(buf, sizeof(buf));
                sleep(1);
                ioctl(FD, FIONREAD, &len);
                bzero(buf, sizeof(buf));
                sleep(1);
                ioctl(FD, FIONREAD, &len);
@@ -266,7 +281,7 @@ coursync()
                 * try to get command mode.
                 */
                sleep(1);
                 * try to get command mode.
                 */
                sleep(1);
-               write(FD, "+++", 3);
+               cour_write(FD, "+++", 3);
                sleep(1);
                /*
                 * Toggle DTR to force anyone off that might have left
                sleep(1);
                /*
                 * Toggle DTR to force anyone off that might have left
@@ -276,12 +291,10 @@ coursync()
                sleep(1);
                ioctl(FD, TIOCSDTR, 0);
        }
                sleep(1);
                ioctl(FD, TIOCSDTR, 0);
        }
-       write(FD, "\rAT Z\r", 6);
+       cour_write(FD, "\rAT Z\r", 6);
        return (0);
 }
 
        return (0);
 }
 
-#undef write
-
 cour_write(fd, cp, n)
 int fd;
 char *cp;
 cour_write(fd, cp, n)
 int fd;
 char *cp;
@@ -322,8 +335,6 @@ verbose_read()
 /*
  * Code stolen from /usr/src/lib/libc/gen/sleep.c
  */
 /*
  * Code stolen from /usr/src/lib/libc/gen/sleep.c
  */
-#include <sys/time.h>
-
 #define mask(s) (1<<((s)-1))
 #define setvec(vec, a) \
         vec.sv_handler = a; vec.sv_mask = vec.sv_onstack = 0
 #define mask(s) (1<<((s)-1))
 #define setvec(vec, a) \
         vec.sv_handler = a; vec.sv_mask = vec.sv_onstack = 0