1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
#include "buf_misc.h"
/*
int bbuf_line_new(bbuf_line *buf, int size)
{
bbuf *newbuf=NULL;
bbuf_line *bline=NULL;
newbuf = bbuf_new(size);
if (newbuf == NULL)
{
return -1;
}
bline = malloc(sizeof(bbuf_line));
if (bline == NULL)
{
return -1;
}
memset(bline, 0, sizeof(bbuf_line));
bline->buf = newbuf;
buf = bline;
return 0;
}
int bbuf_line_pattern(bbuf_line *buf, char *patt, int size)
{
return -1;
}
int bbuf_line_add(bbuf_line *buf_line, bbuf *new_data)
{
return -1;
}
int bbuf_line_get_line(bbuf_line *buf_line, bbuf *line)
{
return -1;
}
int bbuf_line_free(bbuf_line *buf)
{
return -1;
}
*/
BufLine::BufLine(int size)
{
buf = new Buf(size);
sep=0x0;
memset(pattern,0,BUF_PATTER_SIZE);
}
BufLine::~BufLine()
{
delete buf;
}
int BufLine::setpattern(char *pattern)
{
return -1;
}
int BufLine::setseperator(char s)
{
this->sep = s;
return 0;
}
int BufLine::add(char *string, int size)
{
return -1;
}
int BufLine::add(Buf *newdata)
{
buf->concat(newdata);
return 0;
}
int BufLine::pop_line(char **val, int *size)
{
int idx;
if (1 == buf->findc('\n',&idx))
{
buf->popsubstring(idx,val,size);
buf->shiftleft(1);//remove seperator character
return 0;
}
return -1;
}
int BufLine::print()
{
buf->print();
return -1;
}
/*
RETURN_IF_PATTERN_FOUND(*detect_pattern)(char *INPUT_BUFFER, int INPUT_SIZE)
*/
int BufLine::pop_pattern(int (*detect_pattern)(char *, int, int*), char **val, int *size)
{
int detected=0;
char *buf;
int buf_size = 0;
int data_size = 0;
this->buf->get_ptr(&buf, &buf_size);
if ((detected = detect_pattern(buf, buf_size, &data_size)) != 1)
{
return -1;
}
this->buf->popsubstring(data_size, val, size);
return 0;
}
/*
int bbuf_circ_new(bbuf_circ **circ, int size)
{
bbuf *buf = NULL;
bbuf_circ *cbuf = NULL;
buf = bbuf_new(size);
if (buf == NULL)
{
return -1;
}
cbuf = malloc(sizeof(bbuf_circ));
if (cbuf == NULL)
{
return -1;
}
cbuf->buf = buf;
cbuf->head = 0;
cbuf->tail = 0;
*circ = cbuf;
return 0;
}
int bbuf_circ_add(bbuf_circ *circ, bbuf *new_data)
{
int i=0;
int cnt=0;
if (circ == NULL)
{
return -1;
}
if (new_data == NULL)
{
return -1;
}
if (bbuf_size(new_data) <= 0)
{
return -1;
}
for (i=0;i<bbuf_size(new_data);i++)
{
if (0 == bbuf_circ_put(circ, new_data->buf[i]))
{
cnt++;
}
}
return cnt;
}
int bbuf_circ_get_line(bbuf_circ *circ, bbuf *line)
{
}
int bbuf_circ_reset(bbuf_circ *circ)
{
if (circ == NULL)
{
return -1;
}
circ->head = 0;
circ->tail = 0;
return 0;
}
int bbuf_circ_get(bbuf_circ *circ, char *data)
{
if (circ == NULL)
{
return -1;
}
if (data == NULL)
{
return -1;
}
if (0 == bbuf_circ_empty(circ))
{
*data = circ->buf->buf[circ->tail];
circ->tail = (circ->tail+1)%bbuf_size(circ->buf);
return 0;
}
return -1;
}
int bbuf_circ_put(bbuf_circ *circ, char data)
{
if (NULL == circ)
{
return -1;
}
circ->buf->buf[circ->head] = data;
circ->head = (circ->head+1)%bbuf_size(circ->buf);
if (circ->head == circ->tail)
{
circ->tail = (circ->tail+1)%bbuf_size(circ->buf);
}
return 0;
}
int bbuf_circ_empty(bbuf_circ *circ)
{
if (circ == NULL)
{
return -1;
}
return (circ->tail == circ->head);
}
int bbuf_circ_full(bbuf_circ *circ)
{
//one lost byte
return ((circ->head+1)%bbuf_size(circ->buf) == (circ->tail));
}
int bbuf_circ_free(bbuf_circ *circ)
{
bbuf_free(circ->buf);
circ->buf = NULL;
free(circ);
circ = NULL;
}
*/
|