/[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.19 by sysadm, Sun Oct 5 05:13:00 2025 UTC Revision 1.20 by sysadm, Sun Oct 5 07:38:51 2025 UTC
# Line 24  Line 24 
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  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);  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, int quote_mode);
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)  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  {  {
# Line 73  static const char *lml_tag_quote_color[] Line 73  static const char *lml_tag_quote_color[]
73    
74  static int lml_tag_quote_level = 0;  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, int quote_mode)
77  {  {
78          if (strcasecmp(tag_name, "quote") == 0)          if (strcasecmp(tag_name, "quote") == 0)
79          {          {
# Line 97  static int lml_tag_quote_filter(const ch Line 97  static int lml_tag_quote_filter(const ch
97          return 0;          return 0;
98  }  }
99    
100    static int lml_tag_disabled = 0;
101    
102    static int lml_tag_disable_filter(const char *tag_name, const char *tag_param_buf, char *tag_output_buf, size_t tag_output_buf_len, int quote_mode)
103    {
104            lml_tag_disabled = 1;
105    
106            return snprintf(tag_output_buf, tag_output_buf_len, "%s", (quote_mode ? "" : "[plain]"));
107    }
108    
109  const static char *lml_tag_def[][4] = {  const static char *lml_tag_def[][4] = {
110          // Definition of tuple: {lml_tag, lml_output, default_param | lml_filter_cb, no_lml_output}          // Definition of tuple: {lml_tag, lml_output, default_param | lml_filter_cb, quote_mode_output}
111            {"plain", NULL, (const char *)lml_tag_disable_filter, NULL},
112          {"left", "[", "", "[left]"},          {"left", "[", "", "[left]"},
113          {"right", "]", "", "[right]"},          {"right", "]", "", "[right]"},
114          {"bold", "\033[1m", "", ""}, // does not work in Fterm          {"bold", "\033[1m", "", ""}, // does not work in Fterm
# Line 119  const static char *lml_tag_def[][4] = { Line 129  const static char *lml_tag_def[][4] = {
129          {"/quote", NULL, (const char *)lml_tag_quote_filter, ""},          {"/quote", NULL, (const char *)lml_tag_quote_filter, ""},
130          {"url", "", "", ""},          {"url", "", "", ""},
131          {"/url", "(链接: %s)", NULL, ""},          {"/url", "(链接: %s)", NULL, ""},
132          {"link", "", ""},          {"link", "", "", ""},
133          {"/link", "(链接: %s)", NULL, ""},          {"/link", "(链接: %s)", NULL, ""},
134          {"email", "", ""},          {"email", "", "", ""},
135          {"/email", "(Email: %s)", NULL, ""},          {"/email", "(Email: %s)", NULL, ""},
136          {"user", "", ""},          {"user", "", "", ""},
137          {"/user", "(用户: %s)", NULL, ""},          {"/user", "(用户: %s)", NULL, ""},
138          {"article", "", ""},          {"article", "", "", ""},
139          {"/article", "(文章: %s)", NULL, ""},          {"/article", "(文章: %s)", NULL, ""},
140          {"image", "(图片: %s)", "", "%s"},          {"image", "(图片: %s)", "", "%s"},
141          {"flash", "(Flash: %s)", "", ""},          {"flash", "(Flash: %s)", "", ""},
# Line 152  inline static void lml_init(void) Line 162  inline static void lml_init(void)
162          }          }
163  }  }
164    
165  int lml_render(const char *str_in, char *str_out, int buf_len, int lml_tag)  int lml_render(const char *str_in, char *str_out, int buf_len, int quote_mode)
166  {  {
167          char c;          char c;
168          char tag_param_buf[LML_TAG_PARAM_BUF_LEN];          char tag_param_buf[LML_TAG_PARAM_BUF_LEN];
# Line 169  int lml_render(const char *str_in, char Line 179  int lml_render(const char *str_in, char
179    
180          lml_init();          lml_init();
181    
182            lml_tag_disabled = 0;
183          lml_tag_quote_level = 0;          lml_tag_quote_level = 0;
184    
185          for (i = 0; str_in[i] != '\0'; i++)          for (i = 0; str_in[i] != '\0'; i++)
186          {          {
187                  if (lml_tag && new_line)                  if (quote_mode && !lml_tag_disabled && new_line)
188                  {                  {
189                          if (fb_quote_level > 0)                          if (fb_quote_level > 0)
190                          {                          {
# Line 251  int lml_render(const char *str_in, char Line 262  int lml_render(const char *str_in, char
262                          continue; // ignore '\r'                          continue; // ignore '\r'
263                  }                  }
264    
265                  if (str_in[i] == '[')                  if (!lml_tag_disabled && str_in[i] == '[')
266                  {                  {
267                          tag_start_pos = i + 1;                          tag_start_pos = i + 1;
268                  }                  }
269                  else if (str_in[i] == ']')                  else if (!lml_tag_disabled && str_in[i] == ']')
270                  {                  {
271                          if (tag_start_pos >= 0)                          if (tag_start_pos >= 0)
272                          {                          {
# Line 288  int lml_render(const char *str_in, char Line 299  int lml_render(const char *str_in, char
299                                                                  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);
300                                                                  tag_param_buf[LML_TAG_PARAM_BUF_LEN - 1] = '\0';                                                                  tag_param_buf[LML_TAG_PARAM_BUF_LEN - 1] = '\0';
301                                                          }                                                          }
302                                                          if (lml_tag)                                                          if (quote_mode)
303                                                          {                                                          {
304                                                                  if (lml_tag_def[k][1] != NULL)                                                                  if (lml_tag_def[k][1] != NULL)
305                                                                  {                                                                  {
# Line 297  int lml_render(const char *str_in, char Line 308  int lml_render(const char *str_in, char
308                                                                  else                                                                  else
309                                                                  {                                                                  {
310                                                                          tag_output_len = ((lml_tag_filter_cb)lml_tag_def[k][2])(                                                                          tag_output_len = ((lml_tag_filter_cb)lml_tag_def[k][2])(
311                                                                                  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, quote_mode);
312                                                                  }                                                                  }
313                                                          }                                                          }
314                                                          else                                                          else
# Line 308  int lml_render(const char *str_in, char Line 319  int lml_render(const char *str_in, char
319                                                                  }                                                                  }
320                                                                  else                                                                  else
321                                                                  {                                                                  {
322                                                                          tag_output_len = 0;                                                                          tag_output_len = ((lml_tag_filter_cb)lml_tag_def[k][2])(
323                                                                                    lml_tag_def[k][0], tag_param_buf, tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, quote_mode);
324                                                                  }                                                                  }
325                                                          }                                                          }
326                                                          if (j + tag_output_len >= buf_len)                                                          if (j + tag_output_len >= buf_len)
# Line 330  int lml_render(const char *str_in, char Line 342  int lml_render(const char *str_in, char
342                                  tag_start_pos = -1;                                  tag_start_pos = -1;
343                          }                          }
344                  }                  }
345                  else if (tag_start_pos == -1) // not in LML tag                  else if (lml_tag_disabled || tag_start_pos == -1) // not in LML tag
346                  {                  {
347                          if (str_in[i] & 0b10000000) // head of multi-byte character                          if (str_in[i] & 0b10000000) // head of multi-byte character
348                          {                          {
# Line 368  int lml_render(const char *str_in, char Line 380  int lml_render(const char *str_in, char
380                  }                  }
381          }          }
382    
383          if (lml_tag && lml_tag_quote_level > 0)          if (quote_mode && !lml_tag_disabled && lml_tag_quote_level > 0)
384          {          {
385                  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");
386                  if (j + tag_output_len >= buf_len)                  if (j + tag_output_len >= buf_len)


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

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