| 20 |
#include <stdio.h> |
#include <stdio.h> |
| 21 |
#include <string.h> |
#include <string.h> |
| 22 |
|
|
| 23 |
unsigned int split_line(const char *buffer, int max_len, int *p_eol, int *p_display_len) |
unsigned int split_line(const char *buffer, int max_display_len, int *p_eol, int *p_display_len) |
| 24 |
{ |
{ |
| 25 |
size_t len = strnlen(buffer, LINE_BUFFER_LEN); |
size_t len = strnlen(buffer, LINE_BUFFER_LEN); |
| 26 |
unsigned int i = 0; |
unsigned int i = 0; |
| 60 |
|
|
| 61 |
if (c > 127 && c <= 255) // GBK chinese character |
if (c > 127 && c <= 255) // GBK chinese character |
| 62 |
{ |
{ |
| 63 |
if (*p_display_len + 2 > max_len) |
if (*p_display_len + 2 > max_display_len) |
| 64 |
{ |
{ |
| 65 |
*p_eol = 1; |
*p_eol = 1; |
| 66 |
break; |
break; |
| 70 |
} |
} |
| 71 |
else |
else |
| 72 |
{ |
{ |
| 73 |
if (*p_display_len + 1 > max_len) |
if (*p_display_len + 1 > max_display_len) |
| 74 |
{ |
{ |
| 75 |
*p_eol = 1; |
*p_eol = 1; |
| 76 |
break; |
break; |
| 82 |
return i; |
return i; |
| 83 |
} |
} |
| 84 |
|
|
| 85 |
unsigned int split_file_lines(FILE *fin, int max_len, long *p_line_offsets, int max_line_cnt) |
unsigned int split_file_lines(FILE *fin, int max_display_len, long *p_line_offsets, int max_line_cnt) |
| 86 |
{ |
{ |
| 87 |
char buffer[LINE_BUFFER_LEN]; |
char buffer[LINE_BUFFER_LEN]; |
| 88 |
char *p_buf = buffer; |
char *p_buf = buffer; |
| 98 |
p_buf = buffer; |
p_buf = buffer; |
| 99 |
while (1) |
while (1) |
| 100 |
{ |
{ |
| 101 |
len = split_line(p_buf, max_len, &end_of_line, &display_len); |
len = split_line(p_buf, max_display_len, &end_of_line, &display_len); |
| 102 |
|
|
| 103 |
if (len == 0 || !end_of_line) |
if (len == 0 || !end_of_line) // !end_of_line == EOF |
| 104 |
{ |
{ |
| 105 |
break; |
break; |
| 106 |
} |
} |