Thu Apr 23 00:35:14 2020 UTC ()
Avoid using common symbol definitions.


(joerg)
diff -r1.62 -r1.63 src/usr.bin/tip/tip.c
diff -r1.33 -r1.34 src/usr.bin/tip/tip.h

cvs diff -r1.62 -r1.63 src/usr.bin/tip/tip.c (switch to unified diff)

--- src/usr.bin/tip/tip.c 2019/02/28 17:41:27 1.62
+++ src/usr.bin/tip/tip.c 2020/04/23 00:35:14 1.63
@@ -1,582 +1,646 @@ @@ -1,582 +1,646 @@
1/* $NetBSD: tip.c,v 1.62 2019/02/28 17:41:27 gson Exp $ */ 1/* $NetBSD: tip.c,v 1.63 2020/04/23 00:35:14 joerg Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1983, 1993 4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors 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 16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission. 17 * without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 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 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 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 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 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 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#include <ctype.h> 33#include <ctype.h>
34#include <libgen.h> 34#include <libgen.h>
35 35
36#ifndef lint 36#ifndef lint
37__COPYRIGHT("@(#) Copyright (c) 1983, 1993\ 37__COPYRIGHT("@(#) Copyright (c) 1983, 1993\
38 The Regents of the University of California. All rights reserved."); 38 The Regents of the University of California. All rights reserved.");
39#endif /* not lint */ 39#endif /* not lint */
40 40
41#ifndef lint 41#ifndef lint
42#if 0 42#if 0
43static char sccsid[] = "@(#)tip.c 8.1 (Berkeley) 6/6/93"; 43static char sccsid[] = "@(#)tip.c 8.1 (Berkeley) 6/6/93";
44#endif 44#endif
45__RCSID("$NetBSD: tip.c,v 1.62 2019/02/28 17:41:27 gson Exp $"); 45__RCSID("$NetBSD: tip.c,v 1.63 2020/04/23 00:35:14 joerg Exp $");
46#endif /* not lint */ 46#endif /* not lint */
47 47
48/* 48/*
49 * tip - UNIX link to other systems 49 * tip - UNIX link to other systems
50 * tip [-v] [-speed] system-name 50 * tip [-v] [-speed] system-name
51 * or 51 * or
52 * cu [options] [phone-number|"dir"] 52 * cu [options] [phone-number|"dir"]
53 */ 53 */
54#include "tip.h" 54#include "tip.h"
55#include "pathnames.h" 55#include "pathnames.h"
56 56
 57struct termios term;
 58struct termios defterm;
 59struct termios defchars;
 60
 61FILE *fscript;
 62
 63int attndes[2];
 64int fildes[2];
 65int repdes[2];
 66int FD;
 67#ifndef __lint__ /* not used by hayes.c, but used by some other dialers */
 68int AC;
 69#endif /*__lint__*/
 70int sfd;
 71int pid;
 72uid_t uid, euid;
 73gid_t gid, egid;
 74int stop;
 75int quit;
 76int stoprompt;
 77int timedout;
 78int cumode;
 79int bits8;
 80#define STRIP_PAR (bits8 ? 0377 : 0177)
 81
 82char fname[80];
 83char copyname[80];
 84char ccc;
 85
 86int odisc;
 87int vflag;
 88
 89char *DV;
 90char *EL;
 91char *CM;
 92char *IE;
 93char *OE;
 94char *CU;
 95char *AT;
 96char *PN;
 97char *DI;
 98char *PA;
 99
 100char *PH;
 101char *RM;
 102char *HO;
 103
 104long BR;
 105long FS;
 106
 107long DU;
 108long HW;
 109char *ES;
 110char *EX;
 111char *FO;
 112char *RC;
 113char *RE;
 114char *PR;
 115long DL;
 116long CL;
 117long ET;
 118long HD;
 119char DC;
 120
