subr.c (33a0249fad46f8287b0a625a0231149afdc5b82b) | subr.c (b92f6bd2b8c8170b81fb62bb79e0ba010ddb8f5a) |
---|---|
1/* 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 --- 18 unchanged lines hidden (view full) --- 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 34#ifndef lint | 1/* 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 --- 18 unchanged lines hidden (view full) --- 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 34#ifndef lint |
35static char sccsid[] = "@(#)subr.c 8.1 (Berkeley) 6/4/93"; | 35/*static char sccsid[] = "from: @(#)subr.c 8.1 (Berkeley) 6/4/93";*/ 36static char rcsid[] = "$Id: subr.c,v 1.10 1997/05/11 10:25:38 davidn Exp $"; |
36#endif /* not lint */ 37 38/* 39 * Melbourne getty. 40 */ | 37#endif /* not lint */ 38 39/* 40 * Melbourne getty. 41 */ |
41#define USE_OLD_TTY | 42#define COMPAT_43 |
42#include <stdlib.h> | 43#include <stdlib.h> |
43#include <sgtty.h> 44#include <string.h> | |
45#include <unistd.h> | 44#include <unistd.h> |
45#include <string.h> 46#include <termios.h> 47#include <sys/ioctl.h> 48#include <sys/param.h> 49#include <syslog.h> 50#ifdef DEBUG 51#include <stdio.h> 52#endif |
|
46 47#include "gettytab.h" | 53 54#include "gettytab.h" |
48#include "extern.h" | |
49#include "pathnames.h" | 55#include "pathnames.h" |
56#include "extern.h" |
|
50 | 57 |
51extern struct sgttyb tmode; 52extern struct tchars tc; 53extern struct ltchars ltc; | |
54 | 58 |
59#ifdef COMPAT_43 60static void compatflags __P((long)); 61#endif 62 |
|
55/* 56 * Get a table entry. 57 */ 58void 59gettable(name, buf) | 63/* 64 * Get a table entry. 65 */ 66void 67gettable(name, buf) |
60 char *name, *buf; | 68 const char *name; 69 char *buf; |
61{ 62 register struct gettystrs *sp; 63 register struct gettynums *np; 64 register struct gettyflags *fp; 65 long n; | 70{ 71 register struct gettystrs *sp; 72 register struct gettynums *np; 73 register struct gettyflags *fp; 74 long n; |
66 char *dba[2]; | 75 int l; 76 char *p; 77 char *msg = NULL; 78 const char *dba[2]; 79 80 static int firsttime = 1; 81 |
67 dba[0] = _PATH_GETTYTAB; 68 dba[1] = 0; 69 | 82 dba[0] = _PATH_GETTYTAB; 83 dba[1] = 0; 84 |
70 if (cgetent(&buf, dba, name) != 0) | 85 if (firsttime) { 86 /* 87 * we need to strdup() anything in the strings array 88 * initially in order to simplify things later 89 */ 90 for (sp = gettystrs; sp->field; sp++) 91 if (sp->value != NULL) { 92 /* handle these ones more carefully */ 93 if (sp >= &gettystrs[4] && sp <= &gettystrs[6]) 94 l = 2; 95 else 96 l = strlen(sp->value) + 1; 97 if ((p = malloc(l)) != NULL) { 98 strncpy(p, sp->value, l); 99 p[l-1] = '\0'; 100 } 101 /* 102 * replace, even if NULL, else we'll 103 * have problems with free()ing static mem 104 */ 105 sp->value = p; 106 } 107 firsttime = 0; 108 } 109 110 switch (cgetent(&buf, (char **)dba, (char *)name)) { 111 case 1: 112 msg = "%s: couldn't resolve 'tc=' in gettytab '%s'"; 113 case 0: 114 break; 115 case -1: 116 msg = "%s: unknown gettytab entry '%s'"; 117 break; 118 case -2: 119 msg = "%s: retrieving gettytab entry '%s': %m"; 120 break; 121 case -3: 122 msg = "%s: recursive 'tc=' reference gettytab entry '%s'"; 123 break; 124 default: 125 msg = "%s: unexpected cgetent() error for entry '%s'"; 126 break; 127 } 128 129 if (msg != NULL) { 130 syslog(LOG_ERR, msg, "getty", name); |
71 return; | 131 return; |
132 } |
|
72 | 133 |
73 for (sp = gettystrs; sp->field; sp++) 74 cgetstr(buf, sp->field, &sp->value); | 134 for (sp = gettystrs; sp->field; sp++) { 135 if ((l = cgetustr(buf, (char*)sp->field, &p)) >= 0) { 136 if (sp->value) { 137 /* prefer existing value */ 138 if (strcmp(p, sp->value) != 0) 139 free(sp->value); 140 else { 141 free(p); 142 p = sp->value; 143 } 144 } 145 sp->value = p; 146 } else if (l == -1) { 147 free(sp->value); 148 sp->value = NULL; 149 } 150 } 151 |
75 for (np = gettynums; np->field; np++) { | 152 for (np = gettynums; np->field; np++) { |
76 if (cgetnum(buf, np->field, &n) == -1) | 153 if (cgetnum(buf, (char*)np->field, &n) == -1) |
77 np->set = 0; 78 else { 79 np->set = 1; 80 np->value = n; 81 } 82 } | 154 np->set = 0; 155 else { 156 np->set = 1; 157 np->value = n; 158 } 159 } |
160 |
|
83 for (fp = gettyflags; fp->field; fp++) { | 161 for (fp = gettyflags; fp->field; fp++) { |
84 if (cgetcap(buf, fp->field, ':') == NULL) | 162 if (cgetcap(buf, (char *)fp->field, ':') == NULL) |
85 fp->set = 0; 86 else { 87 fp->set = 1; 88 fp->value = 1 ^ fp->invrt; 89 } 90 } | 163 fp->set = 0; 164 else { 165 fp->set = 1; 166 fp->value = 1 ^ fp->invrt; 167 } 168 } |
169 |
|
91#ifdef DEBUG | 170#ifdef DEBUG |
92 printf("name=\"%s\", buf=\"%s\"\n", name, buf); | 171 printf("name=\"%s\", buf=\"%s\"\r\n", name, buf); |
93 for (sp = gettystrs; sp->field; sp++) | 172 for (sp = gettystrs; sp->field; sp++) |
94 printf("cgetstr: %s=%s\n", sp->field, sp->value); | 173 printf("cgetustr: %s=%s\r\n", sp->field, sp->value); |
95 for (np = gettynums; np->field; np++) | 174 for (np = gettynums; np->field; np++) |
96 printf("cgetnum: %s=%d\n", np->field, np->value); | 175 printf("cgetnum: %s=%d\r\n", np->field, np->value); |
97 for (fp = gettyflags; fp->field; fp++) | 176 for (fp = gettyflags; fp->field; fp++) |
98 printf("cgetflags: %s='%c' set='%c'\n", fp->field, | 177 printf("cgetflags: %s='%c' set='%c'\r\n", fp->field, |
99 fp->value + '0', fp->set + '0'); | 178 fp->value + '0', fp->set + '0'); |
100 exit(1); | |
101#endif /* DEBUG */ 102} 103 104void 105gendefaults() 106{ 107 register struct gettystrs *sp; 108 register struct gettynums *np; 109 register struct gettyflags *fp; 110 111 for (sp = gettystrs; sp->field; sp++) 112 if (sp->value) | 179#endif /* DEBUG */ 180} 181 182void 183gendefaults() 184{ 185 register struct gettystrs *sp; 186 register struct gettynums *np; 187 register struct gettyflags *fp; 188 189 for (sp = gettystrs; sp->field; sp++) 190 if (sp->value) |
113 sp->defalt = sp->value; | 191 sp->defalt = strdup(sp->value); |
114 for (np = gettynums; np->field; np++) 115 if (np->set) 116 np->defalt = np->value; 117 for (fp = gettyflags; fp->field; fp++) 118 if (fp->set) 119 fp->defalt = fp->value; 120 else 121 fp->defalt = fp->invrt; 122} 123 124void 125setdefaults() 126{ 127 register struct gettystrs *sp; 128 register struct gettynums *np; 129 register struct gettyflags *fp; 130 131 for (sp = gettystrs; sp->field; sp++) 132 if (!sp->value) | 192 for (np = gettynums; np->field; np++) 193 if (np->set) 194 np->defalt = np->value; 195 for (fp = gettyflags; fp->field; fp++) 196 if (fp->set) 197 fp->defalt = fp->value; 198 else 199 fp->defalt = fp->invrt; 200} 201 202void 203setdefaults() 204{ 205 register struct gettystrs *sp; 206 register struct gettynums *np; 207 register struct gettyflags *fp; 208 209 for (sp = gettystrs; sp->field; sp++) 210 if (!sp->value) |
133 sp->value = sp->defalt; | 211 sp->value = !sp->defalt ? sp->defalt 212 : strdup(sp->defalt); |
134 for (np = gettynums; np->field; np++) 135 if (!np->set) 136 np->value = np->defalt; 137 for (fp = gettyflags; fp->field; fp++) 138 if (!fp->set) 139 fp->value = fp->defalt; 140} 141 142static char ** 143charnames[] = { 144 &ER, &KL, &IN, &QU, &XN, &XF, &ET, &BK, 145 &SU, &DS, &RP, &FL, &WE, &LN, 0 146}; 147 148static char * 149charvars[] = { | 213 for (np = gettynums; np->field; np++) 214 if (!np->set) 215 np->value = np->defalt; 216 for (fp = gettyflags; fp->field; fp++) 217 if (!fp->set) 218 fp->value = fp->defalt; 219} 220 221static char ** 222charnames[] = { 223 &ER, &KL, &IN, &QU, &XN, &XF, &ET, &BK, 224 &SU, &DS, &RP, &FL, &WE, &LN, 0 225}; 226 227static char * 228charvars[] = { |
150 &tmode.sg_erase, &tmode.sg_kill, &tc.t_intrc, 151 &tc.t_quitc, &tc.t_startc, &tc.t_stopc, 152 &tc.t_eofc, &tc.t_brkc, <c.t_suspc, 153 <c.t_dsuspc, <c.t_rprntc, <c.t_flushc, 154 <c.t_werasc, <c.t_lnextc, 0 | 229 &tmode.c_cc[VERASE], &tmode.c_cc[VKILL], &tmode.c_cc[VINTR], 230 &tmode.c_cc[VQUIT], &tmode.c_cc[VSTART], &tmode.c_cc[VSTOP], 231 &tmode.c_cc[VEOF], &tmode.c_cc[VEOL], &tmode.c_cc[VSUSP], 232 &tmode.c_cc[VDSUSP], &tmode.c_cc[VREPRINT], &tmode.c_cc[VDISCARD], 233 &tmode.c_cc[VWERASE], &tmode.c_cc[VLNEXT], 0 |
155}; 156 157void 158setchars() 159{ 160 register int i; | 234}; 235 236void 237setchars() 238{ 239 register int i; |
161 register char *p; | 240 register const char *p; |
162 163 for (i = 0; charnames[i]; i++) { 164 p = *charnames[i]; 165 if (p && *p) 166 *charvars[i] = *p; 167 else | 241 242 for (i = 0; charnames[i]; i++) { 243 p = *charnames[i]; 244 if (p && *p) 245 *charvars[i] = *p; 246 else |
168 *charvars[i] = '\377'; | 247 *charvars[i] = _POSIX_VDISABLE; |
169 } 170} 171 | 248 } 249} 250 |
172long | 251/* Macros to clear/set/test flags. */ 252#define SET(t, f) (t) |= (f) 253#define CLR(t, f) (t) &= ~(f) 254#define ISSET(t, f) ((t) & (f)) 255 256void |
173setflags(n) 174 int n; 175{ | 257setflags(n) 258 int n; 259{ |
176 register long f; | 260 register tcflag_t iflag, oflag, cflag, lflag; |
177 | 261 |
262#ifdef COMPAT_43 |
|
178 switch (n) { 179 case 0: | 263 switch (n) { 264 case 0: |
180 if (F0set) 181 return(F0); | 265 if (F0set) { 266 compatflags(F0); 267 return; 268 } |
182 break; 183 case 1: | 269 break; 270 case 1: |
184 if (F1set) 185 return(F1); | 271 if (F1set) { 272 compatflags(F1); 273 return; 274 } |
186 break; 187 default: | 275 break; 276 default: |
188 if (F2set) 189 return(F2); | 277 if (F2set) { 278 compatflags(F2); 279 return; 280 } |
190 break; 191 } | 281 break; 282 } |
283#endif |
|
192 | 284 |
193 f = 0; | 285 switch (n) { 286 case 0: 287 if (C0set && I0set && L0set && O0set) { 288 tmode.c_cflag = C0; 289 tmode.c_iflag = I0; 290 tmode.c_lflag = L0; 291 tmode.c_oflag = O0; 292 return; 293 } 294 break; 295 case 1: 296 if (C1set && I1set && L1set && O1set) { 297 tmode.c_cflag = C1; 298 tmode.c_iflag = I1; 299 tmode.c_lflag = L1; 300 tmode.c_oflag = O1; 301 return; 302 } 303 break; 304 default: 305 if (C2set && I2set && L2set && O2set) { 306 tmode.c_cflag = C2; 307 tmode.c_iflag = I2; 308 tmode.c_lflag = L2; 309 tmode.c_oflag = O2; 310 return; 311 } 312 break; 313 } |
194 | 314 |
195 if (AP) 196 f |= ANYP; 197 else if (OP) 198 f |= ODDP; 199 else if (EP) 200 f |= EVENP; | 315 iflag = omode.c_iflag; 316 oflag = omode.c_oflag; 317 cflag = omode.c_cflag; 318 lflag = omode.c_lflag; |
201 | 319 |
320 if (NP) { 321 CLR(cflag, CSIZE|PARENB); 322 SET(cflag, CS8); 323 CLR(iflag, ISTRIP|INPCK|IGNPAR); 324 } else if (AP || EP || OP) { 325 CLR(cflag, CSIZE); 326 SET(cflag, CS7|PARENB); 327 SET(iflag, ISTRIP); 328 if (OP && !EP) { 329 SET(iflag, INPCK|IGNPAR); 330 SET(cflag, PARODD); 331 if (AP) 332 CLR(iflag, INPCK); 333 } else if (EP && !OP) { 334 SET(iflag, INPCK|IGNPAR); 335 CLR(cflag, PARODD); 336 if (AP) 337 CLR(iflag, INPCK); 338 } else if (AP || (EP && OP)) { 339 CLR(iflag, INPCK|IGNPAR); 340 CLR(cflag, PARODD); 341 } 342 } /* else, leave as is */ 343 344#if 0 |
|
202 if (UC) 203 f |= LCASE; | 345 if (UC) 346 f |= LCASE; |
347#endif |
|
204 | 348 |
205 if (NL) 206 f |= CRMOD; | 349 if (HC) 350 SET(cflag, HUPCL); 351 else 352 CLR(cflag, HUPCL); |
207 | 353 |
208 f |= delaybits(); | 354 if (MB) 355 SET(cflag, MDMBUF); 356 else 357 CLR(cflag, MDMBUF); |
209 | 358 |
210 if (n == 1) { /* read mode flags */ 211 if (RW) 212 f |= RAW; 213 else 214 f |= CBREAK; 215 return (f); | 359 if (HW) 360 SET(cflag, CRTSCTS); 361 else 362 CLR(cflag, CRTSCTS); 363 364 if (NL) { 365 SET(iflag, ICRNL); 366 SET(oflag, ONLCR|OPOST); 367 } else { 368 CLR(iflag, ICRNL); 369 CLR(oflag, ONLCR); |
216 } 217 218 if (!HT) | 370 } 371 372 if (!HT) |
219 f |= XTABS; | 373 SET(oflag, OXTABS|OPOST); 374 else 375 CLR(oflag, OXTABS); |
220 | 376 |
377#ifdef XXX_DELAY 378 SET(f, delaybits()); 379#endif 380 381 if (n == 1) { /* read mode flags */ 382 if (RW) { 383 iflag = 0; 384 CLR(oflag, OPOST); 385 CLR(cflag, CSIZE|PARENB); 386 SET(cflag, CS8); 387 lflag = 0; 388 } else { 389 CLR(lflag, ICANON); 390 } 391 goto out; 392 } 393 |
|
221 if (n == 0) | 394 if (n == 0) |
222 return (f); | 395 goto out; |
223 | 396 |
397#if 0 |
|
224 if (CB) | 398 if (CB) |
225 f |= CRTBS; | 399 SET(f, CRTBS); 400#endif |
226 227 if (CE) | 401 402 if (CE) |
228 f |= CRTERA; | 403 SET(lflag, ECHOE); 404 else 405 CLR(lflag, ECHOE); |
229 230 if (CK) | 406 407 if (CK) |
231 f |= CRTKIL; | 408 SET(lflag, ECHOKE); 409 else 410 CLR(lflag, ECHOKE); |
232 233 if (PE) | 411 412 if (PE) |
234 f |= PRTERA; | 413 SET(lflag, ECHOPRT); 414 else 415 CLR(lflag, ECHOPRT); |
235 236 if (EC) | 416 417 if (EC) |
237 f |= ECHO; | 418 SET(lflag, ECHO); 419 else 420 CLR(lflag, ECHO); |
238 239 if (XC) | 421 422 if (XC) |
240 f |= CTLECH; | 423 SET(lflag, ECHOCTL); 424 else 425 CLR(lflag, ECHOCTL); |
241 242 if (DX) | 426 427 if (DX) |
243 f |= DECCTQ; | 428 SET(lflag, IXANY); 429 else 430 CLR(lflag, IXANY); |
244 | 431 |
245 return (f); | 432out: 433 tmode.c_iflag = iflag; 434 tmode.c_oflag = oflag; 435 tmode.c_cflag = cflag; 436 tmode.c_lflag = lflag; |
246} 247 | 437} 438 |
439#ifdef COMPAT_43 440/* 441 * Old TTY => termios, snatched from <sys/kern/tty_compat.c> 442 */ 443void 444compatflags(flags) 445register long flags; 446{ 447 register tcflag_t iflag, oflag, cflag, lflag; 448 449 iflag = BRKINT|ICRNL|IMAXBEL|IXON|IXANY; 450 oflag = OPOST|ONLCR|OXTABS; 451 cflag = CREAD; 452 lflag = ICANON|ISIG|IEXTEN; 453 454 if (ISSET(flags, TANDEM)) 455 SET(iflag, IXOFF); 456 else 457 CLR(iflag, IXOFF); 458 if (ISSET(flags, ECHO)) 459 SET(lflag, ECHO); 460 else 461 CLR(lflag, ECHO); 462 if (ISSET(flags, CRMOD)) { 463 SET(iflag, ICRNL); 464 SET(oflag, ONLCR); 465 } else { 466 CLR(iflag, ICRNL); 467 CLR(oflag, ONLCR); 468 } 469 if (ISSET(flags, XTABS)) 470 SET(oflag, OXTABS); 471 else 472 CLR(oflag, OXTABS); 473 474 475 if (ISSET(flags, RAW)) { 476 iflag &= IXOFF; 477 CLR(lflag, ISIG|ICANON|IEXTEN); 478 CLR(cflag, PARENB); 479 } else { 480 SET(iflag, BRKINT|IXON|IMAXBEL); 481 SET(lflag, ISIG|IEXTEN); 482 if (ISSET(flags, CBREAK)) 483 CLR(lflag, ICANON); 484 else 485 SET(lflag, ICANON); 486 switch (ISSET(flags, ANYP)) { 487 case 0: 488 CLR(cflag, PARENB); 489 break; 490 case ANYP: 491 SET(cflag, PARENB); 492 CLR(iflag, INPCK); 493 break; 494 case EVENP: 495 SET(cflag, PARENB); 496 SET(iflag, INPCK); 497 CLR(cflag, PARODD); 498 break; 499 case ODDP: 500 SET(cflag, PARENB); 501 SET(iflag, INPCK); 502 SET(cflag, PARODD); 503 break; 504 } 505 } 506 507 /* Nothing we can do with CRTBS. */ 508 if (ISSET(flags, PRTERA)) 509 SET(lflag, ECHOPRT); 510 else 511 CLR(lflag, ECHOPRT); 512 if (ISSET(flags, CRTERA)) 513 SET(lflag, ECHOE); 514 else 515 CLR(lflag, ECHOE); 516 /* Nothing we can do with TILDE. */ 517 if (ISSET(flags, MDMBUF)) 518 SET(cflag, MDMBUF); 519 else 520 CLR(cflag, MDMBUF); 521 if (ISSET(flags, NOHANG)) 522 CLR(cflag, HUPCL); 523 else 524 SET(cflag, HUPCL); 525 if (ISSET(flags, CRTKIL)) 526 SET(lflag, ECHOKE); 527 else 528 CLR(lflag, ECHOKE); 529 if (ISSET(flags, CTLECH)) 530 SET(lflag, ECHOCTL); 531 else 532 CLR(lflag, ECHOCTL); 533 if (!ISSET(flags, DECCTQ)) 534 SET(iflag, IXANY); 535 else 536 CLR(iflag, IXANY); 537 CLR(lflag, TOSTOP|FLUSHO|PENDIN|NOFLSH); 538 SET(lflag, ISSET(flags, TOSTOP|FLUSHO|PENDIN|NOFLSH)); 539 540 if (ISSET(flags, RAW|LITOUT|PASS8)) { 541 CLR(cflag, CSIZE); 542 SET(cflag, CS8); 543 if (!ISSET(flags, RAW|PASS8)) 544 SET(iflag, ISTRIP); 545 else 546 CLR(iflag, ISTRIP); 547 if (!ISSET(flags, RAW|LITOUT)) 548 SET(oflag, OPOST); 549 else 550 CLR(oflag, OPOST); 551 } else { 552 CLR(cflag, CSIZE); 553 SET(cflag, CS7); 554 SET(iflag, ISTRIP); 555 SET(oflag, OPOST); 556 } 557 558 tmode.c_iflag = iflag; 559 tmode.c_oflag = oflag; 560 tmode.c_cflag = cflag; 561 tmode.c_lflag = lflag; 562} 563#endif 564 565#ifdef XXX_DELAY |
|
248struct delayval { 249 unsigned delay; /* delay in ms */ 250 int bits; 251}; 252 253/* 254 * below are random guesses, I can't be bothered checking 255 */ --- 22 unchanged lines hidden (view full) --- 278 279struct delayval ffdelay[] = { 280 { 1, FF1 }, 281 { 1750, FF1 }, 282 { 0, FF1 }, 283}; 284 285struct delayval tbdelay[] = { | 566struct delayval { 567 unsigned delay; /* delay in ms */ 568 int bits; 569}; 570 571/* 572 * below are random guesses, I can't be bothered checking 573 */ --- 22 unchanged lines hidden (view full) --- 596 597struct delayval ffdelay[] = { 598 { 1, FF1 }, 599 { 1750, FF1 }, 600 { 0, FF1 }, 601}; 602 603struct delayval tbdelay[] = { |
286 { 1, TAB1 }, 287 { 2, TAB2 }, | 604 { 1, TAB1 }, 605 { 2, TAB2 }, |
288 { 3, XTABS }, /* this is expand tabs */ | 606 { 3, XTABS }, /* this is expand tabs */ |
289 { 100, TAB1 }, 290 { 0, TAB2 }, | 607 { 100, TAB1 }, 608 { 0, TAB2 }, |
291}; 292 293int 294delaybits() 295{ 296 register int f; 297 298 f = adelay(CD, crdelay); --- 10 unchanged lines hidden (view full) --- 309 register struct delayval *dp; 310{ 311 if (ms == 0) 312 return (0); 313 while (dp->delay && ms > dp->delay) 314 dp++; 315 return (dp->bits); 316} | 609}; 610 611int 612delaybits() 613{ 614 register int f; 615 616 f = adelay(CD, crdelay); --- 10 unchanged lines hidden (view full) --- 627 register struct delayval *dp; 628{ 629 if (ms == 0) 630 return (0); 631 while (dp->delay && ms > dp->delay) 632 dp++; 633 return (dp->bits); 634} |
635#endif |
|
317 | 636 |
318char editedhost[32]; | 637char editedhost[MAXHOSTNAMELEN]; |
319 320void 321edithost(pat) | 638 639void 640edithost(pat) |
322 register char *pat; | 641 register const char *pat; |
323{ | 642{ |
324 register char *host = HN; | 643 register const char *host = HN; |
325 register char *res = editedhost; 326 327 if (!pat) 328 pat = ""; 329 while (*pat) { 330 switch (*pat) { 331 332 case '#': --- 19 unchanged lines hidden (view full) --- 352 } 353 if (*host) 354 strncpy(res, host, sizeof editedhost - (res - editedhost) - 1); 355 else 356 *res = '\0'; 357 editedhost[sizeof editedhost - 1] = '\0'; 358} 359 | 644 register char *res = editedhost; 645 646 if (!pat) 647 pat = ""; 648 while (*pat) { 649 switch (*pat) { 650 651 case '#': --- 19 unchanged lines hidden (view full) --- 671 } 672 if (*host) 673 strncpy(res, host, sizeof editedhost - (res - editedhost) - 1); 674 else 675 *res = '\0'; 676 editedhost[sizeof editedhost - 1] = '\0'; 677} 678 |
360struct speedtab { | 679static struct speedtab { |
361 int speed; 362 int uxname; 363} speedtab[] = { | 680 int speed; 681 int uxname; 682} speedtab[] = { |
364 { 50, B50 }, 365 { 75, B75 }, 366 { 110, B110 }, 367 { 134, B134 }, 368 { 150, B150 }, 369 { 200, B200 }, 370 { 300, B300 }, 371 { 600, B600 }, | 683 { 50, B50 }, 684 { 75, B75 }, 685 { 110, B110 }, 686 { 134, B134 }, 687 { 150, B150 }, 688 { 200, B200 }, 689 { 300, B300 }, 690 { 600, B600 }, |
372 { 1200, B1200 }, 373 { 1800, B1800 }, 374 { 2400, B2400 }, 375 { 4800, B4800 }, 376 { 9600, B9600 }, 377 { 19200, EXTA }, | 691 { 1200, B1200 }, 692 { 1800, B1800 }, 693 { 2400, B2400 }, 694 { 4800, B4800 }, 695 { 9600, B9600 }, 696 { 19200, EXTA }, |
378 { 19, EXTA }, /* for people who say 19.2K */ | 697 { 19, EXTA }, /* for people who say 19.2K */ |
379 { 38400, EXTB }, | 698 { 38400, EXTB }, |
380 { 38, EXTB }, 381 { 7200, EXTB }, /* alternative */ | 699 { 38, EXTB }, 700 { 7200, EXTB }, /* alternative */ 701 { 57600, B57600 }, 702 { 115200, B115200 }, |
382 { 0 } 383}; 384 385int 386speed(val) 387 int val; 388{ 389 register struct speedtab *sp; 390 | 703 { 0 } 704}; 705 706int 707speed(val) 708 int val; 709{ 710 register struct speedtab *sp; 711 |
391 if (val <= 15) | 712 if (val <= B115200) |
392 return (val); 393 394 for (sp = speedtab; sp->speed; sp++) 395 if (sp->speed == val) 396 return (sp->uxname); | 713 return (val); 714 715 for (sp = speedtab; sp->speed; sp++) 716 if (sp->speed == val) 717 return (sp->uxname); |
397 | 718 |
398 return (B300); /* default in impossible cases */ 399} 400 401void 402makeenv(env) 403 char *env[]; 404{ 405 static char termbuf[128] = "TERM="; 406 register char *p, *q; 407 register char **ep; 408 409 ep = env; 410 if (TT && *TT) { 411 strcat(termbuf, TT); 412 *ep++ = termbuf; 413 } | 719 return (B300); /* default in impossible cases */ 720} 721 722void 723makeenv(env) 724 char *env[]; 725{ 726 static char termbuf[128] = "TERM="; 727 register char *p, *q; 728 register char **ep; 729 730 ep = env; 731 if (TT && *TT) { 732 strcat(termbuf, TT); 733 *ep++ = termbuf; 734 } |
414 if (p = EV) { | 735 if ((p = EV)) { |
415 q = p; | 736 q = p; |
416 while (q = strchr(q, ',')) { | 737 while ((q = strchr(q, ','))) { |
417 *q++ = '\0'; 418 *ep++ = p; 419 p = q; 420 } 421 if (*p) 422 *ep++ = p; 423 } 424 *ep = (char *)0; 425} 426 427/* 428 * This speed select mechanism is written for the Develcon DATASWITCH. 429 * The Develcon sends a string of the form "B{speed}\n" at a predefined 430 * baud rate. This string indicates the user's actual speed. 431 * The routine below returns the terminal type mapped from derived speed. 432 */ 433struct portselect { | 738 *q++ = '\0'; 739 *ep++ = p; 740 p = q; 741 } 742 if (*p) 743 *ep++ = p; 744 } 745 *ep = (char *)0; 746} 747 748/* 749 * This speed select mechanism is written for the Develcon DATASWITCH. 750 * The Develcon sends a string of the form "B{speed}\n" at a predefined 751 * baud rate. This string indicates the user's actual speed. 752 * The routine below returns the terminal type mapped from derived speed. 753 */ 754struct portselect { |
434 char *ps_baud; 435 char *ps_type; | 755 const char *ps_baud; 756 const char *ps_type; |
436} portspeeds[] = { 437 { "B110", "std.110" }, 438 { "B134", "std.134" }, 439 { "B150", "std.150" }, 440 { "B300", "std.300" }, 441 { "B600", "std.600" }, 442 { "B1200", "std.1200" }, 443 { "B2400", "std.2400" }, 444 { "B4800", "std.4800" }, 445 { "B9600", "std.9600" }, 446 { "B19200", "std.19200" }, 447 { 0 } 448}; 449 | 757} portspeeds[] = { 758 { "B110", "std.110" }, 759 { "B134", "std.134" }, 760 { "B150", "std.150" }, 761 { "B300", "std.300" }, 762 { "B600", "std.600" }, 763 { "B1200", "std.1200" }, 764 { "B2400", "std.2400" }, 765 { "B4800", "std.4800" }, 766 { "B9600", "std.9600" }, 767 { "B19200", "std.19200" }, 768 { 0 } 769}; 770 |
450char * | 771const char * |
451portselector() 452{ | 772portselector() 773{ |
453 char c, baud[20], *type = "default"; | 774 char c, baud[20]; 775 const char *type = "default"; |
454 register struct portselect *ps; 455 int len; 456 457 alarm(5*60); 458 for (len = 0; len < sizeof (baud) - 1; len++) { 459 if (read(STDIN_FILENO, &c, 1) <= 0) 460 break; 461 c &= 0177; --- 15 unchanged lines hidden (view full) --- 477 478/* 479 * This auto-baud speed select mechanism is written for the Micom 600 480 * portselector. Selection is done by looking at how the character '\r' 481 * is garbled at the different speeds. 482 */ 483#include <sys/time.h> 484 | 776 register struct portselect *ps; 777 int len; 778 779 alarm(5*60); 780 for (len = 0; len < sizeof (baud) - 1; len++) { 781 if (read(STDIN_FILENO, &c, 1) <= 0) 782 break; 783 c &= 0177; --- 15 unchanged lines hidden (view full) --- 799 800/* 801 * This auto-baud speed select mechanism is written for the Micom 600 802 * portselector. Selection is done by looking at how the character '\r' 803 * is garbled at the different speeds. 804 */ 805#include <sys/time.h> 806 |
485char * | 807const char * |
486autobaud() 487{ 488 int rfds; 489 struct timeval timeout; | 808autobaud() 809{ 810 int rfds; 811 struct timeval timeout; |
490 char c, *type = "9600-baud"; 491 int null = 0; | 812 char c; 813 const char *type = "9600-baud"; |
492 | 814 |
493 ioctl(0, TIOCFLUSH, &null); | 815 (void)tcflush(0, TCIOFLUSH); |
494 rfds = 1 << 0; 495 timeout.tv_sec = 5; 496 timeout.tv_usec = 0; 497 if (select(32, (fd_set *)&rfds, (fd_set *)NULL, 498 (fd_set *)NULL, &timeout) <= 0) 499 return (type); 500 if (read(STDIN_FILENO, &c, sizeof(char)) != sizeof(char)) 501 return (type); 502 timeout.tv_sec = 0; 503 timeout.tv_usec = 20; 504 (void) select(32, (fd_set *)NULL, (fd_set *)NULL, 505 (fd_set *)NULL, &timeout); | 816 rfds = 1 << 0; 817 timeout.tv_sec = 5; 818 timeout.tv_usec = 0; 819 if (select(32, (fd_set *)&rfds, (fd_set *)NULL, 820 (fd_set *)NULL, &timeout) <= 0) 821 return (type); 822 if (read(STDIN_FILENO, &c, sizeof(char)) != sizeof(char)) 823 return (type); 824 timeout.tv_sec = 0; 825 timeout.tv_usec = 20; 826 (void) select(32, (fd_set *)NULL, (fd_set *)NULL, 827 (fd_set *)NULL, &timeout); |
506 ioctl(0, TIOCFLUSH, &null); | 828 (void)tcflush(0, TCIOFLUSH); |
507 switch (c & 0377) { 508 509 case 0200: /* 300-baud */ 510 type = "300-baud"; 511 break; 512 513 case 0346: /* 1200-baud */ 514 type = "1200-baud"; --- 17 unchanged lines hidden --- | 829 switch (c & 0377) { 830 831 case 0200: /* 300-baud */ 832 type = "300-baud"; 833 break; 834 835 case 0346: /* 1200-baud */ 836 type = "1200-baud"; --- 17 unchanged lines hidden --- |