lock alias file while rebuilding if flock system call available
[unix-history] / usr / src / usr.bin / tip / aculib / v3451.c
CommitLineData
05862919 1#ifndef lint
a9910fe5 2static char sccsid[] = "@(#)v3451.c 4.4 (Berkeley) %G%";
05862919 3#endif
5e071e26 4
5e071e26
RC
5/*
6 * Routines for calling up on a Vadic 3451 Modem
7 */
8#include "tip.h"
5e071e26 9
6f2a0ce9 10static jmp_buf Sjbuf;
5e071e26 11
05862919 12v3451_dialer(num, acu)
5e071e26
RC
13 register char *num;
14 char *acu;
15{
6f2a0ce9
SL
16 int ok, (*func)();
17 int slow = number(value(BAUDRATE)) < 1200, rw = 2;
5e071e26
RC
18 char phone[50];
19#ifdef ACULOG
20 char line[80];
21#endif
5e071e26 22
5e071e26
RC
23 /*
24 * Get in synch
25 */
6f2a0ce9
SL
26 vawrite("I\r", 1 + slow);
27 vawrite("I\r", 1 + slow);
28 vawrite("I\r", 1 + slow);
29 vawrite("\005\r", 2 + slow);
30 if (!expect("READY")) {
5e071e26
RC
31 printf("can't synchronize with vadic 3451\n");
32#ifdef ACULOG
33 logent(value(HOST), num, "vadic", "can't synch up");
34#endif
35 return (0);
36 }
37 ioctl(FD, TIOCHPCL, 0);
38 sleep(1);
6f2a0ce9
SL
39 vawrite("D\r", 2 + slow);
40 if (!expect("NUMBER?")) {
5e071e26
RC
41 printf("Vadic will not accept dial command\n");
42#ifdef ACULOG
43 logent(value(HOST), num, "vadic", "will not accept dial");
44#endif
45 return (0);
46 }
6f2a0ce9
SL
47 strcpy(phone, num);
48 strcat(phone, "\r");
49 vawrite(phone, 1 + slow);
50 if (!expect(phone)) {
5e071e26
RC
51 printf("Vadic will not accept phone number\n");
52#ifdef ACULOG
53 logent(value(HOST), num, "vadic", "will not accept number");
54#endif
55 return (0);
56 }
57 func = signal(SIGINT,SIG_IGN);
6f2a0ce9
SL
58 /*
59 * You cannot interrupt the Vadic when its dialing;
60 * even dropping DTR does not work (definitely a
61 * brain damaged design).
62 */
63 vawrite("\r", 1 + slow);
64 vawrite("\r", 1 + slow);
65 if (!expect("DIALING:")) {
5e071e26
RC
66 printf("Vadic failed to dial\n");
67#ifdef ACULOG
68 logent(value(HOST), num, "vadic", "failed to dial");
69#endif
70 return (0);
6f2a0ce9
SL
71 }
72 if (boolean(value(VERBOSE)))
73 printf("\ndialing...");
5e071e26 74 ok = expect("ON LINE");
6f2a0ce9
SL
75 signal(SIGINT, func);
76 if (!ok) {
5e071e26
RC
77 printf("call failed\n");
78#ifdef ACULOG
79 logent(value(HOST), num, "vadic", "call failed");
80#endif
81 return (0);
82 }
6f2a0ce9 83 ioctl(FD, TIOCFLUSH, &rw);
5e071e26
RC
84 return (1);
85}
86
05862919 87v3451_disconnect()
5e071e26 88{
6f2a0ce9 89
5e071e26 90 close(FD);
5e071e26
RC
91}
92
05862919 93v3451_abort()
5e071e26 94{
5e071e26 95
6f2a0ce9 96 close(FD);
5e071e26
RC
97}
98
6f2a0ce9
SL
99static
100vawrite(cp, delay)
101 register char *cp;
102 int delay;
103{
5e071e26 104
6f2a0ce9
SL
105 for (; *cp; sleep(delay), cp++)
106 write(FD, cp, 1);
107}
5e071e26 108
6f2a0ce9
SL
109static
110expect(cp)
111 register char *cp;
5e071e26 112{
6f2a0ce9
SL
113 char buf[300];
114 register char *rp = buf;
115 int alarmtr(), timeout = 30, online = 0;
116
117 if (strcmp(cp, "\"\"") == 0)
118 return (1);
5e071e26
RC
119 *rp = 0;
120 /*
121 * If we are waiting for the Vadic to complete
122 * dialing and get a connection, allow more time
123 * Unfortunately, the Vadic times out 24 seconds after
124 * the last digit is dialed
125 */
6f2a0ce9
SL
126 online = strcmp(cp, "ON LINE") == 0;
127 if (online)
128 timeout = number(value(DIALTIMEOUT));
5e071e26 129 signal(SIGALRM, alarmtr);
6f2a0ce9
SL
130 if (setjmp(Sjbuf))
131 return (0);
132 alarm(timeout);
133 while (notin(cp, buf) && rp < buf + sizeof (buf) - 1) {
134 if (online && notin("FAILED CALL", buf) == 0)
135 return (0);
136 if (read(FD, rp, 1) < 0) {
5e071e26 137 alarm(0);
6f2a0ce9 138 return (0);
5e071e26 139 }
6f2a0ce9 140 if (*rp &= 0177)
5e071e26
RC
141 rp++;
142 *rp = '\0';
5e071e26
RC
143 }
144 alarm(0);
6f2a0ce9 145 return (1);
5e071e26
RC
146}
147
6f2a0ce9 148static
5e071e26
RC
149alarmtr()
150{
6f2a0ce9 151
5e071e26
RC
152 longjmp(Sjbuf, 1);
153}
154
6f2a0ce9 155static
5e071e26 156notin(sh, lg)
6f2a0ce9 157 char *sh, *lg;
5e071e26 158{
6f2a0ce9
SL
159
160 for (; *lg; lg++)
5e071e26 161 if (prefix(sh, lg))
6f2a0ce9
SL
162 return (0);
163 return (1);
5e071e26
RC
164}
165
6f2a0ce9 166static
5e071e26 167prefix(s1, s2)
6f2a0ce9 168 register char *s1, *s2;
5e071e26 169{
6f2a0ce9 170 register char c;
5e071e26
RC
171
172 while ((c = *s1++) == *s2++)
173 if (c == '\0')
6f2a0ce9
SL
174 return (1);
175 return (c == '\0');
5e071e26 176}