| 178 |
|
|
| 179 |
tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, |
tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, |
| 180 |
(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")); |
| 181 |
if (j + tag_output_len >= buf_len - 1) |
if (j + tag_output_len >= buf_len) |
| 182 |
{ |
{ |
| 183 |
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); |
| 184 |
str_out[j] = '\0'; |
str_out[j] = '\0'; |
| 185 |
return j; |
return j; |
| 186 |
} |
} |
| 201 |
|
|
| 202 |
tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, |
tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, |
| 203 |
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]); |
| 204 |
if (j + tag_output_len >= buf_len - 1) |
if (j + tag_output_len >= buf_len) |
| 205 |
{ |
{ |
| 206 |
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); |
| 207 |
str_out[j] = '\0'; |
str_out[j] = '\0'; |
| 208 |
return j; |
return j; |
| 209 |
} |
} |
| 214 |
new_line = 0; |
new_line = 0; |
| 215 |
} |
} |
| 216 |
|
|
| 217 |
|
if (str_in[i] == '\033' && str_in[i + 1] == '[') // Escape sequence -- copy directly |
| 218 |
|
{ |
| 219 |
|
for (k = i + 2; str_in[k] != '\0' && str_in[k] != 'm'; k++) |
| 220 |
|
; |
| 221 |
|
|
| 222 |
|
if (str_in[k] == 'm') // Valid |
| 223 |
|
{ |
| 224 |
|
if (j + (k - i + 1) >= buf_len) |
| 225 |
|
{ |
| 226 |
|
log_error("Buffer is not longer enough for output string %d >= %d\n", j + (k - i + 1), buf_len); |
| 227 |
|
str_out[j] = '\0'; |
| 228 |
|
return j; |
| 229 |
|
} |
| 230 |
|
memcpy(str_out + j, str_in + i, (size_t)(k - i + 1)); |
| 231 |
|
i = k; |
| 232 |
|
continue; |
| 233 |
|
} |
| 234 |
|
else // reach end of string |
| 235 |
|
{ |
| 236 |
|
break; |
| 237 |
|
} |
| 238 |
|
} |
| 239 |
|
|
| 240 |
if (str_in[i] == '\n') |
if (str_in[i] == '\n') |
| 241 |
{ |
{ |
| 242 |
tag_start_pos = -1; // jump out of tag at end of line |
tag_start_pos = -1; // jump out of tag at end of line |
| 293 |
tag_output_len = ((lml_tag_filter_cb)LML_tag_def[k][2])( |
tag_output_len = ((lml_tag_filter_cb)LML_tag_def[k][2])( |
| 294 |
LML_tag_def[k][0], tag_param_buf, tag_output_buf, LML_TAG_OUTPUT_BUF_LEN); |
LML_tag_def[k][0], tag_param_buf, tag_output_buf, LML_TAG_OUTPUT_BUF_LEN); |
| 295 |
} |
} |
| 296 |
if (j + tag_output_len >= buf_len - 1) |
if (j + tag_output_len >= buf_len) |
| 297 |
{ |
{ |
| 298 |
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); |
| 299 |
str_out[j] = '\0'; |
str_out[j] = '\0'; |
| 300 |
return j; |
return j; |
| 301 |
} |
} |
| 316 |
{ |
{ |
| 317 |
if (str_in[i] < 0 || str_in[i] > 127) // GBK chinese character |
if (str_in[i] < 0 || str_in[i] > 127) // GBK chinese character |
| 318 |
{ |
{ |
| 319 |
if (j + 2 >= buf_len - 1) |
if (j + 2 >= buf_len) |
| 320 |
{ |
{ |
| 321 |
log_error("Buffer is not longer enough for output string %ld >= %d\n", j + 2, buf_len - 1); |
log_error("Buffer is not longer enough for output string %ld >= %d\n", j + 2, buf_len); |
| 322 |
str_out[j] = '\0'; |
str_out[j] = '\0'; |
| 323 |
return j; |
return j; |
| 324 |
} |
} |
| 330 |
} |
} |
| 331 |
} |
} |
| 332 |
|
|
| 333 |
if (j + 1 >= buf_len - 1) |
if (j + 1 >= buf_len) |
| 334 |
{ |
{ |
| 335 |
log_error("Buffer is not longer enough for output string %ld >= %d\n", j + 1, buf_len - 1); |
log_error("Buffer is not longer enough for output string %ld >= %d\n", j + 1, buf_len); |
| 336 |
str_out[j] = '\0'; |
str_out[j] = '\0'; |
| 337 |
return j; |
return j; |
| 338 |
} |
} |
| 347 |
if (lml_tag_quote_level > 0) |
if (lml_tag_quote_level > 0) |
| 348 |
{ |
{ |
| 349 |
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"); |
| 350 |
if (j + tag_output_len >= buf_len - 1) |
if (j + tag_output_len >= buf_len) |
| 351 |
{ |
{ |
| 352 |
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); |
| 353 |
str_out[j] = '\0'; |
str_out[j] = '\0'; |
| 354 |
return j; |
return j; |
| 355 |
} |
} |