Richard Boegli's CnC_Generals_Zero_Hour Fork
WIP
This is documentation of Richard Boegil's Zero Hour Fork
Loading...
Searching...
No Matches
streamer.cpp
Go to the documentation of this file.
1
/*
2
** Command & Conquer Generals Zero Hour(tm)
3
** Copyright 2025 Electronic Arts Inc.
4
**
5
** This program is free software: you can redistribute it and/or modify
6
** it under the terms of the GNU General Public License as published by
7
** the Free Software Foundation, either version 3 of the License, or
8
** (at your option) any later version.
9
**
10
** This program is distributed in the hope that it will be useful,
11
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
** GNU General Public License for more details.
14
**
15
** You should have received a copy of the GNU General Public License
16
** along with this program. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
20
#include "
streamer.h
"
21
#ifdef _WIN32
22
#include <windows.h>
23
#endif
24
25
26
Streamer::Streamer
() : streambuf()
27
{
28
int
state=unbuffered();
29
unbuffered(0);
// 0 = buffered, 1 = unbuffered
30
}
31
32
Streamer::~Streamer
()
33
{
35
//sync();
37
delete
[](base());
38
}
39
40
int
Streamer::setOutputDevice
(
OutputDevice
*device)
41
{
42
Output_Device
=device;
43
return
(0);
44
}
45
46
47
// put n chars from string into buffer
48
int
Streamer::xsputn
(
const
char
* buf,
int
size)
//implementation of sputn
49
{
50
if
(size<=0)
// Nothing to do
51
return
(0);
52
53
const
unsigned
char
*ptr=(
const
unsigned
char
*)buf;
54
for
(
int
i=0; i<size; i++, ptr++)
55
{
56
if
(*ptr==
'\n'
)
57
{
58
if
(
overflow
(*ptr)==EOF)
59
return
(i);
60
}
61
else
if
(sputc(*ptr)==EOF)
62
return
(i);
63
}
64
return
(size);
65
}
66
67
// Flush the buffer and make more room if needed
68
int
Streamer::overflow
(
int
c)
69
{
70
if
(c==EOF)
71
return
(
sync
());
72
if
((pbase()==0) && (
doallocate
()==0))
73
return
(EOF);
74
if
((pptr() >= epptr()) && (
sync
()==EOF))
75
return
(EOF);
76
else
{
77
sputc(c);
78
if
((unbuffered() && c==
'\n'
|| pptr() >= epptr())
79
&&
sync
()==EOF) {
80
return
(EOF);
81
}
82
return
(c);
83
}
84
}
85
86
// This is a write only stream, this should never happen
87
int
Streamer::underflow
(
void
)
88
{
89
return
(EOF);
90
}
91
92
int
Streamer::doallocate
()
93
{
94
if
(base()==
NULL
)
95
{
96
char
*buf=
new
char
[(2*
STREAMER_BUFSIZ
)];
// deleted by destructor
97
memset(buf,0,2*
STREAMER_BUFSIZ
);
98
99
// Buffer
100
setb(
101
buf,
// base pointer
102
buf+
STREAMER_BUFSIZ
,
// ebuf pointer (end of buffer);
103
0);
// 0 = manual deletion of buff
104
105
// Get area
106
setg(
107
buf,
// eback
108
buf,
// gptr
109
buf);
// egptr
110
111
buf+=
STREAMER_BUFSIZ
;
112
// Put area
113
setp(buf,buf+
STREAMER_BUFSIZ
);
114
return
(1);
115
}
116
else
117
return
(0);
118
}
119
120
121
int
Streamer::sync
()
122
{
123
if
(pptr()<=pbase()) {
124
return
(0);
125
}
126
127
int
wlen=pptr()-pbase();
128
129
if
(
Output_Device
)
130
{
131
Output_Device
->print(pbase(),wlen);
132
}
133
134
if
(unbuffered()) {
135
setp(pbase(),pbase());
136
}
137
else
{
138
setp(pbase(),pbase()+
STREAMER_BUFSIZ
);
139
}
140
return
(0);
141
}
NULL
#define NULL
Definition
BaseType.h:92
OutputDevice
Definition
odevice.h:25
Streamer::xsputn
int xsputn(const char *s, int n)
Definition
streamer.cpp:46
Streamer::Output_Device
OutputDevice * Output_Device
Definition
streamer.h:57
Streamer::doallocate
int doallocate()
Definition
streamer.cpp:92
Streamer::Streamer
Streamer()
Definition
streamer.cpp:26
Streamer::sync
int sync()
Definition
streamer.cpp:122
Streamer::underflow
int underflow(void)
Definition
streamer.cpp:87
Streamer::~Streamer
virtual ~Streamer()
Definition
streamer.cpp:32
Streamer::setOutputDevice
int setOutputDevice(OutputDevice *output_device)
Definition
streamer.cpp:38
Streamer::overflow
int overflow(int=EOF)
Definition
streamer.cpp:67
streamer.h
STREAMER_BUFSIZ
#define STREAMER_BUFSIZ
Definition
streamer.h:40
Code
Tools
mangler
wlib
streamer.cpp
Generated by
1.13.2