No empty .Rs/.Re
[netbsd-mini2440.git] / usr.bin / tip / aculib / df.c
blob5b2cc257cb92467641f32241f0d7ea90e3a863dd
1 /* $NetBSD: df.c,v 1.8 2006/04/03 00:51:14 perry Exp $ */
3 /*
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 #ifndef lint
34 #if 0
35 static char sccsid[] = "@(#)df.c 8.1 (Berkeley) 6/6/93";
36 #endif
37 __RCSID("$NetBSD: df.c,v 1.8 2006/04/03 00:51:14 perry Exp $");
38 #endif /* not lint */
41 * Dial the DF02-AC or DF03-AC
44 #include "tip.h"
46 static jmp_buf Sjbuf;
48 static int df_dialer(char *, char *, int);
49 static void timeout(int);
51 int
52 df02_dialer(char *num, char *acu)
55 return (df_dialer(num, acu, 0));
58 int
59 df03_dialer(char *num, char *acu)
62 return (df_dialer(num, acu, 1));
65 static int
66 /*ARGSUSED*/
67 df_dialer(char *num, char *acu __unused, int df03)
69 int f = FD;
70 struct termios cntrl;
71 speed_t volatile spd;
72 char c;
74 spd = 0;
75 c = '\0';
76 (void)tcgetattr(f, &cntrl);
77 cntrl.c_cflag |= HUPCL;
78 (void)tcsetattr(f, TCSANOW, &cntrl);
79 if (setjmp(Sjbuf)) {
80 (void)printf("connection timed out\r\n");
81 df_disconnect();
82 return (0);
84 if (boolean(value(VERBOSE)))
85 (void)printf("\ndialing...");
86 (void)fflush(stdout);
87 #ifdef TIOCMSET
88 if (df03) {
89 int st = TIOCM_ST; /* secondary Transmit flag */
91 (void)tcgetattr(f, &cntrl);
92 spd = cfgetospeed(&cntrl);
93 if (spd != B1200) { /* must dial at 1200 baud */
94 (void)cfsetospeed(&cntrl, B1200);
95 (void)cfsetispeed(&cntrl, B1200);
96 (void)tcsetattr(f, TCSAFLUSH, &cntrl);
97 (void)ioctl(f, TIOCMBIC, &st); /* clear ST for 300 baud */
98 } else
99 (void)ioctl(f, TIOCMBIS, &st); /* set ST for 1200 baud */
101 #endif
102 (void)signal(SIGALRM, timeout);
103 (void)alarm(5 * strlen(num) + 10);
104 (void)tcflush(f, TCIOFLUSH);
105 (void)write(f, "\001", 1);
106 (void)sleep(1);
107 (void)write(f, "\002", 1);
108 (void)write(f, num, strlen(num));
109 (void)read(f, &c, 1);
110 #ifdef TIOCMSET
111 if (df03 && spd != B1200) {
112 (void)cfsetospeed(&cntrl, spd);
113 (void)cfsetispeed(&cntrl, spd);
114 (void)tcsetattr(f, TCSAFLUSH, &cntrl);
116 #endif
117 return (c == 'A');
120 void
121 df_disconnect(void)
124 (void)write(FD, "\001", 1);
125 (void)sleep(1);
126 (void)tcflush(FD, TCIOFLUSH);
130 void
131 df_abort(void)
134 df_disconnect();
138 static void
139 /*ARGSUSED*/
140 timeout(int dummy __unused)
143 longjmp(Sjbuf, 1);