/[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.15 by sysadm, Tue Sep 30 03:02:06 2025 UTC Revision 1.19 by sysadm, Sun Oct 5 05:13:00 2025 UTC
# 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  const static char *LML_tag_def[][4] = {  const static char *lml_tag_def[][4] = {
101          // 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, no_lml_output}
102          {"left", "[", "", "[left]"},          {"left", "[", "", "[left]"},
103          {"right", "]", "", "[right]"},          {"right", "]", "", "[right]"},
# Line 118  const static char *LML_tag_def[][4] = { Line 118  const static char *LML_tag_def[][4] = {
118          {"quote", NULL, (const char *)lml_tag_quote_filter, ""},          {"quote", NULL, (const char *)lml_tag_quote_filter, ""},
119          {"/quote", NULL, (const char *)lml_tag_quote_filter, ""},          {"/quote", NULL, (const char *)lml_tag_quote_filter, ""},
120          {"url", "", "", ""},          {"url", "", "", ""},
121          {"/url", "(链接: %s)", NULL, "(链接: %s)"},          {"/url", "(链接: %s)", NULL, ""},
122          {"link", "", ""},          {"link", "", ""},
123          {"/link", "(链接: %s)", NULL, "(链接: %s)"},          {"/link", "(链接: %s)", NULL, ""},
124          {"email", "", ""},          {"email", "", ""},
125          {"/email", "(Email: %s)", NULL, "(Email: %s)"},          {"/email", "(Email: %s)", NULL, ""},
126          {"user", "", ""},          {"user", "", ""},
127          {"/user", "(用户: %s)", NULL, "(用户: %s)"},          {"/user", "(用户: %s)", NULL, ""},
128          {"article", "", ""},          {"article", "", ""},
129          {"/article", "(文章: %s)", NULL, "(文章: %s)"},          {"/article", "(文章: %s)", NULL, ""},
130          {"image", "(图片: %s)", "", "(图片: %s)"},          {"image", "(图片: %s)", "", "%s"},
131          {"flash", "(Flash: %s)", "", "(Flash: %s)"},          {"flash", "(Flash: %s)", "", ""},
132          {"bwf", "\033[1;31m****\033[m", "", "****"},          {"bwf", "\033[1;31m****\033[m", "", "****"},
133  };  };
134    
135  #define LML_TAG_COUNT 31  #define LML_TAG_COUNT 31
136    
137  static int LML_tag_name_len[LML_TAG_COUNT];  static int lml_tag_name_len[LML_TAG_COUNT];
138  static int LML_init = 0;  static int lml_ready = 0;
139    
140  inline static void lml_init(void)  inline static void lml_init(void)
141  {  {
142          int i;          int i;
143    
144          if (!LML_init)          if (!lml_ready)
145          {          {
146                  for (i = 0; i < LML_TAG_COUNT; i++)                  for (i = 0; i < LML_TAG_COUNT; i++)
147                  {                  {
148                          LML_tag_name_len[i] = (int)strlen(LML_tag_def[i][0]);                          lml_tag_name_len[i] = (int)strlen(lml_tag_def[i][0]);
149                  }                  }
150    
151                  LML_init = 1;                  lml_ready = 1;
152          }          }
153  }  }
154    
155  int lml_plain(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 lml_tag)
156  {  {
157          char c;          char c;
158          char tag_param_buf[LML_TAG_PARAM_BUF_LEN];          char tag_param_buf[LML_TAG_PARAM_BUF_LEN];
# Line 269  int lml_plain(const char *str_in, char * Line 269  int lml_plain(const char *str_in, char *
269    
270                                  for (k = 0; k < LML_TAG_COUNT; k++)                                  for (k = 0; k < LML_TAG_COUNT; k++)
271                                  {                                  {
272                                          if (strncasecmp(LML_tag_def[k][0], str_in + tag_start_pos, (size_t)LML_tag_name_len[k]) == 0)                                          if (strncasecmp(lml_tag_def[k][0], str_in + tag_start_pos, (size_t)lml_tag_name_len[k]) == 0)
273                                          {                                          {
274                                                  tag_param_pos = -1;                                                  tag_param_pos = -1;
275                                                  switch (str_in[tag_start_pos + LML_tag_name_len[k]])                                                  switch (str_in[tag_start_pos + lml_tag_name_len[k]])
276                                                  {                                                  {
277                                                  case ' ':                                                  case ' ':
278                                                          tag_param_pos = tag_start_pos + LML_tag_name_len[k] + 1;                                                          tag_param_pos = tag_start_pos + lml_tag_name_len[k] + 1;
279                                                          while (str_in[tag_param_pos] == ' ')                                                          while (str_in[tag_param_pos] == ' ')
280                                                          {                                                          {
281                                                                  tag_param_pos++;                                                                  tag_param_pos++;
# Line 283  int lml_plain(const char *str_in, char * Line 283  int lml_plain(const char *str_in, char *
283                                                          strncpy(tag_param_buf, str_in + tag_param_pos, (size_t)MIN(tag_end_pos - tag_param_pos, LML_TAG_PARAM_BUF_LEN));                                                          strncpy(tag_param_buf, str_in + tag_param_pos, (size_t)MIN(tag_end_pos - tag_param_pos, LML_TAG_PARAM_BUF_LEN));
284                                                          tag_param_buf[MIN(tag_end_pos - tag_param_pos, LML_TAG_PARAM_BUF_LEN)] = '\0';                                                          tag_param_buf[MIN(tag_end_pos - tag_param_pos, LML_TAG_PARAM_BUF_LEN)] = '\0';
285                                                  case ']':                                                  case ']':
286                                                          if (tag_param_pos == -1 && LML_tag_def[k][1] != NULL && LML_tag_def[k][2] != NULL) // Apply default param if not defined                                                          if (tag_param_pos == -1 && lml_tag_def[k][1] != NULL && lml_tag_def[k][2] != NULL) // Apply default param if not defined
287                                                          {                                                          {
288                                                                  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);
289                                                                  tag_param_buf[LML_TAG_PARAM_BUF_LEN - 1] = '\0';                                                                  tag_param_buf[LML_TAG_PARAM_BUF_LEN - 1] = '\0';
290                                                          }                                                          }
291                                                          if (lml_tag)                                                          if (lml_tag)
292                                                          {                                                          {
293                                                                  if (LML_tag_def[k][1] != NULL)                                                                  if (lml_tag_def[k][1] != NULL)
294                                                                  {                                                                  {
295                                                                          tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, LML_tag_def[k][1], tag_param_buf);                                                                          tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, lml_tag_def[k][1], tag_param_buf);
296                                                                  }                                                                  }
297                                                                  else                                                                  else
298                                                                  {                                                                  {
299                                                                          tag_output_len = ((lml_tag_filter_cb)LML_tag_def[k][2])(                                                                          tag_output_len = ((lml_tag_filter_cb)lml_tag_def[k][2])(
300                                                                                  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);
301                                                                  }                                                                  }
302                                                          }                                                          }
303                                                          else                                                          else
304                                                          {                                                          {
305                                                                  if (LML_tag_def[k][3] != NULL)                                                                  if (lml_tag_def[k][3] != NULL)
306                                                                  {                                                                  {
307                                                                          tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, LML_tag_def[k][3], tag_param_buf);                                                                          tag_output_len = snprintf(tag_output_buf, LML_TAG_OUTPUT_BUF_LEN, lml_tag_def[k][3], tag_param_buf);
308                                                                  }                                                                  }
309                                                                  else                                                                  else
310                                                                  {                                                                  {


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

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