subr.c (9651) | subr.c (15645) |
---|---|
1/* | 1/* |
2 * Copyright (c) 1983 The Regents of the University of California. 3 * All rights reserved. | 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. |
4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the --- 12 unchanged lines hidden (view full) --- 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. | 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the --- 12 unchanged lines hidden (view full) --- 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. |
32 * 33 * PATCHES MAGIC LEVEL PATCH THAT GOT US HERE 34 * -------------------- ----- ---------------------- 35 * CURRENT PATCH LEVEL: 1 00150 36 * -------------------- ----- ---------------------- 37 * 38 * 22 Apr 93 Rodney W. Grimes support for 57600 and 115200 baud 39 * | |
40 */ 41 42#ifndef lint | 32 */ 33 34#ifndef lint |
43static char sccsid[] = "@(#)subr.c 5.10 (Berkeley) 2/26/91"; | 35/*static char sccsid[] = "from: @(#)subr.c 8.1 (Berkeley) 6/4/93";*/ 36static char rcsid[] = "$Id: subr.c,v 1.1.1.2 1996/04/13 15:33:14 joerg Exp $"; |
44#endif /* not lint */ 45 46/* 47 * Melbourne getty. 48 */ | 37#endif /* not lint */ 38 39/* 40 * Melbourne getty. 41 */ |
49#include <sys/param.h> 50#include <sgtty.h> | 42#define COMPAT_43 43#include <stdlib.h> |
51#include <unistd.h> 52#include <string.h> | 44#include <unistd.h> 45#include <string.h> |
46#include <termios.h> 47#include <sys/ioctl.h> 48#include <sys/param.h> 49#ifdef DEBUG 50#include <stdio.h> 51#endif 52 |
|
53#include "gettytab.h" | 53#include "gettytab.h" |
54#include "pathnames.h" 55#include "extern.h" |
|
54 | 56 |
55extern struct sgttyb tmode; 56extern struct tchars tc; 57extern struct ltchars ltc; | |
58 | 57 |
58#ifdef COMPAT_43 59static void compatflags __P((long)); 60#endif 61 |
|
59/* 60 * Get a table entry. 61 */ | 62/* 63 * Get a table entry. 64 */ |
62gettable(name, buf, area) 63 char *name, *buf, *area; | 65void 66gettable(name, buf) 67 const char *name; 68 char *buf; |
64{ 65 register struct gettystrs *sp; 66 register struct gettynums *np; 67 register struct gettyflags *fp; | 69{ 70 register struct gettystrs *sp; 71 register struct gettynums *np; 72 register struct gettyflags *fp; |
68 register n; | 73 long n; 74 const char *dba[2]; 75 dba[0] = _PATH_GETTYTAB; 76 dba[1] = 0; |
69 | 77 |
70 hopcount = 0; /* new lookup, start fresh */ 71 if (getent(buf, name) != 1) | 78 if (cgetent(&buf, dba, name) != 0) |
72 return; 73 74 for (sp = gettystrs; sp->field; sp++) | 79 return; 80 81 for (sp = gettystrs; sp->field; sp++) |
75 sp->value = getstr(sp->field, &area); | 82 cgetstr(buf, sp->field, &sp->value); |
76 for (np = gettynums; np->field; np++) { | 83 for (np = gettynums; np->field; np++) { |
77 n = getnum(np->field); 78 if (n == -1) | 84 if (cgetnum(buf, np->field, &n) == -1) |
79 np->set = 0; 80 else { 81 np->set = 1; 82 np->value = n; 83 } 84 } 85 for (fp = gettyflags; fp->field; fp++) { | 85 np->set = 0; 86 else { 87 np->set = 1; 88 np->value = n; 89 } 90 } 91 for (fp = gettyflags; fp->field; fp++) { |
86 n = getflag(fp->field); 87 if (n == -1) | 92 if (cgetcap(buf, fp->field, ':') == NULL) |
88 fp->set = 0; 89 else { 90 fp->set = 1; | 93 fp->set = 0; 94 else { 95 fp->set = 1; |
91 fp->value = n ^ fp->invrt; | 96 fp->value = 1 ^ fp->invrt; |
92 } 93 } | 97 } 98 } |
99#ifdef DEBUG 100 printf("name=\"%s\", buf=\"%s\"\r\n", name, buf); 101 for (sp = gettystrs; sp->field; sp++) 102 printf("cgetstr: %s=%s\r\n", sp->field, sp->value); 103 for (np = gettynums; np->field; np++) 104 printf("cgetnum: %s=%d\r\n", np->field, np->value); 105 for (fp = gettyflags; fp->field; fp++) 106 printf("cgetflags: %s='%c' set='%c'\r\n", fp->field, 107 fp->value + '0', fp->set + '0'); 108#endif /* DEBUG */ |
|
94} 95 | 109} 110 |
111void |
|
96gendefaults() 97{ 98 register struct gettystrs *sp; 99 register struct gettynums *np; 100 register struct gettyflags *fp; 101 102 for (sp = gettystrs; sp->field; sp++) 103 if (sp->value) 104 sp->defalt = sp->value; 105 for (np = gettynums; np->field; np++) 106 if (np->set) 107 np->defalt = np->value; 108 for (fp = gettyflags; fp->field; fp++) 109 if (fp->set) 110 fp->defalt = fp->value; 111 else 112 fp->defalt = fp->invrt; 113} 114 | 112gendefaults() 113{ 114 register struct gettystrs *sp; 115 register struct gettynums *np; 116 register struct gettyflags *fp; 117 118 for (sp = gettystrs; sp->field; sp++) 119 if (sp->value) 120 sp->defalt = sp->value; 121 for (np = gettynums; np->field; np++) 122 if (np->set) 123 np->defalt = np->value; 124 for (fp = gettyflags; fp->field; fp++) 125 if (fp->set) 126 fp->defalt = fp->value; 127 else 128 fp->defalt = fp->invrt; 129} 130 |
131void |
|
115setdefaults() 116{ 117 register struct gettystrs *sp; 118 register struct gettynums *np; 119 register struct gettyflags *fp; 120 121 for (sp = gettystrs; sp->field; sp++) 122 if (!sp->value) --- 9 unchanged lines hidden (view full) --- 132static char ** 133charnames[] = { 134 &ER, &KL, &IN, &QU, &XN, &XF, &ET, &BK, 135 &SU, &DS, &RP, &FL, &WE, &LN, 0 136}; 137 138static char * 139charvars[] = { | 132setdefaults() 133{ 134 register struct gettystrs *sp; 135 register struct gettynums *np; 136 register struct gettyflags *fp; 137 138 for (sp = gettystrs; sp->field; sp++) 139 if (!sp->value) --- 9 unchanged lines hidden (view full) --- 149static char ** 150charnames[] = { 151 &ER, &KL, &IN, &QU, &XN, &XF, &ET, &BK, 152 &SU, &DS, &RP, &FL, &WE, &LN, 0 153}; 154 155static char * 156charvars[] = { |
140 &tmode.sg_erase, &tmode.sg_kill, &tc.t_intrc, 141 &tc.t_quitc, &tc.t_startc, &tc.t_stopc, 142 &tc.t_eofc, &tc.t_brkc, <c.t_suspc, 143 <c.t_dsuspc, <c.t_rprntc, <c.t_flushc, 144 <c.t_werasc, <c.t_lnextc, 0 | 157 &tmode.c_cc[VERASE], &tmode.c_cc[VKILL], &tmode.c_cc[VINTR], 158 &tmode.c_cc[VQUIT], &tmode.c_cc[VSTART], &tmode.c_cc[VSTOP], 159 &tmode.c_cc[VEOF], &tmode.c_cc[VEOL], &tmode.c_cc[VSUSP], 160 &tmode.c_cc[VDSUSP], &tmode.c_cc[VREPRINT], &tmode.c_cc[VDISCARD], 161 &tmode.c_cc[VWERASE], &tmode.c_cc[VLNEXT], 0 |
145}; 146 | 162}; 163 |
164void |
|
147setchars() 148{ 149 register int i; | 165setchars() 166{ 167 register int i; |
150 register char *p; | 168 register const char *p; |
151 152 for (i = 0; charnames[i]; i++) { 153 p = *charnames[i]; 154 if (p && *p) 155 *charvars[i] = *p; 156 else | 169 170 for (i = 0; charnames[i]; i++) { 171 p = *charnames[i]; 172 if (p && *p) 173 *charvars[i] = *p; 174 else |
157 *charvars[i] = '\377'; | 175 *charvars[i] = _POSIX_VDISABLE; |
158 } 159} 160 | 176 } 177} 178 |
161long | 179/* Macros to clear/set/test flags. */ 180#define SET(t, f) (t) |= (f) 181#define CLR(t, f) (t) &= ~(f) 182#define ISSET(t, f) ((t) & (f)) 183 184void |
162setflags(n) | 185setflags(n) |
186 int n; |
|
163{ | 187{ |
164 register long f; | 188 register tcflag_t iflag, oflag, cflag, lflag; |
165 | 189 |
190#ifdef COMPAT_43 |
|
166 switch (n) { 167 case 0: | 191 switch (n) { 192 case 0: |
168 if (F0set) 169 return(F0); | 193 if (F0set) { 194 compatflags(F0); 195 return; 196 } |
170 break; 171 case 1: | 197 break; 198 case 1: |
172 if (F1set) 173 return(F1); | 199 if (F1set) { 200 compatflags(F1); 201 return; 202 } |
174 break; 175 default: | 203 break; 204 default: |
176 if (F2set) 177 return(F2); | 205 if (F2set) { 206 compatflags(F2); 207 return; 208 } |
178 break; 179 } | 209 break; 210 } |
211#endif |
|
180 | 212 |
181 f = 0; | 213 switch (n) { 214 case 0: 215 if (C0set && I0set && L0set && O0set) { 216 tmode.c_cflag = C0; 217 tmode.c_iflag = I0; 218 tmode.c_lflag = L0; 219 tmode.c_oflag = O0; 220 return; 221 } 222 break; 223 case 1: 224 if (C1set && I1set && L1set && O1set) { 225 tmode.c_cflag = C1; 226 tmode.c_iflag = I1; 227 tmode.c_lflag = L1; 228 tmode.c_oflag = O1; 229 return; 230 } 231 break; 232 default: 233 if (C2set && I2set && L2set && O2set) { 234 tmode.c_cflag = C2; 235 tmode.c_iflag = I2; 236 tmode.c_lflag = L2; 237 tmode.c_oflag = O2; 238 return; 239 } 240 break; 241 } |
182 | 242 |
183 if (AP) 184 f |= ANYP; 185 else if (OP) 186 f |= ODDP; 187 else if (EP) 188 f |= EVENP; 189 if (NP) 190 f |= PASS8; | 243 iflag = omode.c_iflag; 244 oflag = omode.c_oflag; 245 cflag = omode.c_cflag; 246 lflag = omode.c_lflag; |
191 | 247 |
248 if (NP) { 249 CLR(cflag, CSIZE|PARENB); 250 SET(cflag, CS8); 251 CLR(iflag, ISTRIP|INPCK|IGNPAR); 252 } else if (AP || EP || OP) { 253 CLR(cflag, CSIZE); 254 SET(cflag, CS7|PARENB); 255 SET(iflag, ISTRIP); 256 if (OP && !EP) { 257 SET(iflag, INPCK|IGNPAR); 258 SET(cflag, PARODD); 259 if (AP) 260 CLR(iflag, INPCK); 261 } else if (EP && !OP) { 262 SET(iflag, INPCK|IGNPAR); 263 CLR(cflag, PARODD); 264 if (AP) 265 CLR(iflag, INPCK); 266 } else if (AP || (EP && OP)) { 267 CLR(iflag, INPCK|IGNPAR); 268 CLR(cflag, PARODD); 269 } 270 } /* else, leave as is */ 271 272#if 0 |
|
192 if (UC) 193 f |= LCASE; | 273 if (UC) 274 f |= LCASE; |
275#endif |
|
194 | 276 |
195 if (NL) 196 f |= CRMOD; | 277 if (HC) 278 SET(cflag, HUPCL); 279 else 280 CLR(cflag, HUPCL); |
197 | 281 |
198 f |= delaybits(); | 282 if (MB) 283 SET(cflag, MDMBUF); 284 else 285 CLR(cflag, MDMBUF); |
199 | 286 |
200 if (n == 1) { /* read mode flags */ 201 if (RW) 202 f |= RAW; 203 else 204 f |= CBREAK; 205 return (f); | 287 if (NL) { 288 SET(iflag, ICRNL); 289 SET(oflag, ONLCR|OPOST); 290 } else { 291 CLR(iflag, ICRNL); 292 CLR(oflag, ONLCR); |
206 } 207 208 if (!HT) | 293 } 294 295 if (!HT) |
209 f |= XTABS; | 296 SET(oflag, OXTABS|OPOST); 297 else 298 CLR(oflag, OXTABS); |
210 | 299 |
300#ifdef XXX_DELAY 301 SET(f, delaybits()); 302#endif 303 304 if (n == 1) { /* read mode flags */ 305 if (RW) { 306 iflag = 0; 307 CLR(oflag, OPOST); 308 CLR(cflag, CSIZE|PARENB); 309 SET(cflag, CS8); 310 lflag = 0; 311 } else { 312 CLR(lflag, ICANON); 313 } 314 goto out; 315 } 316 |
|
211 if (n == 0) | 317 if (n == 0) |
212 return (f); | 318 goto out; |
213 | 319 |
320#if 0 |
|
214 if (CB) | 321 if (CB) |
215 f |= CRTBS; | 322 SET(f, CRTBS); 323#endif |
216 217 if (CE) | 324 325 if (CE) |
218 f |= CRTERA; | 326 SET(lflag, ECHOE); 327 else 328 CLR(lflag, ECHOE); |
219 220 if (CK) | 329 330 if (CK) |
221 f |= CRTKIL; | 331 SET(lflag, ECHOKE); 332 else 333 CLR(lflag, ECHOKE); |
222 223 if (PE) | 334 335 if (PE) |
224 f |= PRTERA; | 336 SET(lflag, ECHOPRT); 337 else 338 CLR(lflag, ECHOPRT); |
225 226 if (EC) | 339 340 if (EC) |
227 f |= ECHO; | 341 SET(lflag, ECHO); 342 else 343 CLR(lflag, ECHO); |
228 229 if (XC) | 344 345 if (XC) |
230 f |= CTLECH; | 346 SET(lflag, ECHOCTL); 347 else 348 CLR(lflag, ECHOCTL); |
231 232 if (DX) | 349 350 if (DX) |
233 f |= DECCTQ; | 351 SET(lflag, IXANY); 352 else 353 CLR(lflag, IXANY); |
234 | 354 |
235 return (f); | 355out: 356 tmode.c_iflag = iflag; 357 tmode.c_oflag = oflag; 358 tmode.c_cflag = cflag; 359 tmode.c_lflag = lflag; |
236} 237 | 360} 361 |
362#ifdef COMPAT_43 363/* 364 * Old TTY => termios, snatched from <sys/kern/tty_compat.c> 365 */ 366void 367compatflags(flags) 368register long flags; 369{ 370 register tcflag_t iflag, oflag, cflag, lflag; 371 372 iflag = BRKINT|ICRNL|IMAXBEL|IXON|IXANY; 373 oflag = OPOST|ONLCR|OXTABS; 374 cflag = CREAD; 375 lflag = ICANON|ISIG|IEXTEN; 376 377 if (ISSET(flags, TANDEM)) 378 SET(iflag, IXOFF); 379 else 380 CLR(iflag, IXOFF); 381 if (ISSET(flags, ECHO)) 382 SET(lflag, ECHO); 383 else 384 CLR(lflag, ECHO); 385 if (ISSET(flags, CRMOD)) { 386 SET(iflag, ICRNL); 387 SET(oflag, ONLCR); 388 } else { 389 CLR(iflag, ICRNL); 390 CLR(oflag, ONLCR); 391 } 392 if (ISSET(flags, XTABS)) 393 SET(oflag, OXTABS); 394 else 395 CLR(oflag, OXTABS); 396 397 398 if (ISSET(flags, RAW)) { 399 iflag &= IXOFF; 400 CLR(lflag, ISIG|ICANON|IEXTEN); 401 CLR(cflag, PARENB); 402 } else { 403 SET(iflag, BRKINT|IXON|IMAXBEL); 404 SET(lflag, ISIG|IEXTEN); 405 if (ISSET(flags, CBREAK)) 406 CLR(lflag, ICANON); 407 else 408 SET(lflag, ICANON); 409 switch (ISSET(flags, ANYP)) { 410 case 0: 411 CLR(cflag, PARENB); 412 break; 413 case ANYP: 414 SET(cflag, PARENB); 415 CLR(iflag, INPCK); 416 break; 417 case EVENP: 418 SET(cflag, PARENB); 419 SET(iflag, INPCK); 420 CLR(cflag, PARODD); 421 break; 422 case ODDP: 423 SET(cflag, PARENB); 424 SET(iflag, INPCK); 425 SET(cflag, PARODD); 426 break; 427 } 428 } 429 430 /* Nothing we can do with CRTBS. */ 431 if (ISSET(flags, PRTERA)) 432 SET(lflag, ECHOPRT); 433 else 434 CLR(lflag, ECHOPRT); 435 if (ISSET(flags, CRTERA)) 436 SET(lflag, ECHOE); 437 else 438 CLR(lflag, ECHOE); 439 /* Nothing we can do with TILDE. */ 440 if (ISSET(flags, MDMBUF)) 441 SET(cflag, MDMBUF); 442 else 443 CLR(cflag, MDMBUF); 444 if (ISSET(flags, NOHANG)) 445 CLR(cflag, HUPCL); 446 else 447 SET(cflag, HUPCL); 448 if (ISSET(flags, CRTKIL)) 449 SET(lflag, ECHOKE); 450 else 451 CLR(lflag, ECHOKE); 452 if (ISSET(flags, CTLECH)) 453 SET(lflag, ECHOCTL); 454 else 455 CLR(lflag, ECHOCTL); 456 if (!ISSET(flags, DECCTQ)) 457 SET(iflag, IXANY); 458 else 459 CLR(iflag, IXANY); 460 CLR(lflag, TOSTOP|FLUSHO|PENDIN|NOFLSH); 461 SET(lflag, ISSET(flags, TOSTOP|FLUSHO|PENDIN|NOFLSH)); 462 463 if (ISSET(flags, RAW|LITOUT|PASS8)) { 464 CLR(cflag, CSIZE); 465 SET(cflag, CS8); 466 if (!ISSET(flags, RAW|PASS8)) 467 SET(iflag, ISTRIP); 468 else 469 CLR(iflag, ISTRIP); 470 if (!ISSET(flags, RAW|LITOUT)) 471 SET(oflag, OPOST); 472 else 473 CLR(oflag, OPOST); 474 } else { 475 CLR(cflag, CSIZE); 476 SET(cflag, CS7); 477 SET(iflag, ISTRIP); 478 SET(oflag, OPOST); 479 } 480 481 tmode.c_iflag = iflag; 482 tmode.c_oflag = oflag; 483 tmode.c_cflag = cflag; 484 tmode.c_lflag = lflag; 485} 486#endif 487 488#ifdef XXX_DELAY |
|
238struct delayval { 239 unsigned delay; /* delay in ms */ 240 int bits; 241}; 242 243/* 244 * below are random guesses, I can't be bothered checking 245 */ 246 247struct delayval crdelay[] = { | 489struct delayval { 490 unsigned delay; /* delay in ms */ 491 int bits; 492}; 493 494/* 495 * below are random guesses, I can't be bothered checking 496 */ 497 498struct delayval crdelay[] = { |
248 1, CR1, 249 2, CR2, 250 3, CR3, 251 83, CR1, 252 166, CR2, 253 0, CR3, | 499 { 1, CR1 }, 500 { 2, CR2 }, 501 { 3, CR3 }, 502 { 83, CR1 }, 503 { 166, CR2 }, 504 { 0, CR3 }, |
254}; 255 256struct delayval nldelay[] = { | 505}; 506 507struct delayval nldelay[] = { |
257 1, NL1, /* special, calculated */ 258 2, NL2, 259 3, NL3, 260 100, NL2, 261 0, NL3, | 508 { 1, NL1 }, /* special, calculated */ 509 { 2, NL2 }, 510 { 3, NL3 }, 511 { 100, NL2 }, 512 { 0, NL3 }, |
262}; 263 264struct delayval bsdelay[] = { | 513}; 514 515struct delayval bsdelay[] = { |
265 1, BS1, 266 0, 0, | 516 { 1, BS1 }, 517 { 0, 0 }, |
267}; 268 269struct delayval ffdelay[] = { | 518}; 519 520struct delayval ffdelay[] = { |
270 1, FF1, 271 1750, FF1, 272 0, FF1, | 521 { 1, FF1 }, 522 { 1750, FF1 }, 523 { 0, FF1 }, |
273}; 274 275struct delayval tbdelay[] = { | 524}; 525 526struct delayval tbdelay[] = { |
276 1, TAB1, 277 2, TAB2, 278 3, XTABS, /* this is expand tabs */ 279 100, TAB1, 280 0, TAB2, | 527 { 1, TAB1 }, 528 { 2, TAB2 }, 529 { 3, XTABS }, /* this is expand tabs */ 530 { 100, TAB1 }, 531 { 0, TAB2 }, |
281}; 282 | 532}; 533 |
534int |
|
283delaybits() 284{ | 535delaybits() 536{ |
285 register f; | 537 register int f; |
286 287 f = adelay(CD, crdelay); 288 f |= adelay(ND, nldelay); 289 f |= adelay(FD, ffdelay); 290 f |= adelay(TD, tbdelay); 291 f |= adelay(BD, bsdelay); 292 return (f); 293} 294 | 538 539 f = adelay(CD, crdelay); 540 f |= adelay(ND, nldelay); 541 f |= adelay(FD, ffdelay); 542 f |= adelay(TD, tbdelay); 543 f |= adelay(BD, bsdelay); 544 return (f); 545} 546 |
547int |
|
295adelay(ms, dp) 296 register ms; 297 register struct delayval *dp; 298{ 299 if (ms == 0) 300 return (0); 301 while (dp->delay && ms > dp->delay) 302 dp++; 303 return (dp->bits); 304} | 548adelay(ms, dp) 549 register ms; 550 register struct delayval *dp; 551{ 552 if (ms == 0) 553 return (0); 554 while (dp->delay && ms > dp->delay) 555 dp++; 556 return (dp->bits); 557} |
558#endif |
|
305 | 559 |
306char editedhost[MAXHOSTNAMELEN]; | 560char editedhost[MAXHOSTNAMELEN]; |
307 | 561 |
562void |
|
308edithost(pat) | 563edithost(pat) |
309 register char *pat; | 564 register const char *pat; |
310{ | 565{ |
311 register char *host = HN; | 566 register const char *host = HN; |
312 register char *res = editedhost; 313 314 if (!pat) 315 pat = ""; 316 while (*pat) { 317 switch (*pat) { 318 319 case '#': --- 19 unchanged lines hidden (view full) --- 339 } 340 if (*host) 341 strncpy(res, host, sizeof editedhost - (res - editedhost) - 1); 342 else 343 *res = '\0'; 344 editedhost[sizeof editedhost - 1] = '\0'; 345} 346 | 567 register char *res = editedhost; 568 569 if (!pat) 570 pat = ""; 571 while (*pat) { 572 switch (*pat) { 573 574 case '#': --- 19 unchanged lines hidden (view full) --- 594 } 595 if (*host) 596 strncpy(res, host, sizeof editedhost - (res - editedhost) - 1); 597 else 598 *res = '\0'; 599 editedhost[sizeof editedhost - 1] = '\0'; 600} 601 |
347struct speedtab { | 602static struct speedtab { |
348 int speed; 349 int uxname; 350} speedtab[] = { | 603 int speed; 604 int uxname; 605} speedtab[] = { |
351 50, B50, 352 75, B75, 353 110, B110, 354 134, B134, 355 150, B150, 356 200, B200, 357 300, B300, 358 600, B600, 359 1200, B1200, 360 1800, B1800, 361 2400, B2400, 362 4800, B4800, 363 9600, B9600, 364 19200, EXTA, 365 19, EXTA, /* for people who say 19.2K */ 366 38400, EXTB, 367 38, EXTB, 368 7200, EXTB, /* alternative */ 369 57600, B57600, 370 115200, B115200, 371 0 | 606 { 50, B50 }, 607 { 75, B75 }, 608 { 110, B110 }, 609 { 134, B134 }, 610 { 150, B150 }, 611 { 200, B200 }, 612 { 300, B300 }, 613 { 600, B600 }, 614 { 1200, B1200 }, 615 { 1800, B1800 }, 616 { 2400, B2400 }, 617 { 4800, B4800 }, 618 { 9600, B9600 }, 619 { 19200, EXTA }, 620 { 19, EXTA }, /* for people who say 19.2K */ 621 { 38400, EXTB }, 622 { 38, EXTB }, 623 { 7200, EXTB }, /* alternative */ 624 { 57600, B57600 }, 625 { 115200, B115200 }, 626 { 0 } |
372}; 373 | 627}; 628 |
629int |
|
374speed(val) | 630speed(val) |
631 int val; |
|
375{ 376 register struct speedtab *sp; 377 378 if (val <= B115200) 379 return (val); 380 381 for (sp = speedtab; sp->speed; sp++) 382 if (sp->speed == val) 383 return (sp->uxname); 384 385 return (B300); /* default in impossible cases */ 386} 387 | 632{ 633 register struct speedtab *sp; 634 635 if (val <= B115200) 636 return (val); 637 638 for (sp = speedtab; sp->speed; sp++) 639 if (sp->speed == val) 640 return (sp->uxname); 641 642 return (B300); /* default in impossible cases */ 643} 644 |
645void |
|
388makeenv(env) 389 char *env[]; 390{ 391 static char termbuf[128] = "TERM="; 392 register char *p, *q; 393 register char **ep; | 646makeenv(env) 647 char *env[]; 648{ 649 static char termbuf[128] = "TERM="; 650 register char *p, *q; 651 register char **ep; |
394 char *index(); | |
395 396 ep = env; 397 if (TT && *TT) { 398 strcat(termbuf, TT); 399 *ep++ = termbuf; 400 } | 652 653 ep = env; 654 if (TT && *TT) { 655 strcat(termbuf, TT); 656 *ep++ = termbuf; 657 } |
401 if (p = EV) { | 658 if ((p = EV)) { |
402 q = p; | 659 q = p; |
403 while (q = index(q, ',')) { | 660 while ((q = strchr(q, ','))) { |
404 *q++ = '\0'; 405 *ep++ = p; 406 p = q; 407 } 408 if (*p) 409 *ep++ = p; 410 } 411 *ep = (char *)0; 412} 413 414/* 415 * This speed select mechanism is written for the Develcon DATASWITCH. 416 * The Develcon sends a string of the form "B{speed}\n" at a predefined 417 * baud rate. This string indicates the user's actual speed. 418 * The routine below returns the terminal type mapped from derived speed. 419 */ 420struct portselect { | 661 *q++ = '\0'; 662 *ep++ = p; 663 p = q; 664 } 665 if (*p) 666 *ep++ = p; 667 } 668 *ep = (char *)0; 669} 670 671/* 672 * This speed select mechanism is written for the Develcon DATASWITCH. 673 * The Develcon sends a string of the form "B{speed}\n" at a predefined 674 * baud rate. This string indicates the user's actual speed. 675 * The routine below returns the terminal type mapped from derived speed. 676 */ 677struct portselect { |
421 char *ps_baud; 422 char *ps_type; | 678 const char *ps_baud; 679 const char *ps_type; |
423} portspeeds[] = { 424 { "B110", "std.110" }, 425 { "B134", "std.134" }, 426 { "B150", "std.150" }, 427 { "B300", "std.300" }, 428 { "B600", "std.600" }, 429 { "B1200", "std.1200" }, 430 { "B2400", "std.2400" }, 431 { "B4800", "std.4800" }, 432 { "B9600", "std.9600" }, 433 { "B19200", "std.19200" }, 434 { 0 } 435}; 436 | 680} portspeeds[] = { 681 { "B110", "std.110" }, 682 { "B134", "std.134" }, 683 { "B150", "std.150" }, 684 { "B300", "std.300" }, 685 { "B600", "std.600" }, 686 { "B1200", "std.1200" }, 687 { "B2400", "std.2400" }, 688 { "B4800", "std.4800" }, 689 { "B9600", "std.9600" }, 690 { "B19200", "std.19200" }, 691 { 0 } 692}; 693 |
437char * | 694const char * |
438portselector() 439{ | 695portselector() 696{ |
440 char c, baud[20], *type = "default"; | 697 char c, baud[20]; 698 const char *type = "default"; |
441 register struct portselect *ps; 442 int len; 443 444 alarm(5*60); 445 for (len = 0; len < sizeof (baud) - 1; len++) { 446 if (read(STDIN_FILENO, &c, 1) <= 0) 447 break; 448 c &= 0177; --- 15 unchanged lines hidden (view full) --- 464 465/* 466 * This auto-baud speed select mechanism is written for the Micom 600 467 * portselector. Selection is done by looking at how the character '\r' 468 * is garbled at the different speeds. 469 */ 470#include <sys/time.h> 471 | 699 register struct portselect *ps; 700 int len; 701 702 alarm(5*60); 703 for (len = 0; len < sizeof (baud) - 1; len++) { 704 if (read(STDIN_FILENO, &c, 1) <= 0) 705 break; 706 c &= 0177; --- 15 unchanged lines hidden (view full) --- 722 723/* 724 * This auto-baud speed select mechanism is written for the Micom 600 725 * portselector. Selection is done by looking at how the character '\r' 726 * is garbled at the different speeds. 727 */ 728#include <sys/time.h> 729 |
472char * | 730const char * |
473autobaud() 474{ 475 int rfds; 476 struct timeval timeout; | 731autobaud() 732{ 733 int rfds; 734 struct timeval timeout; |
477 char c, *type = "9600-baud"; 478 int null = 0; | 735 char c; 736 const char *type = "9600-baud"; |
479 | 737 |
480 ioctl(0, TIOCFLUSH, &null); | 738 (void)tcflush(0, TCIOFLUSH); |
481 rfds = 1 << 0; 482 timeout.tv_sec = 5; 483 timeout.tv_usec = 0; 484 if (select(32, (fd_set *)&rfds, (fd_set *)NULL, 485 (fd_set *)NULL, &timeout) <= 0) 486 return (type); 487 if (read(STDIN_FILENO, &c, sizeof(char)) != sizeof(char)) 488 return (type); 489 timeout.tv_sec = 0; 490 timeout.tv_usec = 20; 491 (void) select(32, (fd_set *)NULL, (fd_set *)NULL, 492 (fd_set *)NULL, &timeout); | 739 rfds = 1 << 0; 740 timeout.tv_sec = 5; 741 timeout.tv_usec = 0; 742 if (select(32, (fd_set *)&rfds, (fd_set *)NULL, 743 (fd_set *)NULL, &timeout) <= 0) 744 return (type); 745 if (read(STDIN_FILENO, &c, sizeof(char)) != sizeof(char)) 746 return (type); 747 timeout.tv_sec = 0; 748 timeout.tv_usec = 20; 749 (void) select(32, (fd_set *)NULL, (fd_set *)NULL, 750 (fd_set *)NULL, &timeout); |
493 ioctl(0, TIOCFLUSH, &null); | 751 (void)tcflush(0, TCIOFLUSH); |
494 switch (c & 0377) { 495 496 case 0200: /* 300-baud */ 497 type = "300-baud"; 498 break; 499 500 case 0346: /* 1200-baud */ 501 type = "1200-baud"; --- 17 unchanged lines hidden --- | 752 switch (c & 0377) { 753 754 case 0200: /* 300-baud */ 755 type = "300-baud"; 756 break; 757 758 case 0346: /* 1200-baud */ 759 type = "1200-baud"; --- 17 unchanged lines hidden --- |