57__dead static void tipusage(void); 121__dead static void tipusage(void);
58 122
59int escape(void); 123int escape(void);
60__dead static void intprompt(int); 124__dead static void intprompt(int);
61__dead static void tipin(void); 125__dead static void tipin(void);
62 126
63char PNbuf[256]; /* This limits the size of a number */ 127char PNbuf[256]; /* This limits the size of a number */
64 128
65static char path_phones[] = _PATH_PHONES; 129static char path_phones[] = _PATH_PHONES;
66 130
67int 131int
68main(int argc, char *argv[]) 132main(int argc, char *argv[])
69{ 133{
70 char *System = NULL; 134 char *System = NULL;
71 int c, i; 135 int c, i;
72 char *p; 136 char *p;
73 const char *q; 137 const char *q;
74 char sbuf[12]; 138 char sbuf[12];
75 int cmdlineBR; 139 int cmdlineBR;
76 int fcarg; 140 int fcarg;
77 141
78 setprogname(argv[0]); 142 setprogname(argv[0]);
79 gid = getgid(); 143 gid = getgid();
80 egid = getegid(); 144 egid = getegid();
81 uid = getuid(); 145 uid = getuid();
82 euid = geteuid(); 146 euid = geteuid();
83 if (strcmp(getprogname(), "cu") == 0) { 147 if (strcmp(getprogname(), "cu") == 0) {
84 cumode = 1; 148 cumode = 1;
85 cumain(argc, argv); 149 cumain(argc, argv);
86 goto cucommon; 150 goto cucommon;
87 } 151 }
88 152
89 if (argc > 4) 153 if (argc > 4)
90 tipusage(); 154 tipusage();
91 155
92 if (!isatty(0)) 156 if (!isatty(0))
93 errx(EXIT_FAILURE, "must be interactive"); 157 errx(EXIT_FAILURE, "must be interactive");
94 158
95 cmdlineBR = 0; 159 cmdlineBR = 0;
96 while((c = getopt(argc, argv, "v0123456789")) != -1) { 160 while((c = getopt(argc, argv, "v0123456789")) != -1) {
97 switch(c) { 161 switch(c) {
98 162
99 case 'v': 163 case 'v':
100 vflag++; 164 vflag++;
101 break; 165 break;
102 166
103 case '0': case '1': case '2': case '3': case '4': 167 case '0': case '1': case '2': case '3': case '4':
104 case '5': case '6': case '7': case '8': case '9': 168 case '5': case '6': case '7': case '8': case '9':
105 cmdlineBR = cmdlineBR * 10 + (c - '0'); 169 cmdlineBR = cmdlineBR * 10 + (c - '0');
106 BR = cmdlineBR; 170 BR = cmdlineBR;
107 break; 171 break;
108 172
109 default: 173 default:
110 warnx("%s, unknown option", argv[1]); 174 warnx("%s, unknown option", argv[1]);
111 break; 175 break;
112 } 176 }
113 } 177 }
114 178
115 argc -= optind; 179 argc -= optind;
116 argv += optind; 180 argv += optind;
117 181
118 if (argc != 1) 182 if (argc != 1)
119 tipusage(); 183 tipusage();
120 else 184 else
121 System = argv[0]; 185 System = argv[0];
122 186
123 187
124 if (System == NULL) 188 if (System == NULL)
125 goto notnumber; 189 goto notnumber;
126 if (isalpha((unsigned char)*System)) 190 if (isalpha((unsigned char)*System))
127 goto notnumber; 191 goto notnumber;
128 /* 192 /*
129 * System name is really a phone number... 193 * System name is really a phone number...
130 * Copy the number then stomp on the original (in case the number 194 * Copy the number then stomp on the original (in case the number
131 * is private, we don't want 'ps' or 'w' to find it). 195 * is private, we don't want 'ps' or 'w' to find it).
132 */ 196 */
133 if (strlen(System) > sizeof PNbuf - 1) { 197 if (strlen(System) > sizeof PNbuf - 1) {
134 errx(1, "phone number too long (max = %d bytes)", 198 errx(1, "phone number too long (max = %d bytes)",
135 (int)sizeof(PNbuf) - 1); 199 (int)sizeof(PNbuf) - 1);
136 } 200 }
137 (void)strlcpy(PNbuf, System, sizeof(PNbuf)); 201 (void)strlcpy(PNbuf, System, sizeof(PNbuf));
138 for (p = System; *p; p++) 202 for (p = System; *p; p++)
139 *p = '\0'; 203 *p = '\0';
140 PN = PNbuf; 204 PN = PNbuf;
141 (void)snprintf(sbuf, sizeof sbuf, "tip%d", (int)BR); 205 (void)snprintf(sbuf, sizeof sbuf, "tip%d", (int)BR);
142 System = sbuf; 206 System = sbuf;
143 207
144notnumber: 208notnumber:
145 (void)signal(SIGINT, cleanup); 209 (void)signal(SIGINT, cleanup);
146 (void)signal(SIGQUIT, cleanup); 210 (void)signal(SIGQUIT, cleanup);
147 (void)signal(SIGHUP, cleanup); 211 (void)signal(SIGHUP, cleanup);
148 (void)signal(SIGTERM, cleanup); 212 (void)signal(SIGTERM, cleanup);
149 213
150 if ((i = hunt(System)) == 0) { 214 if ((i = hunt(System)) == 0) {
151 errx(3, "all ports busy"); 215 errx(3, "all ports busy");
152 } 216 }
153 if (i == -1) { 217 if (i == -1) {
154 errx(3, "link down"); 218 errx(3, "link down");
155 } 219 }
156 setbuf(stdout, NULL); 220 setbuf(stdout, NULL);
157 221
158 /* 222 /*
159 * Kludge, their's no easy way to get the initialization 223 * Kludge, their's no easy way to get the initialization
160 * in the right order, so force it here 224 * in the right order, so force it here
161 */ 225 */
162 if ((PH = getenv("PHONES")) == NULL) 226 if ((PH = getenv("PHONES")) == NULL)
163 PH = path_phones; 227 PH = path_phones;
164 vinit(); /* init variables */ 228 vinit(); /* init variables */
165 setparity("none"); /* set the parity table */ 229 setparity("none"); /* set the parity table */
166 230
167 /* 231 /*
168 * Hardwired connections require the 232 * Hardwired connections require the
169 * line speed set before they make any transmissions 233 * line speed set before they make any transmissions
170 * (this is particularly true of things like a DF03-AC) 234 * (this is particularly true of things like a DF03-AC)
171 */ 235 */
172 if (HW) { 236 if (HW) {
173 if (ttysetup((speed_t)number(value(BAUDRATE))) != 0) { 237 if (ttysetup((speed_t)number(value(BAUDRATE))) != 0) {
174 errx(3, "bad baud rate %d", 238 errx(3, "bad baud rate %d",
175 (int)number(value(BAUDRATE))); 239 (int)number(value(BAUDRATE)));
176 } 240 }
177 } 241 }
178 if ((q = tip_connect()) != NULL) { 242 if ((q = tip_connect()) != NULL) {
179 errx(1, "\07%s\n[EOT]", q); 243 errx(1, "\07%s\n[EOT]", q);
180 } 244 }
181 if (!HW) { 245 if (!HW) {
182 if (ttysetup((speed_t)number(value(BAUDRATE))) != 0) { 246 if (ttysetup((speed_t)number(value(BAUDRATE))) != 0) {
183 errx(3, "bad baud rate %d", 247 errx(3, "bad baud rate %d",
184 (int)number(value(BAUDRATE))); 248 (int)number(value(BAUDRATE)));
185 } 249 }
186 } 250 }
187 251
188 252
189cucommon: 253cucommon:
190 /* 254 /*
191 * From here down the code is shared with 255 * From here down the code is shared with
192 * the "cu" version of tip. 256 * the "cu" version of tip.
193 */ 257 */
194 258
195 /* 259 /*
196 * Direct connections with no carrier require using O_NONBLOCK on 260 * Direct connections with no carrier require using O_NONBLOCK on
197 * open, but we don't want to keep O_NONBLOCK after open because it 261 * open, but we don't want to keep O_NONBLOCK after open because it
198 * will cause busy waits. 262 * will cause busy waits.
199 */ 263 */
200 if (DC && 264 if (DC &&
201 ((fcarg = fcntl(FD, F_GETFL, 0)) < 0 || 265 ((fcarg = fcntl(FD, F_GETFL, 0)) < 0 ||
202 fcntl(FD, F_SETFL, fcarg & ~O_NONBLOCK) < 0)) { 266 fcntl(FD, F_SETFL, fcarg & ~O_NONBLOCK) < 0)) {
203 err(1, "can't clear O_NONBLOCK"); 267 err(1, "can't clear O_NONBLOCK");
204 } 268 }
205 269
206 (void)tcgetattr(0, &defterm); 270 (void)tcgetattr(0, &defterm);
207 term = defterm; 271 term = defterm;
208 term.c_lflag &= ~(ICANON|IEXTEN|ECHO); 272 term.c_lflag &= ~(ICANON|IEXTEN|ECHO);
209 term.c_iflag &= ~(INPCK|ICRNL); 273 term.c_iflag &= ~(INPCK|ICRNL);
210 term.c_oflag &= ~OPOST; 274 term.c_oflag &= ~OPOST;
211 term.c_cc[VMIN] = 1; 275 term.c_cc[VMIN] = 1;
212 term.c_cc[VTIME] = 0; 276 term.c_cc[VTIME] = 0;
213 defchars = term; 277 defchars = term;
214 term.c_cc[VINTR] = term.c_cc[VQUIT] = term.c_cc[VSUSP] = 278 term.c_cc[VINTR] = term.c_cc[VQUIT] = term.c_cc[VSUSP] =
215 term.c_cc[VDSUSP] = term.c_cc[VDISCARD] = 279 term.c_cc[VDSUSP] = term.c_cc[VDISCARD] =
216 term.c_cc[VLNEXT] = _POSIX_VDISABLE; 280 term.c_cc[VLNEXT] = _POSIX_VDISABLE;
217 raw(); 281 raw();
218 282
219 (void)pipe(attndes); 283 (void)pipe(attndes);
220 (void)pipe(fildes); 284 (void)pipe(fildes);
221 (void)pipe(repdes); 285 (void)pipe(repdes);
222 (void)signal(SIGALRM, alrmtimeout); 286 (void)signal(SIGALRM, alrmtimeout);
223 287
224 /* 288 /*
225 * Everything's set up now: 289 * Everything's set up now:
226 * connection established (hardwired or dialup) 290 * connection established (hardwired or dialup)
227 * line conditioned (baud rate, mode, etc.) 291 * line conditioned (baud rate, mode, etc.)
228 * internal data structures (variables) 292 * internal data structures (variables)
229 * so, fork one process for local side and one for remote. 293 * so, fork one process for local side and one for remote.
230 */ 294 */
231 (void)printf("%s", cumode ? "Connected\r\n" : "\07connected\r\n"); 295 (void)printf("%s", cumode ? "Connected\r\n" : "\07connected\r\n");
232 switch (pid = fork()) { 296 switch (pid = fork()) {
233 default: 297 default:
234 tipin(); 298 tipin();
235 break; 299 break;
236 case 0: 300 case 0:
237 tipout(); 301 tipout();
238 break; 302 break;
239 case -1: 303 case -1:
240 err(1, "can't fork"); 304 err(1, "can't fork");
241 } 305 }
242 /*NOTREACHED*/ 306 /*NOTREACHED*/
243 exit(0); /* XXX: pacify gcc */ 307 exit(0); /* XXX: pacify gcc */
244} 308}
245 309
246void 310void
247tipusage(void) 311tipusage(void)
248{ 312{
249 (void)fprintf(stderr, "usage: %s [-v] [-speed] system-name\n", 313 (void)fprintf(stderr, "usage: %s [-v] [-speed] system-name\n",
250 getprogname()); 314 getprogname());
251 (void)fprintf(stderr, " %s [-v] [-speed] phone-number\n", 315 (void)fprintf(stderr, " %s [-v] [-speed] phone-number\n",
252 getprogname()); 316 getprogname());
253 exit(1); 317 exit(1);
254} 318}
255 319
256void 320void
257/*ARGSUSED*/ 321/*ARGSUSED*/
258cleanup(int dummy __unused) 322cleanup(int dummy __unused)
259{ 323{
260 324
261 if (odisc) 325 if (odisc)
262 (void)ioctl(0, TIOCSETD, &odisc); 326 (void)ioctl(0, TIOCSETD, &odisc);
263 _exit(0); 327 _exit(0);
264} 328}
265 329
266/* 330/*
267 * put the controlling keyboard into raw mode 331 * put the controlling keyboard into raw mode
268 */ 332 */
269void 333void
270raw(void) 334raw(void)
271{ 335{
272 336
273 (void)tcsetattr(0, TCSADRAIN, &term); 337 (void)tcsetattr(0, TCSADRAIN, &term);
274} 338}
275 339
276 340
277/* 341/*
278 * return keyboard to normal mode 342 * return keyboard to normal mode
279 */ 343 */
280void 344void
281unraw(void) 345unraw(void)
282{ 346{
283 347
284 (void)tcsetattr(0, TCSADRAIN, &defterm); 348 (void)tcsetattr(0, TCSADRAIN, &defterm);
285} 349}
286 350
287static jmp_buf promptbuf; 351static jmp_buf promptbuf;
288 352
289/* 353/*
290 * Print string ``s'', then read a string 354 * Print string ``s'', then read a string
291 * in from the terminal. Handles signals & allows use of 355 * in from the terminal. Handles signals & allows use of
292 * normal erase and kill characters. 356 * normal erase and kill characters.
293 */ 357 */
294int 358int
295prompt(const char *s, char *volatile p, size_t l) 359prompt(const char *s, char *volatile p, size_t l)
296{ 360{
297 int c; 361 int c;
298 char *b = p; 362 char *b = p;
299 sig_t oint, oquit; 363 sig_t oint, oquit;
300 364
301 stoprompt = 0; 365 stoprompt = 0;
302 oint = signal(SIGINT, intprompt); 366 oint = signal(SIGINT, intprompt);
303 oquit = signal(SIGQUIT, SIG_IGN); 367 oquit = signal(SIGQUIT, SIG_IGN);
304 unraw(); 368 unraw();
305 (void)printf("%s", s); 369 (void)printf("%s", s);
306 if (setjmp(promptbuf) == 0) 370 if (setjmp(promptbuf) == 0)
307 while ((c = getchar()) != EOF && (*p = c) != '\n' && 371 while ((c = getchar()) != EOF && (*p = c) != '\n' &&
308 b + l > p) 372 b + l > p)
309 p++; 373 p++;
310 *p = '\0'; 374 *p = '\0';
311 375
312 raw(); 376 raw();
313 (void)signal(SIGINT, oint); 377 (void)signal(SIGINT, oint);
314 (void)signal(SIGQUIT, oquit); 378 (void)signal(SIGQUIT, oquit);
315 return (stoprompt || p == b); 379 return (stoprompt || p == b);
316} 380}
317 381
318/* 382/*
319 * Interrupt service routine during prompting 383 * Interrupt service routine during prompting
320 */ 384 */
321static void 385static void
322/*ARGSUSED*/ 386/*ARGSUSED*/
323intprompt(int dummy __unused) 387intprompt(int dummy __unused)
324{ 388{
325 389
326 (void)signal(SIGINT, SIG_IGN); 390 (void)signal(SIGINT, SIG_IGN);
327 stoprompt = 1; 391 stoprompt = 1;
328 (void)printf("\r\n"); 392 (void)printf("\r\n");
329 longjmp(promptbuf, 1); 393 longjmp(promptbuf, 1);
330} 394}
331 395
332/* 396/*
333 * getchar() wrapper that checks for EOF on the local end. 397 * getchar() wrapper that checks for EOF on the local end.
334 */ 398 */
335static int 399static int
336xgetchar(void) 400xgetchar(void)
337{ 401{
338 int c = getchar(); 402 int c = getchar();
339 if (__predict_false(c == EOF)) { 403 if (__predict_false(c == EOF)) {
340 cleanup(SIGHUP); 404 cleanup(SIGHUP);
341 /* NOTREACHED */ 405 /* NOTREACHED */
342 } 406 }
343 407
344 return c & STRIP_PAR; 408 return c & STRIP_PAR;
345} 409}
346 410
347 411
348/* 412/*
349 * ****TIPIN TIPIN**** 413 * ****TIPIN TIPIN****
350 */ 414 */
351static void 415static void
352tipin(void) 416tipin(void)
353{ 417{
354 char gch, bol = 1; 418 char gch, bol = 1;
355 419
356 /* 420 /*
357 * Kinda klugey here... 421 * Kinda klugey here...
358 * check for scripting being turned on from the .tiprc file, 422 * check for scripting being turned on from the .tiprc file,
359 * but be careful about just using setscript(), as we may 423 * but be careful about just using setscript(), as we may
360 * send a SIGEMT before tipout has a chance to set up catching 424 * send a SIGEMT before tipout has a chance to set up catching
361 * it; so wait a second, then setscript() 425 * it; so wait a second, then setscript()
362 */ 426 */
363 if (boolean(value(SCRIPT))) { 427 if (boolean(value(SCRIPT))) {
364 (void)sleep(1); 428 (void)sleep(1);
365 setscript(); 429 setscript();
366 } 430 }
367 431
368 for (;;) { 432 for (;;) {
369 gch = xgetchar(); 433 gch = xgetchar();
370 if ((gch == character(value(ESCAPE))) && bol) { 434 if ((gch == character(value(ESCAPE))) && bol) {
371 if (!(gch = escape())) 435 if (!(gch = escape()))
372 continue; 436 continue;
373 } else if (!cumode && 437 } else if (!cumode &&
374 gch && gch == character(value(RAISECHAR))) { 438 gch && gch == character(value(RAISECHAR))) {
375 setboolean(value(RAISE), !boolean(value(RAISE))); 439 setboolean(value(RAISE), !boolean(value(RAISE)));
376 continue; 440 continue;
377 } else if (gch == '\r' || gch == '\n') { 441 } else if (gch == '\r' || gch == '\n') {
378 bol = 1; 442 bol = 1;
379 xpwrite(FD, &gch, 1); 443 xpwrite(FD, &gch, 1);
380 if (boolean(value(HALFDUPLEX))) 444 if (boolean(value(HALFDUPLEX)))
381 (void)printf("%s\n", gch == '\r' ? "\r" : ""); 445 (void)printf("%s\n", gch == '\r' ? "\r" : "");
382 continue; 446 continue;
383 } else if (!cumode && gch && gch == character(value(FORCE))) 447 } else if (!cumode && gch && gch == character(value(FORCE)))
384 gch = xgetchar(); 448 gch = xgetchar();
385 bol = any(gch, value(EOL)); 449 bol = any(gch, value(EOL));
386 if (boolean(value(RAISE)) && islower((unsigned char)gch)) 450 if (boolean(value(RAISE)) && islower((unsigned char)gch))
387 gch = toupper((unsigned char)gch); 451 gch = toupper((unsigned char)gch);
388 xpwrite(FD, &gch, 1); 452 xpwrite(FD, &gch, 1);
389 if (boolean(value(HALFDUPLEX))) 453 if (boolean(value(HALFDUPLEX)))
390 (void)printf("%c", gch); 454 (void)printf("%c", gch);
391 } 455 }
392} 456}
393 457
394/* 458/*
395 * Escape handler -- 459 * Escape handler --
396 * called on recognition of ``escapec'' at the beginning of a line 460 * called on recognition of ``escapec'' at the beginning of a line
397 */ 461 */
398int 462int
399escape(void) 463escape(void)
400{ 464{
401 char gch; 465 char gch;
402 esctable_t *p; 466 esctable_t *p;
403 char c = character(value(ESCAPE)); 467 char c = character(value(ESCAPE));
404 468
405 gch = xgetchar(); 469 gch = xgetchar();
406 for (p = etable; p->e_char; p++) 470 for (p = etable; p->e_char; p++)
407 if (p->e_char == gch) { 471 if (p->e_char == gch) {
408 if ((p->e_flags&PRIV) && uid) 472 if ((p->e_flags&PRIV) && uid)
409 continue; 473 continue;
410 (void)printf("%s", ctrl(c)); 474 (void)printf("%s", ctrl(c));
411 (*p->e_func)(gch); 475 (*p->e_func)(gch);
412 return (0); 476 return (0);
413 } 477 }
414 /* ESCAPE ESCAPE forces ESCAPE */ 478 /* ESCAPE ESCAPE forces ESCAPE */
415 if (c != gch) 479 if (c != gch)
416 xpwrite(FD, &c, 1); 480 xpwrite(FD, &c, 1);
417 return (gch); 481 return (gch);
418} 482}
419 483
420int 484int
421any(char c, const char *p) 485any(char c, const char *p)
422{ 486{
423 487
424 while (p && *p) 488 while (p && *p)
425 if (*p++ == c) 489 if (*p++ == c)
426 return (1); 490 return (1);
427 return (0); 491 return (0);
428} 492}
429 493
430char * 494char *
431interp(const char *s) 495interp(const char *s)
432{ 496{
433 static char buf[256]; 497 static char buf[256];
434 char *p = buf, c; 498 char *p = buf, c;
435 const char *q; 499 const char *q;
436 500
437 while ((c = *s++) != 0 && buf + sizeof buf - p > 2) { 501 while ((c = *s++) != 0 && buf + sizeof buf - p > 2) {
438 for (q = "\nn\rr\tt\ff\033E\bb"; *q; q++) 502 for (q = "\nn\rr\tt\ff\033E\bb"; *q; q++)
439 if (*q++ == c) { 503 if (*q++ == c) {
440 *p++ = '\\'; *p++ = *q; 504 *p++ = '\\'; *p++ = *q;
441 goto next; 505 goto next;
442 } 506 }
443 if (c < 040) { 507 if (c < 040) {
444 *p++ = '^'; *p++ = c + 'A'-1; 508 *p++ = '^'; *p++ = c + 'A'-1;
445 } else if (c == 0177) { 509 } else if (c == 0177) {
446 *p++ = '^'; *p++ = '?'; 510 *p++ = '^'; *p++ = '?';
447 } else 511 } else
448 *p++ = c; 512 *p++ = c;
449 next: 513 next:
450 ; 514 ;
451 } 515 }
452 *p = '\0'; 516 *p = '\0';
453 return (buf); 517 return (buf);
454} 518}
455 519
456char * 520char *
457ctrl(char c) 521ctrl(char c)
458{ 522{
459 static char s[3]; 523 static char s[3];
460 524
461 if (c < 040 || c == 0177) { 525 if (c < 040 || c == 0177) {
462 s[0] = '^'; 526 s[0] = '^';
463 s[1] = c == 0177 ? '?' : c+'A'-1; 527 s[1] = c == 0177 ? '?' : c+'A'-1;
464 s[2] = '\0'; 528 s[2] = '\0';
465 } else { 529 } else {
466 s[0] = c; 530 s[0] = c;
467 s[1] = '\0'; 531 s[1] = '\0';
468 } 532 }
469 return (s); 533 return (s);
470} 534}
471 535
472/* 536/*
473 * Help command 537 * Help command
474 */ 538 */
475void 539void
476help(char c) 540help(char c)
477{ 541{
478 esctable_t *p; 542 esctable_t *p;
479 543
480 (void)printf("%c\r\n", c); 544 (void)printf("%c\r\n", c);
481 for (p = etable; p->e_char; p++) { 545 for (p = etable; p->e_char; p++) {
482 if ((p->e_flags&PRIV) && uid) 546 if ((p->e_flags&PRIV) && uid)
483 continue; 547 continue;
484 (void)printf("%2s", ctrl(character(value(ESCAPE)))); 548 (void)printf("%2s", ctrl(character(value(ESCAPE))));
485 (void)printf("%-2s %c %s\r\n", ctrl(p->e_char), 549 (void)printf("%-2s %c %s\r\n", ctrl(p->e_char),
486 p->e_flags&EXP ? '*': ' ', p->e_help); 550 p->e_flags&EXP ? '*': ' ', p->e_help);
487 } 551 }
488} 552}
489 553
490/* 554/*
491 * Set up the "remote" tty's state 555 * Set up the "remote" tty's state
492 */ 556 */
493int 557int
494ttysetup(speed_t spd) 558ttysetup(speed_t spd)
495{ 559{
496 struct termios cntrl; 560 struct termios cntrl;
497 561
498 (void)tcgetattr(FD, &cntrl); 562 (void)tcgetattr(FD, &cntrl);
499 (void)cfsetospeed(&cntrl, spd); 563 (void)cfsetospeed(&cntrl, spd);
500 (void)cfsetispeed(&cntrl, spd); 564 (void)cfsetispeed(&cntrl, spd);
501 cntrl.c_cflag &= ~(CSIZE|PARENB); 565 cntrl.c_cflag &= ~(CSIZE|PARENB);
502 cntrl.c_cflag |= CS8; 566 cntrl.c_cflag |= CS8;
503 if (DC) 567 if (DC)
504 cntrl.c_cflag |= CLOCAL; 568 cntrl.c_cflag |= CLOCAL;
505 if (boolean(value(HARDWAREFLOW))) 569 if (boolean(value(HARDWAREFLOW)))
506 cntrl.c_cflag |= CRTSCTS; 570 cntrl.c_cflag |= CRTSCTS;
507 cntrl.c_iflag &= ~(ISTRIP|ICRNL); 571 cntrl.c_iflag &= ~(ISTRIP|ICRNL);
508 cntrl.c_oflag &= ~OPOST; 572 cntrl.c_oflag &= ~OPOST;
509 cntrl.c_lflag &= ~(ICANON|ISIG|IEXTEN|ECHO); 573 cntrl.c_lflag &= ~(ICANON|ISIG|IEXTEN|ECHO);
510 cntrl.c_cc[VMIN] = 1; 574 cntrl.c_cc[VMIN] = 1;
511 cntrl.c_cc[VTIME] = 0; 575 cntrl.c_cc[VTIME] = 0;
512 if (boolean(value(TAND))) 576 if (boolean(value(TAND)))
513 cntrl.c_iflag |= IXOFF|IXON; 577 cntrl.c_iflag |= IXOFF|IXON;
514 else 578 else
515 cntrl.c_iflag &= ~(IXOFF|IXON); 579 cntrl.c_iflag &= ~(IXOFF|IXON);
516 return tcsetattr(FD, TCSAFLUSH, &cntrl); 580 return tcsetattr(FD, TCSAFLUSH, &cntrl);
517} 581}
518 582
519static char partab[0200]; 583static char partab[0200];
520 584
521/* 585/*
522 * Do a write to the remote machine with the correct parity. 586 * Do a write to the remote machine with the correct parity.
523 * We are doing 8 bit wide output, so we just generate a character 587 * We are doing 8 bit wide output, so we just generate a character
524 * with the right parity and output it. 588 * with the right parity and output it.
525 */ 589 */
526void 590void
527xpwrite(int fd, char *buf, size_t n) 591xpwrite(int fd, char *buf, size_t n)
528{ 592{
529 size_t i; 593 size_t i;
530 char *bp; 594 char *bp;
531 595
532 bp = buf; 596 bp = buf;
533 if (bits8 == 0) 597 if (bits8 == 0)
534 for (i = 0; i < n; i++) { 598 for (i = 0; i < n; i++) {
535 *bp = partab[(*bp) & 0177]; 599 *bp = partab[(*bp) & 0177];
536 bp++; 600 bp++;
537 } 601 }
538 if (write(fd, buf, n) < 0) { 602 if (write(fd, buf, n) < 0) {
539 if (errno == EIO) 603 if (errno == EIO)
540 tipabort("Lost carrier."); 604 tipabort("Lost carrier.");
541 /* this is questionable */ 605 /* this is questionable */
542 warn("write"); 606 warn("write");
543 } 607 }
544} 608}
545 609
546/* 610/*
547 * Build a parity table with appropriate high-order bit. 611 * Build a parity table with appropriate high-order bit.
548 */ 612 */
549void 613void
550setparity(const char *defparity) 614setparity(const char *defparity)
551{ 615{
552 int i, flip, clr, set; 616 int i, flip, clr, set;
553 const char *parity; 617 const char *parity;
554 static char *curpar; 618 static char *curpar;
555 619
556 if (value(PARITY) == NULL || ((char *)value(PARITY))[0] == '\0') { 620 if (value(PARITY) == NULL || ((char *)value(PARITY))[0] == '\0') {
557 if (curpar != NULL) 621 if (curpar != NULL)
558 free(curpar); 622 free(curpar);
559 value(PARITY) = curpar = strdup(defparity); 623 value(PARITY) = curpar = strdup(defparity);
560 } 624 }
561 parity = value(PARITY); 625 parity = value(PARITY);
562 if (strcmp(parity, "none") == 0) { 626 if (strcmp(parity, "none") == 0) {
563 bits8 = 1; 627 bits8 = 1;
564 return; 628 return;
565 } 629 }
566 bits8 = 0; 630 bits8 = 0;
567 flip = 0; 631 flip = 0;
568 clr = 0377; 632 clr = 0377;
569 set = 0; 633 set = 0;
570 if (strcmp(parity, "odd") == 0) 634 if (strcmp(parity, "odd") == 0)
571 flip = 0200; /* reverse bit 7 */ 635 flip = 0200; /* reverse bit 7 */
572 else if (strcmp(parity, "zero") == 0) 636 else if (strcmp(parity, "zero") == 0)
573 clr = 0177; /* turn off bit 7 */ 637 clr = 0177; /* turn off bit 7 */
574 else if (strcmp(parity, "one") == 0) 638 else if (strcmp(parity, "one") == 0)
575 set = 0200; /* turn on bit 7 */ 639 set = 0200; /* turn on bit 7 */
576 else if (strcmp(parity, "even") != 0) { 640 else if (strcmp(parity, "even") != 0) {
577 (void)fprintf(stderr, "%s: unknown parity value\r\n", parity); 641 (void)fprintf(stderr, "%s: unknown parity value\r\n", parity);
578 (void)fflush(stderr); 642 (void)fflush(stderr);
579 } 643 }
580 for (i = 0; i < 0200; i++) 644 for (i = 0; i < 0200; i++)
581 partab[i] = ((evenpartab[i] ^ flip) | set) & clr; 645 partab[i] = ((evenpartab[i] ^ flip) | set) & clr;
582} 646}

