blob: eabc2d3375bd7338fba0b4fa6f91b90c7f69377b (
plain)
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
|
#include "config.h"
#include "rematchmsg.h"
#include "message.h"
#include <ctype.h>
ReMatchMsg::ReMatchMsg(Message *m, int flag, int flag2)
: msg(m), header_only(flag), mergelines(flag2), eof(0),
lastc(0), end_headers(0)
{
start=msg->tell();
}
ReMatchMsg::~ReMatchMsg()
{
}
int ReMatchMsg::CurrentChar()
{
if (eof) return (-1);
return (msg->peek());
}
int ReMatchMsg::NextChar()
{
if (eof) return (-1);
int c;
for (;;)
{
c=msg->get_c();
if (c < 0)
{
eof=1;
if (lastc != '\n')
{
c='\n';
lastc='\n';
}
return (c);
}
if (c == '\r') continue; // Eat carriage returns.
if (c == '\n')
{
int nextc=msg->peek();
if (nextc == '\r' || nextc == '\n')
{
if (mergelines)
end_headers=msg->tell();
mergelines=0;
if (header_only) eof=1;
return (c);
}
if (mergelines && isspace(nextc)) continue;
}
lastc=c;
return (c);
}
}
off_t ReMatchMsg::GetCurrentPos()
{
return (msg->tell());
}
void ReMatchMsg::SetCurrentPos(off_t p)
{
if (p < msg->tell()) eof=0;
if ( p < start || p == 0)
{
msg->seek(start);
lastc=0;
}
else
{
msg->seek(p-1);
lastc=msg->get_c();
}
if (p < end_headers) mergelines=1;
if (!mergelines && header_only) eof=1;
}
|