From d087e13f61c4a9b5060998f1fcf86efc2c46c348 Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Wed, 28 Feb 2018 09:10:27 +1000 Subject: [PATCH] experiments with word wrap --- src/www_msgs.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/www_msgs.c b/src/www_msgs.c index 56e70a3..f35a901 100644 --- a/src/www_msgs.c +++ b/src/www_msgs.c @@ -707,11 +707,12 @@ static char *www_wordwrap(char *content, int cutoff) { char *ret; int at = 0; int extra = 0; + int quote_line = 0; for (i=0;i' && line_count < 4) { + quote_line = 1; + } + if (content[i] == '\r' && content[i+1] != '\r') { - if (content[i+1] == ' ') { + if (content[i+1] == ' ' || quote_line == 1) { content[at++] = '\r'; + line_count = 0; + quote_line = 0; } else { if (at > 0 && content[at-1] != '\r' && content[at-1] != ' ') { content[at++] = ' '; + line_count++; } } } else if (content[i] == '\r' && content[i+1] == '\r') { content[at++] = '\r'; content[at++] = '\r'; + line_count = 0; + quote_line = 0; i++; } else { content[at++] = content[i]; + line_count++; } } //content[at++] = content[i]; @@ -748,6 +759,9 @@ static char *www_wordwrap(char *content, int cutoff) { return NULL; } + line_count = 0; + quote_line = 0; + for (i=0;i' && line_count < 4) { + quote_line = 1; + ret[at++] = content[i]; } else { ret[at++] = content[i]; } @@ -764,12 +780,21 @@ static char *www_wordwrap(char *content, int cutoff) { if (content[i] == '\r') { line_count = 0; last_space = NULL; + quote_line == 0; } else if (line_count == cutoff) { // wrap - if (last_space != NULL) { + if (quote_line == 1) { + while (content[i] != '\r') { + i++; + } + last_space = NULL; + line_count = 0; + quote_line = 0; + } else if (last_space != NULL) { *last_space = '\r'; line_count = strlen(&last_space[1]); last_space = NULL; + quote_line = 0; } else { extra++; ret = (char *)realloc(ret, strlen(content) + extra + 1); @@ -780,6 +805,7 @@ static char *www_wordwrap(char *content, int cutoff) { ret[at] = '\0'; last_space = NULL; line_count = 0; + quote_line = 0; } } else { line_count++;