| 6 |
* Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com> |
* Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com> |
| 7 |
*/ |
*/ |
| 8 |
|
|
| 9 |
|
#ifdef HAVE_CONFIG_H |
| 10 |
|
#include "config.h" |
| 11 |
|
#endif |
| 12 |
|
|
| 13 |
#include "article_cache.h" |
#include "article_cache.h" |
| 14 |
#include "lml.h" |
#include "lml.h" |
| 15 |
#include "log.h" |
#include "log.h" |
| 67 |
char header[ARTICLE_HEADER_MAX_LEN]; |
char header[ARTICLE_HEADER_MAX_LEN]; |
| 68 |
size_t header_len; |
size_t header_len; |
| 69 |
long header_line_cnt; |
long header_line_cnt; |
| 70 |
|
size_t body_len; |
| 71 |
|
long body_line_cnt; |
| 72 |
char footer[ARTICLE_FOOTER_MAX_LEN]; |
char footer[ARTICLE_FOOTER_MAX_LEN]; |
| 73 |
size_t footer_len; |
size_t footer_len; |
| 74 |
long footer_line_cnt; |
long footer_line_cnt; |
| 124 |
header_len = strnlen(header, sizeof(header)); |
header_len = strnlen(header, sizeof(header)); |
| 125 |
footer_len = strnlen(footer, sizeof(footer)); |
footer_len = strnlen(footer, sizeof(footer)); |
| 126 |
|
|
| 127 |
header_line_cnt = split_data_lines(header, SCREEN_COLS, cache.line_offsets, MAX_SPLIT_FILE_LINES, 1, NULL); |
header_line_cnt = split_data_lines(header, SCREEN_COLS, cache.line_offsets, |
| 128 |
|
MAX_SPLIT_FILE_LINES, 1, NULL); |
| 129 |
|
|
| 130 |
if (header_len != cache.line_offsets[header_line_cnt]) |
if (header_len != cache.line_offsets[header_line_cnt]) |
| 131 |
{ |
{ |
| 132 |
#ifdef _DEBUG |
#ifdef _DEBUG |
| 133 |
log_error("Header of article(aid=%d) is truncated from %ld to %ld\n", p_article->aid, header_len, cache.line_offsets[header_line_cnt]); |
log_error("Header of article(aid=%d) is truncated from %ld to %ld\n, body_line=%ld, body_line_limit=%ld", |
| 134 |
|
p_article->aid, header_len, cache.line_offsets[header_line_cnt], |
| 135 |
|
header_line_cnt, MAX_SPLIT_FILE_LINES); |
| 136 |
#endif |
#endif |
| 137 |
header_len = (size_t)cache.line_offsets[header_line_cnt]; |
header_len = (size_t)cache.line_offsets[header_line_cnt]; |
| 138 |
} |
} |
| 139 |
|
|
| 140 |
// Apply LML render to content body |
// Apply LML render to content body |
| 141 |
cache.data_len = header_len + (size_t)lml_render(content, content_f, ARTICLE_CONTENT_MAX_LEN, SCREEN_COLS, 0); |
body_len = (size_t)lml_render(content, content_f, ARTICLE_CONTENT_MAX_LEN, SCREEN_COLS, 0); |
| 142 |
|
cache.data_len = header_len + body_len; |
| 143 |
|
|
| 144 |
cache.line_total = header_line_cnt + |
body_line_cnt = split_data_lines(content_f, SCREEN_COLS + 1, &(cache.line_offsets[header_line_cnt]), |
| 145 |
split_data_lines(content_f, SCREEN_COLS + 1, cache.line_offsets + header_line_cnt, MAX_SPLIT_FILE_LINES - header_line_cnt, 1, NULL); |
MAX_SPLIT_FILE_LINES - header_line_cnt, 1, NULL); |
| 146 |
|
cache.line_total = header_line_cnt + body_line_cnt; |
| 147 |
|
|
| 148 |
if (cache.data_len - header_len != (size_t)cache.line_offsets[cache.line_total]) |
if (body_len != (size_t)cache.line_offsets[cache.line_total]) |
| 149 |
{ |
{ |
| 150 |
#ifdef _DEBUG |
#ifdef _DEBUG |
| 151 |
log_error("Body of article(aid=%d) is truncated from %ld to %ld\n", |
log_error("Body of article(aid=%d) is truncated from %ld to %ld, body_line=%ld, body_line_limit=%ld\n", |
| 152 |
p_article->aid, cache.data_len - header_len, cache.line_offsets[cache.line_total]); |
p_article->aid, body_len, cache.line_offsets[cache.line_total], |
| 153 |
|
body_line_cnt, MAX_SPLIT_FILE_LINES - header_line_cnt); |
| 154 |
#endif |
#endif |
| 155 |
cache.data_len = header_len + (size_t)(cache.line_offsets[cache.line_total]); |
cache.data_len = header_len + (size_t)(cache.line_offsets[cache.line_total]); |
| 156 |
} |
} |
| 160 |
cache.line_offsets[i] += (long)header_len; |
cache.line_offsets[i] += (long)header_len; |
| 161 |
} |
} |
| 162 |
|
|
| 163 |
footer_line_cnt = split_data_lines(footer, SCREEN_COLS, cache.line_offsets + cache.line_total, MAX_SPLIT_FILE_LINES - cache.line_total, 1, NULL); |
footer_line_cnt = split_data_lines(footer, SCREEN_COLS, &(cache.line_offsets[cache.line_total]), |
| 164 |
|
MAX_SPLIT_FILE_LINES - cache.line_total, 1, NULL); |
| 165 |
|
|
| 166 |
if (footer_len != cache.line_offsets[cache.line_total + footer_line_cnt]) |
if (footer_len != cache.line_offsets[cache.line_total + footer_line_cnt]) |
| 167 |
{ |
{ |
| 168 |
#ifdef _DEBUG |
#ifdef _DEBUG |
| 169 |
log_error("Footer of article(aid=%d) is truncated from %ld to %ld\n", |
log_error("Footer of article(aid=%d) is truncated from %ld to %ld, footer_line=%ld, footer_line_limit=%ld\n", |
| 170 |
p_article->aid, footer_len, cache.line_offsets[cache.line_total + footer_line_cnt]); |
p_article->aid, footer_len, cache.line_offsets[cache.line_total + footer_line_cnt], |
| 171 |
|
footer_line_cnt, MAX_SPLIT_FILE_LINES - cache.line_total); |
| 172 |
#endif |
#endif |
| 173 |
footer_len = (size_t)(cache.line_offsets[cache.line_total + footer_line_cnt]); |
footer_len = (size_t)(cache.line_offsets[cache.line_total + footer_line_cnt]); |
| 174 |
} |
} |