Sync usage with man page.
[netbsd-mini2440.git] / usr.bin / tip / aculib / biz22.c
blob6f6cd0cd34b4d7462c09b791554ae2947b9baec3
1 /* $NetBSD: biz22.c,v 1.11 2006/04/03 02:25:27 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[] = "@(#)biz22.c 8.1 (Berkeley) 6/6/93";
36 #endif
37 __RCSID("$NetBSD: biz22.c,v 1.11 2006/04/03 02:25:27 perry Exp $");
38 #endif /* not lint */
40 #include "tip.h"
42 #define DISCONNECT_CMD "\20\04" /* disconnection string */
44 static int btimeout = 0;
45 static jmp_buf timeoutbuf;
47 static int biz_dialer(char *, const char *);
48 static int cmd(const char *);
49 static int detect(const char *);
50 static void sigALRM(int);
53 * Dial up on a BIZCOMP Model 1022 with either
54 * tone dialing (mod = "V")
55 * pulse dialing (mod = "W")
57 static int
58 biz_dialer(char *num, const char *mod)
60 int connected = 0;
61 char cbuf[40];
63 if (boolean(value(VERBOSE)))
64 (void)printf("\nstarting call...");
66 * Disable auto-answer and configure for tone/pulse
67 * dialing
69 if (cmd("\02K\r")) {
70 (void)printf("can't initialize bizcomp...");
71 return (0);
73 (void)strncpy(cbuf, "\02.\r", sizeof(cbuf) - 1);
74 cbuf[1] = *mod;
75 if (cmd(cbuf)) {
76 (void)printf("can't set dialing mode...");
77 return (0);
79 (void)snprintf(cbuf, sizeof cbuf, "\02D%s\r", num);
80 (void)write(FD, cbuf, strlen(cbuf));
81 if (!detect("7\r")) {
82 (void)printf("can't get dial tone...");
83 return (0);
85 if (boolean(value(VERBOSE)))
86 (void)printf("ringing...");
88 * The reply from the BIZCOMP should be:
89 * 2 \r or 7 \r failure
90 * 1 \r success
92 connected = detect("1\r");
93 if (btimeout)
94 biz22_disconnect(); /* insurance */
95 return (connected);
98 int
99 /*ARGSUSED*/
100 biz22w_dialer(char *num, char *acu __unused)
103 return (biz_dialer(num, "W"));
107 /*ARGSUSED*/
108 biz22f_dialer(char *num, char *acu __unused)
111 return (biz_dialer(num, "V"));
114 void
115 biz22_disconnect(void)
118 (void)write(FD, DISCONNECT_CMD, 4);
119 (void)sleep(2);
120 (void)tcflush(FD, TCIOFLUSH);
123 void
124 biz22_abort(void)
127 (void)write(FD, "\02", 1);
130 static void
131 /*ARGSUSED*/
132 sigALRM(int dummy __unused)
135 btimeout = 1;
136 longjmp(timeoutbuf, 1);
139 static int
140 cmd(const char *s)
142 sig_t f;
143 char c;
145 (void)write(FD, s, strlen(s));
146 f = signal(SIGALRM, sigALRM);
147 if (setjmp(timeoutbuf)) {
148 biz22_abort();
149 (void)signal(SIGALRM, f);
150 return (1);
152 (void)alarm((unsigned)number(value(DIALTIMEOUT)));
153 (void)read(FD, &c, 1);
154 (void)alarm(0);
155 (void)signal(SIGALRM, f);
156 c &= 0177;
157 return (c != '\r');
160 static int
161 detect(const char * volatile s)
163 sig_t f;
164 char c;
166 f = signal(SIGALRM, sigALRM);
167 btimeout = 0;
168 while (*s) {
169 if (setjmp(timeoutbuf)) {
170 biz22_abort();
171 break;
173 (void)alarm((unsigned)number(value(DIALTIMEOUT)));
174 (void)read(FD, &c, 1);
175 (void)alarm(0);
176 c &= 0177;
177 if (c != *s++)
178 return (0);
180 (void)signal(SIGALRM, f);
181 return (btimeout == 0);