* 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. */
| 357 | * not, back up from the end by words until we find a place to split. |
| 358 | */ |
| 359 | static char * |
| 360 | split(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 |
no test coverage detected