| 9 |
* * |
* * |
| 10 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
| 11 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
| 12 |
* the Free Software Foundation; either version 2 of the License, or * |
* the Free Software Foundation; either version 3 of the License, or * |
| 13 |
* (at your option) any later version. * |
* (at your option) any later version. * |
| 14 |
* * |
* * |
| 15 |
***************************************************************************/ |
***************************************************************************/ |
| 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) |
unsigned int split_line(const char *buffer, int max_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); |
|
int display_len = 0; |
|
| 26 |
unsigned int i = 0; |
unsigned int i = 0; |
| 27 |
*p_eol = 0; |
*p_eol = 0; |
| 28 |
|
*p_display_len = 0; |
| 29 |
|
|
| 30 |
if (len == 0) |
if (len == 0) |
| 31 |
{ |
{ |
| 60 |
|
|
| 61 |
if (c > 127 && c <= 255) // GBK chinese character |
if (c > 127 && c <= 255) // GBK chinese character |
| 62 |
{ |
{ |
| 63 |
if (display_len + 2 > max_len) |
if (*p_display_len + 2 > max_len) |
| 64 |
{ |
{ |
| 65 |
*p_eol = 1; |
*p_eol = 1; |
| 66 |
break; |
break; |
| 67 |
} |
} |
| 68 |
i++; |
i++; |
| 69 |
display_len += 2; |
*p_display_len += 2; |
| 70 |
} |
} |
| 71 |
else |
else |
| 72 |
{ |
{ |
| 73 |
if (display_len >= max_len) |
if (*p_display_len + 1 > max_len) |
| 74 |
{ |
{ |
| 75 |
*p_eol = 1; |
*p_eol = 1; |
| 76 |
break; |
break; |
| 77 |
} |
} |
| 78 |
display_len++; |
(*p_display_len)++; |
| 79 |
} |
} |
| 80 |
} |
} |
| 81 |
|
|
| 89 |
unsigned int line_cnt = 0; |
unsigned int line_cnt = 0; |
| 90 |
unsigned int len = 0; |
unsigned int len = 0; |
| 91 |
int end_of_line = 0; |
int end_of_line = 0; |
| 92 |
|
int display_len = 0; |
| 93 |
|
|
| 94 |
p_line_offsets[line_cnt] = 0L; |
p_line_offsets[line_cnt] = 0L; |
| 95 |
|
|
| 96 |
while (fgets(p_buf, (int)(sizeof(buffer) - len), fin)) |
while (fgets(p_buf, (int)(sizeof(buffer) - len), fin)) |
| 98 |
p_buf = buffer; |
p_buf = buffer; |
| 99 |
while (1) |
while (1) |
| 100 |
{ |
{ |
| 101 |
len = split_line(p_buf, max_len, &end_of_line); |
len = split_line(p_buf, max_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 |
} |
} |