| 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; |
| 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) |