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

Function split

win/X11/winmesg.c:359–383  ·  view source on GitHub ↗

* Make sure the given string is shorter than the given pixel width. If * not, back up from the end by words until we find a place to split. */

Source from the content-addressed store, hash-verified

357 * not, back up from the end by words until we find a place to split.
358 */
359static char *
360split(char *s,
361 XFontStruct *fs, /* Font for the window. */
362 Dimension pixel_width)
363{
364 char save, *end, *remainder;
365
366 save = '\0';
367 remainder = 0;
368 end = eos(s); /* point to null at end of string */
369
370 /* assume that if end == s, XXXXXX returns 0) */
371 while ((Dimension) XTextWidth(fs, s, (int) strlen(s)) > pixel_width) {
372 *end-- = save;
373 while (*end != ' ') {
374 if (end == s)
375 panic("split: eos!");
376 --end;
377 }
378 save = *end;
379 *end = '\0';
380 remainder = end + 1;
381 }
382 return remainder;
383}
384
385/*
386 * Add a line of text to the window. The first line in the circular list

Callers 1

append_messageFunction · 0.85

Calls 2

eosFunction · 0.85
panicFunction · 0.50

Tested by

no test coverage detected