/[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.8 by sysadm, Thu May 15 14:17:53 2025 UTC
# Line 76  int split_line(const char *buffer, int m Line 76  int split_line(const char *buffer, int m
76          return i;          return i;
77  }  }
78    
79  int split_file_lines(FILE *fin, int max_display_len, long *p_line_offsets, int max_line_cnt)  int split_data_lines(const char *p_buf, int max_display_len, long *p_line_offsets, int max_line_cnt)
80  {  {
         char buffer[LINE_BUFFER_LEN];  
         char *p_buf = buffer;  
81          int line_cnt = 0;          int line_cnt = 0;
82          int len = 0;          int len = 0;
83          int end_of_line = 0;          int end_of_line = 0;
# Line 87  int split_file_lines(FILE *fin, int max_ Line 85  int split_file_lines(FILE *fin, int max_
85    
86          p_line_offsets[line_cnt] = 0L;          p_line_offsets[line_cnt] = 0L;
87    
88          while (fgets(p_buf, (int)sizeof(buffer) - len, fin))          while (1)
89          {          {
90                  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);  
91    
92                          if (len == 0 || !end_of_line) // !end_of_line == EOF                  if (len == 0 || !end_of_line) // !end_of_line == EOF
93                          {                  {
94                                  break;                          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;  
                         }  
   
                         p_line_offsets[line_cnt + 1] = p_line_offsets[line_cnt] + len;  
                         line_cnt++;  
                         p_buf += len;  
95                  }                  }
96    
97                  // Move p_buf[0 .. len - 1] to head of buffer                  // Exceed max_line_cnt
98                  for (int i = 0; i < len; i++)                  if (line_cnt + 1 >= max_line_cnt)
99                  {                  {
100                          buffer[i] = p_buf[i];                          log_error("File line count %d reaches limit\n", line_cnt + 1);
101                            return line_cnt;
102                  }                  }
103                  p_buf = buffer + len;  
104                    p_line_offsets[line_cnt + 1] = p_line_offsets[line_cnt] + len;
105                    line_cnt++;
106                    p_buf += len;
107          }          }
108    
109          if (len > 0 && line_cnt + 1 < max_line_cnt)          if (len > 0 && line_cnt + 1 < max_line_cnt)


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

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