/[LeafOK_CVS]/lbbs/src/str_process.c
ViewVC logotype

Contents of /lbbs/src/str_process.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.11 - (show annotations)
Mon Jun 2 15:01:55 2025 UTC (9 months, 2 weeks ago) by sysadm
Branch: MAIN
Changes since 1.10: +2 -1 lines
Content type: text/x-csrc
Add LML render

1 /***************************************************************************
2 str_process.c - description
3 -------------------
4 Copyright : (C) 2004-2025 by Leaflet
5 Email : leaflet@leafok.com
6 ***************************************************************************/
7
8 /***************************************************************************
9 * *
10 * 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 *
12 * the Free Software Foundation; either version 3 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
17 #include "str_process.h"
18 #include "common.h"
19 #include "log.h"
20 #include <stdio.h>
21 #include <string.h>
22
23 int split_line(const char *buffer, int max_display_len, int *p_eol, int *p_display_len)
24 {
25 int i;
26 *p_eol = 0;
27 *p_display_len = 0;
28 char c;
29
30 for (i = 0; buffer[i] != '\0'; i++)
31 {
32 c = buffer[i];
33
34 if (c == '\r' || c == '\7') // skip
35 {
36 continue;
37 }
38
39 if (c == '\n')
40 {
41 i++;
42 *p_eol = 1;
43 break;
44 }
45
46 if (c == '\033' && buffer[i + 1] == '[') // Skip control sequence
47 {
48 i += 2;
49 while (buffer[i] != '\0' && buffer[i] != 'm')
50 {
51 i++;
52 }
53 continue;
54 }
55
56 if (c < 0 || c > 127) // GBK chinese character
57 {
58 if (*p_display_len + 2 > max_display_len)
59 {
60 break;
61 }
62 i++;
63 (*p_display_len) += 2;
64 }
65 else
66 {
67 if (*p_display_len + 1 > max_display_len)
68 {
69 break;
70 }
71 (*p_display_len)++;
72 }
73 }
74
75 return i;
76 }
77
78 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;
81 int len = 0;
82 int end_of_line = 0;
83 int display_len = 0;
84
85 p_line_offsets[line_cnt] = 0L;
86
87 while (1)
88 {
89 len = split_line(p_buf, max_display_len, &end_of_line, &display_len);
90
91 if (len == 0) // EOF
92 {
93 break;
94 }
95
96 // Exceed max_line_cnt
97 if (line_cnt + 1 >= line_offsets_count)
98 {
99 log_error("Line count %d reaches limit %d\n", line_cnt + 1, line_offsets_count);
100 return line_cnt;
101 }
102
103 p_line_offsets[line_cnt + 1] = p_line_offsets[line_cnt] + len;
104 line_cnt++;
105 p_buf += len;
106 }
107
108 return line_cnt;
109 }

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