/[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.8 by sysadm, Sat Jun 14 10:03:32 2025 UTC Revision 1.14 by sysadm, Wed Jul 16 05:24:08 2025 UTC
# Line 14  Line 14 
14   *                                                                         *   *                                                                         *
15   ***************************************************************************/   ***************************************************************************/
16    
17    #include "common.h"
18  #include "lml.h"  #include "lml.h"
19  #include "log.h"  #include "log.h"
 #include "common.h"  
20  #include <stdio.h>  #include <stdio.h>
21  #include <string.h>  #include <string.h>
22  #include <sys/param.h>  #include <sys/param.h>
# Line 81  static int lml_tag_quote_filter(const ch Line 81  static int lml_tag_quote_filter(const ch
81                  {                  {
82                          lml_tag_quote_level++;                          lml_tag_quote_level++;
83                  }                  }
84                  return snprintf(tag_output_buf, tag_output_buf_len, lml_tag_quote_color[lml_tag_quote_level % LML_TAG_QUOTE_LEVEL_LOOP]);                  return snprintf(tag_output_buf, tag_output_buf_len, "%s",
85                                                    lml_tag_quote_color[lml_tag_quote_level % LML_TAG_QUOTE_LEVEL_LOOP]);
86          }          }
87          else if (strcasecmp(tag_name, "/quote") == 0)          else if (strcasecmp(tag_name, "/quote") == 0)
88          {          {
# Line 89  static int lml_tag_quote_filter(const ch Line 90  static int lml_tag_quote_filter(const ch
90                  {                  {
91                          lml_tag_quote_level--;                          lml_tag_quote_level--;
92                  }                  }
93                  return snprintf(tag_output_buf, tag_output_buf_len,                  return snprintf(tag_output_buf, tag_output_buf_len, "%s",
94                                                  (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"));
95          }          }
96    
# Line 116  const static char *LML_tag_def[][3] = { Line 117  const static char *LML_tag_def[][3] = {
117          {"quote", NULL, (const char *)lml_tag_quote_filter},          {"quote", NULL, (const char *)lml_tag_quote_filter},
118          {"/quote", NULL, (const char *)lml_tag_quote_filter},          {"/quote", NULL, (const char *)lml_tag_quote_filter},
119          {"url", "", ""},          {"url", "", ""},
120          {"/url", "(链接: %s)", NULL},          {"/url", "(閾炬帴: %s)", NULL},
121          {"link", "", ""},          {"link", "", ""},
122          {"/link", "(链接: %s)", NULL},          {"/link", "(閾炬帴: %s)", NULL},
123          {"email", "", ""},          {"email", "", ""},
124          {"/email", "(Email: %s)", NULL},          {"/email", "(Email: %s)", NULL},
125          {"user", "", ""},          {"user", "", ""},
126          {"/user", "(用户: %s)", NULL},          {"/user", "(鐢ㄦ埛: %s)", NULL},
127          {"article", "", ""},          {"article", "", ""},
128          {"/article", "(文章: %s)", NULL},          {"/article", "(鏂囩珷: %s)", NULL},
129          {"image", "(图片: %s)", ""},          {"image", "(鍥剧墖: %s)", ""},
130          {"flash", "(Flash: %s)", ""},          {"flash", "(Flash: %s)", ""},
131          {"bwf", "\033[1;31m****\033[m", ""},          {"bwf", "\033[1;31m****\033[m", ""},
132  };  };
# Line 152  inline static void lml_init(void) Line 153  inline static void lml_init(void)
153    
154  int lml_plain(const char *str_in, char *str_out, int buf_len)  int lml_plain(const char *str_in, char *str_out, int buf_len)
155  {  {
156            char c;
157          char tag_param_buf[LML_TAG_PARAM_BUF_LEN];          char tag_param_buf[LML_TAG_PARAM_BUF_LEN];
158          char tag_output_buf[LML_TAG_OUTPUT_BUF_LEN];          char tag_output_buf[LML_TAG_OUTPUT_BUF_LEN];
159          int i;          int i;
# Line 176  int lml_plain(const char *str_in, char * Line 178  int lml_plain(const char *str_in, char *
178                          {                          {
179                                  lml_tag_quote_level -= fb_quote_level;                                  lml_tag_quote_level -= fb_quote_level;
180    
181                                  tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN,                                  tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, "%s",
182                                                                                    (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"));
183                                  if (j + tag_output_len >= buf_len)                                  if (j + tag_output_len >= buf_len)
184                                  {                                  {
# Line 199  int lml_plain(const char *str_in, char * Line 201  int lml_plain(const char *str_in, char *
201                          {                          {
202                                  lml_tag_quote_level += fb_quote_level;                                  lml_tag_quote_level += fb_quote_level;
203    
204                                  tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN,                                  tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, "%s",
205                                                                                    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]);
206                                  if (j + tag_output_len >= buf_len)                                  if (j + tag_output_len >= buf_len)
207                                  {                                  {
# Line 228  int lml_plain(const char *str_in, char * Line 230  int lml_plain(const char *str_in, char *
230                                          return j;                                          return j;
231                                  }                                  }
232                                  memcpy(str_out + j, str_in + i, (size_t)(k - i + 1));                                  memcpy(str_out + j, str_in + i, (size_t)(k - i + 1));
233                                    j += (k - i + 1);
234                                  i = k;                                  i = k;
235                                  continue;                                  continue;
236                          }                          }
# Line 314  int lml_plain(const char *str_in, char * Line 317  int lml_plain(const char *str_in, char *
317                  }                  }
318                  else if (tag_start_pos == -1) // not in LML tag                  else if (tag_start_pos == -1) // not in LML tag
319                  {                  {
320                          if (str_in[i] < 0 || str_in[i] > 127) // GBK chinese character                          if (str_in[i] & 0b10000000) // head of multi-byte character
321                          {                          {
322                                  if (j + 2 >= buf_len)                                  if (j + 4 >= buf_len) // Assuming UTF-8 CJK characters use 4 bytes, though most of them actually use 3 bytes
323                                  {                                  {
324                                          log_error("Buffer is not longer enough for output string %ld >= %d\n", j + 2, buf_len);                                          log_error("Buffer is not longer enough for output string %ld >= %d\n", j + 4, buf_len);
325                                          str_out[j] = '\0';                                          str_out[j] = '\0';
326                                          return j;                                          return j;
327                                  }                                  }
328                                  str_out[j++] = str_in[i++];  
329                                  if (str_in[i] == '\0')                                  c = (str_in[i] & 0b01110000) << 1;
330                                    while (c & 0b10000000)
331                                  {                                  {
332                                          str_out[j] = '\0';                                          str_out[j++] = str_in[i++];
333                                          return j;                                          if (str_in[i] == '\0')
334                                            {
335                                                    str_out[j] = '\0';
336                                                    return j;
337                                            }
338                                            c = (c & 0b01111111) << 1;
339                                  }                                  }
340                          }                          }
341    


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

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