put reasonable SCCS headers on
[unix-history] / usr / src / usr.bin / tip / aculib / df.c
CommitLineData
d0aeaf5a 1/*
be11e13c
KB
2 * Copyright (c) 1983 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are permitted
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
d0aeaf5a
DF
16 */
17
05862919 18#ifndef lint
be11e13c
KB
19static char sccsid[] = "@(#)df.c 5.2 (Berkeley) %G%";
20#endif /* not lint */
05862919 21
6476f6e0 22/*
1a99c50b 23 * Dial the DF02-AC or DF03-AC
6476f6e0
BJ
24 */
25
26#include "tip.h"
6476f6e0 27
05862919 28static jmp_buf Sjbuf;
6476f6e0
BJ
29static timeout();
30
1a99c50b 31df02_dialer(num, acu)
d8feebc2 32 char *num, *acu;
1a99c50b 33{
05862919 34
3f48242d 35 return (df_dialer(num, acu, 0));
1a99c50b 36}
1a99c50b 37
1a99c50b 38df03_dialer(num, acu)
d8feebc2 39 char *num, *acu;
1a99c50b 40{
05862919 41
3f48242d 42 return (df_dialer(num, acu, 1));
1a99c50b 43}
1a99c50b
SL
44
45df_dialer(num, acu, df03)
d8feebc2
SL
46 char *num, *acu;
47 int df03;
6476f6e0
BJ
48{
49 register int f = FD;
1a99c50b 50 struct sgttyb buf;
05862919
SL
51 int speed = 0, rw = 2;
52 char c = '\0';
6476f6e0
BJ
53
54 ioctl(f, TIOCHPCL, 0); /* make sure it hangs up when done */
55 if (setjmp(Sjbuf)) {
56 printf("connection timed out\r\n");
57 df_disconnect();
3f48242d 58 return (0);
6476f6e0
BJ
59 }
60 if (boolean(value(VERBOSE)))
61 printf("\ndialing...");
62 fflush(stdout);
1a99c50b
SL
63#ifdef TIOCMSET
64 if (df03) {
05862919
SL
65 int st = TIOCM_ST; /* secondary Transmit flag */
66
1a99c50b
SL
67 ioctl(f, TIOCGETP, &buf);
68 if (buf.sg_ospeed != B1200) { /* must dial at 1200 baud */
69 speed = buf.sg_ospeed;
70 buf.sg_ospeed = buf.sg_ispeed = B1200;
71 ioctl(f, TIOCSETP, &buf);
72 ioctl(f, TIOCMBIC, &st); /* clear ST for 300 baud */
73 } else
74 ioctl(f, TIOCMBIS, &st); /* set ST for 1200 baud */
75 }
76#endif
6476f6e0
BJ
77 signal(SIGALRM, timeout);
78 alarm(5 * strlen(num) + 10);
05862919 79 ioctl(f, TIOCFLUSH, &rw);
6476f6e0 80 write(f, "\001", 1);
1a99c50b 81 sleep(1);
6476f6e0
BJ
82 write(f, "\002", 1);
83 write(f, num, strlen(num));
05862919 84 read(f, &c, 1);
1a99c50b
SL
85#ifdef TIOCMSET
86 if (df03 && speed) {
87 buf.sg_ispeed = buf.sg_ospeed = speed;
88 ioctl(f, TIOCSETP, &buf);
89 }
90#endif
3f48242d 91 return (c == 'A');
6476f6e0
BJ
92}
93
6476f6e0
BJ
94df_disconnect()
95{
05862919
SL
96 int rw = 2;
97
6476f6e0
BJ
98 write(FD, "\001", 1);
99 sleep(1);
05862919 100 ioctl(FD, TIOCFLUSH, &rw);
6476f6e0
BJ
101}
102
103
104df_abort()
105{
05862919
SL
106
107 df_disconnect();
6476f6e0
BJ
108}
109
110
111static
112timeout()
113{
05862919 114
6476f6e0
BJ
115 longjmp(Sjbuf, 1);
116}