xref: /csrg-svn/usr.bin/tip/aculib/df.c (revision 13138)
1 /*	df.c	4.6	83/06/15	*/
2 /*
3  * Dial the DF02-AC or DF03-AC
4  */
5 
6 #if defined(DF02) || defined(DF03)
7 #include "tip.h"
8 #include <setjmp.h>
9 
10 static char *sccsid = "@(#)df.c	4.6 06/15/83";
11 static jmp_buf	Sjbuf;
12 static timeout();
13 
14 #if DF02
15 df02_dialer(num, acu)
16 	char *num, *acu;
17 {
18 	return (df_dialer(num, acu, 0));
19 }
20 #endif
21 
22 #if DF03
23 df03_dialer(num, acu)
24 	char *num, *acu;
25 {
26 	return (df_dialer(num, acu, 1));
27 }
28 #endif
29 
30 df_dialer(num, acu, df03)
31 	char *num, *acu;
32 	int df03;
33 {
34 	register int f = FD;
35 	struct sgttyb buf;
36 	int speed = 0, c = 0;
37 #ifdef TIOCMSET
38 	int st = MST;		/* Secondary Transmit flag, for speed select */
39 #endif
40 
41 	ioctl(f, TIOCHPCL, 0);		/* make sure it hangs up when done */
42 	if (setjmp(Sjbuf)) {
43 		printf("connection timed out\r\n");
44 		df_disconnect();
45 		return (0);
46 	}
47 	if (boolean(value(VERBOSE)))
48 		printf("\ndialing...");
49 	fflush(stdout);
50 #ifdef TIOCMSET
51 	if (df03) {
52 		ioctl(f, TIOCGETP, &buf);
53 		if (buf.sg_ospeed != B1200) {	/* must dial at 1200 baud */
54 			speed = buf.sg_ospeed;
55 			buf.sg_ospeed = buf.sg_ispeed = B1200;
56 			ioctl(f, TIOCSETP, &buf);
57 			ioctl(f, TIOCMBIC, &st); /* clear ST for 300 baud */
58 		} else
59 			ioctl(f, TIOCMBIS, &st); /* set ST for 1200 baud */
60 	}
61 #endif
62 	signal(SIGALRM, timeout);
63 	alarm(5 * strlen(num) + 10);
64 	ioctl(f, TIOCFLUSH, 0);
65 	write(f, "\001", 1);
66 	sleep(1);
67 	write(f, "\002", 1);
68 	write(f, num, strlen(num));
69 	read(f, (char *)&c, 1);
70 #ifdef TIOCMSET
71 	if (df03 && speed) {
72 		buf.sg_ispeed = buf.sg_ospeed = speed;
73 		ioctl(f, TIOCSETP, &buf);
74 	}
75 #endif
76 	return (c == 'A');
77 }
78 
79 
80 df_disconnect()
81 {
82 	write(FD, "\001", 1);
83 	sleep(1);
84 	ioctl(FD, TIOCFLUSH, 0);
85 }
86 
87 
88 df_abort()
89 {
90 	write(FD, "\001", 1);
91 	sleep(1);
92 	ioctl(FD, TIOCFLUSH, 0);
93 }
94 
95 
96 static
97 timeout()
98 {
99 	longjmp(Sjbuf, 1);
100 }
101 #endif
102