expand tabs into proper number of spaces (in place) */
| 426 | |
| 427 | /* expand tabs into proper number of spaces (in place) */ |
| 428 | char * |
| 429 | tabexpand( |
| 430 | char *sbuf) /* assumed to be [BUFSZ] but can be smaller provided that |
| 431 | * expanded string fits; expansion bigger than BUFSZ-1 |
| 432 | * will be truncated */ |
| 433 | { |
| 434 | char buf[BUFSZ + 10]; |
| 435 | char *bp, *s = sbuf; |
| 436 | int idx; |
| 437 | |
| 438 | if (!*s) |
| 439 | return sbuf; |
| 440 | for (bp = buf, idx = 0; *s; s++) { |
| 441 | if (*s == '\t') { |
| 442 | /* |
| 443 | * clang-8's optimizer at -Os has been observed to mis-compile |
| 444 | * this code. Symptom is nethack getting stuck in an apparent |
| 445 | * infinite loop (or perhaps just an extremely long one) when |
| 446 | * examining data.base entries. |
| 447 | * clang-9 doesn't exhibit this problem. [Was the incorrect |
| 448 | * optimization fixed or just disabled?] |
| 449 | */ |
| 450 | do |
| 451 | *bp++ = ' '; |
| 452 | while (++idx % 8); |
| 453 | } else { |
| 454 | *bp++ = *s; |
| 455 | ++idx; |
| 456 | } |
| 457 | if (idx >= BUFSZ) { |
| 458 | bp = &buf[BUFSZ - 1]; |
| 459 | break; |
| 460 | } |
| 461 | } |
| 462 | *bp = 0; |
| 463 | return strcpy(sbuf, buf); |
| 464 | } |
| 465 | |
| 466 | #define VISCTRL_NBUF 5 |
| 467 | /* make a displayable string from a character */ |
no outgoing calls
no test coverage detected