dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / tip / aculib / biz22.c
blob2141b0e90652b01d93b7bc7b936bc95f713283fe
1 /*
2 * Copyright 2000 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 */
6 /*
7 * Copyright (c) 1983 Regents of the University of California.
8 * All rights reserved. The Berkeley software License Agreement
9 * specifies the terms and conditions for redistribution.
12 #pragma ident "%Z%%M% %I% %E% SMI"
14 #include "tip.h"
16 #define DISCONNECT_CMD "\20\04" /* disconnection string */
18 static void sigALRM(void);
19 static int cmd(char *);
20 static int detect(char *);
22 static int timeout = 0;
23 static sigjmp_buf timeoutbuf;
25 void biz22_disconnect(void);
28 * Dial up on a BIZCOMP Model 1022 with either
29 * tone dialing (mod = "V")
30 * pulse dialing (mod = "W")
32 static int
33 biz_dialer(char *num, char *mod)
35 int connected = 0;
36 char cbuf[40];
38 if (boolean(value(VERBOSE)))
39 (void) printf("\nstarting call...");
41 * Disable auto-answer and configure for tone/pulse
42 * dialing
44 if (cmd("\02K\r")) {
45 (void) printf("can't initialize bizcomp...");
46 return (0);
48 (void) strcpy(cbuf, "\02.\r");
49 cbuf[1] = *mod;
50 if (cmd(cbuf)) {
51 (void) printf("can't set dialing mode...");
52 return (0);
54 (void) strcpy(cbuf, "\02D");
55 (void) strlcat(cbuf, num, sizeof (cbuf));
56 (void) strlcat(cbuf, "\r", sizeof (cbuf));
57 (void) write(FD, cbuf, strlen(cbuf));
58 if (!detect("7\r")) {
59 (void) printf("can't get dial tone...");
60 return (0);
62 if (boolean(value(VERBOSE)))
63 (void) printf("ringing...");
65 * The reply from the BIZCOMP should be:
66 * 2 \r or 7 \r failure
67 * 1 \r success
69 connected = detect("1\r");
70 #ifdef ACULOG
71 if (timeout) {
72 char line[80];
74 (void) sprintf(line, "%d second dial timeout",
75 number(value(DIALTIMEOUT)));
76 logent(value(HOST), num, "biz1022", line);
78 #endif
79 if (timeout)
80 biz22_disconnect(); /* insurance */
81 return (connected);
84 /* ARGSUSED */
85 int
86 biz22w_dialer(char *num, char *acu)
89 return (biz_dialer(num, "W"));
92 /* ARGSUSED */
93 int
94 biz22f_dialer(char *num, char *acu)
97 return (biz_dialer(num, "V"));
100 void
101 biz22_disconnect(void)
104 (void) write(FD, DISCONNECT_CMD, 4);
105 (void) sleep(2);
106 (void) ioctl(FD, TCFLSH, TCOFLUSH);
109 void
110 biz22_abort(void)
113 (void) write(FD, "\02", 1);
116 static void
117 sigALRM(void)
120 timeout = 1;
121 siglongjmp(timeoutbuf, 1);
124 static int
125 cmd(char *s)
127 char c;
128 sig_handler_t f;
130 (void) write(FD, s, strlen(s));
131 f = signal(SIGALRM, (sig_handler_t)sigALRM);
132 if (sigsetjmp(timeoutbuf, 1)) {
133 biz22_abort();
134 (void) signal(SIGALRM, f);
135 return (1);
137 (void) alarm(number(value(DIALTIMEOUT)));
138 (void) read(FD, &c, 1);
139 (void) alarm(0);
140 (void) signal(SIGALRM, f);
141 c &= 0177;
142 return (c != '\r');
145 static int
146 detect(char *s)
148 char c;
149 sig_handler_t f;
151 f = signal(SIGALRM, (sig_handler_t)sigALRM);
152 timeout = 0;
153 while (*s) {
154 if (sigsetjmp(timeoutbuf, 1)) {
155 biz22_abort();
156 break;
158 (void) alarm(number(value(DIALTIMEOUT)));
159 (void) read(FD, &c, 1);
160 (void) alarm(0);
161 c &= 0177;
162 if (c != *s++)
163 return (0);
165 (void) signal(SIGALRM, f);
166 return (timeout == 0);