fiddling with word wrap

This commit is contained in:
Andrew Pamment 2018-02-27 21:36:32 +10:00
parent 4aa2c4f6c1
commit 50d2bab142
2 changed files with 33 additions and 8 deletions

View File

@ -62,7 +62,7 @@ char *www_blog() {
strcat(page, buffer);
len += strlen(buffer);
sprintf(buffer, "<div class=\"blog-entry\">");
sprintf(buffer, "<div class=\"blog-entry\"><p>");
if (len + strlen(buffer) > max_len - 1) {
max_len += 4096;
page = (char *)realloc(page, max_len);
@ -72,13 +72,22 @@ char *www_blog() {
for (j=0;j<strlen(blog_entries[i]->body);j++) {
if (blog_entries[i]->body[j] == '\r') {
sprintf(buffer, "<br />");
if (len + strlen(buffer) > max_len - 1) {
max_len += 4096;
page = (char *)realloc(page, max_len);
if (blog_entries[i]->body[j+1] == '\r') {
sprintf(buffer, "</p><p>");
if (len + strlen(buffer) > max_len - 1) {
max_len += 4096;
page = (char *)realloc(page, max_len);
}
strcat(page, buffer);
len += strlen(buffer);
} else {
if (len + 1 > max_len - 1) {
max_len += 4096;
page = (char *)realloc(page, max_len);
}
page[len++] = ' ';
page[len] = '\0';
}
strcat(page, buffer);
len += strlen(buffer);
} else {
if (len + 1 > max_len - 1) {
max_len += 4096;
@ -88,7 +97,7 @@ char *www_blog() {
page[len] = '\0';
}
}
sprintf(buffer, "</div>");
sprintf(buffer, "</p></div>");
if (len + strlen(buffer) > max_len - 1) {
max_len += 4096;
page = (char *)realloc(page, max_len);

View File

@ -710,6 +710,22 @@ static char *www_wordwrap(char *content, int cutoff) {
if (ret == NULL) {
return NULL;
}
at = 0;
for (i=0;i<len;i++) {
if (content[i] == '\r' && content[i+1] != '\r') {
content[at++] = ' ';
content[at++] = content[i+1];
i++;
} else if (content[i] == '\r' && content[i+1] == '\r') {
content[at++] = '\r';
i++;
} else {
content[at++] = content[i];
}
}
content[at] = '\0';
at = 0;
for (i=0;i<len;i++) {
if (content[i] == '\n') {