tty_setup(): * Get the tty parameters and initialize the editing state */
| 492 | * Get the tty parameters and initialize the editing state |
| 493 | */ |
| 494 | private int |
| 495 | tty_setup(EditLine *el) |
| 496 | { |
| 497 | int rst = 1; |
| 498 | |
| 499 | if (el->el_flags & EDIT_DISABLED) |
| 500 | return 0; |
| 501 | |
| 502 | if (!isatty(el->el_outfd)) { |
| 503 | #ifdef DEBUG_TTY |
| 504 | (void) fprintf(el->el_errfile, "%s: isatty: %s\n", __func__, |
| 505 | strerror(errno)); |
| 506 | #endif /* DEBUG_TTY */ |
| 507 | return -1; |
| 508 | } |
| 509 | if (tty_getty(el, &el->el_tty.t_or) == -1) { |
| 510 | #ifdef DEBUG_TTY |
| 511 | (void) fprintf(el->el_errfile, "%s: tty_getty: %s\n", __func__, |
| 512 | strerror(errno)); |
| 513 | #endif /* DEBUG_TTY */ |
| 514 | return -1; |
| 515 | } |
| 516 | el->el_tty.t_ts = el->el_tty.t_ex = el->el_tty.t_ed = el->el_tty.t_or; |
| 517 | |
| 518 | el->el_tty.t_speed = tty__getspeed(&el->el_tty.t_ex); |
| 519 | el->el_tty.t_tabs = tty__gettabs(&el->el_tty.t_ex); |
| 520 | el->el_tty.t_eight = tty__geteightbit(&el->el_tty.t_ex); |
| 521 | |
| 522 | tty_setup_flags(el, &el->el_tty.t_ex, EX_IO); |
| 523 | |
| 524 | /* |
| 525 | * Reset the tty chars to reasonable defaults |
| 526 | * If they are disabled, then enable them. |
| 527 | */ |
| 528 | if (rst) { |
| 529 | if (tty__cooked_mode(&el->el_tty.t_ts)) { |
| 530 | tty__getchar(&el->el_tty.t_ts, el->el_tty.t_c[TS_IO]); |
| 531 | /* |
| 532 | * Don't affect CMIN and CTIME for the editor mode |
| 533 | */ |
| 534 | for (rst = 0; rst < C_NCC - 2; rst++) |
| 535 | if (el->el_tty.t_c[TS_IO][rst] != |
| 536 | el->el_tty.t_vdisable |
| 537 | && el->el_tty.t_c[ED_IO][rst] != |
| 538 | el->el_tty.t_vdisable) |
| 539 | el->el_tty.t_c[ED_IO][rst] = |
| 540 | el->el_tty.t_c[TS_IO][rst]; |
| 541 | for (rst = 0; rst < C_NCC; rst++) |
| 542 | if (el->el_tty.t_c[TS_IO][rst] != |
| 543 | el->el_tty.t_vdisable) |
| 544 | el->el_tty.t_c[EX_IO][rst] = |
| 545 | el->el_tty.t_c[TS_IO][rst]; |
| 546 | } |
| 547 | tty__setchar(&el->el_tty.t_ex, el->el_tty.t_c[EX_IO]); |
| 548 | if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ex) == -1) { |
| 549 | #ifdef DEBUG_TTY |
| 550 | (void) fprintf(el->el_errfile, "%s: tty_setty: %s\n", |
| 551 | __func__, strerror(errno)); |
no test coverage detected