/[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.36 by sysadm, Thu Oct 30 07:51:47 2025 UTC Revision 1.40 by sysadm, Fri Oct 31 07:57:02 2025 UTC
# Line 18  Line 18 
18  #include "lml.h"  #include "lml.h"
19  #include "log.h"  #include "log.h"
20  #include "str_process.h"  #include "str_process.h"
21    #include <ctype.h>
22  #include <stdio.h>  #include <stdio.h>
23  #include <string.h>  #include <string.h>
24  #include <sys/param.h>  #include <sys/param.h>
# Line 251  int lml_render(const char *str_in, char Line 252  int lml_render(const char *str_in, char
252                          new_line = 0;                          new_line = 0;
253                  }                  }
254    
255                  if (str_in[i] == '\033' && str_in[i + 1] == '[') // Escape sequence -- copy directly                  if (lml_tag_disabled && new_line)
256                  {                  {
257                          for (k = i + 2; str_in[k] != '\0' && str_in[k] != 'm' && str_in[k] != '\033'; k++)                          new_line = 0;
258                    }
259    
260                    if (str_in[i] == '\033' && str_in[i + 1] == '[') // Escape sequence
261                    {
262                            for (k = i + 2; isdigit(str_in[k]) || str_in[k] == ';' || str_in[k] == '?'; k++)
263                                  ;                                  ;
264    
265                          if (str_in[k] != 'm') // invalid                          if (str_in[k] == 'm') // valid -- copy directly
266                            {
267                                    CHECK_AND_APPEND_OUTPUT(str_out, buf_len, j, str_in + i, k - i + 1, line_width);
268                            }
269                            else if (isalpha(str_in[k]))
270                            {
271                                    // unsupported ANSI CSI command
272                            }
273                            else
274                          {                          {
275                                  k--;                                  k--;
276                          }                          }
277    
                         CHECK_AND_APPEND_OUTPUT(str_out, buf_len, j, str_in + i, k - i + 1, line_width);  
278                          i = k;                          i = k;
279                          continue;                          continue;
280                  }                  }
# Line 272  int lml_render(const char *str_in, char Line 285  int lml_render(const char *str_in, char
285                          {                          {
286                                  tag_end_pos = i - 1;                                  tag_end_pos = i - 1;
287                                  tag_output_len = tag_end_pos - tag_start_pos + 1;                                  tag_output_len = tag_end_pos - tag_start_pos + 1;
288                                  CHECK_AND_APPEND_OUTPUT(str_out, buf_len, j, str_in + tag_start_pos, tag_output_len, line_width);  
289                                    if (line_width + tag_output_len > width)
290                                    {
291                                            CHECK_AND_APPEND_OUTPUT(str_out, buf_len, j, "\n", 1, line_width);
292                                            new_line = 1;
293                                            line_width = 0;
294                                            i--; // redo at current i
295                                    }
296                                    else
297                                    {
298                                            CHECK_AND_APPEND_OUTPUT(str_out, buf_len, j, str_in + tag_start_pos, tag_output_len, line_width);
299                                    }
300                          }                          }
301    
302                          if (fb_quote_level > 0)                          if (fb_quote_level > 0)
# Line 285  int lml_render(const char *str_in, char Line 309  int lml_render(const char *str_in, char
309                                  fb_quote_level = 0;                                  fb_quote_level = 0;
310                          }                          }
311    
312                            if (new_line)
313                            {
314                                    continue;
315                            }
316    
317                          tag_start_pos = -1;                          tag_start_pos = -1;
318                          tag_name_pos = -1;                          tag_name_pos = -1;
319                          new_line = 1;                          new_line = 1;
320                          line_width = 0;                          line_width = -1;
321                  }                  }
322                  else if (str_in[i] == '\r' || str_in[i] == '\7')                  else if (str_in[i] == '\r' || str_in[i] == '\7')
323                  {                  {
# Line 376  int lml_render(const char *str_in, char Line 405  int lml_render(const char *str_in, char
405    
406                          if (!tag_name_found)                          if (!tag_name_found)
407                          {                          {
408                                  tag_output_len = tag_end_pos - tag_start_pos + 1;                                  if (line_width + 1 > width)
409                                  CHECK_AND_APPEND_OUTPUT(str_out, buf_len, j, str_in + tag_start_pos, tag_output_len, line_width);                                  {
410                                            CHECK_AND_APPEND_OUTPUT(str_out, buf_len, j, "\n", 1, line_width);
411                                            new_line = 1;
412                                            line_width = 0;
413                                            i--; // redo at current i
414                                            continue;
415                                    }
416    
417                                    CHECK_AND_APPEND_OUTPUT(str_out, buf_len, j, "[", 1, line_width);
418                                    i = tag_start_pos; // restart from tag_start_pos + 1
419                                    tag_start_pos = -1;
420                                    tag_name_pos = -1;
421                                    continue;
422                          }                          }
423    
424                          tag_start_pos = -1;                          tag_start_pos = -1;
# Line 390  int lml_render(const char *str_in, char Line 431  int lml_render(const char *str_in, char
431                                  CHECK_AND_APPEND_OUTPUT(str_out, buf_len, j, "\n", 1, line_width);                                  CHECK_AND_APPEND_OUTPUT(str_out, buf_len, j, "\n", 1, line_width);
432                                  new_line = 1;                                  new_line = 1;
433                                  line_width = 0;                                  line_width = 0;
434                                  i--; // redo at current $i                                  i--; // redo at current i
435                                  continue;                                  continue;
436                          }                          }
437    


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

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