| 66 |
#define LML_TAG_QUOTE_LEVEL_LOOP 3 |
#define LML_TAG_QUOTE_LEVEL_LOOP 3 |
| 67 |
|
|
| 68 |
static const char *lml_tag_quote_color[] = { |
static const char *lml_tag_quote_color[] = { |
| 69 |
"\033[33m", |
"\033[33m", // yellow |
| 70 |
"\033[32m", |
"\033[32m", // green |
| 71 |
"\033[35m", |
"\033[35m", // magenta |
| 72 |
}; |
}; |
| 73 |
|
|
| 74 |
static int lml_tag_quote_level = 0; |
static int lml_tag_quote_level = 0; |
| 90 |
{ |
{ |
| 91 |
lml_tag_quote_level--; |
lml_tag_quote_level--; |
| 92 |
} |
} |
| 93 |
if (lml_tag_quote_level > 0) |
return snprintf(tag_output_buf, tag_output_buf_len, |
| 94 |
{ |
(lml_tag_quote_level > 0 ? lml_tag_quote_color[lml_tag_quote_level % LML_TAG_QUOTE_LEVEL_LOOP] : "\033[m")); |
|
return snprintf(tag_output_buf, tag_output_buf_len, lml_tag_quote_color[lml_tag_quote_level % LML_TAG_QUOTE_LEVEL_LOOP]); |
|
|
} |
|
|
else |
|
|
{ |
|
|
return snprintf(tag_output_buf, tag_output_buf_len, "\033[m"); |
|
|
} |
|
| 95 |
} |
} |
| 96 |
|
|
| 97 |
return 0; |
return 0; |
| 101 |
{"left", "[", ""}, |
{"left", "[", ""}, |
| 102 |
{"right", "]", NULL}, |
{"right", "]", NULL}, |
| 103 |
{"bold", "\033[1m", ""}, |
{"bold", "\033[1m", ""}, |
| 104 |
{"/bold", "\033[21m", NULL}, |
{"/bold", "\033[22m", NULL}, |
| 105 |
{"b", "\033[1m", ""}, |
{"b", "\033[1m", ""}, |
| 106 |
{"/b", "\033[21m", NULL}, |
{"/b", "\033[22m", NULL}, |
| 107 |
{"italic", "\033[3m", ""}, |
{"italic", "\033[5m", ""}, // use blink instead |
| 108 |
{"/italic", "\033[23m", NULL}, |
{"/italic", "\033[25m", NULL}, |
| 109 |
{"i", "\033[3m", ""}, |
{"i", "\033[5m", ""}, |
| 110 |
{"/i", "\033[23m", NULL}, |
{"/i", "\033[25m", NULL}, |
| 111 |
{"underline", "\033[4m", ""}, |
{"underline", "\033[4m", ""}, |
| 112 |
{"/underline", "\033[24m", NULL}, |
{"/underline", "\033[24m", NULL}, |
| 113 |
{"u", "\033[4m", ""}, |
{"u", "\033[4m", ""}, |
| 162 |
int tag_end_pos = -1; |
int tag_end_pos = -1; |
| 163 |
int tag_param_pos = -1; |
int tag_param_pos = -1; |
| 164 |
int tag_output_len; |
int tag_output_len; |
| 165 |
|
int new_line = 1; |
| 166 |
|
int fb_quote_level = 0; |
| 167 |
|
|
| 168 |
lml_init(); |
lml_init(); |
| 169 |
|
|
| 171 |
|
|
| 172 |
for (i = 0; str_in[i] != '\0'; i++) |
for (i = 0; str_in[i] != '\0'; i++) |
| 173 |
{ |
{ |
| 174 |
|
if (new_line) |
| 175 |
|
{ |
| 176 |
|
if (fb_quote_level > 0) |
| 177 |
|
{ |
| 178 |
|
lml_tag_quote_level -= fb_quote_level; |
| 179 |
|
|
| 180 |
|
tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, |
| 181 |
|
(lml_tag_quote_level > 0 ? lml_tag_quote_color[lml_tag_quote_level % LML_TAG_QUOTE_LEVEL_LOOP] : "\033[m")); |
| 182 |
|
if (j + tag_output_len >= buf_len - 1) |
| 183 |
|
{ |
| 184 |
|
log_error("Buffer is not longer enough for output string %d >= %d\n", j + tag_output_len, buf_len - 1); |
| 185 |
|
str_out[j] = '\0'; |
| 186 |
|
return j; |
| 187 |
|
} |
| 188 |
|
memcpy(str_out + j, tag_output_buf, (size_t)tag_output_len); |
| 189 |
|
j += tag_output_len; |
| 190 |
|
|
| 191 |
|
fb_quote_level = 0; |
| 192 |
|
} |
| 193 |
|
|
| 194 |
|
while (str_in[i + fb_quote_level * 2] == ':' && str_in[i + fb_quote_level * 2 + 1] == ' ') // FB2000 quote leading str |
| 195 |
|
{ |
| 196 |
|
fb_quote_level++; |
| 197 |
|
} |
| 198 |
|
|
| 199 |
|
if (fb_quote_level > 0) |
| 200 |
|
{ |
| 201 |
|
lml_tag_quote_level += fb_quote_level; |
| 202 |
|
|
| 203 |
|
tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, |
| 204 |
|
lml_tag_quote_color[(lml_tag_quote_level) % LML_TAG_QUOTE_LEVEL_LOOP]); |
| 205 |
|
if (j + tag_output_len >= buf_len - 1) |
| 206 |
|
{ |
| 207 |
|
log_error("Buffer is not longer enough for output string %d >= %d\n", j + tag_output_len, buf_len - 1); |
| 208 |
|
str_out[j] = '\0'; |
| 209 |
|
return j; |
| 210 |
|
} |
| 211 |
|
memcpy(str_out + j, tag_output_buf, (size_t)tag_output_len); |
| 212 |
|
j += tag_output_len; |
| 213 |
|
} |
| 214 |
|
|
| 215 |
|
new_line = 0; |
| 216 |
|
} |
| 217 |
|
|
| 218 |
|
if (str_in[i] == '\n') |
| 219 |
|
{ |
| 220 |
|
tag_start_pos = -1; // jump out of tag at end of line |
| 221 |
|
new_line = 1; |
| 222 |
|
} |
| 223 |
|
else if (str_in[i] == '\r') |
| 224 |
|
{ |
| 225 |
|
continue; // ignore '\r' |
| 226 |
|
} |
| 227 |
|
|
| 228 |
if (str_in[i] == '[') |
if (str_in[i] == '[') |
| 229 |
{ |
{ |
| 230 |
tag_start_pos = i + 1; |
tag_start_pos = i + 1; |
| 322 |
} |
} |
| 323 |
} |
} |
| 324 |
|
|
| 325 |
|
if (lml_tag_quote_level > 0) |
| 326 |
|
{ |
| 327 |
|
tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, "\033[m"); |
| 328 |
|
if (j + tag_output_len >= buf_len - 1) |
| 329 |
|
{ |
| 330 |
|
log_error("Buffer is not longer enough for output string %d >= %d\n", j + tag_output_len, buf_len - 1); |
| 331 |
|
str_out[j] = '\0'; |
| 332 |
|
return j; |
| 333 |
|
} |
| 334 |
|
memcpy(str_out + j, tag_output_buf, (size_t)tag_output_len); |
| 335 |
|
j += tag_output_len; |
| 336 |
|
} |
| 337 |
|
|
| 338 |
str_out[j] = '\0'; |
str_out[j] = '\0'; |
| 339 |
|
|
| 340 |
return j; |
return j; |
| 341 |
} |
} |