BSD 4_4 release
[unix-history] / usr / src / usr.bin / tip / aculib / biz31.c
index d573cf6..412974d 100644 (file)
@@ -1,12 +1,48 @@
-/*     biz31.c 4.3     81/11/20        */
+/*
+ * Copyright (c) 1983, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * 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
+static char sccsid[] = "@(#)biz31.c    8.1 (Berkeley) 6/6/93";
+#endif /* not lint */
+
 #include "tip.h"
 
 #include "tip.h"
 
-#if BIZ1031
 #define MAXRETRY       3               /* sync up retry count */
 #define MAXRETRY       3               /* sync up retry count */
-#define DISCONNECT     "\21\25\11\24"  /* disconnection string */
+#define DISCONNECT_CMD "\21\25\11\24"  /* disconnection string */
 
 
-static int sigALRM();
-static int timeout = 0;
+static void sigALRM();
+static int timeout = 0;
+static jmp_buf timeoutbuf;
 
 /*
  * Dial up on a BIZCOMP Model 1031 with either
 
 /*
  * Dial up on a BIZCOMP Model 1031 with either
@@ -32,7 +68,7 @@ biz_dialer(num, mod)
        echo(mod);
        echo("$\r$\n");
        echo("$>$.$ #\re$ ");                   /* disconnection sequence */
        echo(mod);
        echo("$\r$\n");
        echo("$>$.$ #\re$ ");                   /* disconnection sequence */
-       echo(DISCONNECT);
+       echo(DISCONNECT_CMD);
        echo("\r$\n$\r$\n");
        echo("$>$.$ #\rr$ ");                   /* repeat dial */
        echo(num);
        echo("\r$\n$\r$\n");
        echo("$>$.$ #\rr$ ");                   /* repeat dial */
        echo(num);
@@ -60,32 +96,35 @@ biz_dialer(num, mod)
                flush("CONNECTION\r\n\07");
        if (timeout)
                biz31_disconnect();     /* insurance */
                flush("CONNECTION\r\n\07");
        if (timeout)
                biz31_disconnect();     /* insurance */
-       return(connected);
+       return (connected);
 }
 
 biz31w_dialer(num, acu)
        char *num, *acu;
 {
 }
 
 biz31w_dialer(num, acu)
        char *num, *acu;
 {
-       return(biz_dialer(num, "w"));
+
+       return (biz_dialer(num, "w"));
 }
 
 biz31f_dialer(num, acu)
        char *num, *acu;
 {
 }
 
 biz31f_dialer(num, acu)
        char *num, *acu;
 {
-       return(biz_dialer(num, "f"));
+
+       return (biz_dialer(num, "f"));
 }
 
 biz31_disconnect()
 {
 }
 
 biz31_disconnect()
 {
-       write(FD, DISCONNECT, 4);
+
+       write(FD, DISCONNECT_CMD, 4);
        sleep(2);
        ioctl(FD, TIOCFLUSH);
 }
 
 biz31_abort()
 {
        sleep(2);
        ioctl(FD, TIOCFLUSH);
 }
 
 biz31_abort()
 {
+
        write(FD, "\33", 1);
        write(FD, "\33", 1);
-       timeout = 1;
 }
 
 static int
 }
 
 static int
@@ -94,72 +133,74 @@ echo(s)
 {
        char c;
 
 {
        char c;
 
-       while (c = *s++)
-               switch(c)
-               {
-                       case '$':
-                               read(FD, &c, 1);
-                               s++;
-                               break;
-                       case '#':
-                               c = *s++;
-                               write(FD, &c, 1);
-                               break;
-                       default:
-                               write(FD, &c, 1);
-                               read(FD, &c, 1);
-               }
+       while (c = *s++) switch (c) {
+
+       case '$':
+               read(FD, &c, 1);
+               s++;
+               break;
+
+       case '#':
+               c = *s++;
+               write(FD, &c, 1);
+               break;
+
+       default:
+               write(FD, &c, 1);
+               read(FD, &c, 1);
+       }
 }
 
 }
 
-static int
+static void
 sigALRM()
 {
 sigALRM()
 {
-       signal(SIGALRM, SIG_IGN);
-       printf("\07timeout waiting for reply\n");
+
        timeout = 1;
        timeout = 1;
+       longjmp(timeoutbuf, 1);
 }
 
 static int
 detect(s)
        register char *s;
 {
 }
 
 static int
 detect(s)
        register char *s;
 {
+       sig_t f;
        char c;
 
        char c;
 
-       signal(SIGALRM, biz31_abort);
+       f = signal(SIGALRM, sigALRM);
        timeout = 0;
        timeout = 0;
-       while (*s)
-       {
+       while (*s) {
+               if (setjmp(timeoutbuf)) {
+                       printf("\07timeout waiting for reply\n");
+                       biz31_abort();
+                       break;
+               }
                alarm(number(value(DIALTIMEOUT)));
                read(FD, &c, 1);
                alarm(0);
                alarm(number(value(DIALTIMEOUT)));
                read(FD, &c, 1);
                alarm(0);
-               if (timeout)
-                       return(0);
                if (c != *s++)
                if (c != *s++)
-                       return(0);
+                       break;
        }
        }
-       signal(SIGALRM, SIG_DFL);
-       return(1);
+       signal(SIGALRM, f);
+       return (timeout == 0);
 }
 
 static int
 flush(s)
        register char *s;
 {
 }
 
 static int
 flush(s)
        register char *s;
 {
+       sig_t f;
        char c;
 
        char c;
 
-       signal(SIGALRM, sigALRM);
-       timeout = 0;
-       while (*s++)
-       {
+       f = signal(SIGALRM, sigALRM);
+       while (*s++) {
+               if (setjmp(timeoutbuf))
+                       break;
                alarm(10);
                read(FD, &c, 1);
                alarm(0);
                alarm(10);
                read(FD, &c, 1);
                alarm(0);
-               if (timeout)
-                       break;
        }
        }
-       signal(SIGALRM, SIG_DFL);
+       signal(SIGALRM, f);
        timeout = 0;                    /* guard against disconnection */
        timeout = 0;                    /* guard against disconnection */
-       return(1);
 }
 
 /*
 }
 
 /*
@@ -192,8 +233,8 @@ retry:
                if (chars(b) != 10) {
        nono:
                        if (already > MAXRETRY)
                if (chars(b) != 10) {
        nono:
                        if (already > MAXRETRY)
-                               return(0);
-                       write(fd, DISCONNECT, 4);
+                               return (0);
+                       write(fd, DISCONNECT_CMD, 4);
                        sleep(2);
                        already++;
                        goto retry;
                        sleep(2);
                        already++;
                        goto retry;
@@ -203,6 +244,5 @@ retry:
                                goto nono;
                }
        }
                                goto nono;
                }
        }
-       return(1);
+       return (1);
 }
 }
-#endif