cvs diff -r1.33 -r1.34 src/usr.bin/tip/tip.h (switch to unified diff)

--- src/usr.bin/tip/tip.h 2013/10/21 14:47:46 1.33
+++ src/usr.bin/tip/tip.h 2020/04/23 00:35:14 1.34
@@ -1,336 +1,335 @@ @@ -1,336 +1,335 @@
1/* $NetBSD: tip.h,v 1.33 2013/10/21 14:47:46 christos Exp $ */ 1/* $NetBSD: tip.h,v 1.34 2020/04/23 00:35:14 joerg Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1989, 1993 4 * Copyright (c) 1989, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution. 15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors 16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software 17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission. 18 * without specific prior written permission.
19 * 19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE. 30 * SUCH DAMAGE.
31 * 31 *
32 * @(#)tip.h 8.1 (Berkeley) 6/6/93 32 * @(#)tip.h 8.1 (Berkeley) 6/6/93
33 */ 33 */
34 34
35/* 35/*
36 * tip - terminal interface program 36 * tip - terminal interface program
37 */ 37 */
38 38
39#include <sys/param.h> 39#include <sys/param.h>
40#include <sys/ioctl.h> 40#include <sys/ioctl.h>
41#include <sys/time.h> 41#include <sys/time.h>
42#include <sys/wait.h> 42#include <sys/wait.h>
43#include <machine/endian.h> 43#include <machine/endian.h>
44 44
45#include <err.h> 45#include <err.h>
46#include <fcntl.h> 46#include <fcntl.h>
47#include <errno.h> 47#include <errno.h>
48#include <dirent.h> 48#include <dirent.h>
49#include <pwd.h> 49#include <pwd.h>
50#include <setjmp.h> 50#include <setjmp.h>
51#include <signal.h> 51#include <signal.h>
52#include <stdio.h> 52#include <stdio.h>
53#include <stdlib.h> 53#include <stdlib.h>
54#include <string.h> 54#include <string.h>
55#include <termios.h> 55#include <termios.h>
56#include <time.h> 56#include <time.h>
57#include <unistd.h> 57#include <unistd.h>
58 58
59/* 59/*
60 * Remote host attributes 60 * Remote host attributes
61 */ 61 */
62char *DV; /* UNIX device(s) to open */ 62extern char *DV; /* UNIX device(s) to open */
63char *EL; /* chars marking an EOL */ 63extern char *EL; /* chars marking an EOL */
64char *CM; /* initial connection message */ 64extern char *CM; /* initial connection message */
65char *IE; /* EOT to expect on input */ 65extern char *IE; /* EOT to expect on input */
66char *OE; /* EOT to send to complete FT */ 66extern char *OE; /* EOT to send to complete FT */
67char *CU; /* call unit if making a phone call */ 67extern char *CU; /* call unit if making a phone call */
68char *AT; /* acu type */ 68extern char *AT; /* acu type */
69char *PN; /* phone number(s) */ 69extern char *PN; /* phone number(s) */
70char *DI; /* disconnect string */ 70extern char *DI; /* disconnect string */
71char *PA; /* parity to be generated */ 71extern char *PA; /* parity to be generated */
72 72
73char *PH; /* phone number file */ 73extern char *PH; /* phone number file */
74char *RM; /* remote file name */ 74extern char *RM; /* remote file name */
75char *HO; /* host name */ 75extern char *HO; /* host name */
76 76
77long BR; /* line speed for conversation */ 77extern long BR; /* line speed for conversation */
78long FS; /* frame size for transfers */ 78extern long FS; /* frame size for transfers */
79 79
80long DU; /* this host is dialed up */ 80extern long DU; /* this host is dialed up */
81long HW; /* this device is hardwired, see hunt.c */ 81extern long HW; /* this device is hardwired, see hunt.c */
82char *ES; /* escape character */ 82extern char *ES; /* escape character */
83char *EX; /* exceptions */ 83extern char *EX; /* exceptions */
84char *FO; /* force (literal next) char*/ 84extern char *FO; /* force (literal next) char*/
85char *RC; /* raise character */ 85extern char *RC; /* raise character */
86char *RE; /* script record file */ 86extern char *RE; /* script record file */
87char *PR; /* remote prompt */ 87extern char *PR; /* remote prompt */
88long DL; /* line delay for file transfers to remote */ 88extern long DL; /* line delay for file transfers to remote */
89long CL; /* char delay for file transfers to remote */ 89extern long CL; /* char delay for file transfers to remote */
90long ET; /* echocheck timeout */ 90extern long ET; /* echocheck timeout */
91long HD; /* this host is half duplex - do local echo */ 91extern long HD; /* this host is half duplex - do local echo */
92char DC; /* this host is directly connected. */ 92extern char DC; /* this host is directly connected. */
93 93
94/* 94/*
95 * String value table 95 * String value table
96 */ 96 */
97typedef 97typedef
98 struct { 98 struct {
99 const char *v_name; /* whose name is it */ 99 const char *v_name; /* whose name is it */
100 uint8_t v_type; /* for interpreting set's */ 100 uint8_t v_type; /* for interpreting set's */
101 uint8_t v_access; /* protection of touchy ones */ 101 uint8_t v_access; /* protection of touchy ones */
102 const char *v_abrev; /* possible abreviation */ 102 const char *v_abrev; /* possible abreviation */
103 void *v_value; /* casted to a union later */ 103 void *v_value; /* casted to a union later */
104 /* 104 /*
105 * XXX: this assumes that the storage space 105 * XXX: this assumes that the storage space
106 * of a pointer >= that of a long 106 * of a pointer >= that of a long
107 */ 107 */
108 } 108 }
109 value_t; 109 value_t;
110 110
111#define STRING 01 /* string valued */ 111#define STRING 01 /* string valued */
112#define BOOL 02 /* true-false value */ 112#define BOOL 02 /* true-false value */
113#define NUMBER 04 /* numeric value */ 113#define NUMBER 04 /* numeric value */
114#define CHAR 010 /* character value */ 114#define CHAR 010 /* character value */
115 115
116#define WRITE 01 /* write access to variable */ 116#define WRITE 01 /* write access to variable */
117#define READ 02 /* read access */ 117#define READ 02 /* read access */
118 118
119#define CHANGED 01 /* low bit is used to show modification */ 119#define CHANGED 01 /* low bit is used to show modification */
120#define PUBLIC 1 /* public access rights */ 120#define PUBLIC 1 /* public access rights */
121#define PRIVATE 03 /* private to definer */ 121#define PRIVATE 03 /* private to definer */
122#define ROOT 05 /* root defined */ 122#define ROOT 05 /* root defined */
123 123
124#define TRUE 1 124#define TRUE 1
125#define FALSE 0 125#define FALSE 0
126 126
127#define ENVIRON 020 /* initialize out of the environment */ 127#define ENVIRON 020 /* initialize out of the environment */
128#define IREMOTE 040 /* initialize out of remote structure */ 128#define IREMOTE 040 /* initialize out of remote structure */
129#define INIT 0100 /* static data space used for initialization */ 129#define INIT 0100 /* static data space used for initialization */
130#define TMASK 017 130#define TMASK 017
131 131
132/* 132/*
133 * Definition of ACU line description 133 * Definition of ACU line description
134 */ 134 */
135typedef 135typedef
136 struct { 136 struct {
137 const char *acu_name; 137 const char *acu_name;
138 int (*acu_dialer)(char *, char *); 138 int (*acu_dialer)(char *, char *);
139 void (*acu_disconnect)(void); 139 void (*acu_disconnect)(void);
140 void (*acu_abort)(void); 140 void (*acu_abort)(void);
141 } 141 }
142 acu_t; 142 acu_t;
143 143
144/* 144/*
145 * variable manipulation stuff -- 145 * variable manipulation stuff --
146 * if we defined the value entry in value_t, then we couldn't 146 * if we defined the value entry in value_t, then we couldn't
147 * initialize it in vars.c, so we cast it as needed to keep lint 147 * initialize it in vars.c, so we cast it as needed to keep lint
148 * happy. 148 * happy.
149 */ 149 */
150 150
151#define value(v) vtable[v].v_value 151#define value(v) vtable[v].v_value
152 152
153#define number(v) ((int)(intptr_t)(v)) 153#define number(v) ((int)(intptr_t)(v))
154#define boolean(v) ((short)(intptr_t)(v)) 154#define boolean(v) ((short)(intptr_t)(v))
155#define character(v) ((char)(intptr_t)(v)) 155#define character(v) ((char)(intptr_t)(v))
156#define address(v) ((long *)(intptr_t)(v)) 156#define address(v) ((long *)(intptr_t)(v))
157 157
158#define setnumber(v,n) do { (v) = (char *)(intptr_t)(n); } while (/*CONSTCOND*/0) 158#define setnumber(v,n) do { (v) = (char *)(intptr_t)(n); } while (/*CONSTCOND*/0)
159#define setboolean(v,n) do { (v) = (char *)(intptr_t)(n); } while (/*CONSTCOND*/0) 159#define setboolean(v,n) do { (v) = (char *)(intptr_t)(n); } while (/*CONSTCOND*/0)
160#define setcharacter(v,n) do { (v) = (char *)(intptr_t)(n); } while (/*CONSTCOND*/0) 160#define setcharacter(v,n) do { (v) = (char *)(intptr_t)(n); } while (/*CONSTCOND*/0)
161#define setaddress(v,n) do { (v) = (char *)(intptr_t)(n); } while (/*CONSTCOND*/0) 161#define setaddress(v,n) do { (v) = (char *)(intptr_t)(n); } while (/*CONSTCOND*/0)
162 162
163/* 163/*
164 * Escape command table definitions -- 164 * Escape command table definitions --
165 * lookup in this table is performed when ``escapec'' is recognized 165 * lookup in this table is performed when ``escapec'' is recognized
166 * at the begining of a line (as defined by the eolmarks variable). 166 * at the begining of a line (as defined by the eolmarks variable).
167*/ 167*/
168 168
169typedef 169typedef
170 struct { 170 struct {
171 char e_char; /* char to match on */ 171 char e_char; /* char to match on */
172 char e_flags; /* experimental, privileged */ 172 char e_flags; /* experimental, privileged */
173 const char *e_help; /* help string */ 173 const char *e_help; /* help string */
174 void (*e_func)(char); /* command */ 174 void (*e_func)(char); /* command */
175 } 175 }
176 esctable_t; 176 esctable_t;
177 177
178#define NORM 00 /* normal protection, execute anyone */ 178#define NORM 00 /* normal protection, execute anyone */
179#define EXP 01 /* experimental, mark it with a `*' on help */ 179#define EXP 01 /* experimental, mark it with a `*' on help */
180#define PRIV 02 /* privileged, root execute only */ 180#define PRIV 02 /* privileged, root execute only */
181 181
182extern int vflag; /* verbose during reading of .tiprc file */ 182extern int vflag; /* verbose during reading of .tiprc file */
183extern value_t vtable[]; /* variable table */ 183extern value_t vtable[]; /* variable table */
184 184
185/* 185/*
186 * Definition of indices into variable table so 186 * Definition of indices into variable table so
187 * value(DEFINE) turns into a static address. 187 * value(DEFINE) turns into a static address.
188 * 188 *
189 * XXX: keep in sync with vtable[] in vars.c 189 * XXX: keep in sync with vtable[] in vars.c
190 */ 190 */
191 191
192#define BEAUTIFY 0 192#define BEAUTIFY 0
193#define BAUDRATE 1 193#define BAUDRATE 1
194#define DIALTIMEOUT 2 194#define DIALTIMEOUT 2
195#define EOFREAD 3 195#define EOFREAD 3
196#define EOFWRITE 4 196#define EOFWRITE 4
197#define EOL 5 197#define EOL 5
198#define ESCAPE 6 198#define ESCAPE 6
199#define EXCEPTIONS 7 199#define EXCEPTIONS 7
200#define FORCE 8 200#define FORCE 8
201#define FRAMESIZE 9 201#define FRAMESIZE 9
202#define HOST 10 202#define HOST 10
203#define PHONES 11 203#define PHONES 11
204#define PROMPT 12 204#define PROMPT 12
205#define RAISE 13 205#define RAISE 13
206#define RAISECHAR 14 206#define RAISECHAR 14
207#define RECORD 15 207#define RECORD 15
208#define REMOTE 16 208#define REMOTE 16
209#define SCRIPT 17 209#define SCRIPT 17
210#define TABEXPAND 18 210#define TABEXPAND 18
211#define VERBOSE 19 211#define VERBOSE 19
212#define SHELL 20 212#define SHELL 20
213#define HOME 21 213#define HOME 21
214#define ECHOCHECK 22 214#define ECHOCHECK 22
215#define DISCONNECT 23 215#define DISCONNECT 23
216#define TAND 24 216#define TAND 24
217#define LDELAY 25 217#define LDELAY 25
218#define CDELAY 26 218#define CDELAY 26
219#define ETIMEOUT 27 219#define ETIMEOUT 27
220#define RAWFTP 28 220#define RAWFTP 28
221#define HALFDUPLEX 29 221#define HALFDUPLEX 29
222#define LECHO 30 222#define LECHO 30
223#define PARITY 31 223#define PARITY 31
224#define HARDWAREFLOW 32 224#define HARDWAREFLOW 32
225 225
226struct termios term; /* current mode of terminal */ 226extern struct termios term; /* current mode of terminal */
227struct termios defterm; /* initial mode of terminal */ 227extern struct termios defterm; /* initial mode of terminal */
228struct termios defchars; /* current mode with initial chars */ 228extern struct termios defchars; /* current mode with initial chars */
229 229
230FILE *fscript; /* FILE for scripting */ 230extern FILE *fscript; /* FILE for scripting */
231 231
232int attndes[2]; /* coprocess wakeup channel */ 232extern int attndes[2]; /* coprocess wakeup channel */
233int fildes[2]; /* file transfer synchronization channel */ 233extern int fildes[2]; /* file transfer synchronization channel */
234int repdes[2]; /* read process synchronization channel */ 234extern int repdes[2]; /* read process synchronization channel */
235int FD; /* open file descriptor to remote host */ 235extern int FD; /* open file descriptor to remote host */
236#ifndef __lint__ /* not used by hayes.c, but used by some other dialers */ 236#ifndef __lint__ /* not used by hayes.c, but used by some other dialers */
237int AC; /* open file descriptor to dialer (v831 only) */ 237extern int AC; /* open file descriptor to dialer (v831 only) */
238#endif /*__lint__*/ 238#endif /*__lint__*/
239int vflag; /* print .tiprc initialization sequence */ 239extern int sfd; /* for ~< operation */
240int sfd; /* for ~< operation */ 240extern int pid; /* pid of tipout */
241int pid; /* pid of tipout */ 241extern uid_t uid, euid; /* real and effective user id's */
242uid_t uid, euid; /* real and effective user id's */ 242extern gid_t gid, egid; /* real and effective group id's */
243gid_t gid, egid; /* real and effective group id's */ 243extern int stop; /* stop transfer session flag */
244int stop; /* stop transfer session flag */ 244extern int quit; /* same; but on other end */
245int quit; /* same; but on other end */ 245extern int stoprompt; /* for interrupting a prompt session */
246int stoprompt; /* for interrupting a prompt session */ 246extern int timedout; /* ~> transfer timedout */
247int timedout; /* ~> transfer timedout */ 247extern int cumode; /* simulating the "cu" program */
248int cumode; /* simulating the "cu" program */ 248extern int bits8; /* terminal is in 8-bit mode */
249int bits8; /* terminal is in 8-bit mode */ 
250#define STRIP_PAR (bits8 ? 0377 : 0177) 249#define STRIP_PAR (bits8 ? 0377 : 0177)
251 250
252char fname[80]; /* file name buffer for ~< */ 251extern char fname[80]; /* file name buffer for ~< */
253char copyname[80]; /* file name buffer for ~> */ 252extern char copyname[80]; /* file name buffer for ~> */
254char ccc; /* synchronization character */ 253extern char ccc; /* synchronization character */
255 254
256int odisc; /* initial tty line discipline */ 255extern int odisc; /* initial tty line discipline */
257 256
258extern acu_t acutable[]; 257extern acu_t acutable[];
259extern esctable_t etable[]; 258extern esctable_t etable[];
260extern unsigned char evenpartab[]; 259extern unsigned char evenpartab[];
261 260
262void alrmtimeout(int); 261void alrmtimeout(int);
263int any(char, const char *); 262int any(char, const char *);
264void chdirectory(char); 263void chdirectory(char);
265void cleanup(int) __dead; 264void cleanup(int) __dead;
266const char *tip_connect(void); 265const char *tip_connect(void);
267void consh(char); 266void consh(char);
268char *ctrl(char); 267char *ctrl(char);
269void cumain(int, char **); 268void cumain(int, char **);
270void cu_put(char); 269void cu_put(char);
271void cu_take(char); 270void cu_take(char);
272void disconnect(const char *); 271void disconnect(const char *);
273char *expand(char *); 272char *expand(char *);
274void finish(char) __dead; 273void finish(char) __dead;
275void genbrk(char); 274void genbrk(char);
276void getfl(char); 275void getfl(char);
277char *getremote(char *); 276char *getremote(char *);
278void hardwareflow(const char *); 277void hardwareflow(const char *);
279void help(char); 278void help(char);
280int hunt(char *); 279int hunt(char *);
281char *interp(const char *); 280char *interp(const char *);
282void pipefile(char); 281void pipefile(char);
283void pipeout(char); 282void pipeout(char);
284int prompt(const char *, char *, size_t); 283int prompt(const char *, char *, size_t);
285void xpwrite(int, char *, size_t); 284void xpwrite(int, char *, size_t);
286void raw(void); 285void raw(void);
287void sendchar(char); 286void sendchar(char);
288void sendfile(char); 287void sendfile(char);
289void setparity(const char *); 288void setparity(const char *);
290void setscript(void); 289void setscript(void);
291void shell(char); 290void shell(char);
292void suspend(char); 291void suspend(char);
293void tandem(const char *); 292void tandem(const char *);
294void tipabort(const char *) __dead; 293void tipabort(const char *) __dead;
295void tipout(void) __dead; 294void tipout(void) __dead;
296int ttysetup(speed_t); 295int ttysetup(speed_t);
297void unraw(void); 296void unraw(void);
298void variable(char); 297void variable(char);
299void vinit(void); 298void vinit(void);
300char *vinterp(char *, char); 299char *vinterp(char *, char);
301void vlex(char *); 300void vlex(char *);
302int vstring(const char *, char *); 301int vstring(const char *, char *);
303 302
304void biz22_abort(void); 303void biz22_abort(void);
305void biz22_disconnect(void); 304void biz22_disconnect(void);
306int biz22f_dialer(char *, char *); 305int biz22f_dialer(char *, char *);
307int biz22w_dialer(char *, char *); 306int biz22w_dialer(char *, char *);
308void biz31_abort(void); 307void biz31_abort(void);
309void biz31_disconnect(void); 308void biz31_disconnect(void);
310int biz31f_dialer(char *, char *); 309int biz31f_dialer(char *, char *);
311int biz31w_dialer(char *, char *); 310int biz31w_dialer(char *, char *);
312void cour_abort(void); 311void cour_abort(void);
313int cour_dialer(char *, char *); 312int cour_dialer(char *, char *);
314void cour_disconnect(void); 313void cour_disconnect(void);
315int df02_dialer(char *, char *); 314int df02_dialer(char *, char *);
316int df03_dialer(char *, char *); 315int df03_dialer(char *, char *);
317void df_abort(void); 316void df_abort(void);
318void df_disconnect(void); 317void df_disconnect(void);
319void dn_abort(void); 318void dn_abort(void);
320int dn_dialer(char *, char *); 319int dn_dialer(char *, char *);
321void dn_disconnect(void); 320void dn_disconnect(void);
322void hay_abort(void); 321void hay_abort(void);
323int hay_dialer(char *, char *); 322int hay_dialer(char *, char *);
324void hay_disconnect(void); 323void hay_disconnect(void);
325void t3000_abort(void); 324void t3000_abort(void);
326int t3000_dialer(char *, char *); 325int t3000_dialer(char *, char *);
327void t3000_disconnect(void); 326void t3000_disconnect(void);
328void v3451_abort(void); 327void v3451_abort(void);
329int v3451_dialer(char *, char *); 328int v3451_dialer(char *, char *);
330void v3451_disconnect(void); 329void v3451_disconnect(void);
331void v831_abort(void); 330void v831_abort(void);
332int v831_dialer(char *, char *); 331int v831_dialer(char *, char *);
333void v831_disconnect(void); 332void v831_disconnect(void);
334void ven_abort(void); 333void ven_abort(void);
335int ven_dialer(char *, char *); 334int ven_dialer(char *, char *);
336void ven_disconnect(void); 335void ven_disconnect(void);