| 103 |
{ |
{ |
| 104 |
lml_tag_disabled = 1; |
lml_tag_disabled = 1; |
| 105 |
|
|
| 106 |
return snprintf(tag_output_buf, tag_output_buf_len, "%s", (quote_mode ? "" : "[plain]")); |
return snprintf(tag_output_buf, tag_output_buf_len, "%s", (quote_mode ? "[plain]" : "")); |
| 107 |
|
} |
| 108 |
|
|
| 109 |
|
static int lml_tag_user_disabled = 0; |
| 110 |
|
|
| 111 |
|
static int lml_tag_user_disable_filter(const char *tag_name, const char *tag_param_buf, char *tag_output_buf, size_t tag_output_buf_len, int quote_mode) |
| 112 |
|
{ |
| 113 |
|
lml_tag_user_disabled = 1; |
| 114 |
|
tag_output_buf[0] = '\0'; |
| 115 |
|
return 0; |
| 116 |
|
} |
| 117 |
|
|
| 118 |
|
static int lml_tag_user_enable_filter(const char *tag_name, const char *tag_param_buf, char *tag_output_buf, size_t tag_output_buf_len, int quote_mode) |
| 119 |
|
{ |
| 120 |
|
lml_tag_user_disabled = 0; |
| 121 |
|
tag_output_buf[0] = '\0'; |
| 122 |
|
return 0; |
| 123 |
} |
} |
| 124 |
|
|
| 125 |
typedef struct lml_tag_def_t |
typedef struct lml_tag_def_t |
| 134 |
const LML_TAG_DEF lml_tag_def[] = { |
const LML_TAG_DEF lml_tag_def[] = { |
| 135 |
// Definition of tuple: {lml_tag, lml_output, default_param, quote_mode_output, lml_filter_cb} |
// Definition of tuple: {lml_tag, lml_output, default_param, quote_mode_output, lml_filter_cb} |
| 136 |
{"plain", NULL, NULL, NULL, lml_tag_disable_filter}, |
{"plain", NULL, NULL, NULL, lml_tag_disable_filter}, |
| 137 |
|
{"nolml", NULL, NULL, NULL, lml_tag_user_disable_filter}, |
| 138 |
|
{"lml", NULL, NULL, NULL, lml_tag_user_enable_filter}, |
| 139 |
{"left", "[", "", "[left]", NULL}, |
{"left", "[", "", "[left]", NULL}, |
| 140 |
{"right", "]", "", "[right]", NULL}, |
{"right", "]", "", "[right]", NULL}, |
| 141 |
{"bold", "\033[1m", "", "", NULL}, // does not work in Fterm |
{"bold", "\033[1m", "", "", NULL}, // does not work in Fterm |
| 169 |
{"bwf", "\033[1;31m****\033[m", "", "****", NULL}, |
{"bwf", "\033[1;31m****\033[m", "", "****", NULL}, |
| 170 |
}; |
}; |
| 171 |
|
|
| 172 |
#define LML_TAG_COUNT 32 |
#define LML_TAG_COUNT (sizeof(lml_tag_def) / sizeof(LML_TAG_DEF)) |
| 173 |
|
|
| 174 |
static int lml_tag_name_len[LML_TAG_COUNT]; |
static int lml_tag_name_len[LML_TAG_COUNT]; |
| 175 |
static int lml_ready = 0; |
static int lml_ready = 0; |
| 207 |
lml_init(); |
lml_init(); |
| 208 |
|
|
| 209 |
lml_tag_disabled = 0; |
lml_tag_disabled = 0; |
| 210 |
|
lml_tag_user_disabled = 0; |
| 211 |
lml_tag_quote_level = 0; |
lml_tag_quote_level = 0; |
| 212 |
|
|
| 213 |
for (i = 0; str_in[i] != '\0'; i++) |
for (i = 0; str_in[i] != '\0'; i++) |
| 214 |
{ |
{ |
| 215 |
if (quote_mode && !lml_tag_disabled && new_line) |
if (!quote_mode && !lml_tag_disabled && new_line) |
| 216 |
{ |
{ |
| 217 |
if (fb_quote_level > 0) |
if (fb_quote_level > 0) |
| 218 |
{ |
{ |
| 327 |
strncpy(tag_param_buf, lml_tag_def[k].default_param, LML_TAG_PARAM_BUF_LEN - 1); |
strncpy(tag_param_buf, lml_tag_def[k].default_param, LML_TAG_PARAM_BUF_LEN - 1); |
| 328 |
tag_param_buf[LML_TAG_PARAM_BUF_LEN - 1] = '\0'; |
tag_param_buf[LML_TAG_PARAM_BUF_LEN - 1] = '\0'; |
| 329 |
} |
} |
| 330 |
if (quote_mode) |
if (!quote_mode && !lml_tag_user_disabled) |
| 331 |
{ |
{ |
| 332 |
if (lml_tag_def[k].tag_output != NULL) |
if (lml_tag_def[k].tag_output != NULL) |
| 333 |
{ |
{ |
| 334 |
tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, lml_tag_def[k].tag_output, tag_param_buf); |
tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, lml_tag_def[k].tag_output, tag_param_buf); |
| 335 |
} |
} |
| 336 |
else |
else if (lml_tag_def[k].tag_filter_cb != NULL) |
| 337 |
{ |
{ |
| 338 |
tag_output_len = lml_tag_def[k].tag_filter_cb( |
tag_output_len = lml_tag_def[k].tag_filter_cb( |
| 339 |
lml_tag_def[k].tag_name, tag_param_buf, tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, quote_mode); |
lml_tag_def[k].tag_name, tag_param_buf, tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, 0); |
| 340 |
|
} |
| 341 |
|
else |
| 342 |
|
{ |
| 343 |
|
tag_output_len = 0; |
| 344 |
} |
} |
| 345 |
} |
} |
| 346 |
else |
else // if (quote_mode || lml_tag_user_disabled) |
| 347 |
{ |
{ |
| 348 |
if (lml_tag_def[k].quote_mode_output != NULL) |
if (lml_tag_def[k].quote_mode_output != NULL) |
| 349 |
{ |
{ |
| 350 |
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].quote_mode_output, tag_param_buf); |
| 351 |
} |
} |
| 352 |
else |
else if (lml_tag_def[k].tag_filter_cb != NULL) |
| 353 |
{ |
{ |
| 354 |
tag_output_len = lml_tag_def[k].tag_filter_cb( |
tag_output_len = lml_tag_def[k].tag_filter_cb( |
| 355 |
lml_tag_def[k].tag_name, tag_param_buf, tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, quote_mode); |
lml_tag_def[k].tag_name, tag_param_buf, tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, 1); |
| 356 |
|
} |
| 357 |
|
else |
| 358 |
|
{ |
| 359 |
|
tag_output_len = 0; |
| 360 |
} |
} |
| 361 |
} |
} |
| 362 |
if (j + tag_output_len >= buf_len) |
if (j + tag_output_len >= buf_len) |
| 416 |
} |
} |
| 417 |
} |
} |
| 418 |
|
|
| 419 |
if (quote_mode && !lml_tag_disabled && lml_tag_quote_level > 0) |
if (!quote_mode && !lml_tag_disabled && lml_tag_quote_level > 0) |
| 420 |
{ |
{ |
| 421 |
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"); |
| 422 |
if (j + tag_output_len >= buf_len) |
if (j + tag_output_len >= buf_len) |