| 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 |
#define LML_TAG_COUNT 19 |
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); |
| 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) |
| 30 |
|
{ |
| 31 |
|
if (strcasecmp(tag_name, "color") == 0) |
| 32 |
|
{ |
| 33 |
|
if (strcasecmp(tag_param_buf, "red") == 0) |
| 34 |
|
{ |
| 35 |
|
return snprintf(tag_output_buf, tag_output_buf_len, "\033[1;31m"); |
| 36 |
|
} |
| 37 |
|
else if (strcasecmp(tag_param_buf, "green") == 0) |
| 38 |
|
{ |
| 39 |
|
return snprintf(tag_output_buf, tag_output_buf_len, "\033[1;32m"); |
| 40 |
|
} |
| 41 |
|
else if (strcasecmp(tag_param_buf, "yellow") == 0) |
| 42 |
|
{ |
| 43 |
|
return snprintf(tag_output_buf, tag_output_buf_len, "\033[1;33m"); |
| 44 |
|
} |
| 45 |
|
else if (strcasecmp(tag_param_buf, "blue") == 0) |
| 46 |
|
{ |
| 47 |
|
return snprintf(tag_output_buf, tag_output_buf_len, "\033[1;34m"); |
| 48 |
|
} |
| 49 |
|
else if (strcasecmp(tag_param_buf, "magenta") == 0) |
| 50 |
|
{ |
| 51 |
|
return snprintf(tag_output_buf, tag_output_buf_len, "\033[1;35m"); |
| 52 |
|
} |
| 53 |
|
else if (strcasecmp(tag_param_buf, "cyan") == 0) |
| 54 |
|
{ |
| 55 |
|
return snprintf(tag_output_buf, tag_output_buf_len, "\033[1;36m"); |
| 56 |
|
} |
| 57 |
|
else if (strcasecmp(tag_param_buf, "black") == 0) |
| 58 |
|
{ |
| 59 |
|
return snprintf(tag_output_buf, tag_output_buf_len, "\033[1;30;47m"); |
| 60 |
|
} |
| 61 |
|
} |
| 62 |
|
return 0; |
| 63 |
|
} |
| 64 |
|
|
| 65 |
const static char *LML_tag_def[][3] = { |
const static char *LML_tag_def[][3] = { |
| 66 |
{"left", "[", ""}, |
{"left", "[", ""}, |
| 67 |
{"right", "]", NULL}, |
{"right", "]", NULL}, |
| 68 |
|
{"bold", "\033[1m", ""}, |
| 69 |
|
{"/bold", "\033[21m", NULL}, |
| 70 |
|
{"b", "\033[1m", ""}, |
| 71 |
|
{"/b", "\033[21m", NULL}, |
| 72 |
|
{"italic", "\033[3m", ""}, |
| 73 |
|
{"/italic", "\033[23m", NULL}, |
| 74 |
|
{"i", "\033[3m", ""}, |
| 75 |
|
{"/i", "\033[23m", NULL}, |
| 76 |
{"underline", "\033[4m", ""}, |
{"underline", "\033[4m", ""}, |
| 77 |
{"/underline", "\033[24m", NULL}, |
{"/underline", "\033[24m", NULL}, |
| 78 |
{"u", "\033[4m", ""}, |
{"u", "\033[4m", ""}, |
| 79 |
{"/u", "\033[24m", NULL}, |
{"/u", "\033[24m", NULL}, |
| 80 |
|
{"color", NULL, (const char *)lml_tag_color_filter}, |
| 81 |
|
{"/color", "\033[m", NULL}, |
| 82 |
{"url", "", ""}, |
{"url", "", ""}, |
| 83 |
{"/url", "(Á´½Ó: %s)", NULL}, |
{"/url", "(Á´½Ó: %s)", NULL}, |
| 84 |
{"link", "", ""}, |
{"link", "", ""}, |
| 91 |
{"/article", "(ÎÄÕÂ: %s)", NULL}, |
{"/article", "(ÎÄÕÂ: %s)", NULL}, |
| 92 |
{"image", "(ͼƬ: %s)", ""}, |
{"image", "(ͼƬ: %s)", ""}, |
| 93 |
{"flash", "(Flash: %s)", ""}, |
{"flash", "(Flash: %s)", ""}, |
| 94 |
{"bwf", "\033[31m****\033[m", ""}, |
{"bwf", "\033[1;31m****\033[m", ""}, |
| 95 |
}; |
}; |
| 96 |
|
|
| 97 |
|
#define LML_TAG_COUNT 29 |
| 98 |
|
|
| 99 |
static int LML_tag_name_len[LML_TAG_COUNT]; |
static int LML_tag_name_len[LML_TAG_COUNT]; |
| 100 |
static int LML_init = 0; |
static int LML_init = 0; |
| 101 |
|
|
| 162 |
strncpy(tag_param_buf, str_in + tag_param_pos, (size_t)MIN(tag_end_pos - tag_param_pos, LML_TAG_PARAM_BUF_LEN)); |
strncpy(tag_param_buf, str_in + tag_param_pos, (size_t)MIN(tag_end_pos - tag_param_pos, LML_TAG_PARAM_BUF_LEN)); |
| 163 |
tag_param_buf[MIN(tag_end_pos - tag_param_pos, LML_TAG_PARAM_BUF_LEN)] = '\0'; |
tag_param_buf[MIN(tag_end_pos - tag_param_pos, LML_TAG_PARAM_BUF_LEN)] = '\0'; |
| 164 |
case ']': |
case ']': |
| 165 |
if (tag_param_pos == -1 && LML_tag_def[k][2] != NULL) // Apply default param if not defined |
if (tag_param_pos == -1 && LML_tag_def[k][1] != NULL && LML_tag_def[k][2] != NULL) // Apply default param if not defined |
| 166 |
{ |
{ |
| 167 |
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); |
| 168 |
tag_param_buf[LML_TAG_PARAM_BUF_LEN - 1] = '\0'; |
tag_param_buf[LML_TAG_PARAM_BUF_LEN - 1] = '\0'; |
| 169 |
} |
} |
| 170 |
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) |
| 171 |
|
{ |
| 172 |
|
tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, LML_tag_def[k][1], tag_param_buf); |
| 173 |
|
} |
| 174 |
|
else |
| 175 |
|
{ |
| 176 |
|
tag_output_len = ((lml_tag_filter_cb)LML_tag_def[k][2])( |
| 177 |
|
LML_tag_def[k][0], tag_param_buf, tag_output_buf, LML_TAG_OUTPUT_BUF_LEN); |
| 178 |
|
} |
| 179 |
if (j + tag_output_len >= buf_len - 1) |
if (j + tag_output_len >= buf_len - 1) |
| 180 |
{ |
{ |
| 181 |
log_error("Buffer is not longer enough for output string %d >= %d\n", j + tag_output_len, buf_len - 1); |
log_error("Buffer is not longer enough for output string %d >= %d\n", j + tag_output_len, buf_len - 1); |