| 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 |
{ |
{ |
| 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)++; |
| 75 |
return i; |
return i; |
| 76 |
} |
} |
| 77 |
|
|
| 78 |
int split_data_lines(const char *p_buf, 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 |
{ |
{ |
| 80 |
int line_cnt = 0; |
int line_cnt = 0; |
| 81 |
int len = 0; |
int len = 0; |
| 88 |
{ |
{ |
| 89 |
len = split_line(p_buf, max_display_len, &end_of_line, &display_len); |
len = split_line(p_buf, max_display_len, &end_of_line, &display_len); |
| 90 |
|
|
| 91 |
if (len == 0 || !end_of_line) // !end_of_line == EOF |
if (len == 0) // EOF |
| 92 |
{ |
{ |
| 93 |
break; |
break; |
| 94 |
} |
} |
| 95 |
|
|
| 96 |
// Exceed max_line_cnt |
// Exceed max_line_cnt |
| 97 |
if (line_cnt + 1 >= max_line_cnt) |
if (line_cnt + 1 >= line_offsets_count) |
| 98 |
{ |
{ |
| 99 |
log_error("File line count %d reaches limit\n", line_cnt + 1); |
log_error("Line count %d reaches limit %d\n", line_cnt + 1, line_offsets_count); |
| 100 |
return line_cnt; |
return line_cnt; |
| 101 |
} |
} |
| 102 |
|
|
| 105 |
p_buf += len; |
p_buf += len; |
| 106 |
} |
} |
| 107 |
|
|
|
if (len > 0 && line_cnt + 1 < max_line_cnt) |
|
|
{ |
|
|
p_line_offsets[line_cnt + 1] = p_line_offsets[line_cnt] + len; |
|
|
line_cnt++; |
|
|
} |
|
|
|
|
| 108 |
return line_cnt; |
return line_cnt; |
| 109 |
} |
} |