MCPcopy Create free account
hub / github.com/NetHack/NetHack / compress_str

Function compress_str

win/tty/wintty.c:2195–2223  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2193#endif
2194
2195static const char *
2196compress_str(const char *str)
2197{
2198 static char cbuf[BUFSZ];
2199
2200 /* compress out consecutive spaces if line is too long;
2201 topline wrapping converts space at wrap point into newline,
2202 we reverse that here */
2203 if ((int) strlen(str) >= CO || strchr(str, '\n')) {
2204 const char *in_str = str;
2205 char c, *outstr = cbuf, *outend = &cbuf[sizeof cbuf - 1];
2206 boolean was_space = TRUE; /* True discards all leading spaces;
2207 False would retain one if present */
2208
2209 while ((c = *in_str++) != '\0' && outstr < outend) {
2210 if (c == '\n')
2211 c = ' ';
2212 if (was_space && c == ' ')
2213 continue;
2214 *outstr++ = c;
2215 was_space = (c == ' ');
2216 }
2217 if ((was_space && outstr > cbuf) || outstr == outend)
2218 --outstr; /* remove trailing space or make room for terminator */
2219 *outstr = '\0';
2220 str = cbuf;
2221 }
2222 return str;
2223}
2224
2225void
2226tty_putstr(winid window, int attr, const char *str)

Callers 1

tty_putstrFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected