#include "util.h" void string_truncate(char *string, size_t max_len) { size_t len = strlen(string) + 1; if (len <= max_len) return; strncpy(&string[max_len - 4], "...\0", 4); } void string_wrap(char *string, size_t max_len, size_t max_lines) { char *line = string; for (size_t i = 1; i < max_lines; i++) { char *p = line; char *prev; do { prev = p; p = strchr(prev+1, ' '); } while (p && p - line < (int)max_len); if (!p && strlen(line) < max_len) break; if (prev && prev != line) { line = prev + 1; *prev = '\n'; } } string_truncate(line, max_len); }