MCPcopy Index your code
hub / github.com/NetHack/NetHack / tabexpand

Function tabexpand

src/hacklib.c:428–464  ·  view source on GitHub ↗

expand tabs into proper number of spaces (in place) */

Source from the content-addressed store, hash-verified

426
427/* expand tabs into proper number of spaces (in place) */
428char *
429tabexpand(
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 */

Callers 7

tty_display_fileFunction · 0.85
qt_display_fileMethod · 0.85
doextversionFunction · 0.85
checkfileFunction · 0.85
dowhatdoes_coreFunction · 0.85
qt_display_fileMethod · 0.85
Gem_display_fileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected