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

Diff of /lbbs/src/str_process.c

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

Revision 1.7 by sysadm, Thu May 15 13:02:33 2025 UTC Revision 1.11 by sysadm, Mon Jun 2 15:01:55 2025 UTC
# Line 25  int split_line(const char *buffer, int m Line 25  int split_line(const char *buffer, int m
25          int i;          int i;
26          *p_eol = 0;          *p_eol = 0;
27          *p_display_len = 0;          *p_display_len = 0;
28            char c;
29    
30          for (i = 0; buffer[i] != '\0'; i++)          for (i = 0; buffer[i] != '\0'; i++)
31          {          {
32                  char c = buffer[i];                  c = buffer[i];
33    
34                  if (c == '\r' || c == '\7') // skip                  if (c == '\r' || c == '\7') // skip
35                  {                  {
# Line 52  int split_line(const char *buffer, int m Line 53  int split_line(const char *buffer, int m
53                          continue;                          continue;
54                  }                  }
55    
56                  if (c > 127 && c <= 255) // GBK chinese character                  if (c < 0 || c > 127) // GBK chinese character
57                  {                  {
58                          if (*p_display_len + 2 > max_display_len)                          if (*p_display_len + 2 > max_display_len)
59                          {                          {
                                 *p_eol = 1;  
60                                  break;                                  break;
61                          }                          }
62                          i++;                          i++;
63                          *p_display_len += 2;                          (*p_display_len) += 2;
64                  }                  }
65                  else                  else
66                  {                  {
67                          if (*p_display_len + 1 > max_display_len)                          if (*p_display_len + 1 > max_display_len)
68                          {                          {
                                 *p_eol = 1;  
69                                  break;                                  break;
70                          }                          }
71                          (*p_display_len)++;                          (*p_display_len)++;
# Line 76  int split_line(const char *buffer, int m Line 75  int split_line(const char *buffer, int m
75          return i;          return i;
76  }  }
77    
78  int split_file_lines(FILE *fin, int max_display_len, long *p_line_offsets, int max_line_cnt)  long split_data_lines(const char *p_buf, int max_display_len, long *p_line_offsets, long line_offsets_count)
79  {  {
         char buffer[LINE_BUFFER_LEN];  
         char *p_buf = buffer;  
80          int line_cnt = 0;          int line_cnt = 0;
81          int len = 0;          int len = 0;
82          int end_of_line = 0;          int end_of_line = 0;
# Line 87  int split_file_lines(FILE *fin, int max_ Line 84  int split_file_lines(FILE *fin, int max_
84    
85          p_line_offsets[line_cnt] = 0L;          p_line_offsets[line_cnt] = 0L;
86    
87          while (fgets(p_buf, (int)sizeof(buffer) - len, fin))          while (1)
88          {          {
89                  p_buf = buffer;                  len = split_line(p_buf, max_display_len, &end_of_line, &display_len);
                 while (1)  
                 {  
                         len = split_line(p_buf, max_display_len, &end_of_line, &display_len);  
   
                         if (len == 0 || !end_of_line) // !end_of_line == EOF  
                         {  
                                 break;  
                         }  
   
                         // Exceed max_line_cnt  
                         if (line_cnt + 1 >= max_line_cnt)  
                         {  
                                 log_error("File line count %d reaches limit\n", line_cnt + 1);  
                                 return line_cnt;  
                         }  
90    
91                          p_line_offsets[line_cnt + 1] = p_line_offsets[line_cnt] + len;                  if (len == 0) // EOF
92                          line_cnt++;                  {
93                          p_buf += len;                          break;
94                  }                  }
95    
96                  // Move p_buf[0 .. len - 1] to head of buffer                  // Exceed max_line_cnt
97                  for (int i = 0; i < len; i++)                  if (line_cnt + 1 >= line_offsets_count)
98                  {                  {
99                          buffer[i] = p_buf[i];                          log_error("Line count %d reaches limit %d\n", line_cnt + 1, line_offsets_count);
100                            return line_cnt;
101                  }                  }
                 p_buf = buffer + len;  
         }  
102    
         if (len > 0 && line_cnt + 1 < max_line_cnt)  
         {  
103                  p_line_offsets[line_cnt + 1] = p_line_offsets[line_cnt] + len;                  p_line_offsets[line_cnt + 1] = p_line_offsets[line_cnt] + len;
104                  line_cnt++;                  line_cnt++;
105                    p_buf += len;
106          }          }
107    
108          return line_cnt;          return line_cnt;


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

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