| 381 | } |
| 382 | |
| 383 | static int ttydisc_write_oproc(struct lwp_tty *tp, char c) |
| 384 | { |
| 385 | unsigned int scnt, error; |
| 386 | |
| 387 | MPASS(CMP_FLAG(o, OPOST)); |
| 388 | MPASS(CTL_VALID(c)); |
| 389 | |
| 390 | #define PRINT_NORMAL() ttyoutq_write_nofrag(&tp->t_outq, &c, 1) |
| 391 | switch (c) |
| 392 | { |
| 393 | case CEOF: |
| 394 | /* End-of-text dropping. */ |
| 395 | if (CMP_FLAG(o, ONOEOT)) |
| 396 | return 0; |
| 397 | return PRINT_NORMAL(); |
| 398 | |
| 399 | case CERASE2: |
| 400 | /* Handle backspace to fix tab expansion. */ |
| 401 | if (PRINT_NORMAL() != 0) |
| 402 | return (-1); |
| 403 | if (tp->t_column > 0) |
| 404 | tp->t_column--; |
| 405 | return 0; |
| 406 | |
| 407 | case CTAB: |
| 408 | /* Tab expansion. */ |
| 409 | scnt = 8 - (tp->t_column & 7); |
| 410 | if (CMP_FLAG(o, TAB3)) |
| 411 | { |
| 412 | error = ttyoutq_write_nofrag(&tp->t_outq, " ", scnt); |
| 413 | } |
| 414 | else |
| 415 | { |
| 416 | error = PRINT_NORMAL(); |
| 417 | } |
| 418 | if (error) |
| 419 | return (-1); |
| 420 | |
| 421 | tp->t_column += scnt; |
| 422 | MPASS((tp->t_column % 8) == 0); |
| 423 | return 0; |
| 424 | |
| 425 | case CNL: |
| 426 | /* Newline conversion. */ |
| 427 | if (CMP_FLAG(o, ONLCR)) |
| 428 | { |
| 429 | /* Convert \n to \r\n. */ |
| 430 | error = ttyoutq_write_nofrag(&tp->t_outq, "\r\n", 2); |
| 431 | } |
| 432 | else |
| 433 | { |
| 434 | error = PRINT_NORMAL(); |
| 435 | } |
| 436 | if (error) |
| 437 | return (-1); |
| 438 | |
| 439 | if (CMP_FLAG(o, ONLCR | ONLRET)) |
| 440 | { |
no test coverage detected