/[LeafOK_CVS]/lbbs/src/lml.c
ViewVC logotype

Diff of /lbbs/src/lml.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.5 by sysadm, Tue Jun 3 02:30:18 2025 UTC Revision 1.9 by sysadm, Sat Jun 14 10:10:28 2025 UTC
# Line 75  static int lml_tag_quote_level = 0; Line 75  static int lml_tag_quote_level = 0;
75    
76  static int lml_tag_quote_filter(const char *tag_name, const char *tag_param_buf, char *tag_output_buf, size_t tag_output_buf_len)  static int lml_tag_quote_filter(const char *tag_name, const char *tag_param_buf, char *tag_output_buf, size_t tag_output_buf_len)
77  {  {
   
78          if (strcasecmp(tag_name, "quote") == 0)          if (strcasecmp(tag_name, "quote") == 0)
79          {          {
80                  if (lml_tag_quote_level <= LML_TAG_QUOTE_MAX_LEVEL)                  if (lml_tag_quote_level <= LML_TAG_QUOTE_MAX_LEVEL)
# Line 100  static int lml_tag_quote_filter(const ch Line 99  static int lml_tag_quote_filter(const ch
99  const static char *LML_tag_def[][3] = {  const static char *LML_tag_def[][3] = {
100          {"left", "[", ""},          {"left", "[", ""},
101          {"right", "]", NULL},          {"right", "]", NULL},
102          {"bold", "\033[1m", ""},          {"bold", "\033[1m", ""}, // does not work in Fterm
103          {"/bold", "\033[22m", NULL},          {"/bold", "\033[22m", NULL},
104          {"b", "\033[1m", ""},          {"b", "\033[1m", ""},
105          {"/b", "\033[22m", NULL},          {"/b", "\033[22m", NULL},
106          {"italic", "\033[5m", ""}, // use blink instead          {"italic", "\033[5m", ""},       // use blink instead
107          {"/italic", "\033[25m", NULL},          {"/italic", "\033[m", NULL}, // \033[25m does not work in Fterm
108          {"i", "\033[5m", ""},          {"i", "\033[5m", ""},
109          {"/i", "\033[25m", NULL},          {"/i", "\033[m", NULL},
110          {"underline", "\033[4m", ""},          {"underline", "\033[4m", ""},
111          {"/underline", "\033[24m", NULL},          {"/underline", "\033[m", NULL}, // \033[24m does not work in Fterm
112          {"u", "\033[4m", ""},          {"u", "\033[4m", ""},
113          {"/u", "\033[24m", NULL},          {"/u", "\033[m", NULL},
114          {"color", NULL, (const char *)lml_tag_color_filter},          {"color", NULL, (const char *)lml_tag_color_filter},
115          {"/color", "\033[m", NULL},          {"/color", "\033[m", NULL},
116          {"quote", NULL, (const char *)lml_tag_quote_filter},          {"quote", NULL, (const char *)lml_tag_quote_filter},
# Line 179  int lml_plain(const char *str_in, char * Line 178  int lml_plain(const char *str_in, char *
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                                  }                                  }
# Line 202  int lml_plain(const char *str_in, char * Line 201  int lml_plain(const char *str_in, char *
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                                  }                                  }
# Line 215  int lml_plain(const char *str_in, char * Line 214  int lml_plain(const char *str_in, char *
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                                    j += (k - i + 1);
232                                    i = k;
233                                    continue;
234                            }
235                            else // reach end of string
236                            {
237                                    break;
238                            }
239                    }
240    
241                  if (str_in[i] == '\n')                  if (str_in[i] == '\n')
242                  {                  {
243                          tag_start_pos = -1; // jump out of tag at end of line                          tag_start_pos = -1; // jump out of tag at end of line
# Line 271  int lml_plain(const char *str_in, char * Line 294  int lml_plain(const char *str_in, char *
294                                                                  tag_output_len = ((lml_tag_filter_cb)LML_tag_def[k][2])(                                                                  tag_output_len = ((lml_tag_filter_cb)LML_tag_def[k][2])(
295                                                                          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);
296                                                          }                                                          }
297                                                          if (j + tag_output_len >= buf_len - 1)                                                          if (j + tag_output_len >= buf_len)
298                                                          {                                                          {
299                                                                  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);
300                                                                  str_out[j] = '\0';                                                                  str_out[j] = '\0';
301                                                                  return j;                                                                  return j;
302                                                          }                                                          }
# Line 294  int lml_plain(const char *str_in, char * Line 317  int lml_plain(const char *str_in, char *
317                  {                  {
318                          if (str_in[i] < 0 || str_in[i] > 127) // GBK chinese character                          if (str_in[i] < 0 || str_in[i] > 127) // GBK chinese character
319                          {                          {
320                                  if (j + 2 >= buf_len - 1)                                  if (j + 2 >= buf_len)
321                                  {                                  {
322                                          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);
323                                          str_out[j] = '\0';                                          str_out[j] = '\0';
324                                          return j;                                          return j;
325                                  }                                  }
# Line 308  int lml_plain(const char *str_in, char * Line 331  int lml_plain(const char *str_in, char *
331                                  }                                  }
332                          }                          }
333    
334                          if (j + 1 >= buf_len - 1)                          if (j + 1 >= buf_len)
335                          {                          {
336                                  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);
337                                  str_out[j] = '\0';                                  str_out[j] = '\0';
338                                  return j;                                  return j;
339                          }                          }
# Line 325  int lml_plain(const char *str_in, char * Line 348  int lml_plain(const char *str_in, char *
348          if (lml_tag_quote_level > 0)          if (lml_tag_quote_level > 0)
349          {          {
350                  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");
351                  if (j + tag_output_len >= buf_len - 1)                  if (j + tag_output_len >= buf_len)
352                  {                  {
353                          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);
354                          str_out[j] = '\0';                          str_out[j] = '\0';
355                          return j;                          return j;
356                  }                  }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1