| 81 |
{ |
{ |
| 82 |
lml_tag_quote_level++; |
lml_tag_quote_level++; |
| 83 |
} |
} |
| 84 |
return snprintf(tag_output_buf, tag_output_buf_len, lml_tag_quote_color[lml_tag_quote_level % LML_TAG_QUOTE_LEVEL_LOOP]); |
return snprintf(tag_output_buf, tag_output_buf_len, "%s", |
| 85 |
|
lml_tag_quote_color[lml_tag_quote_level % LML_TAG_QUOTE_LEVEL_LOOP]); |
| 86 |
} |
} |
| 87 |
else if (strcasecmp(tag_name, "/quote") == 0) |
else if (strcasecmp(tag_name, "/quote") == 0) |
| 88 |
{ |
{ |
| 90 |
{ |
{ |
| 91 |
lml_tag_quote_level--; |
lml_tag_quote_level--; |
| 92 |
} |
} |
| 93 |
return snprintf(tag_output_buf, tag_output_buf_len, |
return snprintf(tag_output_buf, tag_output_buf_len, "%s", |
| 94 |
(lml_tag_quote_level > 0 ? lml_tag_quote_color[lml_tag_quote_level % LML_TAG_QUOTE_LEVEL_LOOP] : "\033[m")); |
(lml_tag_quote_level > 0 ? lml_tag_quote_color[lml_tag_quote_level % LML_TAG_QUOTE_LEVEL_LOOP] : "\033[m")); |
| 95 |
} |
} |
| 96 |
|
|
| 97 |
return 0; |
return 0; |
| 98 |
} |
} |
| 99 |
|
|
| 100 |
const static char *LML_tag_def[][3] = { |
const static char *LML_tag_def[][4] = { |
| 101 |
{"left", "[", ""}, |
// Definition of tuple: {lml_tag, lml_output, default_param | lml_filter_cb, no_lml_output} |
| 102 |
{"right", "]", NULL}, |
{"left", "[", "", "[left]"}, |
| 103 |
{"bold", "\033[1m", ""}, // does not work in Fterm |
{"right", "]", "", "[right]"}, |
| 104 |
{"/bold", "\033[22m", NULL}, |
{"bold", "\033[1m", "", ""}, // does not work in Fterm |
| 105 |
{"b", "\033[1m", ""}, |
{"/bold", "\033[22m", NULL, ""}, |
| 106 |
{"/b", "\033[22m", NULL}, |
{"b", "\033[1m", "", ""}, |
| 107 |
{"italic", "\033[5m", ""}, // use blink instead |
{"/b", "\033[22m", NULL, ""}, |
| 108 |
{"/italic", "\033[m", NULL}, // \033[25m does not work in Fterm |
{"italic", "\033[5m", "", ""}, // use blink instead |
| 109 |
{"i", "\033[5m", ""}, |
{"/italic", "\033[m", NULL, ""}, // \033[25m does not work in Fterm |
| 110 |
{"/i", "\033[m", NULL}, |
{"i", "\033[5m", "", ""}, |
| 111 |
{"underline", "\033[4m", ""}, |
{"/i", "\033[m", NULL, ""}, |
| 112 |
{"/underline", "\033[m", NULL}, // \033[24m does not work in Fterm |
{"underline", "\033[4m", "", ""}, |
| 113 |
{"u", "\033[4m", ""}, |
{"/underline", "\033[m", NULL, ""}, // \033[24m does not work in Fterm |
| 114 |
{"/u", "\033[m", NULL}, |
{"u", "\033[4m", "", ""}, |
| 115 |
{"color", NULL, (const char *)lml_tag_color_filter}, |
{"/u", "\033[m", NULL, ""}, |
| 116 |
{"/color", "\033[m", NULL}, |
{"color", NULL, (const char *)lml_tag_color_filter, ""}, |
| 117 |
{"quote", NULL, (const char *)lml_tag_quote_filter}, |
{"/color", "\033[m", NULL, ""}, |
| 118 |
{"/quote", NULL, (const char *)lml_tag_quote_filter}, |
{"quote", NULL, (const char *)lml_tag_quote_filter, ""}, |
| 119 |
{"url", "", ""}, |
{"/quote", NULL, (const char *)lml_tag_quote_filter, ""}, |
| 120 |
{"/url", "(链接: %s)", NULL}, |
{"url", "", "", ""}, |
| 121 |
|
{"/url", "(閾炬帴: %s)", NULL, "(閾炬帴: %s)"}, |
| 122 |
{"link", "", ""}, |
{"link", "", ""}, |
| 123 |
{"/link", "(链接: %s)", NULL}, |
{"/link", "(閾炬帴: %s)", NULL, "(閾炬帴: %s)"}, |
| 124 |
{"email", "", ""}, |
{"email", "", ""}, |
| 125 |
{"/email", "(Email: %s)", NULL}, |
{"/email", "(Email: %s)", NULL, "(Email: %s)"}, |
| 126 |
{"user", "", ""}, |
{"user", "", ""}, |
| 127 |
{"/user", "(用户: %s)", NULL}, |
{"/user", "(鐢ㄦ埛: %s)", NULL, "(鐢ㄦ埛: %s)"}, |
| 128 |
{"article", "", ""}, |
{"article", "", ""}, |
| 129 |
{"/article", "(文章: %s)", NULL}, |
{"/article", "(鏂囩珷: %s)", NULL, "(鏂囩珷: %s)"}, |
| 130 |
{"image", "(图片: %s)", ""}, |
{"image", "(鍥剧墖: %s)", "", "(鍥剧墖: %s)"}, |
| 131 |
{"flash", "(Flash: %s)", ""}, |
{"flash", "(Flash: %s)", "", "(Flash: %s)"}, |
| 132 |
{"bwf", "\033[1;31m****\033[m", ""}, |
{"bwf", "\033[1;31m****\033[m", "", "****"}, |
| 133 |
}; |
}; |
| 134 |
|
|
| 135 |
#define LML_TAG_COUNT 31 |
#define LML_TAG_COUNT 31 |
| 152 |
} |
} |
| 153 |
} |
} |
| 154 |
|
|
| 155 |
int lml_plain(const char *str_in, char *str_out, int buf_len) |
int lml_plain(const char *str_in, char *str_out, int buf_len, int lml_tag) |
| 156 |
{ |
{ |
| 157 |
|
char c; |
| 158 |
char tag_param_buf[LML_TAG_PARAM_BUF_LEN]; |
char tag_param_buf[LML_TAG_PARAM_BUF_LEN]; |
| 159 |
char tag_output_buf[LML_TAG_OUTPUT_BUF_LEN]; |
char tag_output_buf[LML_TAG_OUTPUT_BUF_LEN]; |
| 160 |
int i; |
int i; |
| 173 |
|
|
| 174 |
for (i = 0; str_in[i] != '\0'; i++) |
for (i = 0; str_in[i] != '\0'; i++) |
| 175 |
{ |
{ |
| 176 |
if (new_line) |
if (lml_tag && new_line) |
| 177 |
{ |
{ |
| 178 |
if (fb_quote_level > 0) |
if (fb_quote_level > 0) |
| 179 |
{ |
{ |
| 180 |
lml_tag_quote_level -= fb_quote_level; |
lml_tag_quote_level -= fb_quote_level; |
| 181 |
|
|
| 182 |
tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, |
tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, "%s", |
| 183 |
(lml_tag_quote_level > 0 ? lml_tag_quote_color[lml_tag_quote_level % LML_TAG_QUOTE_LEVEL_LOOP] : "\033[m")); |
(lml_tag_quote_level > 0 ? lml_tag_quote_color[lml_tag_quote_level % LML_TAG_QUOTE_LEVEL_LOOP] : "\033[m")); |
| 184 |
if (j + tag_output_len >= buf_len) |
if (j + tag_output_len >= buf_len) |
| 185 |
{ |
{ |
| 202 |
{ |
{ |
| 203 |
lml_tag_quote_level += fb_quote_level; |
lml_tag_quote_level += fb_quote_level; |
| 204 |
|
|
| 205 |
tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, |
tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, "%s", |
| 206 |
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]); |
| 207 |
if (j + tag_output_len >= buf_len) |
if (j + tag_output_len >= buf_len) |
| 208 |
{ |
{ |
| 288 |
strncpy(tag_param_buf, LML_tag_def[k][2], LML_TAG_PARAM_BUF_LEN - 1); |
strncpy(tag_param_buf, LML_tag_def[k][2], LML_TAG_PARAM_BUF_LEN - 1); |
| 289 |
tag_param_buf[LML_TAG_PARAM_BUF_LEN - 1] = '\0'; |
tag_param_buf[LML_TAG_PARAM_BUF_LEN - 1] = '\0'; |
| 290 |
} |
} |
| 291 |
if (LML_tag_def[k][1] != NULL) |
if (lml_tag) |
| 292 |
{ |
{ |
| 293 |
tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, LML_tag_def[k][1], tag_param_buf); |
if (LML_tag_def[k][1] != NULL) |
| 294 |
|
{ |
| 295 |
|
tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, LML_tag_def[k][1], tag_param_buf); |
| 296 |
|
} |
| 297 |
|
else |
| 298 |
|
{ |
| 299 |
|
tag_output_len = ((lml_tag_filter_cb)LML_tag_def[k][2])( |
| 300 |
|
LML_tag_def[k][0], tag_param_buf, tag_output_buf, LML_TAG_OUTPUT_BUF_LEN); |
| 301 |
|
} |
| 302 |
} |
} |
| 303 |
else |
else |
| 304 |
{ |
{ |
| 305 |
tag_output_len = ((lml_tag_filter_cb)LML_tag_def[k][2])( |
if (LML_tag_def[k][3] != NULL) |
| 306 |
LML_tag_def[k][0], tag_param_buf, tag_output_buf, LML_TAG_OUTPUT_BUF_LEN); |
{ |
| 307 |
|
tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, LML_tag_def[k][3], tag_param_buf); |
| 308 |
|
} |
| 309 |
|
else |
| 310 |
|
{ |
| 311 |
|
tag_output_len = 0; |
| 312 |
|
} |
| 313 |
} |
} |
| 314 |
if (j + tag_output_len >= buf_len) |
if (j + tag_output_len >= buf_len) |
| 315 |
{ |
{ |
| 332 |
} |
} |
| 333 |
else if (tag_start_pos == -1) // not in LML tag |
else if (tag_start_pos == -1) // not in LML tag |
| 334 |
{ |
{ |
| 335 |
if (str_in[i] < 0 || str_in[i] > 127) // GBK chinese character |
if (str_in[i] & 0b10000000) // head of multi-byte character |
| 336 |
{ |
{ |
| 337 |
if (j + 2 >= buf_len) |
if (j + 4 >= buf_len) // Assuming UTF-8 CJK characters use 4 bytes, though most of them actually use 3 bytes |
| 338 |
{ |
{ |
| 339 |
log_error("Buffer is not longer enough for output string %ld >= %d\n", j + 2, buf_len); |
log_error("Buffer is not longer enough for output string %ld >= %d\n", j + 4, buf_len); |
| 340 |
str_out[j] = '\0'; |
str_out[j] = '\0'; |
| 341 |
return j; |
return j; |
| 342 |
} |
} |
| 343 |
str_out[j++] = str_in[i++]; |
|
| 344 |
if (str_in[i] == '\0') |
c = (str_in[i] & 0b01110000) << 1; |
| 345 |
|
while (c & 0b10000000) |
| 346 |
{ |
{ |
| 347 |
str_out[j] = '\0'; |
str_out[j++] = str_in[i++]; |
| 348 |
return j; |
if (str_in[i] == '\0') |
| 349 |
|
{ |
| 350 |
|
str_out[j] = '\0'; |
| 351 |
|
return j; |
| 352 |
|
} |
| 353 |
|
c = (c & 0b01111111) << 1; |
| 354 |
} |
} |
| 355 |
} |
} |
| 356 |
|
|
| 368 |
} |
} |
| 369 |
} |
} |
| 370 |
|
|
| 371 |
if (lml_tag_quote_level > 0) |
if (lml_tag && lml_tag_quote_level > 0) |
| 372 |
{ |
{ |
| 373 |
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"); |
| 374 |
if (j + tag_output_len >= buf_len) |
if (j + tag_output_len >= buf_len) |