| 24 |
#define LML_TAG_PARAM_BUF_LEN 256 |
#define LML_TAG_PARAM_BUF_LEN 256 |
| 25 |
#define LML_TAG_OUTPUT_BUF_LEN 1024 |
#define LML_TAG_OUTPUT_BUF_LEN 1024 |
| 26 |
|
|
| 27 |
typedef int (*lml_tag_filter_cb)(const char *tag_name, const char *tag_param_buf, char *tag_output_buf, size_t tag_output_buf_len); |
typedef int (*lml_tag_filter_cb)(const char *tag_name, const char *tag_param_buf, char *tag_output_buf, size_t tag_output_buf_len, int quote_mode); |
| 28 |
|
|
| 29 |
static int lml_tag_color_filter(const char *tag_name, const char *tag_param_buf, char *tag_output_buf, size_t tag_output_buf_len) |
static int lml_tag_color_filter(const char *tag_name, const char *tag_param_buf, char *tag_output_buf, size_t tag_output_buf_len, int quote_mode) |
| 30 |
{ |
{ |
| 31 |
if (strcasecmp(tag_name, "color") == 0) |
if (strcasecmp(tag_name, "color") == 0) |
| 32 |
{ |
{ |
| 63 |
} |
} |
| 64 |
|
|
| 65 |
#define LML_TAG_QUOTE_MAX_LEVEL 10 |
#define LML_TAG_QUOTE_MAX_LEVEL 10 |
|
#define LML_TAG_QUOTE_LEVEL_LOOP 3 |
|
| 66 |
|
|
| 67 |
static const char *lml_tag_quote_color[] = { |
static const char *lml_tag_quote_color[] = { |
| 68 |
"\033[33m", // yellow |
"\033[33m", // yellow |
| 70 |
"\033[35m", // magenta |
"\033[35m", // magenta |
| 71 |
}; |
}; |
| 72 |
|
|
| 73 |
|
static const int LML_TAG_QUOTE_LEVEL_LOOP = (int)(sizeof(lml_tag_quote_color) / sizeof(const char *)); |
| 74 |
|
|
| 75 |
static int lml_tag_quote_level = 0; |
static int lml_tag_quote_level = 0; |
| 76 |
|
|
| 77 |
static int lml_tag_quote_filter(const char *tag_name, const char *tag_param_buf, char *tag_output_buf, size_t tag_output_buf_len) |
static int lml_tag_quote_filter(const char *tag_name, const char *tag_param_buf, char *tag_output_buf, size_t tag_output_buf_len, int quote_mode) |
| 78 |
{ |
{ |
| 79 |
if (strcasecmp(tag_name, "quote") == 0) |
if (strcasecmp(tag_name, "quote") == 0) |
| 80 |
{ |
{ |
| 98 |
return 0; |
return 0; |
| 99 |
} |
} |
| 100 |
|
|
| 101 |
const static char *LML_tag_def[][4] = { |
static int lml_tag_disabled = 0; |
| 102 |
// Definition of tuple: {lml_tag, lml_output, default_param | lml_filter_cb, no_lml_output} |
|
| 103 |
{"left", "[", "", "[left]"}, |
static int lml_tag_disable_filter(const char *tag_name, const char *tag_param_buf, char *tag_output_buf, size_t tag_output_buf_len, int quote_mode) |
| 104 |
{"right", "]", "", "[right]"}, |
{ |
| 105 |
{"bold", "\033[1m", "", ""}, // does not work in Fterm |
lml_tag_disabled = 1; |
| 106 |
{"/bold", "\033[22m", NULL, ""}, |
|
| 107 |
{"b", "\033[1m", "", ""}, |
return snprintf(tag_output_buf, tag_output_buf_len, "%s", (quote_mode ? "[plain]" : "")); |
| 108 |
{"/b", "\033[22m", NULL, ""}, |
} |
| 109 |
{"italic", "\033[5m", "", ""}, // use blink instead |
|
| 110 |
{"/italic", "\033[m", NULL, ""}, // \033[25m does not work in Fterm |
typedef struct lml_tag_def_t |
| 111 |
{"i", "\033[5m", "", ""}, |
{ |
| 112 |
{"/i", "\033[m", NULL, ""}, |
const char *tag_name; // tag name |
| 113 |
{"underline", "\033[4m", "", ""}, |
const char *tag_output; // output string |
| 114 |
{"/underline", "\033[m", NULL, ""}, // \033[24m does not work in Fterm |
const char *default_param; // default param string |
| 115 |
{"u", "\033[4m", "", ""}, |
const char *quote_mode_output; // output string in quote mode |
| 116 |
{"/u", "\033[m", NULL, ""}, |
lml_tag_filter_cb tag_filter_cb; // tag filter callback |
| 117 |
{"color", NULL, (const char *)lml_tag_color_filter, ""}, |
} LML_TAG_DEF; |
| 118 |
{"/color", "\033[m", NULL, ""}, |
|
| 119 |
{"quote", NULL, (const char *)lml_tag_quote_filter, ""}, |
const LML_TAG_DEF lml_tag_def[] = { |
| 120 |
{"/quote", NULL, (const char *)lml_tag_quote_filter, ""}, |
// Definition of tuple: {lml_tag, lml_output, default_param, quote_mode_output, lml_filter_cb} |
| 121 |
{"url", "", "", ""}, |
{"plain", NULL, NULL, NULL, lml_tag_disable_filter}, |
| 122 |
{"/url", "(链接: %s)", NULL, ""}, |
{"nolml", "", NULL, "", NULL}, // deprecated |
| 123 |
{"link", "", ""}, |
{"lml", "", NULL, "", NULL}, // deprecated |
| 124 |
{"/link", "(链接: %s)", NULL, ""}, |
{"align", "", "", "", NULL}, // N/A |
| 125 |
{"email", "", ""}, |
{"/align", "", "", "", NULL}, // N/A |
| 126 |
{"/email", "(Email: %s)", NULL, ""}, |
{"size", "", "", "", NULL}, // N/A |
| 127 |
{"user", "", ""}, |
{"/size", "", "", "", NULL}, // N/A |
| 128 |
{"/user", "(用户: %s)", NULL, ""}, |
{"left", "[", "", "[left]", NULL}, |
| 129 |
{"article", "", ""}, |
{"right", "]", "", "[right]", NULL}, |
| 130 |
{"/article", "(文章: %s)", NULL, ""}, |
{"bold", "\033[1m", "", "", NULL}, // does not work in Fterm |
| 131 |
{"image", "(图片: %s)", "", "%s"}, |
{"/bold", "\033[22m", NULL, "", NULL}, |
| 132 |
{"flash", "(Flash: %s)", "", ""}, |
{"b", "\033[1m", "", "", NULL}, |
| 133 |
{"bwf", "\033[1;31m****\033[m", "", "****"}, |
{"/b", "\033[22m", NULL, "", NULL}, |
| 134 |
|
{"italic", "\033[5m", "", "", NULL}, // use blink instead |
| 135 |
|
{"/italic", "\033[m", NULL, "", NULL}, // \033[25m does not work in Fterm |
| 136 |
|
{"i", "\033[5m", "", "", NULL}, |
| 137 |
|
{"/i", "\033[m", NULL, "", NULL}, |
| 138 |
|
{"underline", "\033[4m", "", "", NULL}, |
| 139 |
|
{"/underline", "\033[m", NULL, "", NULL}, // \033[24m does not work in Fterm |
| 140 |
|
{"u", "\033[4m", "", "", NULL}, |
| 141 |
|
{"/u", "\033[m", NULL, "", NULL}, |
| 142 |
|
{"color", NULL, NULL, "", lml_tag_color_filter}, |
| 143 |
|
{"/color", "\033[m", NULL, "", NULL}, |
| 144 |
|
{"quote", NULL, NULL, "", lml_tag_quote_filter}, |
| 145 |
|
{"/quote", NULL, NULL, "", lml_tag_quote_filter}, |
| 146 |
|
{"url", "", "", "", NULL}, |
| 147 |
|
{"/url", "(链接: %s)", NULL, "", NULL}, |
| 148 |
|
{"link", "", "", "", NULL}, |
| 149 |
|
{"/link", "(链接: %s)", NULL, "", NULL}, |
| 150 |
|
{"email", "", "", "", NULL}, |
| 151 |
|
{"/email", "(Email: %s)", NULL, "", NULL}, |
| 152 |
|
{"user", "", "", "", NULL}, |
| 153 |
|
{"/user", "(用户: %s)", NULL, "", NULL}, |
| 154 |
|
{"article", "", "", "", NULL}, |
| 155 |
|
{"/article", "(文章: %s)", NULL, "", NULL}, |
| 156 |
|
{"image", "(图片: %s)", "", "%s", NULL}, |
| 157 |
|
{"flash", "(Flash: %s)", "", "", NULL}, |
| 158 |
|
{"bwf", "\033[1;31m****\033[m", "", "****", NULL}, |
| 159 |
}; |
}; |
| 160 |
|
|
| 161 |
#define LML_TAG_COUNT 31 |
#define LML_TAG_COUNT (sizeof(lml_tag_def) / sizeof(LML_TAG_DEF)) |
| 162 |
|
|
| 163 |
static int LML_tag_name_len[LML_TAG_COUNT]; |
static int lml_tag_name_len[LML_TAG_COUNT]; |
| 164 |
static int LML_init = 0; |
static int lml_ready = 0; |
| 165 |
|
|
| 166 |
inline static void lml_init(void) |
inline static void lml_init(void) |
| 167 |
{ |
{ |
| 168 |
int i; |
int i; |
| 169 |
|
|
| 170 |
if (!LML_init) |
if (!lml_ready) |
| 171 |
{ |
{ |
| 172 |
for (i = 0; i < LML_TAG_COUNT; i++) |
for (i = 0; i < LML_TAG_COUNT; i++) |
| 173 |
{ |
{ |
| 174 |
LML_tag_name_len[i] = (int)strlen(LML_tag_def[i][0]); |
lml_tag_name_len[i] = (int)strlen(lml_tag_def[i].tag_name); |
| 175 |
} |
} |
| 176 |
|
|
| 177 |
LML_init = 1; |
lml_ready = 1; |
| 178 |
} |
} |
| 179 |
} |
} |
| 180 |
|
|
| 181 |
int lml_render(const char *str_in, char *str_out, int buf_len, int lml_tag) |
int lml_render(const char *str_in, char *str_out, int buf_len, int quote_mode) |
| 182 |
{ |
{ |
| 183 |
char c; |
char c; |
| 184 |
char tag_param_buf[LML_TAG_PARAM_BUF_LEN]; |
char tag_param_buf[LML_TAG_PARAM_BUF_LEN]; |
| 187 |
int j = 0; |
int j = 0; |
| 188 |
int k; |
int k; |
| 189 |
int tag_start_pos = -1; |
int tag_start_pos = -1; |
| 190 |
|
int tag_name_pos = -1; |
| 191 |
int tag_end_pos = -1; |
int tag_end_pos = -1; |
| 192 |
int tag_param_pos = -1; |
int tag_param_pos = -1; |
| 193 |
int tag_output_len; |
int tag_output_len; |
| 194 |
int new_line = 1; |
int new_line = 1; |
| 195 |
int fb_quote_level = 0; |
int fb_quote_level = 0; |
| 196 |
|
int tag_name_found; |
| 197 |
|
|
| 198 |
lml_init(); |
lml_init(); |
| 199 |
|
|
| 200 |
|
lml_tag_disabled = 0; |
| 201 |
lml_tag_quote_level = 0; |
lml_tag_quote_level = 0; |
| 202 |
|
|
| 203 |
for (i = 0; str_in[i] != '\0'; i++) |
for (i = 0; str_in[i] != '\0'; i++) |
| 204 |
{ |
{ |
| 205 |
if (lml_tag && new_line) |
if (!quote_mode && !lml_tag_disabled && new_line) |
| 206 |
{ |
{ |
| 207 |
if (fb_quote_level > 0) |
if (fb_quote_level > 0) |
| 208 |
{ |
{ |
| 232 |
lml_tag_quote_level += fb_quote_level; |
lml_tag_quote_level += fb_quote_level; |
| 233 |
|
|
| 234 |
tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, "%s", |
tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, "%s", |
| 235 |
lml_tag_quote_color[(lml_tag_quote_level) % LML_TAG_QUOTE_LEVEL_LOOP]); |
lml_tag_quote_color[lml_tag_quote_level % LML_TAG_QUOTE_LEVEL_LOOP]); |
| 236 |
if (j + tag_output_len >= buf_len) |
if (j + tag_output_len >= buf_len) |
| 237 |
{ |
{ |
| 238 |
log_error("Buffer is not longer enough for output string %d >= %d\n", j + tag_output_len, buf_len); |
log_error("Buffer is not longer enough for output string %d >= %d\n", j + tag_output_len, buf_len); |
| 270 |
} |
} |
| 271 |
} |
} |
| 272 |
|
|
| 273 |
if (str_in[i] == '\n') |
if (str_in[i] == '\n') // jump out of tag at end of line |
| 274 |
{ |
{ |
| 275 |
tag_start_pos = -1; // jump out of tag at end of line |
if (tag_start_pos != -1) // tag is not closed |
| 276 |
|
{ |
| 277 |
|
tag_end_pos = i - 1; |
| 278 |
|
tag_output_len = tag_end_pos - tag_start_pos + 1; |
| 279 |
|
if (j + tag_output_len >= buf_len) |
| 280 |
|
{ |
| 281 |
|
log_error("Buffer is not longer enough for output string %ld >= %d\n", j + tag_output_len, buf_len); |
| 282 |
|
str_out[j] = '\0'; |
| 283 |
|
return j; |
| 284 |
|
} |
| 285 |
|
|
| 286 |
|
memcpy(str_out + j, str_in + tag_start_pos, (size_t)tag_output_len); |
| 287 |
|
j += tag_output_len; |
| 288 |
|
} |
| 289 |
|
|
| 290 |
|
tag_start_pos = -1; |
| 291 |
|
tag_name_pos = -1; |
| 292 |
new_line = 1; |
new_line = 1; |
| 293 |
} |
} |
| 294 |
else if (str_in[i] == '\r') |
else if (str_in[i] == '\r') |
| 296 |
continue; // ignore '\r' |
continue; // ignore '\r' |
| 297 |
} |
} |
| 298 |
|
|
| 299 |
if (str_in[i] == '[') |
if (!lml_tag_disabled && str_in[i] == '[') |
| 300 |
{ |
{ |
| 301 |
tag_start_pos = i + 1; |
tag_start_pos = i; |
| 302 |
|
tag_name_pos = i + 1; |
| 303 |
} |
} |
| 304 |
else if (str_in[i] == ']') |
else if (!lml_tag_disabled && str_in[i] == ']' && tag_name_pos >= 0) |
| 305 |
{ |
{ |
| 306 |
if (tag_start_pos >= 0) |
tag_end_pos = i; |
|
{ |
|
|
tag_end_pos = i; |
|
| 307 |
|
|
| 308 |
// Skip space characters |
// Skip space characters |
| 309 |
while (str_in[tag_start_pos] == ' ') |
while (str_in[tag_name_pos] == ' ') |
| 310 |
{ |
{ |
| 311 |
tag_start_pos++; |
tag_name_pos++; |
| 312 |
} |
} |
| 313 |
|
|
| 314 |
for (k = 0; k < LML_TAG_COUNT; k++) |
for (tag_name_found = 0, k = 0; k < LML_TAG_COUNT; k++) |
| 315 |
|
{ |
| 316 |
|
if (strncasecmp(lml_tag_def[k].tag_name, str_in + tag_name_pos, (size_t)lml_tag_name_len[k]) == 0) |
| 317 |
{ |
{ |
| 318 |
if (strncasecmp(LML_tag_def[k][0], str_in + tag_start_pos, (size_t)LML_tag_name_len[k]) == 0) |
tag_param_pos = -1; |
| 319 |
|
switch (str_in[tag_name_pos + lml_tag_name_len[k]]) |
| 320 |
{ |
{ |
| 321 |
tag_param_pos = -1; |
case ' ': |
| 322 |
switch (str_in[tag_start_pos + LML_tag_name_len[k]]) |
tag_name_found = 1; |
| 323 |
|
tag_param_pos = tag_name_pos + lml_tag_name_len[k] + 1; |
| 324 |
|
while (str_in[tag_param_pos] == ' ') |
| 325 |
|
{ |
| 326 |
|
tag_param_pos++; |
| 327 |
|
} |
| 328 |
|
strncpy(tag_param_buf, str_in + tag_param_pos, (size_t)MIN(tag_end_pos - tag_param_pos, LML_TAG_PARAM_BUF_LEN)); |
| 329 |
|
tag_param_buf[MIN(tag_end_pos - tag_param_pos, LML_TAG_PARAM_BUF_LEN)] = '\0'; |
| 330 |
|
case ']': |
| 331 |
|
tag_name_found = 1; |
| 332 |
|
if (tag_param_pos == -1 && lml_tag_def[k].tag_output != NULL && lml_tag_def[k].default_param != NULL) // Apply default param if not defined |
| 333 |
|
{ |
| 334 |
|
strncpy(tag_param_buf, lml_tag_def[k].default_param, LML_TAG_PARAM_BUF_LEN - 1); |
| 335 |
|
tag_param_buf[LML_TAG_PARAM_BUF_LEN - 1] = '\0'; |
| 336 |
|
} |
| 337 |
|
if (!quote_mode) |
| 338 |
{ |
{ |
| 339 |
case ' ': |
if (lml_tag_def[k].tag_output != NULL) |
|
tag_param_pos = tag_start_pos + LML_tag_name_len[k] + 1; |
|
|
while (str_in[tag_param_pos] == ' ') |
|
| 340 |
{ |
{ |
| 341 |
tag_param_pos++; |
tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, lml_tag_def[k].tag_output, tag_param_buf); |
| 342 |
} |
} |
| 343 |
strncpy(tag_param_buf, str_in + tag_param_pos, (size_t)MIN(tag_end_pos - tag_param_pos, LML_TAG_PARAM_BUF_LEN)); |
else if (lml_tag_def[k].tag_filter_cb != NULL) |
|
tag_param_buf[MIN(tag_end_pos - tag_param_pos, LML_TAG_PARAM_BUF_LEN)] = '\0'; |
|
|
case ']': |
|
|
if (tag_param_pos == -1 && LML_tag_def[k][1] != NULL && LML_tag_def[k][2] != NULL) // Apply default param if not defined |
|
| 344 |
{ |
{ |
| 345 |
strncpy(tag_param_buf, LML_tag_def[k][2], LML_TAG_PARAM_BUF_LEN - 1); |
tag_output_len = lml_tag_def[k].tag_filter_cb( |
| 346 |
tag_param_buf[LML_TAG_PARAM_BUF_LEN - 1] = '\0'; |
lml_tag_def[k].tag_name, tag_param_buf, tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, 0); |
| 347 |
} |
} |
| 348 |
if (lml_tag) |
else |
| 349 |
{ |
{ |
| 350 |
if (LML_tag_def[k][1] != NULL) |
tag_output_len = 0; |
|
{ |
|
|
tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, LML_tag_def[k][1], tag_param_buf); |
|
|
} |
|
|
else |
|
|
{ |
|
|
tag_output_len = ((lml_tag_filter_cb)LML_tag_def[k][2])( |
|
|
LML_tag_def[k][0], tag_param_buf, tag_output_buf, LML_TAG_OUTPUT_BUF_LEN); |
|
|
} |
|
| 351 |
} |
} |
| 352 |
else |
} |
| 353 |
|
else // if (quote_mode) |
| 354 |
|
{ |
| 355 |
|
if (lml_tag_def[k].quote_mode_output != NULL) |
| 356 |
{ |
{ |
| 357 |
if (LML_tag_def[k][3] != NULL) |
tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, lml_tag_def[k].quote_mode_output, tag_param_buf); |
|
{ |
|
|
tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, LML_tag_def[k][3], tag_param_buf); |
|
|
} |
|
|
else |
|
|
{ |
|
|
tag_output_len = 0; |
|
|
} |
|
| 358 |
} |
} |
| 359 |
if (j + tag_output_len >= buf_len) |
else if (lml_tag_def[k].tag_filter_cb != NULL) |
| 360 |
|
{ |
| 361 |
|
tag_output_len = lml_tag_def[k].tag_filter_cb( |
| 362 |
|
lml_tag_def[k].tag_name, tag_param_buf, tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, 1); |
| 363 |
|
} |
| 364 |
|
else |
| 365 |
{ |
{ |
| 366 |
log_error("Buffer is not longer enough for output string %d >= %d\n", j + tag_output_len, buf_len); |
tag_output_len = 0; |
|
str_out[j] = '\0'; |
|
|
return j; |
|
| 367 |
} |
} |
|
memcpy(str_out + j, tag_output_buf, (size_t)tag_output_len); |
|
|
j += tag_output_len; |
|
|
break; |
|
|
default: // tag_name not match |
|
|
continue; |
|
| 368 |
} |
} |
| 369 |
|
if (j + tag_output_len >= buf_len) |
| 370 |
|
{ |
| 371 |
|
log_error("Buffer is not longer enough for output string %d >= %d\n", j + tag_output_len, buf_len); |
| 372 |
|
str_out[j] = '\0'; |
| 373 |
|
return j; |
| 374 |
|
} |
| 375 |
|
memcpy(str_out + j, tag_output_buf, (size_t)tag_output_len); |
| 376 |
|
j += tag_output_len; |
| 377 |
break; |
break; |
| 378 |
|
default: // tag_name not match |
| 379 |
|
continue; |
| 380 |
} |
} |
| 381 |
|
break; |
| 382 |
|
} |
| 383 |
|
} |
| 384 |
|
|
| 385 |
|
if (!tag_name_found) |
| 386 |
|
{ |
| 387 |
|
tag_output_len = tag_end_pos - tag_start_pos + 1; |
| 388 |
|
if (j + tag_output_len >= buf_len) |
| 389 |
|
{ |
| 390 |
|
log_error("Buffer is not longer enough for output string %ld >= %d\n", j + tag_output_len, buf_len); |
| 391 |
|
str_out[j] = '\0'; |
| 392 |
|
return j; |
| 393 |
} |
} |
| 394 |
|
|
| 395 |
tag_start_pos = -1; |
memcpy(str_out + j, str_in + tag_start_pos, (size_t)tag_output_len); |
| 396 |
|
j += tag_output_len; |
| 397 |
} |
} |
| 398 |
|
|
| 399 |
|
tag_start_pos = -1; |
| 400 |
|
tag_name_pos = -1; |
| 401 |
} |
} |
| 402 |
else if (tag_start_pos == -1) // not in LML tag |
else if (lml_tag_disabled || tag_name_pos == -1) // not in LML tag |
| 403 |
{ |
{ |
| 404 |
if (str_in[i] & 0b10000000) // head of multi-byte character |
if (str_in[i] & 0x80) // head of multi-byte character |
| 405 |
{ |
{ |
| 406 |
if (j + 4 >= buf_len) // Assuming UTF-8 CJK characters use 4 bytes, though most of them actually use 3 bytes |
if (j + 4 >= buf_len) // Assuming UTF-8 CJK characters use 4 bytes, though most of them actually use 3 bytes |
| 407 |
{ |
{ |
| 410 |
return j; |
return j; |
| 411 |
} |
} |
| 412 |
|
|
| 413 |
c = (str_in[i] & 0b01110000) << 1; |
c = (str_in[i] & 0x70) << 1; |
| 414 |
while (c & 0b10000000) |
while (c & 0x80) |
| 415 |
{ |
{ |
| 416 |
str_out[j++] = str_in[i++]; |
str_out[j++] = str_in[i++]; |
| 417 |
if (str_in[i] == '\0') |
if (str_in[i] == '\0') |
| 419 |
str_out[j] = '\0'; |
str_out[j] = '\0'; |
| 420 |
return j; |
return j; |
| 421 |
} |
} |
| 422 |
c = (c & 0b01111111) << 1; |
c = (c & 0x7f) << 1; |
| 423 |
} |
} |
| 424 |
} |
} |
| 425 |
|
|
| 437 |
} |
} |
| 438 |
} |
} |
| 439 |
|
|
| 440 |
if (lml_tag && lml_tag_quote_level > 0) |
if (tag_start_pos != -1) // tag is not closed |
| 441 |
|
{ |
| 442 |
|
tag_end_pos = i - 1; |
| 443 |
|
tag_output_len = tag_end_pos - tag_start_pos + 1; |
| 444 |
|
if (j + tag_output_len >= buf_len) |
| 445 |
|
{ |
| 446 |
|
log_error("Buffer is not longer enough for output string %ld >= %d\n", j + tag_output_len, buf_len); |
| 447 |
|
str_out[j] = '\0'; |
| 448 |
|
return j; |
| 449 |
|
} |
| 450 |
|
|
| 451 |
|
memcpy(str_out + j, str_in + tag_start_pos, (size_t)tag_output_len); |
| 452 |
|
j += tag_output_len; |
| 453 |
|
} |
| 454 |
|
|
| 455 |
|
if (!quote_mode && !lml_tag_disabled && lml_tag_quote_level > 0) |
| 456 |
{ |
{ |
| 457 |
tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, "\033[m"); |
tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, "\033[m"); |
| 458 |
if (j + tag_output_len >= buf_len) |
if (j + tag_output_len >= buf_len) |