date and time created 81/05/09 16:45:06 by root
authorBill Joy <root@ucbvax.Berkeley.EDU>
Sun, 10 May 1981 07:45:06 +0000 (23:45 -0800)
committerBill Joy <root@ucbvax.Berkeley.EDU>
Sun, 10 May 1981 07:45:06 +0000 (23:45 -0800)
SCCS-vsn: usr.bin/tip/acu.c 4.1

usr/src/usr.bin/tip/acu.c [new file with mode: 0644]

diff --git a/usr/src/usr.bin/tip/acu.c b/usr/src/usr.bin/tip/acu.c
new file mode 100644 (file)
index 0000000..4be22b1
--- /dev/null
@@ -0,0 +1,147 @@
+/*     acu.c   4.1     81/05/09        */
+#include "tip.h"
+#include <setjmp.h>
+
+static acu_t *acu = NOACU;
+static int conflag;
+static int acuabort();
+static acu_t *acutype();
+static jmp_buf jmpbuf;
+/*
+ * Establish connection for tip
+ *
+ * If DU is true, we should dial an ACU whose type is AT.
+ * The phone numbers are in PN, and the call unit is in CU.
+ *
+ * If the PN is an '@', then we consult the PHONES file for
+ *   the phone numbers.  This file is /etc/phones, unless overriden
+ *   by an exported shell variable.
+ *
+ * The data base files must be in the format:
+ *     host-name[ \t]*phone-number
+ *   with the possibility of multiple phone numbers
+ *   for a single host acting as a rotary (in the order
+ *   found in the file).
+ */
+char *
+connect()
+{
+       register char *cp = PN;
+       char *phnum, string[256];
+       FILE *fd;
+       int tried = 0;
+
+       if (!DU) {              /* regular connect message */
+               if (CM != NOSTR)
+                       write(FD, cp, size(CM));
+               return(NOSTR);
+       }
+       /*
+        * @ =>'s use data base in PHONES environment variable
+        *        otherwise, use /etc/phones
+        */
+       signal(SIGINT, acuabort);
+       signal(SIGQUIT, acuabort);
+       if (setjmp(jmpbuf)) {
+               signal(SIGINT, SIG_IGN);
+               signal(SIGQUIT, SIG_IGN);
+               printf("\ncall aborted\n");
+               logent(value(HOST), "", "", "call aborted");
+               if (acu != NOACU) {
+                       boolean(value(VERBOSE)) = FALSE;
+                       if (conflag)
+                               disconnect();
+                       else
+                               (*acu->acu_abort)();
+               }
+               delock(uucplock);
+               exit(1);
+       }
+       if ((acu = acutype(AT)) == NOACU)
+               return("unknown ACU type");
+       if (*cp != '@') {
+               while (*cp) {
+                       for (phnum = cp; any(*cp, "0123456789-*="); cp++)
+                               ;
+                       *cp++ = '\0';
+                       
+                       if (conflag = (*acu->acu_dialer)(phnum, CU)) {
+                               logent(value(HOST), phnum, acu->acu_name,
+                                       "call completed");
+                               return(NOSTR);
+                       } else
+                               logent(value(HOST), phnum, acu->acu_name,
+                                       "no answer");
+                       tried++;
+               }
+       } else {
+               if ((fd = fopen(PH, "r")) == NOFILE) {
+                       printf("%s: ", PH);
+                       return("can't open phone number file");
+               }
+               while (fgets(string, sizeof(string), fd) != NOSTR) {
+                       for (cp = string; !any(*cp, " \t\n"); cp++)
+                               ;
+                       if (*cp == '\n') {
+                               fclose(fd);
+                               return("unrecognizable host name");
+                       }
+                       *cp++ = '\0';
+                       if (strcmp(string, value(HOST)))
+                               continue;
+                       while (any(*cp, " \t"))
+                               cp++;
+                       if (*cp == '\n') {
+                               fclose(fd);
+                               return("missing phone number");
+                       }
+                       for (phnum = cp; any(*cp, "0123456789-*="); cp++)
+                               ;
+                       *cp = '\0';
+                       
+                       if (conflag = (*acu->acu_dialer)(phnum)) {
+                               fclose(fd);
+                               logent(value(HOST), phnum, acu->acu_name,
+                                       "call completed");
+                               return(NOSTR);
+                       } else
+                               logent(value(HOST), phnum, acu->acu_name,
+                                       "no answer");
+                       tried++;
+               }
+               fclose(fd);
+       }
+       if (!tried)
+               logent(value(HOST), "", acu->acu_name, "missing phone number");
+       return(tried ? "no answer" : "missing phone number");
+}
+
+disconnect()
+{
+       if (!conflag)
+               return;
+       logent(value(HOST), "", acu->acu_name, "call terminated");
+       if (boolean(value(VERBOSE)))
+               printf("\r\ndisconnecting...");
+       (*acu->acu_disconnect)();
+}
+
+static int
+acuabort(s)
+{
+       signal(s, SIG_IGN);
+       longjmp(jmpbuf);
+}
+
+static acu_t *
+acutype(s)
+register char *s;
+{
+       register acu_t *p;
+       extern acu_t acutable[];
+
+       for (p = acutable; p->acu_name != '\0'; p++)
+               if (!strcmp(s, p->acu_name))
+                       return(p);
+       return(NOACU);
+}