1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 * Copyright (c) 2014, Joyent, Inc. All rights reserved. 26 */ 27 28 /* 29 * Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T 30 * All Rights Reserved 31 * 32 */ 33 34 #include <stdio.h> 35 #include <ctype.h> 36 #include <locale.h> 37 #include <sys/types.h> 38 #include <termio.h> 39 #include <sys/stermio.h> 40 #include <sys/termiox.h> 41 #include <string.h> 42 #include <stdlib.h> 43 #include <limits.h> 44 #ifdef EUC 45 #include <sys/stat.h> 46 #include <fcntl.h> 47 #include <unistd.h> 48 #include <sys/param.h> 49 #include <sys/stropts.h> 50 #include <sys/eucioctl.h> 51 #include <sys/csiioctl.h> 52 #include <sys/stream.h> 53 #include <sys/termios.h> 54 #include <sys/ldterm.h> 55 #include <getwidth.h> 56 #endif /* EUC */ 57 #include "stty.h" 58 #include "tmextern.h" 59 60 static char *STTY = "stty: "; 61 static int pitt = 0; 62 static struct termios cb; 63 static struct termio ocb; /* for non-streams devices */ 64 static struct stio stio; 65 static struct termiox termiox; 66 static struct winsize winsize, owinsize; 67 static int term; 68 #ifdef EUC 69 static struct eucioc kwp; 70 static eucwidth_t wp; 71 static ldterm_cs_data_user_t cswp; /* User side codeset width data */ 72 static ldterm_cs_data_user_t kcswp; /* Kernel side codeset width data */ 73 static int invalid_ldterm_dat_file; 74 #endif /* EUC */ 75 76 static void prmodes(void); 77 static void pramodes(void); 78 static void pit(unsigned char what, char *itsname, char *sep); 79 static void delay(int m, char *s); 80 static void prspeed(char *c, int s); 81 static void prencode(void); 82 83 int 84 main(int argc, char *argv[]) 85 { 86 int i; 87 int fd; 88 char *s_arg; /* s_arg: ptr to mode to be set */ 89 #ifdef EUC 90 char *lc; 91 char tmps[PATH_MAX]; 92 #endif /* EUC */ 93 94 (void) setlocale(LC_ALL, ""); 95 #if !defined(TEXT_DOMAIN) 96 #define TEXT_DOMAIN "SYS_TEST" 97 #endif 98 (void) textdomain(TEXT_DOMAIN); 99 100 #ifdef EUC 101 lc = setlocale(LC_CTYPE, (const char *)NULL); 102 if (lc) { 103 (void) sprintf(tmps, _LDTERM_DAT_PATH, lc); 104 105 fd = open(tmps, O_RDONLY, 0); 106 if (fd != -1) { 107 if (read(fd, (void *)&cswp, sizeof (cswp)) < 108 sizeof (cswp)) { 109 (void) fprintf(stderr, gettext( 110 "cannot read entire %s file\n"), tmps); 111 exit(2); 112 } 113 114 (void) close(fd); 115 116 /* 117 * If the ldterm.dat contains invalid data or 118 * the current locale name is too long, we clear 119 * the 'cswp' and flag the invalid ldterm.dat since 120 * we are not going to use the data. 121 */ 122 if (cswp.version > LDTERM_DATA_VERSION || 123 cswp.codeset_type < LDTERM_CS_TYPE_MIN || 124 cswp.codeset_type > LDTERM_CS_TYPE_MAX || 125 strlen(lc) >= MAXNAMELEN || 126 (cswp.codeset_type == LDTERM_CS_TYPE_EUC && 127 cswp.csinfo_num > LDTERM_CS_TYPE_EUC_MAX_SUBCS) || 128 (cswp.codeset_type == LDTERM_CS_TYPE_PCCS && 129 (cswp.csinfo_num < LDTERM_CS_TYPE_PCCS_MIN_SUBCS || 130 cswp.csinfo_num > LDTERM_CS_TYPE_PCCS_MAX_SUBCS))) { 131 (void) memset((void *)&cswp, 0, sizeof (cswp)); 132 invalid_ldterm_dat_file = 1; 133 } else { 134 (void) strcpy(cswp.locale_name, lc); 135 } 136 } 137 } 138 139 getwidth(&wp); 140 #endif /* EUC */ 141 142 if ((term = get_ttymode(0, &ocb, &cb, &stio, &termiox, &winsize 143 #ifdef EUC 144 /* */, &kwp, &kcswp 145 #endif /* EUC */ 146 /* */)) < 0) { 147 perror(STTY); 148 exit(2); 149 } 150 owinsize = winsize; 151 if (argc == 1) { 152 prmodes(); 153 exit(0); 154 } 155 if ((argc == 2) && (argv[1][0] == '-') && (argv[1][2] == '\0')) { 156 switch (argv[1][1]) { 157 case 'a': 158 pramodes(); 159 return (0); 160 case 'g': 161 prencode(); 162 return (0); 163 case '-': 164 prmodes(); /* stty -- */ 165 return (0); 166 default: 167 (void) fprintf(stderr, gettext( 168 "usage: stty [-a| -g]\n")); 169 (void) fprintf(stderr, gettext( 170 " stty [modes]\n")); 171 return (2); 172 } 173 } 174 175 if ((argc == 3) && (argv[1][0] == '-') && 176 (argv[1][2] == '\0') && 177 (argv[2][0] == '-') && 178 (argv[2][1] == '-') && 179 (argv[2][2] == '\0')) { 180 switch (argv[1][1]) { 181 case 'a': 182 pramodes(); 183 return (0); 184 case 'g': 185 prencode(); 186 return (0); 187 default: 188 (void) fprintf(stderr, gettext( 189 "usage: stty [-a| -g]\n")); 190 (void) fprintf(stderr, gettext( 191 " stty [modes]\n")); 192 return (2); 193 } 194 } 195 if ((argc >= 3) && (argv[1][0] == '-') && (argv[1][1] == '-') && 196 (argv[1][2] == '\0')) { 197 /* ignore -- */ 198 --argc; 199 ++argv; 200 } 201 #ifdef EUC 202 s_arg = sttyparse(argc, argv, term, &ocb, &cb, &termiox, &winsize, 203 &wp, &kwp, &cswp, &kcswp); 204 #else 205 s_arg = sttyparse(argc, argv, term, &ocb, &cb, &termiox, &winsize); 206 #endif /* EUC */ 207 if (s_arg != NULL) { 208 char *s = s_arg; 209 if (*s == '-') s++; 210 for (i = 0; not_supported[i]; i++) { 211 if (strcmp(not_supported[i], s) == 0) { 212 (void) fprintf(stderr, 213 gettext( 214 "mode not supported on this device: %s\n"), 215 s_arg); 216 exit(2); 217 } 218 } 219 (void) fprintf(stderr, gettext("unknown mode: %s\n"), s_arg); 220 return (2); 221 } 222 223 if (set_ttymode(0, term, &ocb, &cb, &stio, &termiox, &winsize, &owinsize 224 #ifdef EUC 225 /* */, &kwp, &kcswp, invalid_ldterm_dat_file 226 #endif /* EUC */ 227 /* */) == -1) { 228 perror(STTY); 229 return (2); 230 } 231 return (0); 232 } 233 234 static void 235 prmodes(void) /* print modes, no options, argc is 1 */ 236 { 237 int m; 238 239 if (!(term & ASYNC)) { 240 m = stio.imode; 241 if (m & IUCLC) 242 (void) printf("iuclc "); 243 else 244 (void) printf("-iuclc "); 245 m = stio.omode; 246 if (m & OLCUC) 247 (void) printf("olcuc "); 248 else 249 (void) printf("-olcuc "); 250 if (m & TAB3) 251 (void) printf("tab3 "); 252 m = stio.lmode; 253 if (m & XCASE) 254 (void) printf("xcase "); 255 else 256 (void) printf("-xcase "); 257 if (m & STFLUSH) 258 (void) printf("stflush "); 259 else 260 (void) printf("-stflush "); 261 if (m & STWRAP) 262 (void) printf("stwrap "); 263 else 264 (void) printf("-stwrap "); 265 if (m & STAPPL) 266 (void) printf("stappl "); 267 else 268 (void) printf("-stappl "); 269 (void) printf("\n"); 270 } 271 if (term & ASYNC) { 272 m = cb.c_cflag; 273 if ((term & TERMIOS) && cfgetispeed(&cb) != 0 && 274 cfgetispeed(&cb) != cfgetospeed(&cb)) { 275 prspeed("ispeed ", cfgetispeed(&cb)); 276 prspeed("ospeed ", cfgetospeed(&cb)); 277 } else 278 prspeed("speed ", cfgetospeed(&cb)); 279 if (m&PARENB) { 280 if ((m&PAREXT) && (term & TERMIOS)) { 281 if (m&PARODD) 282 (void) printf("markp "); 283 else 284 (void) printf("spacep "); 285 } else { 286 if (m&PARODD) 287 (void) printf("oddp "); 288 else 289 (void) printf("evenp "); 290 } 291 } else 292 (void) printf("-parity "); 293 if (((m&PARENB) && !(m&CS7)) || (!(m&PARENB) && !(m&CS8))) 294 (void) printf("cs%c ", '5'+(m&CSIZE)/CS6); 295 if (m&CSTOPB) 296 (void) printf("cstopb "); 297 if (m&HUPCL) 298 (void) printf("hupcl "); 299 if (!(m&CREAD)) 300 (void) printf("-cread "); 301 if (m&CLOCAL) 302 (void) printf("clocal "); 303 if (m&LOBLK) 304 (void) printf("loblk "); 305 (void) printf("\n"); 306 if (ocb.c_line != 0) 307 (void) printf(gettext("line = %d; "), ocb.c_line); 308 if (term & WINDOW) { 309 (void) printf(gettext("rows = %d; columns = %d;"), 310 winsize.ws_row, winsize.ws_col); 311 (void) printf(gettext( 312 " ypixels = %d; xpixels = %d;\n"), 313 winsize.ws_ypixel, winsize.ws_xpixel); 314 } 315 if ((cb.c_lflag&ICANON) == 0) 316 (void) printf(gettext("min = %d; time = %d;\n"), 317 cb.c_cc[VMIN], cb.c_cc[VTIME]); 318 if (cb.c_cc[VINTR] != CINTR) 319 pit(cb.c_cc[VINTR], "intr", "; "); 320 if (cb.c_cc[VQUIT] != CQUIT) 321 pit(cb.c_cc[VQUIT], "quit", "; "); 322 if (cb.c_cc[VERASE] != CERASE) 323 pit(cb.c_cc[VERASE], "erase", "; "); 324 if (term & TERMIOS) { 325 if (cb.c_cc[VERASE2] != CERASE2) 326 pit(cb.c_cc[VERASE], "erase2", "; "); 327 } 328 if (cb.c_cc[VKILL] != CKILL) 329 pit(cb.c_cc[VKILL], "kill", "; "); 330 if (cb.c_cc[VEOF] != CEOF) 331 pit(cb.c_cc[VEOF], "eof", "; "); 332 if (cb.c_cc[VEOL] != CNUL) 333 pit(cb.c_cc[VEOL], "eol", "; "); 334 if (cb.c_cc[VEOL2] != CNUL) 335 pit(cb.c_cc[VEOL2], "eol2", "; "); 336 if (cb.c_cc[VSWTCH] != CSWTCH) 337 pit(cb.c_cc[VSWTCH], "swtch", "; "); 338 if (term & TERMIOS) { 339 if (cb.c_cc[VSTART] != CSTART) 340 pit(cb.c_cc[VSTART], "start", "; "); 341 if (cb.c_cc[VSTOP] != CSTOP) 342 pit(cb.c_cc[VSTOP], "stop", "; "); 343 if (cb.c_cc[VSUSP] != CSUSP) 344 pit(cb.c_cc[VSUSP], "susp", "; "); 345 if (cb.c_cc[VDSUSP] != CDSUSP) 346 pit(cb.c_cc[VDSUSP], "dsusp", "; "); 347 if (cb.c_cc[VREPRINT] != CRPRNT) 348 pit(cb.c_cc[VREPRINT], "rprnt", "; "); 349 if (cb.c_cc[VDISCARD] != CFLUSH) 350 pit(cb.c_cc[VDISCARD], "flush", "; "); 351 if (cb.c_cc[VWERASE] != CWERASE) 352 pit(cb.c_cc[VWERASE], "werase", "; "); 353 if (cb.c_cc[VLNEXT] != CLNEXT) 354 pit(cb.c_cc[VLNEXT], "lnext", "; "); 355 if (cb.c_cc[VSTATUS] != CSTATUS) 356 pit(cb.c_cc[VSTATUS], "status", "; "); 357 } 358 if (pitt) (void) printf("\n"); 359 m = cb.c_iflag; 360 if (m&IGNBRK) 361 (void) printf("ignbrk "); 362 else if (m&BRKINT) 363 (void) printf("brkint "); 364 if (!(m&INPCK)) 365 (void) printf("-inpck "); 366 else if (m&IGNPAR) 367 (void) printf("ignpar "); 368 if (m&PARMRK) 369 (void) printf("parmrk "); 370 if (!(m&ISTRIP)) 371 (void) printf("-istrip "); 372 if (m&INLCR) 373 (void) printf("inlcr "); 374 if (m&IGNCR) 375 (void) printf("igncr "); 376 if (m&ICRNL) 377 (void) printf("icrnl "); 378 if (m&IUCLC) 379 (void) printf("iuclc "); 380 if (!(m&IXON)) 381 (void) printf("-ixon "); 382 else if (!(m&IXANY)) 383 (void) printf("-ixany "); 384 if (m&IXOFF) 385 (void) printf("ixoff "); 386 if ((term & TERMIOS) && (m&IMAXBEL)) 387 (void) printf("imaxbel "); 388 m = cb.c_oflag; 389 if (!(m&OPOST)) 390 (void) printf("-opost "); 391 else { 392 if (m&OLCUC) 393 (void) printf("olcuc "); 394 if (m&ONLCR) 395 (void) printf("onlcr "); 396 if (m&OCRNL) 397 (void) printf("ocrnl "); 398 if (m&ONOCR) 399 (void) printf("onocr "); 400 if (m&ONLRET) 401 (void) printf("onlret "); 402 if (m&OFILL) { 403 if (m&OFDEL) 404 (void) printf("del-fill "); 405 else 406 (void) printf("nul-fill "); 407 } 408 delay((m&CRDLY)/CR1, "cr"); 409 delay((m&NLDLY)/NL1, "nl"); 410 delay((m&TABDLY)/TAB1, "tab"); 411 delay((m&BSDLY)/BS1, "bs"); 412 delay((m&VTDLY)/VT1, "vt"); 413 delay((m&FFDLY)/FF1, "ff"); 414 } 415 (void) printf("\n"); 416 m = cb.c_lflag; 417 if (!(m&ISIG)) 418 (void) printf("-isig "); 419 if (!(m&ICANON)) 420 (void) printf("-icanon "); 421 if (m&XCASE) 422 (void) printf("xcase "); 423 (void) printf("-echo "+((m&ECHO) != 0)); 424 (void) printf("-echoe "+((m&ECHOE) != 0)); 425 (void) printf("-echok "+((m&ECHOK) != 0)); 426 if (m&ECHONL) 427 (void) printf("echonl "); 428 if (m&NOFLSH) 429 (void) printf("noflsh "); 430 if (m&TOSTOP) 431 (void) printf("tostop "); 432 if (m&ECHOCTL) 433 (void) printf("echoctl "); 434 if (m&ECHOPRT) 435 (void) printf("echoprt "); 436 if (m&ECHOKE) 437 (void) printf("echoke "); 438 if (m&DEFECHO) 439 (void) printf("defecho "); 440 if (m&FLUSHO) 441 (void) printf("flusho "); 442 if (m&PENDIN) 443 (void) printf("pendin "); 444 if (m&IEXTEN) 445 (void) printf("iexten "); 446 (void) printf("\n"); 447 } 448 if (term & FLOW) { 449 m = termiox.x_hflag; 450 if (m & RTSXOFF) 451 (void) printf("rtsxoff "); 452 if (m & CTSXON) 453 (void) printf("ctsxon "); 454 if (m & DTRXOFF) 455 (void) printf("dtrxoff "); 456 if (m & CDXON) 457 (void) printf("cdxon "); 458 if (m & ISXOFF) 459 (void) printf("isxoff "); 460 m = termiox.x_cflag; 461 switch (m & XMTCLK) { 462 case XCIBRG: (void)printf("xcibrg "); 463 break; 464 case XCTSET: (void)printf("xctset "); 465 break; 466 case XCRSET: (void)printf("xcrset "); 467 } 468 469 switch (m & RCVCLK) { 470 case RCIBRG: (void)printf("rcibrg "); 471 break; 472 case RCTSET: (void)printf("rctset "); 473 break; 474 case RCRSET: (void)printf("rcrset "); 475 } 476 477 switch (m & TSETCLK) { 478 case TSETCOFF: (void)printf("tsetcoff "); 479 break; 480 case TSETCRBRG: (void)printf("tsetcrbrg "); 481 break; 482 case TSETCTBRG: (void)printf("tsetctbrg "); 483 break; 484 case TSETCTSET: (void)printf("tsetctset "); 485 break; 486 case TSETCRSET: (void)printf("tsetcrset "); 487 } 488 489 switch (m & RSETCLK) { 490 case RSETCOFF: (void)printf("rsetcoff "); 491 break; 492 case RSETCRBRG: (void)printf("rsetcrbrg "); 493 break; 494 case RSETCTBRG: (void)printf("rsetctbrg "); 495 break; 496 case RSETCTSET: (void)printf("rsetctset "); 497 break; 498 case RSETCRSET: (void)printf("rsetcrset "); 499 } 500 (void) printf("\n"); 501 } 502 } 503 504 static void 505 pramodes(void) /* print all modes, -a option */ 506 { 507 int m; 508 509 m = cb.c_cflag; 510 if (term & ASYNC) { 511 if ((term & TERMIOS) && cfgetispeed(&cb) != 0 && 512 cfgetispeed(&cb) != cfgetospeed(&cb)) { 513 prspeed("ispeed ", cfgetispeed(&cb)); 514 prspeed("ospeed ", cfgetospeed(&cb)); 515 } else 516 prspeed("speed ", cfgetospeed(&cb)); 517 if (!(term & TERMIOS)) 518 (void) printf(gettext("line = %d; "), ocb.c_line); 519 (void) printf("\n"); 520 if (term & WINDOW) { 521 (void) printf(gettext("rows = %d; columns = %d;"), 522 winsize.ws_row, winsize.ws_col); 523 (void) printf(gettext( 524 " ypixels = %d; xpixels = %d;\n"), 525 winsize.ws_ypixel, winsize.ws_xpixel); 526 } 527 #ifdef EUC 528 if ((term & CSIW) && kcswp.locale_name[0]) { 529 (void) printf("csdata %s\n", kcswp.locale_name); 530 } else { 531 (void) printf("csdata ?\n"); 532 } 533 /* 534 * If kwp.eucw[0] is zero, it means the current codeset type 535 * in the ldterm is not EUC. 536 */ 537 if ((term & EUCW) && kwp.eucw[0]) { 538 (void) printf("eucw %d:%d:%d:%d, ", kwp.eucw[0], 539 kwp.eucw[1], kwp.eucw[2], kwp.eucw[3]); 540 (void) printf("scrw %d:%d:%d:%d\n", kwp.scrw[0], 541 kwp.scrw[1], kwp.scrw[2], kwp.scrw[3]); 542 } else 543 (void) printf("eucw ?, scrw ?\n"); 544 #endif /* EUC */ 545 if ((cb.c_lflag&ICANON) == 0) 546 (void) printf(gettext("min = %d; time = %d;\n"), 547 cb.c_cc[VMIN], cb.c_cc[VTIME]); 548 pit(cb.c_cc[VINTR], "intr", "; "); 549 pit(cb.c_cc[VQUIT], "quit", "; "); 550 pit(cb.c_cc[VERASE], "erase", "; "); 551 if (term & TERMIOS) 552 pit(cb.c_cc[VERASE2], "erase2", "; "); 553 pit(cb.c_cc[VKILL], "kill", ";\n"); 554 pit(cb.c_cc[VEOF], "eof", "; "); 555 pit(cb.c_cc[VEOL], "eol", "; "); 556 pit(cb.c_cc[VEOL2], "eol2", "; "); 557 pit(cb.c_cc[VSWTCH], "swtch", ";\n"); 558 if (term & TERMIOS) { 559 pit(cb.c_cc[VSTART], "start", "; "); 560 pit(cb.c_cc[VSTOP], "stop", "; "); 561 pit(cb.c_cc[VSUSP], "susp", "; "); 562 pit(cb.c_cc[VDSUSP], "dsusp", ";\n"); 563 pit(cb.c_cc[VREPRINT], "rprnt", "; "); 564 pit(cb.c_cc[VDISCARD], "flush", "; "); 565 pit(cb.c_cc[VWERASE], "werase", "; "); 566 pit(cb.c_cc[VLNEXT], "lnext", ";\n"); 567 pit(cb.c_cc[VSTATUS], "status", ";\n"); 568 } 569 } else 570 pit((unsigned)stio.tab, "ctab", "\n"); 571 m = cb.c_cflag; 572 (void) printf("-parenb "+((m&PARENB) != 0)); 573 (void) printf("-parodd "+((m&PARODD) != 0)); 574 (void) printf("cs%c ", '5'+(m&CSIZE)/CS6); 575 (void) printf("-cstopb "+((m&CSTOPB) != 0)); 576 (void) printf("-hupcl "+((m&HUPCL) != 0)); 577 (void) printf("-cread "+((m&CREAD) != 0)); 578 (void) printf("-clocal "+((m&CLOCAL) != 0)); 579 580 (void) printf("-loblk "+((m&LOBLK) != 0)); 581 (void) printf("-crtscts "+((m&CRTSCTS) != 0)); 582 (void) printf("-crtsxoff "+((m&CRTSXOFF) != 0)); 583 if (term & TERMIOS) 584 (void) printf("-parext "+((m&PAREXT) != 0)); 585 586 (void) printf("\n"); 587 m = cb.c_iflag; 588 (void) printf("-ignbrk "+((m&IGNBRK) != 0)); 589 (void) printf("-brkint "+((m&BRKINT) != 0)); 590 (void) printf("-ignpar "+((m&IGNPAR) != 0)); 591 (void) printf("-parmrk "+((m&PARMRK) != 0)); 592 (void) printf("-inpck "+((m&INPCK) != 0)); 593 (void) printf("-istrip "+((m&ISTRIP) != 0)); 594 (void) printf("-inlcr "+((m&INLCR) != 0)); 595 (void) printf("-igncr "+((m&IGNCR) != 0)); 596 (void) printf("-icrnl "+((m&ICRNL) != 0)); 597 (void) printf("-iuclc "+((m&IUCLC) != 0)); 598 (void) printf("\n"); 599 (void) printf("-ixon "+((m&IXON) != 0)); 600 (void) printf("-ixany "+((m&IXANY) != 0)); 601 (void) printf("-ixoff "+((m&IXOFF) != 0)); 602 if (term & TERMIOS) 603 (void) printf("-imaxbel "+((m&IMAXBEL) != 0)); 604 (void) printf("\n"); 605 m = cb.c_lflag; 606 (void) printf("-isig "+((m&ISIG) != 0)); 607 (void) printf("-icanon "+((m&ICANON) != 0)); 608 (void) printf("-xcase "+((m&XCASE) != 0)); 609 (void) printf("-echo "+((m&ECHO) != 0)); 610 (void) printf("-echoe "+((m&ECHOE) != 0)); 611 (void) printf("-echok "+((m&ECHOK) != 0)); 612 (void) printf("-echonl "+((m&ECHONL) != 0)); 613 (void) printf("-noflsh "+((m&NOFLSH) != 0)); 614 if (term & TERMIOS) { 615 (void) printf("\n"); 616 (void) printf("-tostop "+((m&TOSTOP) != 0)); 617 (void) printf("-echoctl "+((m&ECHOCTL) != 0)); 618 (void) printf("-echoprt "+((m&ECHOPRT) != 0)); 619 (void) printf("-echoke "+((m&ECHOKE) != 0)); 620 (void) printf("-defecho "+((m&DEFECHO) != 0)); 621 (void) printf("-flusho "+((m&FLUSHO) != 0)); 622 (void) printf("-pendin "+((m&PENDIN) != 0)); 623 (void) printf("-iexten "+((m&IEXTEN) != 0)); 624 } 625 if (!(term & ASYNC)) { 626 (void) printf("-stflush "+((m&STFLUSH) != 0)); 627 (void) printf("-stwrap "+((m&STWRAP) != 0)); 628 (void) printf("-stappl "+((m&STAPPL) != 0)); 629 } 630 (void) printf("\n"); 631 m = cb.c_oflag; 632 (void) printf("-opost "+((m&OPOST) != 0)); 633 (void) printf("-olcuc "+((m&OLCUC) != 0)); 634 (void) printf("-onlcr "+((m&ONLCR) != 0)); 635 (void) printf("-ocrnl "+((m&OCRNL) != 0)); 636 (void) printf("-onocr "+((m&ONOCR) != 0)); 637 (void) printf("-onlret "+((m&ONLRET) != 0)); 638 (void) printf("-ofill "+((m&OFILL) != 0)); 639 (void) printf("-ofdel "+((m&OFDEL) != 0)); 640 delay((m&CRDLY)/CR1, "cr"); 641 delay((m&NLDLY)/NL1, "nl"); 642 delay((m&TABDLY)/TAB1, "tab"); 643 delay((m&BSDLY)/BS1, "bs"); 644 delay((m&VTDLY)/VT1, "vt"); 645 delay((m&FFDLY)/FF1, "ff"); 646 (void) printf("\n"); 647 if (term & FLOW) { 648 m = termiox.x_hflag; 649 (void) printf("-rtsxoff "+((m&RTSXOFF) != 0)); 650 (void) printf("-ctsxon "+((m&CTSXON) != 0)); 651 (void) printf("-dtrxoff "+((m&DTRXOFF) != 0)); 652 (void) printf("-cdxon "+((m&CDXON) != 0)); 653 (void) printf("-isxoff "+((m&ISXOFF) != 0)); 654 m = termiox.x_cflag; 655 switch (m & XMTCLK) { 656 case XCIBRG: (void)printf("xcibrg "); 657 break; 658 case XCTSET: (void)printf("xctset "); 659 break; 660 case XCRSET: (void)printf("xcrset "); 661 } 662 663 switch (m & RCVCLK) { 664 case RCIBRG: (void)printf("rcibrg "); 665 break; 666 case RCTSET: (void)printf("rctset "); 667 break; 668 case RCRSET: (void)printf("rcrset "); 669 } 670 671 switch (m & TSETCLK) { 672 case TSETCOFF: (void)printf("tsetcoff "); 673 break; 674 case TSETCRBRG: (void)printf("tsetcrbrg "); 675 break; 676 case TSETCTBRG: (void)printf("tsetctbrg "); 677 break; 678 case TSETCTSET: (void)printf("tsetctset "); 679 break; 680 case TSETCRSET: (void)printf("tsetcrset "); 681 } 682 683 switch (m & RSETCLK) { 684 case RSETCOFF: (void)printf("rsetcoff "); 685 break; 686 case RSETCRBRG: (void)printf("rsetcrbrg "); 687 break; 688 case RSETCTBRG: (void)printf("rsetctbrg "); 689 break; 690 case RSETCTSET: (void)printf("rsetctset "); 691 break; 692 case RSETCRSET: (void)printf("rsetcrset "); 693 } 694 (void) printf("\n"); 695 } 696 } 697 698 /* print function for prmodes() and pramodes() */ 699 void 700 pit(unsigned char what, char *itsname, char *sep) 701 { 702 703 pitt++; 704 (void) printf("%s", itsname); 705 if (((term & TERMIOS) && what == _POSIX_VDISABLE) || 706 (!(term & TERMIOS) && what == 0200)) { 707 (void) printf(" = <undef>%s", sep); 708 return; 709 } 710 (void) printf(" = "); 711 if (what & 0200 && !isprint(what)) { 712 (void) printf("-"); 713 what &= ~ 0200; 714 } 715 if (what == 0177) { 716 (void) printf("^?%s", sep); 717 return; 718 } else if (what < ' ') { 719 (void) printf("^"); 720 what += '`'; 721 if (what > 'z') 722 what -= 'a' -'A'; 723 } 724 (void) printf("%c%s", what, sep); 725 } 726 727 void 728 delay(int m, char *s) 729 { 730 if (m) 731 (void) printf("%s%d ", s, m); 732 } 733 734 void 735 prspeed(char *c, int scode) 736 { 737 int sval = -1; 738 int i; 739 740 for (i = 0; speeds[i].string; i++) { 741 if (speeds[i].code == scode) { 742 sval = speeds[i].value; 743 break; 744 } 745 } 746 747 (void) printf("%s%d baud; ", c, sval); 748 } 749 750 /* print current settings for use with */ 751 static void 752 prencode(void) /* another stty cmd, used for -g option */ 753 { 754 int i, last; 755 756 /* 757 * Although there are only 16 control chars defined as of April 1995, 758 * prencode() and encode() will not have to be changed if up to MAX_CC 759 * control chars are defined in the future. A maximum of MAX_CC rather 760 * than NCCS control chars are printed because the last control slot 761 * is unused. "stty -g" prints out a total of NUM_FIELDS fields 762 * (NUM_MODES modes + MAX_CC control chars). First print the input, 763 * output, control, and line discipline modes. 764 */ 765 (void) printf("%x:%x:%x:%x", cb.c_iflag, cb.c_oflag, cb.c_cflag, 766 cb.c_lflag); 767 768 /* Print the control character fields. */ 769 if (term & TERMIOS) 770 last = MAX_CC; 771 else 772 last = NCC; 773 #ifdef EUC 774 if (term & CSIW) { 775 for (i = 0; i < MAX_CC; i++) 776 (void) printf(":%x", (i >= last) ? 0 : cb.c_cc[i]); 777 /* 778 * Print out ldterm_cs_data_user_t data fields for 779 * PSARC/1999/140 TCR2. This change introduces additional 780 * 44 fields that come from the ldterm_cs_data_user_t data 781 * structure. 782 */ 783 (void) printf(":%x:%x:%x:", kcswp.version, kcswp.codeset_type, 784 kcswp.csinfo_num); 785 if (*kcswp.locale_name == '\0') { 786 (void) printf("00"); 787 } else { 788 for (i = 0; i < MAXNAMELEN && 789 kcswp.locale_name[i] != '\0'; i++) 790 (void) printf("%02x", kcswp.locale_name[i]); 791 } 792 for (i = 0; i < LDTERM_CS_MAX_CODESETS; i++) 793 (void) printf(":%x:%x:%x:%x", 794 kcswp.eucpc_data[i].byte_length, 795 kcswp.eucpc_data[i].screen_width, 796 kcswp.eucpc_data[i].msb_start, 797 kcswp.eucpc_data[i].msb_end); 798 } else { 799 #endif /* EUC */ 800 for (i = 0; i < last; i++) 801 (void) printf(":%x", cb.c_cc[i]); 802 #ifdef EUC 803 } 804 #endif /* EUC */ 805 (void) printf("\n"); 806 } 807